How alex-web-serious/timetable-v2-final works
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: app.py FastAPI application · requirements.txt Backend dependencies · App.tsx Timetable UI · generator.py Scheduling engine
Components 14
Browser client
- Vite bootstrap
frontend/src/main.tsx - Timetable UI · Loads defaults, edits inputs, submits generation, and presents exports.
frontend/src/App.tsx - UI styling
frontend/src/App.css - Frontend dependencies · React, TypeScript, Vite, Tailwind, and Lucide.
frontend/package.json
Backend service
- FastAPI application · CORS-enabled health, defaults, generation, and download endpoints.
backend/app.py - API schemas · Validates scheduling requests and responses.
backend/schemas.py - Default configurations
backend/default_data.py - Scheduling engine · Builds constraints, solves schedules, and reports infeasibility.
backend/generator.py - Constraint model
backend/generator.py - OR-Tools CP-SAT
backend/generator.py - Canonical timetable
backend/generator.py - In-memory result cache · Stores the current result across generation and download requests.
backend/app_state.py - PDF and Excel rendering · Renders the canonical schedule using ReportLab and Pandas/openpyxl.
backend/generator.py - Backend dependencies · FastAPI, Uvicorn, OR-Tools, Pandas, openpyxl, and ReportLab.
backend/requirements.txt
Connections 17
- 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