How vince760/ana_600_capstone works
1. Two-tier application architecture
- The repo is split into a Next.js 14 frontend in src/ and a Python FastAPI backend in backend/.
- The frontend handles participant UX flows, while the backend owns assessment logic, model inference, explanation generation, and persistence.
2. Frontend as the participant-facing research app
- src/app/ contains the main user journeys: auth pages, onboarding steps, assessment results, and protected research screens like assistant, forecast, simulator, risk, and upload.
- The frontend uses reusable UI components in src/components/ and Supabase client/server helpers in src/lib/supabase/ for auth/session handling.
3. Backend API as the system of record for assessments
- backend/api/ is the runtime API layer exposed by FastAPI.
- Key modules separate concerns: main.py for app wiring, auth.py for auth integration, store.py for persistence, service.py for orchestration, models.py/schemas.py for request-response contracts, and reference.py for static onboarding schema delivery.
4. Inference pipeline is isolated from the HTTP layer
- backend/inference/ contains the model-serving boundary: artifact loading, feature engineering, prediction, calibration, and schema/constants.
- This is the part that turns onboarding inputs into a probability and SHAP-style feature drivers, independent of the API transport layer.
5. Model artifact and feature contract are versioned separately
- The deployed model is not trained at request time; it is loaded from backend/artifacts/expenshilo_artifact.pkl.
- The artifact is paired with a feature contract and summary metadata, which lets the backend keep prediction, calibration, and explanation behavior stable across requests.
6. Explanation subsystem has deterministic and LLM branches
- backend/api/explanations.py is the explanation boundary.
- It translates model outputs into participant-facing content using two paths: a structured explanation path with deterministic plain language, and an LLM explanation path using Anthropic Claude.
- This is the main research variable: control vs structured explanation vs LLM-mediated explanation.
7. Supabase is the persistence and identity backend
- The repo uses Supabase for both auth and research data storage.
- Backend code under backend/supabase/ defines the schema, while runtime storage records assessments, explanation payloads, and survey responses.
- The frontend also uses Supabase helpers for session-aware route protection.
8. Research workflow is stateful across multiple user steps
- The user flow starts with onboarding, then creates an assessment, then shows results, then collects survey responses.
- Assessment records are the linkage point across modules: raw inputs, engineered features, prediction output, explanation payloads, experiment arm, and follow-up survey data all hang off the same assessment identity.
9. Offline research pipeline is separate from runtime serving
- Files like backend/scf_spending_pipeline.py, backend/train_expenshilo_artifact.py, and the backend/EDA/ scripts are for dataset analysis, target construction, model comparison, and artifact export.
- These scripts operate on research data in backend/data/ and are not part of the live request path.
10. Data boundary and source of truth
- The backend’s research data originates from SCF and related local extracts in backend/data/.
- Runtime does not query raw datasets directly; it relies on the exported artifact and feature engineering logic, which keeps serving reproducible and decoupled from training inputs.
11. Tests protect the critical boundaries
- backend/tests/ covers inference features, API behavior, and explanation generation.
- This indicates the highest-risk areas are the model-feature contract, the HTTP assessment flow, and the fidelity of explanation text.
12. Operational packaging and deployment
- run_api.py and Procfile support backend execution, while .github/workflows/backend-ci-cd.yml suggests CI/CD automation for the backend.
- The repo also includes root-level Node and Python requirements, showing it is a full-stack monorepo with separate runtime environments.
13. What an architecture diagram should emphasize
- The most important nodes are: participant browser/UI, Next.js frontend, FastAPI backend, inference/artifact layer, explanation layer with Claude, and Supabase persistence/auth.
- The key arrows are: onboarding inputs from UI to API, prediction/explanation return from backend to UI, and persisted research records from backend to Supabase.
Main entry points: layout.tsx Next.js app · service.py Assessment service · main.py API app · store.py Assessment store
Components 20
Next.js frontend
Participant-facing app and shared UI
- Participant browser · Participant-facing web session
src/app/page.tsx - Next.js app · App routing, layouts, and protected journeys
src/app/layout.tsx - Auth flow · Login and signup entrypoints
src/app/(auth)/login/page.tsx - Onboarding flow · Research consent and household input collection
src/app/(onboarding)/onboarding/review/page.tsx - Assessment results · Risk and explanation presentation
src/app/assessment-results/page.tsx - Protected screens · Assistant, forecast, simulator, risk, upload, and settings
src/app/(protected)/assistant/page.tsx - UI components · Reusable shell, forms, charts, and controls
src/components/risk/risk-gauge.tsx - Supabase helpers · Browser-side session and route protection
src/lib/supabase/client.ts
FastAPI backend
Assessment API, inference, and explanation services
- API app · FastAPI wiring and runtime startup
backend/api/main.py - Assessment service · Coordinates request handling and assessment lifecycle
backend/api/service.py - Auth bridge · Backend-side auth integration
backend/api/auth.py - Assessment store · Writes assessments, surveys, and explanation payloads
backend/api/store.py - Explanations · Deterministic and Claude-backed participant explanations
backend/api/explanations.py - Inference pipeline · Feature engineering, prediction, and calibration
backend/inference/predictor.py - Artifact bundle · Serialized model and summary metadata
backend/artifacts/expenshilo_artifact.pkl - Reference schema · Onboarding schema and API response shapes
backend/api/reference.py
Offline research
Data analysis, training, and artifact generation
- Offline pipeline · Dataset analysis, target construction, and artifact export
backend/train_expenshilo_artifact.py - SCF data · Source data extracts used for analysis and training
backend/data/SCFP2022.csv
Supabase platform
Auth and persistence boundary
- Supabase schema · Research data and experiment tables
backend/supabase/phase_04_schema.sql - Supabase runtime · Identity and persistent research records
src/lib/supabase/server.ts
Connections 21
- Participant browser → Next.js app: uses · Participant interacts with the Next.js application
- Next.js app → Auth flow: routes to · Public auth screens
- Next.js app → Onboarding flow: guides · Collects research consent and inputs
- Next.js app → Assessment results: shows · Displays assessment output and explanation
- Next.js app → Protected screens: serves · Protected participant tools and dashboards
- Next.js app → UI components: composes · Shared UI primitives and feature components
- Next.js app → Supabase helpers: authenticates via · Session-aware route protection and user state
- Supabase helpers → Supabase runtime: sessions · Client-side auth uses Supabase identity
- Next.js app → API app: calls · Frontend submits onboarding and assessment requests
- API app → Assessment service: delegates · Central request orchestration
- API app → Auth bridge: verifies · Backend auth integration
- Assessment service → Reference schema: validates against · Uses shared onboarding and response contracts
- Assessment service → Inference pipeline: scores · Turns inputs into probability and feature drivers
- Assessment service → Explanations: explains · Builds participant-facing explanation payloads
- Assessment service → Assessment store: persists · Stores assessment lifecycle records
- Explanations → Assessment store: records · Explanation payloads and experiment arm outputs
- Assessment store → Supabase runtime: writes to · Assessment and survey persistence backend
- Supabase runtime → Supabase schema: implements · Database schema for runtime records
- Inference pipeline → Artifact bundle: loads · Model artifact and summary metadata
- Offline pipeline → SCF data: analyzes · Research datasets for model development
- Offline pipeline → Artifact bundle: exports · Produces deployed inference artifact