Style Guides¶
Contributing Code¶
Before committing or pushing changes, we aim to follow a set of standards to keep commits and changes easy to understand and meaningful. These standards are used to enhance communication between fellow contributors who write and read code for the project. Fewer chances of overthinking communication and a higher chance of shipping high quality contributions.
Commit Guidelines¶
We follow and extend this framework, we recommend to at least take a glance or skim through the specification. Basically, we make commits in this format: {emoji} {type} {(scope)<optional>}: {description}.
| Emoji | Type | What it covers |
|---|---|---|
| π¦ | new |
Adding new features, files, or capabilities |
| π§ | update |
Changing existing code, refactoring, improvements, bug fixes |
| ποΈ | remove |
Removing code, files, features, or dependencies |
| π | security |
Security fixes, patches, vulnerability resolutions |
| βοΈ | setup |
Project configs, CI/CD, tooling, build systems |
| β | chore |
Maintenance tasks, dependency updates, housekeeping |
| π§ͺ | test |
Adding, updating, or fixing tests |
| π | docs |
Documentation changes and updates |
| π·οΈ | release |
Version releases and release preparation |
Examples
Conventional Comments¶
When communicating with fellow contributors, it is recommended to follow this format or communicate so in a similar format that is practical and direct to the point.
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