How audit-tools-deca-lab-cornell/audit-tools-backend works
1. Top-level shape
This is a FastAPI + SQLAlchemy backend that serves two product namespaces from one codebase: YEE and Playspace. The app entrypoint is app/main.py, which wires shared middleware/core behavior and mounts product-specific routers under /yee/* and /playspace/*.
2. Hard architectural boundary: product split
The strongest boundary in the repo is auth and data isolation by product. The README and file layout show two separate database URLs, separate Alembic migration histories run with -x product=yee and -x product=playspace, and product-scoped modules under app/products/yee and app/products/playspace.
3. Shared core layer
app/core/ and app/models.py hold the shared domain primitives used by both products: accounts/users, projects, places, auditor profiles, assignments, audits, and related lifecycle state. This layer is the common schema and business vocabulary that both product stacks build on.
4. YEE subsystem
app/products/yee/ contains the YEE-specific routes and logic. The README calls out real user-backed authentication, email verification, approvals, invite acceptance, dashboard/reporting, and submission workflows. This product is the more complete identity-and-workflow system.
5. Playspace subsystem
app/products/playspace/ contains the mobile-facing audit workflow. Its focus is audit session management, assignment management, dashboard views, and management APIs, plus normalized audit storage and scoring-backed draft/submit flows. It also includes instrument definitions, migration helpers, and product-specific seed data.
6. Auth boundary and compatibility path
Auth is intentionally different between the two products. YEE uses the users table in app/auth.py. Playspace uses the same signed User session model for /playspace/auth/signup, /playspace/auth/login, and /playspace/auth/me, but still supports temporary x-demo-* actor-header fallback via app/core/actors.py. That fallback is a key compatibility boundary to show in any diagram.
7. Request flow through the service layer
Routes are thin and delegate into app/products/*/services/. The services layer is where business rules live for audits, assignments, dashboards, administration, management, and privacy. Schemas under app/products/*/schemas/ define API contracts, while route modules under routes/ expose the HTTP surface.
8. Audit and scoring data flow
For Playspace, the core flow is: auth/session → assignment/session lookup → audit draft state → scoring/validation → submit/persist. Supporting modules like audit_state.py, scoring.py, and scoring_metadata.py indicate that audit state is computed and normalized rather than stored as a single opaque blob.
9. Notifications and email side effects
There are two side-effect services: app/email_service.py for verification/invite-related email, and app/notification_service.py plus app/notifications_router.py for notification delivery and retrieval. These are cross-cutting services, but they are especially relevant to YEE approvals/invites and assignment/audit notifications.
10. Database and migration model
app/database.py and alembic/ define the persistence boundary. The repo uses product-scoped migrations and a history that reflects evolving shared-core and product-specific schemas. For architecture diagrams, show the two databases and the fact that code and migrations are coordinated but not interchangeable.
11. Seed and local/demo mode
app/seed.py, app/core/demo_data.py, and app/products/playspace/seed_data.py create deterministic local and test fixtures. Demo auth credentials are intentionally shared in development, which matters because several routes and tests assume seeded accounts and assignments exist.
12. Operational and verification surfaces
The repo includes CI workflows, Postman collections, and a dedicated test suite under tests/, with strong coverage around auth security, notifications, and Playspace API contracts. Deployment guidance in the README explicitly requires running migrations for both product databases before serving traffic.
13. What to draw in an architecture diagram
A good diagram should show: client traffic entering one FastAPI app; branching into YEE vs Playspace routers; each branch using its own auth model and database; both branches sharing core models and utilities; and side channels for email, notifications, seeding, and Alembic migrations. The most important explicit boundary is that a change in one product’s auth or schema is not automatically safe for the other.
Main entry points: services Playspace services · routes.py YEE routes · main.py FastAPI app · routes Playspace routes
Components 17
Shared Core
Code and data used by both product namespaces.
- FastAPI app · Application wiring and top-level router mounting.
app/main.py - Core models · Common domain vocabulary and persistence models used by both products.
app/models.py - Core utils · Shared actors, demo data, and source-material helpers.
app/core
YEE
YEE-specific auth, routes, and workflows.
- YEE auth · Primary user-table authentication for YEE.
app/auth.py - YEE routes · YEE product routes and workflow surface.
app/products/yee/routes.py - YEE scoring · YEE-specific audit submission and scoring behavior.
app/yee_scoring.py
Playspace
Mobile audit workflow and management stack.
- Playspace routes · Playspace HTTP surface for audits, assignments, management, and me endpoints.
app/products/playspace/routes - Playspace services · Business rules for audit sessions, assignments, dashboard, admin, management, privacy, and me.
app/products/playspace/services - Audit state · Computes and tracks draft/submit audit state.
app/products/playspace/audit_state.py - Play scoring · Scoring and metadata used by Playspace audits.
app/products/playspace/scoring.py - Play auth · Playspace signup/login/me session flow plus demo-header compatibility.
app/products/playspace/routes/me.py
Operations
Persistence, migrations, side effects, and local/demo support.
- Databases · Shared persistence boundary with separate product-scoped database URLs and schemas.
app/database.py - Alembic migrations · Product-scoped migration history for shared-core, YEE, and Playspace evolution.
alembic - Email service · Verification and invite-related outbound email.
app/email_service.py - Notifications · Notification creation, delivery, and retrieval surface.
app/notification_service.py - Seed data · Local/demo fixtures and deterministic setup.
app/seed.py - Tests · Coverage for auth, notifications, Playspace APIs, state, scoring, and seed behavior.
tests
Connections 24
- FastAPI app → YEE routes: mounts · Registers YEE router under the product namespace.
- FastAPI app → Playspace routes: mounts · Registers Playspace router under the product namespace.
- FastAPI app → Notifications: exposes · Attaches shared notification endpoints.
- FastAPI app → Databases: uses · Initializes persistence and session wiring.
- YEE routes → YEE auth: auth · YEE routes rely on YEE user authentication.
- YEE routes → Core models: reads/writes · Uses shared domain models and state.
- YEE routes → YEE scoring: delegates · Submission and scoring flow delegates to YEE scoring logic.
- Playspace routes → Playspace services: delegates · HTTP handlers stay thin and call service layer.
- Playspace services → Audit state: computes · Services derive normalized audit state.
- Playspace services → Play scoring: scores · Services invoke audit scoring and metadata.
- Playspace routes → Play auth: auth · Playspace session and demo-header identity flow.
- Play auth → Core utils: fallback · Uses shared demo actor compatibility when needed.
- YEE auth → Core models: links · Binds users to shared account/domain records.
- Core utils → Core models: supports · Provides shared actors and demo fixtures for the core model layer.
- Databases → Alembic migrations: coordinates · Database schema is evolved through Alembic histories.
- Alembic migrations → Core models: evolves · Shared-core baseline and compatibility migrations track model changes.
- Alembic migrations → Playspace services: evolves · Playspace-specific schema changes support audit storage and instruments.
- Email service → YEE routes: supports · Verification and invite workflows use email side effects.
- Notifications → Playspace services: supports · Assignments and audits can create notifications.
- Seed data → Core utils: seeds · Creates deterministic local/demo fixtures.
- Seed data → Playspace services: seeds · Provides Playspace-specific bootstrap data.
- Tests → YEE auth: verifies · Covers auth and security behavior.
- Tests → Notifications: verifies · Covers notification delivery and retrieval.
- Tests → Playspace routes: verifies · Exercises Playspace API contracts and workflows.