Skip to content

Latest commit

 

History

History
229 lines (189 loc) · 13.6 KB

features.md

File metadata and controls

229 lines (189 loc) · 13.6 KB

🧩 Features & Integrations

Full reference for what's built into this project: what each feature does, which module implements it, and how to configure it. README.md only lists the headline items — this is the complete picture.

📋 Quick Reference

  • 🚀 Core — FastAPI, Postgres, Alembic, logging, docs (always included)
  • 🔥 Firebase — Authentication, users, push notifications

Optional services are chosen when the project is generated: Copier's services question offers minimal (the base, pre-selected in an interactive run), custom (pick services one by one), or full (everything, which copier copy --defaults selects). A chosen service's packages are regular dependencies, so uv sync installs everything the project uses.

Two more parts are optional the same way, and are included by full / --defaults:

  • the GitHub extras (CodeQL, Dependabot, issue and pull request templates, CODEOWNERS, SECURITY.md)
  • the extra documentation (guides, architecture, API reference, runbooks, strategy)

🚀 Core

Always included.

  • FastAPI — async web framework. Each API version is its own mounted app with its own interactive docs: app/api/v1/ at /v1 (/v1/docs).
  • Second API version — an empty scaffold in app/api/v2/, mounted at /v2 with its own docs (/v2/docs).
  • Async PostgreSQL — SQLAlchemy 2.0 async engine (asyncpg) for the app, configured in app/core/db.py from settings.db_url.
  • Sync engine for Celery — psycopg engine and session_factory in app/core/db_sync.py, from settings.db_url_sync.
  • Database migrations — Alembic (app/alembic/), run with alembic upgrade head directly.
  • Migration helper scripts — ./scripts/alembic.sh (Linux/macOS) and .\scripts\alembic.bat (Windows).
  • Clean/layered architecture — repository pattern (app/repos/) + dependency injection, with module boundaries enforced by tach (see tach.toml): core → models/schemas → repos → services → api/middleware.
  • Structured logging — Loguru-based (app/core/logger.py): console and rotating file output, request and process IDs.
  • Automatic API documentation — Swagger UI and ReDoc, generated per API version.

🔐 Authentication

  • JWT-based auth — access + refresh tokens, implemented in app/services/auth_service.py. Password hashing via Argon2 (pwdlib). Guide: integrations/auth.md.
  • Logout — logout returns revoked: false and the access token stays valid until it expires (no token blacklist).
  • Protected routes — dependency-injected via app/api/v1/deps/.

🔓 No authentication

This project was generated without the authentication service: it has no User model, no login and no protected routes, so every endpoint is public. Add your own access checks before exposing data that is not public.

📦 Example domain: Items

A small, complete CRUD slice that shows how the layers fit together. Copy it for your own domain, or delete it.

  • Model: app/models/item.py (Item: name, unique; description; is_active), created by the first Alembic revision.
  • Schemas: app/schemas/item.py (ItemCreate, ItemUpdate, ItemResponse).
  • Repository: app/repos/item.py (ItemRepo, on top of BaseRepository).
  • Service: app/services/item_service.py (ItemService): the business rules, raising service exceptions.
  • API: app/api/v1/endpoints/items.py, wired through app/api/v1/deps/items.py: list, read, create, update and delete under /v1/items.
  • Access: every /v1/items route needs a logged-in user (a router-level get_current_user dependency).
  • Access: the /v1/items routes are public, because this project has no authentication.
  • Tests: tests/services/item_service_test.py and tests/api/v1/endpoints/items_test.py.
  • Guide: guides/example-items.md — how a request flows through it, and how to turn it into your own domain.

🔒 Security middleware

All in app/middleware/:

  • CSRF protection (csrf.py) — double-submit cookie check (X-CSRF-Token header against the csrf_token cookie) on state-changing requests.
  • No cross-site request forgery check — this project was generated without that middleware. Add one before you authenticate browser clients with cookies.
  • Security headers (security_headers.py) — OWASP-recommended headers (X-Frame-Options, X-Content-Type-Options, X-XSS-Protection, CSP and more) on every response.
  • Request logging (logging.py)

