# purnasai1807-lgtm/college_project architecture

> Architecture diagram of the GitHub repository purnasai1807-lgtm/college_project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/purnasai1807-lgtm/college_project
- Repository: https://github.com/purnasai1807-lgtm/college_project

## Overview

#### Purpose and principal workflow
ACE Canteen is a mobile-first ordering and operations application for a college canteen. A student initiates the main workflow through the browser app: browse the catalogue, submit an order, track its status, and present a signed pickup link; staff manage the order queue and confirm collection. Admins operate catalogue, inventory, users, and reports. The backend is a FastAPI application that serves the web app and API, while relational state is stored through SQLAlchemy.

#### Components

##### Browser experience
- **Canteen web app** — `frontend/js/app.js`: Main browser client for student, staff, and admin workflows; the README documents those role-specific capabilities.
- **QR pickup page** — `frontend/js/pickup.js`: Handles the mobile-friendly public pickup view; the README describes its limited order details and token submission behavior.
- **Installable app shell** — `frontend/sw.js`: Service worker for the web app; the backend serves it at the origin root, as shown in `backend/app/main.py`.

##### HTTP application and domain workflows
- **FastAPI entry point and page/API host** — `backend/app/main.py`: Defines the application’s HTTP routes, serves the web app and pickup page, and implements API behavior. The excerpt shows page routes and API handlers for authentication, catalogue, inventory, notifications, and canteen status.
- **Identity and role authorization** — `backend/app/security.py`: Hashes and verifies passwords, issues and validates signed bearer tokens, and enforces role requirements for protected routes.
- **Catalogue and category operations** — `backend/app/main.py`: Implements product and category administration and the catalogue-facing API; the excerpt shows product validation and category updates.
- **Order, payment-gated lifecycle, and pickup** — `backend/app/main.py`: Implements order payload and lifecycle behavior; the excerpt identifies checkout, payment-gated order handling, pickup tokens, and staff/admin queue as API responsibilities.
- **Inventory, suppliers, and stock movements** — `backend/app/main.py`: Implements inventory operations, stock thresholds, purchase-order inputs, and stock movement/audit behavior; the README documents batches, suppliers, expiry, and inventory management.
- **Operational reporting and audit history** — `backend/app/main.py`: Implements admin reports and audit routes; the excerpt explicitly marks the reporting and immutable audit-history phase.
- **Request/response contracts** — `backend/app/schemas.py`: Defines validated API inputs and outputs for users, products, orders, and stock adjustments.

##### Persistence and supporting application behavior
- **Relational domain state** — `backend/app/models.py`: Defines SQLAlchemy entities and relationships for users, products, orders, payments, settings, and inventory movements.
- **Database session layer** — `backend/app/database.py`: Creates the SQLite/PostgreSQL-compatible engine and session factory and exposes the request-scoped database dependency.
- **Environment and operational settings** — `backend/app/config.py`: Loads and validates database, security, payment, email, canteen-hours, and pickup-slot settings.
- **Email delivery** — `backend/app/emailer.py`: Provides the application’s email capability; the README documents password-reset and order-ready email behavior, while the excerpted source index shows this module depends on configuration.
- **Development data seeding** — `backend/app/seed.py`: Idempotently creates demo categories, products, and initial inventory movements for local development.
- **Administrator bootstrap** — `backend/app/create_admin.py`: Provides the documented command-line path for creating the first administrator.

##### External actors and systems
- **Student** — null repository path: External user who browses, orders, and checks their order or pickup status.
- **Staff** — null repository path: External user who manages the queue and confirms collection.
- **Admin** — null repository path: External user who manages products, inventory, users, and reports.
- **Phone camera / browser** — null repository path: Opens the HTTPS pickup link from a QR code, as documented in the README.
- **Database** — null repository path: SQLite or PostgreSQL configured through `DATABASE_URL`; stores the application’s relational state.

