Skip to main content

What is the Backend?

The auditor-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:
Root-level files:

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.
On shutdown: database pool disposed → Redis connections closed → OpenTelemetry flushed.

Configuration

All settings live in auditor_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:
See the dev setup guide for the full variable reference.

Middleware Stack


Dependency Injection Pattern

FastAPI’s Depends() injects these into every route handler that needs them:
Two auth dependencies are available:

DAO Pattern

All database queries go through DAO classes in db/dao/. Route handlers must never contain raw SQLAlchemy queries.

Running Alembic Migrations

Migration files live in auditor_app/db/migrations/versions/.