How tien-le/agentic-rag-systems works
1. Overall shape
- This repository is a full-stack application template with two independently built runtimes: a Python backend and a React frontend.
- The main runtime path is: browser → frontend SPA → generated API client → FastAPI backend → PostgreSQL database.
- Supporting services in local/dev/deploy setups include Traefik for HTTP routing, Mailcatcher/SMTP for email flows, and Docker Compose for orchestration.
2. Backend boundary
- The backend lives under backend/app and is a FastAPI service.
- It exposes HTTP API routes, owns authentication/authorization, database access, business logic, and email-triggered workflows.
- The backend is also the source of the OpenAPI schema that the frontend client is generated from.
3. Backend internal layers
- core/ contains app-wide infrastructure concerns: configuration, database session setup, and security utilities.
- models.py defines the SQLModel database entities.
- crud.py contains data access and business operations.
- api/ contains the route layer, split by domain (login, users, items, private) plus shared dependencies and route helpers.
- This separation makes the backend flow: request parsing → dependency injection → CRUD/service logic → persistence.
4. Authentication and user flows
- Authentication is JWT-based, with password hashing handled in the backend security layer.
- The key user flows are login, signup/admin user management, password recovery, password reset, and account deletion.
- Email is part of the auth boundary: the backend renders and sends account and reset-password emails using templates under backend/app/email-templates.
5. Database and schema management
- PostgreSQL is the persistent store.
- Alembic migrations under backend/app/alembic/versions manage schema evolution.
- Startup scripts and pre-start hooks indicate the app expects database readiness and migration state to be handled during container boot or deployment.
- Initial/bootstrap data is handled separately in initial_data.py, which suggests a first-user/bootstrap workflow.
6. Frontend boundary
- The frontend lives under frontend/ and is a React + TypeScript SPA built with Vite.
- It is organized around routes, reusable components, hooks, and generated API client code.
- The frontend does not directly talk to the database or own business rules; it consumes the backend API and renders application state.
7. Frontend data access
- frontend/src/client/ contains generated OpenAPI client code and schema/type definitions.
- scripts/generate-client.sh and frontend/openapi-ts.config.ts indicate the client is regenerated from backend API definitions.
- This creates a clear contract boundary: backend changes API schema, frontend code is regenerated to stay in sync.
8. Frontend UI structure
- routes/ defines the page-level navigation, including auth pages and the authenticated layout.
- components/ is split into domain areas such as Admin, Items, Pending approvals, Sidebar, and UserSettings, plus shared UI primitives under components/ui.
- Hooks such as useAuth, useCustomToast, and useMobile encapsulate cross-cutting frontend behavior like auth state, notifications, and responsiveness.
9. User-facing feature domains
- The app appears to center on an authenticated dashboard with:
- admin user management,
- item CRUD,
- pending items/users review,
- user settings and password/account management.
- The route structure and component folders suggest role-aware sections, with authenticated layouts and admin-only views separated from public auth pages.
10. Operational and deployment topology
- Docker Compose is the main deployment and local-development composition mechanism.
- compose.yml, compose.override.yml, and compose.traefik.yml indicate separate concerns for base stack, local overrides, and reverse-proxy/HTTPS routing.
- Backend and frontend each have their own Dockerfiles and runtime configs, which reinforces their independent build/deploy boundaries.
11. External services and local dev support
- Mailcatcher is used for local email testing, so recovery/signup emails can be observed without real SMTP infrastructure.
- Traefik acts as the edge proxy/load balancer in deployment scenarios.
- Sentry is optionally supported through configuration, so error reporting is an external integration rather than a core subsystem.
12. Testing and quality gates
- Backend tests are Pytest-based and cover routes, CRUD, and startup scripts.
- Frontend end-to-end tests use Playwright and exercise major user flows like login, sign-up, password reset, item management, and admin settings.
- GitHub Actions workflows cover backend tests, Docker Compose tests, Playwright, pre-commit checks, and staged/prod deployment pipelines.
13. What to draw in an architecture diagram
- Show two primary application boxes: “React/Vite SPA” and “FastAPI API”.
- Between them, draw an API contract/client generation link rather than a hand-written integration.
- Behind the backend, show PostgreSQL as the system of record and Alembic as the schema migration path.
- Add SMTP/Mailcatcher as a side channel from the backend for account and recovery emails.
- Place Traefik in front of both frontend and backend in deployed environments, with Docker Compose as the composition layer.
Main entry points: api API · main.tsx SPA · workflows CI/CD · crud.py CRUD
Components 18
Backend
FastAPI service, data model, migrations, and email workflows.
- API · HTTP boundary exposing auth, users, items, and private routes.
backend/app/api - Core · Configuration, database session setup, and security utilities.
backend/app/core - CRUD · Data access and business operations over application entities.
backend/app/crud.py - Models · Persistent database entities and schema definitions.
backend/app/models.py - Emails · Rendered account and password recovery email templates.
backend/app/email-templates - Migrations · Schema evolution and versioned database migrations.
backend/app/alembic/versions - Bootstrap data · Initial data and first-user/bootstrap workflow.
backend/app/initial_data.py
Frontend
React/Vite SPA, generated API client, and UI features.
- SPA · Frontend application shell and route-driven UI.
frontend/src/main.tsx - Routes · Page-level routing and authenticated layouts.
frontend/src/routes - Features · Domain components for admin, items, pending, and settings flows.
frontend/src/components - Hooks · Shared client behavior such as auth, toast, and mobile state.
frontend/src/hooks - API client · Generated client and schema types used by the SPA.
frontend/src/client
Infra
Local development, deployment, and supporting services.
- Mailcatcher/SMTP · Local and deployment email delivery target for auth flows.
- Traefik · Reverse proxy and routing layer in deployed environments.
compose.traefik.yml - Compose · Local development and deployment composition layer.
compose.yml - CI/CD · Testing and deployment workflows for backend, frontend, and compose.
.github/workflows
Other components
- Browser · User entry point for the web app.
- PostgreSQL · Primary persistent store for application data.
Connections 21
- Browser → SPA: uses · Users interact with the SPA in the browser.
- SPA → API client: calls · Frontend requests are made through generated API bindings.
- API client → API: API contract · Client is generated from backend OpenAPI schema.
- Routes → SPA: structures · Routes define top-level navigation and layouts.
- Features → Routes: renders · Feature components are mounted within routed pages.
- Hooks → SPA: supports · Shared hooks provide cross-cutting UI behavior.
- API → Core: depends on · Route handlers use configuration, db, and security helpers.
- API → CRUD: uses · API handlers delegate business operations to CRUD layer.
- CRUD → Models: persists · CRUD operates over SQLModel entities.
- API → Emails: sends · Auth and recovery flows trigger email templates.
- CRUD → PostgreSQL: stores · Application data is written to PostgreSQL.
- Migrations → PostgreSQL: migrates · Alembic versions evolve the database schema.
- Bootstrap data → PostgreSQL: bootstraps · Initial data is loaded during startup.
- API → Mailcatcher/SMTP: delivers · Backend sends account and recovery emails via SMTP.
- Compose → API: runs · Compose orchestrates the backend service.
- Compose → SPA: runs · Compose orchestrates the frontend service.
- Traefik → SPA: routes to · Edge proxy forwards browser traffic to the SPA.
- Traefik → API: routes to · Edge proxy forwards API traffic to the backend.
- CI/CD → API: tests · Backend tests and deployment workflows validate the API.
- CI/CD → SPA: tests · Playwright and frontend workflows validate the SPA.
- CI/CD → Compose: checks · Compose-based integration workflows validate the stack.