#### Relationships
- Student -> Canteen web app: initiates browsing and ordering; evidence: `README.md`.
- Staff -> Canteen web app: initiates queue and pickup workflows; evidence: `README.md`.
- Admin -> Canteen web app: initiates administration and reporting workflows; evidence: `README.md`.
- Phone camera / browser -> QR pickup page: opens the QR link; evidence: `README.md`.
- Canteen web app -> FastAPI entry point and page/API host: uses the application’s HTTP interface; evidence: `README.md` (API use is documented, but the client request implementation is not shown in the excerpts).
- FastAPI entry point and page/API host -> Canteen web app: serves the application home page; evidence: `backend/app/main.py` (excerpt).
- FastAPI entry point and page/API host -> QR pickup page: serves the pickup page; evidence: `backend/app/main.py` (excerpt).
- FastAPI entry point and page/API host -> Identity and role authorization: uses authentication and authorization dependencies; evidence: `backend/app/main.py` (SOURCE INDEX).
- Identity and role authorization -> Database session layer: obtains database access for current-user lookup; evidence: `backend/app/security.py` (excerpt).
- FastAPI entry point and page/API host -> Relational domain state: queries and mutates domain records; evidence: `backend/app/main.py` (SOURCE INDEX).
- FastAPI entry point and page/API host -> Request/response contracts: imports and uses API schemas; evidence: `backend/app/main.py` (SOURCE INDEX).
- Database session layer -> Environment and operational settings: configures the database URL; evidence: `backend/app/database.py` (excerpt).
- Relational domain state -> Database session layer: derives its ORM base from the database module; evidence: `backend/app/models.py` (SOURCE INDEX).
- FastAPI entry point and page/API host -> Email delivery: uses email functionality; evidence: `backend/app/main.py` (SOURCE INDEX).
- Email delivery -> Environment and operational settings: reads application settings; evidence: `backend/app/emailer.py` (SOURCE INDEX).
- FastAPI entry point and page/API host -> Database: persists and reads application state through the session layer; evidence: `backend/app/main.py` (SOURCE INDEX and `backend/app/database.py` excerpt).

#### Coverage limits
The sampled primary `main.py` excerpt omits most route implementations, so finer-grained order/payment/pickup sequencing and provider calls cannot be established. The README documents payment and QR behavior, but no concrete payment-provider call site is shown. Frontend files were read but their contents were not excerpted; detailed client-to-route wiring is therefore not asserted beyond documented behavior. The tree also contains numbered duplicate filenames; their relationship to the primary files is unclear, so this map describes the primary paths.

