# tien-le/agentic-rag-systems architecture

> Architecture diagram of the GitHub repository tien-le/agentic-rag-systems, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tien-le/agentic-rag-systems
- Repository: https://github.com/tien-le/agentic-rag-systems

## Overview

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: [`backend/app/api`](https://github.com/tien-le/agentic-rag-systems/tree/master/backend/app/api) (API), [`frontend/src/main.tsx`](https://github.com/tien-le/agentic-rag-systems/blob/master/frontend/src/main.tsx) (SPA), [`.github/workflows`](https://github.com/tien-le/agentic-rag-systems/blob/master/.github/workflows) (CI/CD), [`backend/app/crud.py`](https://github.com/tien-le/agentic-rag-systems/blob/master/backend/app/crud.py) (CRUD)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_backend["Backend"]
  node_node_backend_api["API"]
  node_node_backend_core["Core<br/>infrastructure"]
  node_node_backend_crud["CRUD<br/>domain logic<br/>[crud.py]"]
  node_node_backend_models["Models<br/>SQLModel entities<br/>[models.py]"]
  node_node_backend_email["Emails<br/>templates"]
  node_node_backend_migrations["Migrations<br/>Alembic"]
  node_node_backend_seed["Bootstrap data<br/>startup data<br/>[initial_data.py]"]
end

subgraph group_group_frontend["Frontend"]
  node_node_spa["SPA<br/>React/Vite app<br/>[main.tsx]"]
  node_node_routes["Routes<br/>navigation"]
  node_node_components["Features<br/>UI modules"]
  node_node_hooks["Hooks<br/>frontend logic"]
  node_node_client["API client<br/>generated OpenAPI"]
end

subgraph group_group_infra["Infra"]
  node_node_smtp["Mailcatcher/SMTP<br/>email service"]
  node_node_traefik{{"Traefik<br/>edge proxy"}}
  node_node_compose["Compose<br/>orchestration<br/>[compose.yml]"]
  node_node_ci["CI/CD<br/>GitHub Actions<br/>[workflows]"]
end

node_node_browser(("Browser<br/>client"))
node_node_db[("PostgreSQL<br/>database")]

node_node_browser -->|"uses"| node_node_spa
node_node_spa -->|"calls"| node_node_client
node_node_client -.->|"API contract"| node_node_backend_api
node_node_routes -->|"structures"| node_node_spa
node_node_components -->|"renders"| node_node_routes
node_node_hooks -->|"supports"| node_node_spa
node_node_backend_api -->|"depends on"| node_node_backend_core
node_node_backend_api -->|"uses"| node_node_backend_crud
node_node_backend_crud -->|"persists"| node_node_backend_models
node_node_backend_api -->|"sends"| node_node_backend_email
node_node_backend_crud -->|"stores"| node_node_db
node_node_backend_migrations -->|"migrates"| node_node_db
node_node_backend_seed -->|"bootstraps"| node_node_db
node_node_backend_api -->|"delivers"| node_node_smtp
node_node_compose -->|"runs"| node_node_backend_api
node_node_compose -->|"runs"| node_node_spa
node_node_traefik -->|"routes to"| node_node_spa
node_node_traefik -->|"routes to"| node_node_backend_api
node_node_ci -->|"tests"| node_node_backend_api
node_node_ci -->|"tests"| node_node_spa
node_node_ci -->|"checks"| node_node_compose

click node_node_spa "https://github.com/tien-le/agentic-rag-systems/blob/master/frontend/src/main.tsx"
click node_node_routes "https://github.com/tien-le/agentic-rag-systems/tree/master/frontend/src/routes"
click node_node_components "https://github.com/tien-le/agentic-rag-systems/tree/master/frontend/src/components"
click node_node_hooks "https://github.com/tien-le/agentic-rag-systems/tree/master/frontend/src/hooks"
click node_node_client "https://github.com/tien-le/agentic-rag-systems/tree/master/frontend/src/client"
click node_node_backend_api "https://github.com/tien-le/agentic-rag-systems/tree/master/backend/app/api"
click node_node_backend_core "https://github.com/tien-le/agentic-rag-systems/tree/master/backend/app/core"
click node_node_backend_crud "https://github.com/tien-le/agentic-rag-systems/blob/master/backend/app/crud.py"
click node_node_backend_models "https://github.com/tien-le/agentic-rag-systems/blob/master/backend/app/models.py"
click node_node_backend_email "https://github.com/tien-le/agentic-rag-systems/tree/master/backend/app/email-templates"
click node_node_backend_migrations "https://github.com/tien-le/agentic-rag-systems/tree/master/backend/app/alembic/versions"
click node_node_backend_seed "https://github.com/tien-le/agentic-rag-systems/blob/master/backend/app/initial_data.py"
click node_node_traefik "https://github.com/tien-le/agentic-rag-systems/blob/master/compose.traefik.yml"
click node_node_compose "https://github.com/tien-le/agentic-rag-systems/blob/master/compose.yml"
click node_node_ci "https://github.com/tien-le/agentic-rag-systems/blob/master/.github/workflows"

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_node_backend_api,node_node_backend_core,node_node_backend_crud,node_node_backend_models,node_node_backend_email,node_node_backend_migrations,node_node_backend_seed toneBlue
class node_node_spa,node_node_routes,node_node_components,node_node_hooks,node_node_client toneAmber
class node_node_smtp,node_node_traefik,node_node_compose,node_node_ci toneMint
class node_node_browser,node_node_db toneNeutral
```

## Components

### Backend

FastAPI service, data model, migrations, and email workflows.

- [API](https://github.com/tien-le/agentic-rag-systems/tree/master/backend/app/api): FastAPI service · HTTP boundary exposing auth, users, items, and private routes. · `backend/app/api`
- [Core](https://github.com/tien-le/agentic-rag-systems/tree/master/backend/app/core): infrastructure · Configuration, database session setup, and security utilities. · `backend/app/core`
- [CRUD](https://github.com/tien-le/agentic-rag-systems/blob/master/backend/app/crud.py): domain logic · Data access and business operations over application entities. · `backend/app/crud.py`
- [Models](https://github.com/tien-le/agentic-rag-systems/blob/master/backend/app/models.py): SQLModel entities · Persistent database entities and schema definitions. · `backend/app/models.py`
- [Emails](https://github.com/tien-le/agentic-rag-systems/tree/master/backend/app/email-templates): templates · Rendered account and password recovery email templates. · `backend/app/email-templates`
- [Migrations](https://github.com/tien-le/agentic-rag-systems/tree/master/backend/app/alembic/versions): Alembic · Schema evolution and versioned database migrations. · `backend/app/alembic/versions`
- [Bootstrap data](https://github.com/tien-le/agentic-rag-systems/blob/master/backend/app/initial_data.py): startup data · Initial data and first-user/bootstrap workflow. · `backend/app/initial_data.py`

### Frontend

React/Vite SPA, generated API client, and UI features.

- [SPA](https://github.com/tien-le/agentic-rag-systems/blob/master/frontend/src/main.tsx): React/Vite app · Frontend application shell and route-driven UI. · `frontend/src/main.tsx`
- [Routes](https://github.com/tien-le/agentic-rag-systems/tree/master/frontend/src/routes): navigation · Page-level routing and authenticated layouts. · `frontend/src/routes`
- [Features](https://github.com/tien-le/agentic-rag-systems/tree/master/frontend/src/components): UI modules · Domain components for admin, items, pending, and settings flows. · `frontend/src/components`
- [Hooks](https://github.com/tien-le/agentic-rag-systems/tree/master/frontend/src/hooks): frontend logic · Shared client behavior such as auth, toast, and mobile state. · `frontend/src/hooks`
- [API client](https://github.com/tien-le/agentic-rag-systems/tree/master/frontend/src/client): generated OpenAPI · Generated client and schema types used by the SPA. · `frontend/src/client`

### Infra

Local development, deployment, and supporting services.

- **Mailcatcher/SMTP**: email service · Local and deployment email delivery target for auth flows.
- [Traefik](https://github.com/tien-le/agentic-rag-systems/blob/master/compose.traefik.yml): edge proxy · Reverse proxy and routing layer in deployed environments. · `compose.traefik.yml`
- [Compose](https://github.com/tien-le/agentic-rag-systems/blob/master/compose.yml): orchestration · Local development and deployment composition layer. · `compose.yml`
- [CI/CD](https://github.com/tien-le/agentic-rag-systems/blob/master/.github/workflows): GitHub Actions · Testing and deployment workflows for backend, frontend, and compose. · `.github/workflows`

### Other components

- **Browser**: client · User entry point for the web app.
- **PostgreSQL**: database · Primary persistent store for application data.

## Connections

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