How owb27/grs works
1. Repository shape
- This is a two-tier monorepo: a React/Vite frontend and a FastAPI backend.
- There is no shared runtime package between them; the boundary is a JSON HTTP API.
2. User-facing frontend
- The frontend lives under frontend/src and is organized by page and feature area: home, quiz, result, methodology, plus shared layout and UI components.
- App.jsx and main.jsx wire routing and app bootstrap; i18n.js and locale files provide bilingual UI (en, zh).
3. Frontend state and API access
- hooks/useQuizFlow.js drives the quiz interaction and result progression.
- lib/api.js is the main client boundary to the backend.
- Result UI components include debug panels and recommendation cards, so the frontend can render both normal recommendations and optional diagnostic detail.
4. Backend HTTP surface
- The API is split into two route modules: app/api/routes/questions.py and app/api/routes/recommend.py.
- GET /questions serves quiz content from the database.
- POST /recommend accepts quiz answers and returns ranked game recommendations.
5. Recommendation pipeline
- The core flow is rule-based first: validate answers, build a user preference profile, score games, and select top candidates.
- The backend then optionally reranks those candidates with an LLM and generates better recommendation reasons.
- If the LLM path is disabled or fails validation/timeouts, the system falls back to the rule-based ranking.
6. Service layer responsibilities
- answer_validation_service.py enforces input correctness.
- profile_service.py turns user answers into a preference profile.
- question_service.py handles question retrieval/business logic.
- recommendation_service.py, rerank_service.py, and reason_service.py coordinate scoring, candidate selection, reranking, and explanation generation.
7. LLM subsystem
- The LLM-specific code is isolated under backend/app/llm.
- It includes prompt templates, client wrappers for reranking and reasoning, an in-memory cache, and quality checks for model output.
- evals/ contains offline evaluation cases and results, showing that prompt/model behavior is treated as a tunable subsystem rather than embedded ad hoc in the main pipeline.
8. Persistence and domain model
- The backend uses SQLModel/SQLAlchemy with PostgreSQL.
- db/models.py, db/session.py, and db/engine.py define the persistence layer.
- Alembic migrations under backend/alembic/versions evolve the schema for questions, games/tags, recommendation tables, and uniqueness constraints.
9. Seed and data management
- Business data is managed through JSON seed files in backend/data_pipeline/seeds.
- Import and upsert scripts under backend/app/db populate or refresh games, tags, questions, and tag weights.
- This indicates the system is designed around curated offline data rather than live scraping or user-generated content.
10. Configuration and external services
- Environment settings in app/core/settings.py and backend/.env.example control database access, LLM behavior, caching, diagnostics, and LangSmith tracing.
- The main external dependencies that affect architecture are PostgreSQL for storage and an LLM provider for optional reranking/reason generation.
11. Testing and CI
- Backend tests cover the recommendation and questions endpoints, including invalid-answer handling and the non-LLM fallback path.
- GitHub Actions CI runs frontend install/build and backend pytest, so both the UI and API are first-class build targets.
12. Architecture to draw
- The main diagram should show: browser UI → FastAPI API → service layer → PostgreSQL and seed-backed domain data, with an optional LLM branch used only after rule-based candidate selection.
- The LLM branch should be drawn as a downstream enhancer, not as the primary recommender.
Main entry points: App.jsx App Shell · db PostgreSQL · ResultPage.jsx Result · main.py FastAPI API
Components 19
Frontend
React/Vite browser app for the quiz flow and results.
- Browser UI · User-facing quiz, methodology, and result experience.
frontend/src - App Shell · Wires app startup, routing, layout, and localization.
frontend/src/App.jsx - Home · Landing page and pipeline overview.
frontend/src/pages/HomePage.jsx - Quiz · Question flow, progress, and answer submission UI.
frontend/src/pages/QuizPage.jsx - Result · Recommendation display and diagnostic panels.
frontend/src/pages/ResultPage.jsx - API Client · Frontend boundary for backend requests.
frontend/src/lib/api.js - Quiz Flow · Coordinates answering, progression, and result loading.
frontend/src/hooks/useQuizFlow.js
Backend
FastAPI API, services, persistence, and optional LLM enhancement.
- FastAPI API · HTTP surface exposing questions and recommendations.
backend/app/main.py - Questions Route · Serves quiz questions over HTTP.
backend/app/api/routes/questions.py - Recommend Route · Accepts answers and returns ranked recommendations.
backend/app/api/routes/recommend.py - Validation · Checks answer correctness and request shape.
backend/app/services/answer_validation_service.py - Profile Builder · Converts quiz answers into a preference profile.
backend/app/services/profile_service.py - Ranker · Scores games and selects top candidates.
backend/app/services/recommendation_service.py - Rerank · Optionally refines candidate ordering with LLM support.
backend/app/services/rerank_service.py - Reasons · Generates user-facing recommendation explanations.
backend/app/services/reason_service.py - LLM Layer · Prompting, clients, cache, and quality checks for optional model use.
backend/app/llm
Data
Seed-backed domain data and database schema evolution.
- PostgreSQL · Persistent store for questions, games, tags, and recommendations.
backend/app/db - Seed Data · Curated offline domain data used to populate and refresh the database.
backend/data_pipeline/seeds - Migrations · Alembic versions for questions, games/tags, and recommendation tables.
backend/alembic/versions
Connections 23
- Browser UI → App Shell: rendered by · The browser experience is composed by app bootstrap and routing.
- App Shell → Home: routes to · Top-level navigation reaches the landing page.
- App Shell → Quiz: routes to · Routing exposes the quiz flow page.
- App Shell → Result: routes to · Routing exposes the result page.
- Quiz → Quiz Flow: uses · The quiz UI delegates interaction state to the flow hook.
- Quiz Flow → API Client: calls · The hook loads questions and submits answers through the API client.
- API Client → FastAPI API: HTTP JSON · Frontend communicates with the backend over the JSON API.
- FastAPI API → Questions Route: mounts · The FastAPI app exposes the questions route module.
- FastAPI API → Recommend Route: mounts · The FastAPI app exposes the recommendation route module.
- Questions Route → PostgreSQL: reads · Question retrieval is backed by persisted domain data.
- Questions Route → Seed Data: refreshes from · Question content is managed through curated seed files and import scripts.
- Recommend Route → Validation: validates · Incoming answers are checked before scoring.
- Recommend Route → Profile Builder: builds · Validated answers are turned into a preference profile.
- Profile Builder → Ranker: feeds · The profile is the input to rule-based scoring.
- Ranker → PostgreSQL: scores from · Ranking uses stored game, tag, and weight data.
- Ranker → Rerank: candidates to · Top candidates can be sent downstream for optional reranking.
- Rerank → LLM Layer: optional use · LLM reranking is an enhancer, not the primary path.
- Rerank → Reasons: improves · Reranking can also support better explanations.
- Reasons → LLM Layer: optional use · Reason generation can be assisted by the LLM layer.
- PostgreSQL → Seed Data: initialized by · Database contents are populated from offline seed JSON.
- Migrations → PostgreSQL: evolves · Alembic migrations maintain the schema over time.
- Result → API Client: reads results · Result UI loads recommendation payloads from the backend.
- Result → LLM Layer: shows diagnostics · Debug panels may expose optional model-related details.