FastAPI backend for the Audit Tools platform. This repository serves two product namespaces from one codebase:
YEE: fullUser-backed authentication, onboarding, approvals, invites, dashboard, reporting, and submission workflowsPlayspace: shared-core dashboard and audit APIs plus a lightweight account-based mobile auth bootstrap used by the current mobile client
- shared SQLAlchemy models and product-scoped database access
- Alembic migrations for both
yeeandplayspace - product REST routes under
/yee/*and/playspace/* - YEE auth, onboarding, invite, reporting, and export flows
- Playspace audit session, assignment, dashboard, and management flows
- deterministic seed data for local development and integration tests
The most important integration boundary in this repository is auth:
YEE auth: implemented with theuserstable inapp/auth.pyPlayspace auth: uses the same signedUsersession model for/playspace/auth/signup,/playspace/auth/login,/playspace/auth/me, and downstream Playspace product routes, withx-demo-*actor headers kept only as a temporary compatibility fallback inapp/core/actors.py
That split is intentional for now. Do not assume a change in one product's auth flow is automatically safe for the other.
Implemented today:
- shared-core account, project, place (with
addressfield), auditor-profile, assignment, and audit models - YEE real auth with email verification, approvals, invite acceptance, and session state
- Playspace-only
playspace_submissionsstorage with scoring-backed draft/submit flows - manager/admin Playspace dashboards with separate audit / survey / full-audit place rollups
- manager multi-user auth: each manager profile now gets a dedicated
Userrecord - Playspace enum types for structured field values
- YEE instrument metadata enrichment for section intros, comment prompts, and grouped question rendering
- manager-scoped YEE edit APIs for projects and places
- Playspace bug report submission and admin/manager review flows
- seeded test data and product-scoped migration support
Still evolving:
- richer settings and lifecycle management
- production automation around migrations and release verification
- removal of the remaining
x-demo-*compatibility fallback once all clients stop sending it - final reporting polish and cap-score decisions
audit-tools-backend/
├── alembic/
├── app/
│ ├── auth.py
│ ├── auth_security.py
│ ├── core/
│ ├── database.py
│ ├── email_service/
│ ├── main.py
│ ├── models.py
│ ├── products/
│ │ ├── playspace/
│ │ │ ├── instruments/
│ │ │ ├── jobs/
│ │ │ ├── routes/
│ │ │ ├── schemas/
│ │ │ └── services/
│ │ └── yee/
│ └── seed.py
├── docs/
├── tests/
├── .env.example
├── README.md
├── SCHEMA.md
└── STRUCTURE.md
- Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -r requirements.txt- Create a local env file:
cp .env.example .env- Set product database URLs for each tier you use (dev, prod, test). You only
need to configure these once - switch targets at runtime with
ENVIRONMENT:
ENVIRONMENT=development
DEV_DATABASE_URL_YEE=postgresql+asyncpg://postgres:postgres@localhost:5432/audit_tools_yee
DEV_DATABASE_URL_PLAYSPACE=postgresql+asyncpg://postgres:postgres@localhost:5432/audit_tools_playspace
DATABASE_URL_YEE=postgresql+asyncpg://...
DATABASE_URL_PLAYSPACE=postgresql+asyncpg://...
TEST_DATABASE_URL_PLAYSPACE=postgresql+asyncpg://...
AUTH_TOKEN_SECRET_KEY=change-me
AUTH_ACCESS_TOKEN_TTL_DAYS=7
AUTH_EMAIL_VERIFY_TTL_HOURS=24
AUTH_VERIFY_URL_TEMPLATE=http://localhost:3000/verify-email?token={token}Resolution order matches Alembic -x environment=...:
ENVIRONMENT |
Playspace URL keys tried (in order) |
|---|---|
development (default) |
DEV_DATABASE_URL_PLAYSPACE → DATABASE_URL_PLAYSPACE |
production |
DATABASE_URL_PLAYSPACE |
test |
TEST_DATABASE_URL_PLAYSPACE → DATABASE_URL_PLAYSPACE |
- Apply migrations to both product databases. Each product has its own Alembic
branch (
yee/playspace) sharing a commoncorebase, so target the product-scoped branch head rather than the barehead:
alembic -x product=yee -x environment=development upgrade yee@head
alembic -x product=playspace -x environment=development upgrade playspace@headFor production or test databases:
alembic -x product=playspace -x environment=production upgrade playspace@head
alembic -x product=playspace -x environment=test upgrade playspace@head- Seed demo data when needed:
./.venv/bin/python -m app.seed --allow-destructiveOr seed one product only:
./.venv/bin/python -m app.seed --allow-destructive --product yee
./.venv/bin/python -m app.seed --allow-destructive --product playspace- Start the API:
uvicorn app.main:app --reloadPoint the server at a different database tier without editing .env:
ENVIRONMENT=production uvicorn app.main:app --reload
ENVIRONMENT=test uvicorn app.main:app --reloadOn startup the backend logs the active ENVIRONMENT and resolved
host/database for each product.
Useful local URLs:
http://127.0.0.1:8000/healthhttp://127.0.0.1:8000/yee/auth/loginhttp://127.0.0.1:8000/yee/instrumenthttp://127.0.0.1:8000/playspace/auth/loginhttp://127.0.0.1:8000/playspace/instrument
The latest YEE website iteration depends on a few backend behaviors that are important for future engineers to preserve:
GET /yee/instrumentnow returns section metadata used by the frontend to render:- section intro text
- per-section optional comment prompts
- block titles
- item-kind hints used for grouped presence/condition question display
PATCH /yee/dashboard/projects/{project_id}allows manager-scoped project editsPATCH /yee/dashboard/places/{place_id}allows manager-scoped place edits, including postal code and address updates
Those contracts are consumed directly by the Next.js frontend for:
- spreadsheet-aligned YEE wording and domain instructions
- conditional domain question rendering
- manager project/place edit flows with persistence
- review/report pages that depend on richer score and instrument context
The current seed flows use the shared demo password:
DemoPass123!
This applies to seeded auth-capable demo accounts used in local development and integration tests.
If a shared demo account drifts from that password in a non-destructive YEE environment, you can restore the seeded demo passwords without wiping the whole database:
./.venv/bin/python -m app.reset_demo_passwordsTo restore only one account:
./.venv/bin/python -m app.reset_demo_passwords --email manager-demo@yee.localThe backend also protects the seeded YEE demo emails by default so invite
acceptance and self-service password reset flows do not mutate those shared
review accounts. You can override that list with PROTECTED_YEE_DEMO_EMAILS
if your deployment needs different protected identities.
Fast checks:
./.venv/bin/python -m py_compile app/auth.py app/seed.py
./.venv/bin/pytest tests/test_auth_security.pyWhen changing PLAYSPACE_RELEASE_POLICY or YEE_RELEASE_POLICY version
fields, update the matching pytest assertions in the same change. See
.cursor/rules/mobile-release-policy-test-sync.mdc and
.claude/skills/mobile-release-policy-test-sync/SKILL.md.
Playspace integration coverage uses a dedicated test database:
TEST_DATABASE_URL_PLAYSPACE=postgresql://... ./.venv/bin/pytest tests/products/playspace- Run migrations for both products before serving new code.
- The checked-in
render.yamlruns both product migrations automatically in itspreDeployCommand(alembic -x product=yee upgrade yee@head && alembic -x product=playspace upgrade playspace@head) before the new release takes traffic. Keep that command in place when editingrender.yaml. If you deploy outside Render, your own release process must run both migrations before traffic shifts. - Treat one-way compatibility migrations as production operations: back up first.
Release sequence on Render:
- Push code; Render builds, then
preDeployCommandmigratesyeethenplayspace. - The new instance starts
uvicornand serves once/healthpasses. - Verify auth and one product-specific flow per namespace.
For the full topology, env keys, cron job, and a manual (non-Render) runbook, see
docs/deployment.md. For which clients consume each namespace, see
docs/client-map.md.
docs/architecture.md: product boundaries, runtime model, and request flowsdocs/client-map.md: which clients consume/yee/*vs/playspace/*docs/deployment.md: production setup and migration runbookdocs/scoring.md: YEE scoring behaviordocs/roles-and-permissions.md: role matrixSCHEMA.md: current schema referenceSTRUCTURE.md: code organization
When changing this repository, double-check:
app/auth.py: product-aware auth behaviorapp/models.pyandalembic/versions/: schema/code alignment, especiallyplayspace_submissionsapp/core/actors.py: Playspace header-based actor resolutionapp/products/playspace/seed_data.pyandapp/seed.py: demo credentials and seeded contractsapp/products/playspace/routes/,app/products/playspace/schemas/, andapp/products/playspace/services/: Playspace API contracts consumed by mobiletests/products/playspace/: API contract coverage for the mobile-facing surfaceapp/products/mobile_release_policy.py: COPA/YEE force-update floors; pair withtests/products/yee/test_mobile_release_policy.pyandtest_playspace_mobile_release_policy_is_public