# audit-tools-deca-lab-cornell/audit-tools-backend architecture

> Architecture diagram of the GitHub repository audit-tools-deca-lab-cornell/audit-tools-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/audit-tools-deca-lab-cornell/audit-tools-backend
- Repository: https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend

## Overview

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: [`app/products/playspace/services`](https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/tree/master/app/products/playspace/services) (Playspace services), [`app/products/yee/routes.py`](https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/products/yee/routes.py) (YEE routes), [`app/main.py`](https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/main.py) (FastAPI app), [`app/products/playspace/routes`](https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/tree/master/app/products/playspace/routes) (Playspace routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_shared["Shared Core"]
  node_n_main["FastAPI app<br/>entrypoint<br/>[main.py]"]
  node_n_shared_models[("Core models<br/>shared schema<br/>[models.py]")]
  node_n_shared_core["Core utils<br/>shared support"]
end

subgraph group_grp_yee["YEE"]
  node_n_auth["YEE auth<br/>users auth<br/>[auth.py]"]
  node_n_yee_routes["YEE routes<br/>product API<br/>[routes.py]"]
  node_n_yee_scoring["YEE scoring<br/>submission logic<br/>[yee_scoring.py]"]
end

subgraph group_grp_playspace["Playspace"]
  node_n_playspace_routes["Playspace routes<br/>product API"]
  node_n_playspace_services["Playspace services<br/>workflow service"]
  node_n_playspace_state(("Audit state<br/>normalized runtime<br/>[audit_state.py]"))
  node_n_playspace_scoring(("Play scoring<br/>scoring runtime<br/>[scoring.py]"))
  node_n_playspace_auth["Play auth<br/>session auth<br/>[me.py]"]
end

subgraph group_grp_ops["Operations"]
  node_n_db[("Databases<br/>persistence<br/>[database.py]")]
  node_n_migrations["Alembic migrations<br/>schema history"]
  node_n_email["Email service<br/>side effect<br/>[email_service.py]"]
  node_n_notifications["Notifications<br/>side effect"]
  node_n_seed["Seed data<br/>bootstrap<br/>[seed.py]"]
  node_n_tests["Tests<br/>verification"]
end

node_n_main -->|"mounts"| node_n_yee_routes
node_n_main -->|"mounts"| node_n_playspace_routes
node_n_main -->|"exposes"| node_n_notifications
node_n_main -->|"uses"| node_n_db
node_n_yee_routes -->|"auth"| node_n_auth
node_n_yee_routes -->|"reads/writes"| node_n_shared_models
node_n_yee_routes -->|"delegates"| node_n_yee_scoring
node_n_playspace_routes -->|"delegates"| node_n_playspace_services
node_n_playspace_services -->|"computes"| node_n_playspace_state
node_n_playspace_services -->|"scores"| node_n_playspace_scoring
node_n_playspace_routes -->|"auth"| node_n_playspace_auth
node_n_playspace_auth -.->|"fallback"| node_n_shared_core
node_n_auth -->|"links"| node_n_shared_models
node_n_shared_core -->|"supports"| node_n_shared_models
node_n_db -->|"coordinates"| node_n_migrations
node_n_migrations -->|"evolves"| node_n_shared_models
node_n_migrations -->|"evolves"| node_n_playspace_services
node_n_email -->|"supports"| node_n_yee_routes
node_n_notifications -->|"supports"| node_n_playspace_services
node_n_seed -->|"seeds"| node_n_shared_core
node_n_seed -->|"seeds"| node_n_playspace_services
node_n_tests -.->|"verifies"| node_n_auth
node_n_tests -.->|"verifies"| node_n_notifications
node_n_tests -.->|"verifies"| node_n_playspace_routes

click node_n_main "https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/main.py"
click node_n_shared_models "https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/models.py"
click node_n_shared_core "https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/tree/master/app/core"
click node_n_auth "https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/auth.py"
click node_n_yee_routes "https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/products/yee/routes.py"
click node_n_yee_scoring "https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/yee_scoring.py"
click node_n_playspace_routes "https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/tree/master/app/products/playspace/routes"
click node_n_playspace_services "https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/tree/master/app/products/playspace/services"
click node_n_playspace_state "https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/products/playspace/audit_state.py"
click node_n_playspace_scoring "https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/products/playspace/scoring.py"
click node_n_playspace_auth "https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/products/playspace/routes/me.py"
click node_n_db "https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/database.py"
click node_n_migrations "https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/tree/master/alembic"
click node_n_email "https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/email_service.py"
click node_n_notifications "https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/notification_service.py"
click node_n_seed "https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/seed.py"
click node_n_tests "https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/tree/master/tests"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_main,node_n_shared_models,node_n_shared_core toneBlue
class node_n_auth,node_n_yee_routes,node_n_yee_scoring toneAmber
class node_n_playspace_routes,node_n_playspace_services,node_n_playspace_state,node_n_playspace_scoring,node_n_playspace_auth toneMint
class node_n_db,node_n_migrations,node_n_email,node_n_notifications,node_n_seed,node_n_tests toneRose
```

## Components

### Shared Core

Code and data used by both product namespaces.

- [FastAPI app](https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/main.py): entrypoint · Application wiring and top-level router mounting. · `app/main.py`
- [Core models](https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/models.py): shared schema · Common domain vocabulary and persistence models used by both products. · `app/models.py`
- [Core utils](https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/tree/master/app/core): shared support · Shared actors, demo data, and source-material helpers. · `app/core`

### YEE

YEE-specific auth, routes, and workflows.

- [YEE auth](https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/auth.py): users auth · Primary user-table authentication for YEE. · `app/auth.py`
- [YEE routes](https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/products/yee/routes.py): product API · YEE product routes and workflow surface. · `app/products/yee/routes.py`
- [YEE scoring](https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/yee_scoring.py): submission logic · YEE-specific audit submission and scoring behavior. · `app/yee_scoring.py`

### Playspace

Mobile audit workflow and management stack.

- [Playspace routes](https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/tree/master/app/products/playspace/routes): product API · Playspace HTTP surface for audits, assignments, management, and me endpoints. · `app/products/playspace/routes`
- [Playspace services](https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/tree/master/app/products/playspace/services): workflow service · Business rules for audit sessions, assignments, dashboard, admin, management, privacy, and me. · `app/products/playspace/services`
- [Audit state](https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/products/playspace/audit_state.py): normalized runtime · Computes and tracks draft/submit audit state. · `app/products/playspace/audit_state.py`
- [Play scoring](https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/products/playspace/scoring.py): scoring runtime · Scoring and metadata used by Playspace audits. · `app/products/playspace/scoring.py`
- [Play auth](https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/products/playspace/routes/me.py): session 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](https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/database.py): persistence · Shared persistence boundary with separate product-scoped database URLs and schemas. · `app/database.py`
- [Alembic migrations](https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/tree/master/alembic): schema history · Product-scoped migration history for shared-core, YEE, and Playspace evolution. · `alembic`
- [Email service](https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/email_service.py): side effect · Verification and invite-related outbound email. · `app/email_service.py`
- [Notifications](https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/notification_service.py): side effect · Notification creation, delivery, and retrieval surface. · `app/notification_service.py`
- [Seed data](https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/blob/master/app/seed.py): bootstrap · Local/demo fixtures and deterministic setup. · `app/seed.py`
- [Tests](https://github.com/audit-tools-deca-lab-cornell/audit-tools-backend/tree/master/tests): verification · Coverage for auth, notifications, Playspace APIs, state, scoring, and seed behavior. · `tests`

## Connections

- 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.