Main entry points: [`backend/app/main.py`](https://github.com/purnasai1807-lgtm/college_project/blob/main/backend/app/main.py) (FastAPI host), [`frontend/js/app.js`](https://github.com/purnasai1807-lgtm/college_project/blob/main/frontend/js/app.js) (Canteen web app), [`backend/app/database.py`](https://github.com/purnasai1807-lgtm/college_project/blob/main/backend/app/database.py) (Database session layer), [`backend/app/security.py`](https://github.com/purnasai1807-lgtm/college_project/blob/main/backend/app/security.py) (Identity and authorization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_actors["External actors"]
  node_student["Student<br/>External user"]
  node_staff["Staff<br/>External user"]
  node_admin["Admin<br/>External user"]
  node_phone["Phone camera / browser<br/>External client"]
  node_database[("Database")]
end

subgraph group_browser["Browser experience"]
  node_webapp["Canteen web app<br/>Browser client"]
  node_pickup["QR pickup page<br/>Browser page"]
end

subgraph group_http["HTTP application"]
  node_api["FastAPI host<br/>HTTP application"]
  node_security["Identity and authorization<br/>Security"]
  node_schemas["API contracts<br/>Validation schemas"]
end

subgraph group_persistence["Persistence and support"]
  node_models["Relational domain state<br/>ORM models"]
  node_sessions["Database session layer<br/>Database access"]
  node_settings["Operational settings<br/>Configuration"]
  node_emailer["Email delivery<br/>Email service"]
end

node_student -->|"Browse and order"| node_webapp
node_staff -->|"Manage queue"| node_webapp
node_admin -->|"Manage operations"| node_webapp
node_phone -->|"Open pickup link"| node_pickup
node_webapp -->|"Use HTTP API"| node_api
node_api -->|"Serve home page"| node_webapp
node_api -->|"Serve pickup page"| node_pickup
node_api -->|"Use authorization"| node_security
node_security -->|"Access user data"| node_sessions
node_api -->|"Query and mutate"| node_models
node_api -->|"Use contracts"| node_schemas
node_sessions -->|"Read database URL"| node_settings
node_models -->|"Derive ORM base"| node_sessions
node_api -->|"Send email"| node_emailer
node_emailer -->|"Read settings"| node_settings
node_api -->|"Persist and read"| node_database

click node_webapp "https://github.com/purnasai1807-lgtm/college_project/blob/main/frontend/js/app.js"
click node_pickup "https://github.com/purnasai1807-lgtm/college_project/blob/main/frontend/js/pickup.js"
click node_api "https://github.com/purnasai1807-lgtm/college_project/blob/main/backend/app/main.py"
click node_security "https://github.com/purnasai1807-lgtm/college_project/blob/main/backend/app/security.py"
click node_schemas "https://github.com/purnasai1807-lgtm/college_project/blob/main/backend/app/schemas.py"
click node_models "https://github.com/purnasai1807-lgtm/college_project/blob/main/backend/app/models.py"
click node_sessions "https://github.com/purnasai1807-lgtm/college_project/blob/main/backend/app/database.py"
click node_settings "https://github.com/purnasai1807-lgtm/college_project/blob/main/backend/app/config.py"
click node_emailer "https://github.com/purnasai1807-lgtm/college_project/blob/main/backend/app/emailer.py"

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_student,node_staff,node_admin,node_phone,node_database toneBlue
class node_webapp,node_pickup toneAmber
class node_api,node_security,node_schemas toneMint
class node_models,node_sessions,node_settings,node_emailer toneRose
```

## Components

### External actors

- **Student**: External user
- **Staff**: External user
- **Admin**: External user
- **Phone camera / browser**: External client
- **Database**: Relational database · SQLite or PostgreSQL configured through DATABASE_URL.

### Browser experience

- [Canteen web app](https://github.com/purnasai1807-lgtm/college_project/blob/main/frontend/js/app.js): Browser client · Supports student ordering, staff queue and pickup workflows, and admin operations and reporting. · `frontend/js/app.js`
- [QR pickup page](https://github.com/purnasai1807-lgtm/college_project/blob/main/frontend/js/pickup.js): Browser page · Public mobile-friendly pickup view accepts a token and shows limited order details. · `frontend/js/pickup.js`

### HTTP application

- [FastAPI host](https://github.com/purnasai1807-lgtm/college_project/blob/main/backend/app/main.py): HTTP application · Hosts pages and APIs for authentication, catalogue, order and payment-gated lifecycle, pickup, inventory, and reporting. · `backend/app/main.py`
- [Identity and authorization](https://github.com/purnasai1807-lgtm/college_project/blob/main/backend/app/security.py): Security · `backend/app/security.py`
- [API contracts](https://github.com/purnasai1807-lgtm/college_project/blob/main/backend/app/schemas.py): Validation schemas · `backend/app/schemas.py`

### Persistence and support

- [Relational domain state](https://github.com/purnasai1807-lgtm/college_project/blob/main/backend/app/models.py): ORM models · Defines users, products, orders, payments, settings, and inventory movements. · `backend/app/models.py`
- [Database session layer](https://github.com/purnasai1807-lgtm/college_project/blob/main/backend/app/database.py): Database access · Creates the engine and session factory and exposes request-scoped database access. · `backend/app/database.py`
- [Operational settings](https://github.com/purnasai1807-lgtm/college_project/blob/main/backend/app/config.py): Configuration · `backend/app/config.py`
- [Email delivery](https://github.com/purnasai1807-lgtm/college_project/blob/main/backend/app/emailer.py): Email service · Supports documented password-reset and order-ready email behavior. · `backend/app/emailer.py`

## Connections

- Student → Canteen web app: Browse and order (evidence: `README.md`)
- Staff → Canteen web app: Manage queue (evidence: `README.md`)
- Admin → Canteen web app: Manage operations (evidence: `README.md`)
- Phone camera / browser → QR pickup page: Open pickup link (evidence: `README.md`)
- Canteen web app → FastAPI host: Use HTTP API · API use is documented; client request implementation is not shown in the excerpts. (evidence: `README.md`)
- FastAPI host → Canteen web app: Serve home page (evidence: `backend/app/main.py`)
- FastAPI host → QR pickup page: Serve pickup page (evidence: `backend/app/main.py`)
- FastAPI host → Identity and authorization: Use authorization (evidence: `backend/app/main.py`)
- Identity and authorization → Database session layer: Access user data (evidence: `backend/app/security.py`)
- FastAPI host → Relational domain state: Query and mutate (evidence: `backend/app/main.py`)
- FastAPI host → API contracts: Use contracts (evidence: `backend/app/main.py`)
- Database session layer → Operational settings: Read database URL (evidence: `backend/app/database.py`)
- Relational domain state → Database session layer: Derive ORM base (evidence: `backend/app/models.py`)
- FastAPI host → Email delivery: Send email (evidence: `backend/app/main.py`)
- Email delivery → Operational settings: Read settings (evidence: `backend/app/emailer.py`)
- FastAPI host → Database: Persist and read · Accesses application state through the session layer. (evidence: `backend/app/main.py`)
