Style Guides
Backend
These are style guides for both Python code and the database schema.
Project, Folder & File Names
Rules
- lowercase
- snake_case
- nouns for folders
- verbs only when it’s an action module
- no hyphens
Examples
app/
├── main.py
├── api/
│ ├── v1/
│ │ ├── routes/
│ │ │ ├── users.py
│ │ │ ├── recipes.py
│ │ │ └── auth.py
│ │ ├── dependencies.py
│ │ └── schemas/
│ │ ├── user.py
│ │ └── recipe.py
├── core/
│ ├── config.py
│ ├── security.py
│ └── logging.py
├── models/
│ ├── user.py
│ ├── recipe.py
│ └── ingredient.py
├── services/
│ ├── user_service.py
│ └── recipe_service.py
├── db/
│ ├── base.py
│ ├── session.py
│ └── migrations/
└── tests/
Avoid
Python Class Names
Use PascalCase
- Pydantic models
- SQLAlchemy models
- Service classes
- Exceptions
Avoid
Function & Method Names
Use snake_case
- Verbs for actions
- Clear, explicit names
FastAPI path operations
Variable Names
Rules
snake_case- Descriptive
- Avoid abbreviations unless common (
id,db,api)
Avoid
Constants
Use UPPER_SNAKE_CASE
Database Table Names
-
Use snake_case
-
Use plural nouns
-
Be consistent
This matches:
- PostgreSQL conventions
- SQLAlchemy defaults
- REST naming
Avoid
Database Column Names
Rules
snake_case- Descriptive
- No table name prefix
- Avoid reserved words
Avoid
SQLAlchemy Model Naming (Best Practice)
Class ↔ Table mapping
class Recipe(Base):
__tablename__ = "recipes"
id = Column(Integer, primary_key=True)
user_id = Column(ForeignKey("users.id"))
title = Column(String)
Pydantic Schema Naming
Suffix-based clarity
API Route Naming
REST-style, plural nouns
GET /api/v1/recipes
POST /api/v1/recipes
GET /api/v1/recipes/{id}
PUT /api/v1/recipes/{id}
DELETE /api/v1/recipes/{id}
Avoid
Test File Naming (pytest)
Test functions:
Type Hints & Docstrings (Strongly Recommended)
def create_recipe(
db: Session,
user_id: int,
data: RecipeCreate,
) -> Recipe:
"""Create a new recipe for a user."""
Linters & Formatters
Required
Recommended config
API response messages
Messages that contain string variable values should be single-quoted, otherwise if numeric use no quotes at all.
String response:
Numeric response:
Docstrings
We use the NumPy style for writing docstrigns
Golden Rule (Very Important)
Python names → snake_case > Classes → PascalCase > DB tables → plural snake_case > DB columns → snake_case