What is the Backend?
Theauditor-backend is a FastAPI application that serves as the single API for both frontend apps. It handles authentication, website management, audit orchestration, billing, RUM, reports, and all business logic.
Framework
FastAPI on Python 3.12 · Uvicorn ASGI server
Database
PostgreSQL via SQLAlchemy 2 (async) · asyncpg driver · Alembic migrations
Cache
Redis via aioredis — sessions, permission cache, scan status
Auth
JWT RS256 · Google OAuth · Microsoft OAuth · AWS Cognito
Payments
Stripe — subscriptions, checkout, webhooks
AI
Google Gemini 2.0 Flash — accessibility fix generation
Project Structure
auditor_app/ — Application core:
web/ — HTTP layer
web/ — HTTP layer
db/ — Data layer
db/ — Data layer
services/ — Business logic
services/ — Business logic
Application Startup Lifecycle
1
Entrypoint
python -m auditor_app calls uvicorn.run() with factory=True, pointing at auditor_app.web.application:get_app.2
App factory runs
get_app() creates the FastAPI instance, registers CORSMiddleware and SessionMiddleware, then mounts the master router at /api.3
Database pool created
An async SQLAlchemy engine is created with
pool_size=20, max_overflow=10. A session factory is stored on app.state.4
OpenTelemetry initialised
If
AUDITOR_APP_OPENTELEMETRY_ENDPOINT is set, FastAPI, SQLAlchemy, and Redis instrumentation is activated and connected to the OTLP exporter.5
Redis pool created
An async Redis connection pool is created and stored on
app.state.redis_pool.6
Redis cache warmed
Four datasets are loaded from PostgreSQL and cached in Redis on every restart: role→permission mappings, accessibility audit rules, scan regions, and uptime monitor API tokens.
Configuration
All settings live inauditor_app/settings.py using pydantic-settings. Every field maps to an environment variable prefixed with AUDITOR_APP_.
Copy .env.sample → .env and fill in your values. Key variables for local dev:
Middleware Stack
Dependency Injection Pattern
FastAPI’sDepends() injects these into every route handler that needs them:
DAO Pattern
All database queries go through DAO classes indb/dao/. Route handlers must never contain raw SQLAlchemy queries.
Running Alembic Migrations
auditor_app/db/migrations/versions/.