⚡ Caching

  • Module: app/services/cache/manager.py (cache_manager), decorators.py (@cache_result). Guide: integrations/caching.md.
  • Redis caching — shared connection pooling, decorator-based caching helpers.
  • Included when the project is generated with include_redis_cache; Redis (redis, the REDIS_* settings, the compose service) comes with it.

⚙️ Background jobs / task queue

  • Module: app/services/task_queue/. Guide: integrations/celery.md.
  • Celery with Redis as the broker, and a ping task to check that a worker is running.
  • Sample scheduled task: seed_fake_users inserts fake users every 10s when ENABLE_DATA_SEEDING=true.
  • Included when the project is generated with include_celery; celery[redis] and psycopg are then regular dependencies.
  • Start a worker: ./scripts/celery_worker.sh (or .bat) — or directly: celery -A app.services.task_queue worker --loglevel=info --pool=solo
  • Start the scheduler: ./scripts/celery_beat.sh (or .bat) — or directly: celery -A app.services.task_queue beat --loglevel=info

☁️ Cloud storage

  • BackBlaze B2 — app/services/back_blaze_b2.py, schemas in app/schemas/back_blaze_bucket.py. Guide: integrations/backblaze.md.
  • Google Cloud Storage — app/services/gcs.py, schemas in app/schemas/google_bucket.py. Guide: integrations/gcs.md.
  • Included because they were chosen when the project was generated; their SDKs are then regular dependencies.

🔥 Firebase

  • Firebase Admin — app/services/firebase.py — authentication and push notifications. Guide: integrations/firebase.md.
  • Credentials: modeled by FirebaseServiceAccount in app/core/credentials/firebase.py, from the FIREBASE_* settings.
  • Included when the project is generated with include_firebase; firebase-admin is then a regular dependency.

💳 Apple Pay

  • Module: app/services/payments/apple_pay.py
  • App Store Server API integration — in-app purchase and subscription verification.
  • Credentials: modeled by ApplePayStoreCredentials in app/core/credentials/apple_pay.py.
  • Included when the project is generated with include_apple_pay; app-store-server-library is then a regular dependency. Guide: integrations/apple-pay.md.
  • Configure: APPLE_PAY_STORE_PRIVATE_KEY_PATH, APPLE_PAY_STORE_ROOT_CERTIFICATE_PATH, plus key/issuer/bundle IDs in .env

📧 Email

  • Module: app/services/email/, providers sharing a common interface (base.py). Guide: integrations/email.md.
  • Brevo: app/services/email/brevo.py, configured with BREVO_API_KEY.
  • Resend: app/services/email/resend.py, configured with RESEND_API_KEY.
  • Included when at least one email provider was chosen at generation; each chosen provider's SDK is then a regular dependency.

🧪 Testing & quality tooling

Always installed via dependency-groups.dev / .test — no extra required.

  • pytest with async support (anyio), coverage reporting (terminal + HTML), and custom markers (unit, integration, slow, websocket). ~90% coverage maintained across modules.
  • ruff — linting and formatting.
  • mypy — static typing, strict on repos/models/services.
  • bandit — security static analysis.
  • detect-secrets — secret-leak scanning.
  • tach — module boundary enforcement (see tach.toml).
  • pre-commit — runs all of the above locally before commit; commitizen additionally lints commit messages against Conventional Commits.

See Contributing.

  • CI — GitHub Actions runs the same lint/type/security suite plus the full test suite against real service containers (Postgres, plus any other service the project uses), with a coverage badge/comment posted per PR (green ≥90%, orange ≥70%).

🌍 Environment management

Always included.

Multi-environment configuration via pydantic-settings (app/core/config.py), reading from .env: local, dev, stg (staging), prd (production). See .env.example for the full variable list.