# alex-web-serious/timetable-v2-final architecture

> Architecture diagram of the GitHub repository alex-web-serious/timetable-v2-final, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alex-web-serious/timetable-v2-final
- Repository: https://github.com/alex-web-serious/timetable-v2-final

## Overview

#### Purpose and Runtime Shape
This repository is a full-stack college timetable generator. A React/Vite browser client collects scheduling parameters, calls a Python FastAPI service, and displays or exports a solver-produced timetable. The backend uses Google OR-Tools CP-SAT for constraint optimization and generates PDF/Excel artifacts.

#### Entry Points
- Backend HTTP application: `backend/app.py`
- Frontend browser bootstrap: `frontend/src/main.tsx`
- Main interactive UI and client-side state: `frontend/src/App.tsx`
- Backend launch is Uvicorn serving the FastAPI `app`; frontend launch is Vite serving `frontend/index.html`.

#### API and Request Boundary
`backend/app.py` is the service boundary: it enables browser access via CORS and exposes health, default-data, timetable generation, and PDF/Excel download endpoints. Request/response validation and API models are defined in `backend/schemas.py`. The frontend should treat this HTTP interface as the sole integration point with scheduling logic.

#### Scheduling Pipeline
`backend/generator.py` is the core domain engine. It receives validated university scheduling inputs, constructs a CP-SAT model, applies teacher/class/slot/capacity requirements, solves feasibility/conflict constraints, and returns a generated timetable or infeasibility feedback. It also owns rendering the solved result into PDF and Excel output, coupling export generation to the canonical schedule representation.

#### Stateful Result and Downloads
Generated schedules and exportable artifacts cross request boundaries through the in-memory result cache in `backend/app_state.py`. Generation writes the current result; download endpoints in `backend/app.py` retrieve it to produce or return PDF/Excel. This is process-local state: deployments with multiple workers/instances need shared storage or session/result identifiers to preserve download consistency.

#### Defaults and UI Configuration Flow
`backend/default_data.py` supplies fallback university configurations through the default-data endpoint. `frontend/src/App.tsx` loads or edits this configuration, maintains parameter-tuning tables, submits generation requests, then renders schedules, errors, and export actions. UI styling and responsive presentation are centered in `frontend/src/App.css` and `frontend/src/index.css`.

#### Material Dependencies and Infrastructure
Backend runtime: Python, FastAPI/Pydantic, Uvicorn, OR-Tools CP-SAT, Pandas, openpyxl, and ReportLab, declared in `backend/requirements.txt`. Frontend runtime: React 19, TypeScript, Vite, Tailwind CSS, and Lucide icons, declared in `frontend/package.json`. There are no indicated databases, queues, authentication providers, or external SaaS dependencies; solver execution, state, and exports are local to the backend process.

