Welcome to this project! This document outlines how to contribute high-quality backend code using Clean Architecture, TDD, and production-grade engineering standards, adapted for Python or cross-language services.
We use Clean Architecture:
/delivery → Entry points: FastAPI views, Flask routes, etc.
/usecase → Business logic, application services
/repository → Persistence adapters: ORM/DB, cache, external APIs
/domain → Core entities, value objects, domain services
- delivery → invokes usecase → which uses repository
- Each layer is decoupled via interfaces/protocols or DI
- No cross-layer logic leakage
- Only implement what The Architect or Project Owner defines
- Follow specs exactly: routes, fields, validation, auth, etc.
- Document assumptions in PRs if unclear
- Format Python code with
black,ruff,isort - Use Conventional Commits e.g.
feat(api): add /refill endpointfix(auth): correct token expiry logic
- Every usecase, delivery, and utility module must be tested
- Use
pytestwithunittest.mockorpytest-mock - Cover:
- Happy path
- Validation error
- Unauthorized/missing token
- Edge cases
- Use
httpx.AsyncClientwithFastAPIorFlasktest clients - Include curl or Postman collections for manual QA
- Example test command:
pytest -v --cov=./ --cov-report=term-missing
- Place test files in same structure under
/tests//tests /delivery /usecase /repository
- Every protected endpoint must use JWT auth
- Required claims:
user_id,email,role - Middleware must inject user info into
request.stateorg - Authorization checks must enforce role access strictly
- Use GitHub Actions for:
- Linting (
ruff) - Testing (
pytest) - Type checks (
mypy) - Security checks (
bandit,safety)
- Linting (
Example test.yaml job:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11
- run: pip install -r requirements-dev.txt
- run: pytest --cov- Each route must have example request/response (OpenAPI or Markdown)
- Inline docstrings for all usecases, models, and public functions
- Shared contracts defined via
pydantic.BaseModel(for validation & docs)
- Refactor using patterns from Refactoring (Fowler), Clean Code (Martin)
- Break large functions into smaller cohesive units
- Avoid premature abstraction but ensure DRY and SRP
By following this guide, you’ll ensure that all contributions are testable, maintainable, and production-ready across languages and services.