Main entry points: [`backend/app.py`](https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/app.py) (FastAPI application), [`backend/requirements.txt`](https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/requirements.txt) (Backend dependencies), [`frontend/src/App.tsx`](https://github.com/alex-web-serious/timetable-v2-final/blob/main/frontend/src/App.tsx) (Timetable UI), [`backend/generator.py`](https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/generator.py) (Scheduling engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Browser client"]
  node_vite["Vite bootstrap<br/>frontend entry<br/>[main.tsx]"]
  node_app_ui["Timetable UI<br/>React state and views<br/>[App.tsx]"]
  node_ui_styles["UI styling<br/>CSS<br/>[App.css]"]
  node_frontend_deps["Frontend dependencies<br/>browser build packages<br/>[package.json]"]
end

subgraph group_backend["Backend service"]
  node_api["FastAPI application<br/>HTTP API boundary<br/>[app.py]"]
  node_schemas["API schemas<br/>Pydantic models<br/>[schemas.py]"]
  node_defaults["Default configurations<br/>fallback data<br/>[default_data.py]"]
  node_generator{{"Scheduling engine<br/>CP-SAT pipeline<br/>[generator.py]"}}
  node_constraints["Constraint model<br/>teacher/class/slot/capacity rules<br/>[generator.py]"]
  node_solver{{"OR-Tools CP-SAT<br/>optimization solver<br/>[generator.py]"}}
  node_schedule["Canonical timetable<br/>solved schedule result<br/>[generator.py]"]
  node_result_cache[("In-memory result cache<br/>process-local state<br/>[app_state.py]")]
  node_exports["PDF and Excel rendering<br/>artifact generator<br/>[generator.py]"]
  node_backend_deps["Backend dependencies<br/>Python runtime packages<br/>[requirements.txt]"]
end

node_vite -->|"mounts"| node_app_ui
node_app_ui -->|"styles with"| node_ui_styles
node_app_ui -->|"HTTP requests"| node_api
node_frontend_deps -.->|"provides runtime"| node_vite
node_api -->|"validates"| node_schemas
node_api -->|"serves defaults"| node_defaults
node_api -->|"generates timetable"| node_generator
node_generator -->|"constructs"| node_constraints
node_constraints -->|"solves with"| node_solver
node_solver -->|"produces"| node_schedule
node_generator -->|"writes result"| node_result_cache
node_api -->|"retrieves for downloads"| node_result_cache
node_schedule -->|"renders to"| node_exports
node_api -->|"returns PDF/Excel"| node_exports
node_backend_deps -.->|"provides runtime"| node_api
node_backend_deps -.->|"provides OR-Tools"| node_solver
node_backend_deps -.->|"provides export libraries"| node_exports

click node_vite "https://github.com/alex-web-serious/timetable-v2-final/blob/main/frontend/src/main.tsx"
click node_app_ui "https://github.com/alex-web-serious/timetable-v2-final/blob/main/frontend/src/App.tsx"
click node_ui_styles "https://github.com/alex-web-serious/timetable-v2-final/blob/main/frontend/src/App.css"
click node_api "https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/app.py"
click node_schemas "https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/schemas.py"
click node_defaults "https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/default_data.py"
click node_generator "https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/generator.py"
click node_constraints "https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/generator.py"
click node_solver "https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/generator.py"
click node_schedule "https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/generator.py"
click node_result_cache "https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/app_state.py"
click node_exports "https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/generator.py"
click node_backend_deps "https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/requirements.txt"
click node_frontend_deps "https://github.com/alex-web-serious/timetable-v2-final/blob/main/frontend/package.json"

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_vite,node_app_ui,node_ui_styles,node_frontend_deps toneBlue
class node_api,node_schemas,node_defaults,node_generator,node_constraints,node_solver,node_schedule,node_result_cache,node_exports,node_backend_deps toneAmber
```

## Components

### Browser client

- [Vite bootstrap](https://github.com/alex-web-serious/timetable-v2-final/blob/main/frontend/src/main.tsx): frontend entry · `frontend/src/main.tsx`
- [Timetable UI](https://github.com/alex-web-serious/timetable-v2-final/blob/main/frontend/src/App.tsx): React state and views · Loads defaults, edits inputs, submits generation, and presents exports. · `frontend/src/App.tsx`
- [UI styling](https://github.com/alex-web-serious/timetable-v2-final/blob/main/frontend/src/App.css): CSS · `frontend/src/App.css`
- [Frontend dependencies](https://github.com/alex-web-serious/timetable-v2-final/blob/main/frontend/package.json): browser build packages · React, TypeScript, Vite, Tailwind, and Lucide. · `frontend/package.json`

### Backend service

- [FastAPI application](https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/app.py): HTTP API boundary · CORS-enabled health, defaults, generation, and download endpoints. · `backend/app.py`
- [API schemas](https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/schemas.py): Pydantic models · Validates scheduling requests and responses. · `backend/schemas.py`
- [Default configurations](https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/default_data.py): fallback data · `backend/default_data.py`
- [Scheduling engine](https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/generator.py): CP-SAT pipeline · Builds constraints, solves schedules, and reports infeasibility. · `backend/generator.py`
- [Constraint model](https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/generator.py): teacher/class/slot/capacity rules · `backend/generator.py`
- [OR-Tools CP-SAT](https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/generator.py): optimization solver · `backend/generator.py`
- [Canonical timetable](https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/generator.py): solved schedule result · `backend/generator.py`
- [In-memory result cache](https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/app_state.py): process-local state · Stores the current result across generation and download requests. · `backend/app_state.py`
- [PDF and Excel rendering](https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/generator.py): artifact generator · Renders the canonical schedule using ReportLab and Pandas/openpyxl. · `backend/generator.py`
- [Backend dependencies](https://github.com/alex-web-serious/timetable-v2-final/blob/main/backend/requirements.txt): Python runtime packages · FastAPI, Uvicorn, OR-Tools, Pandas, openpyxl, and ReportLab. · `backend/requirements.txt`

## Connections

- Vite bootstrap → Timetable UI: mounts
- Timetable UI → UI styling: styles with
- Timetable UI → FastAPI application: HTTP requests · Sole client integration with scheduling logic.
- Frontend dependencies → Vite bootstrap: provides runtime
- FastAPI application → API schemas: validates
- FastAPI application → Default configurations: serves defaults
- FastAPI application → Scheduling engine: generates timetable
- Scheduling engine → Constraint model: constructs
- Constraint model → OR-Tools CP-SAT: solves with
- OR-Tools CP-SAT → Canonical timetable: produces
- Scheduling engine → In-memory result cache: writes result
- FastAPI application → In-memory result cache: retrieves for downloads
- Canonical timetable → PDF and Excel rendering: renders to
- FastAPI application → PDF and Excel rendering: returns PDF/Excel
- Backend dependencies → FastAPI application: provides runtime
- Backend dependencies → OR-Tools CP-SAT: provides OR-Tools
- Backend dependencies → PDF and Excel rendering: provides export libraries
