# asef69/ict_fest_hackathon_preliminary architecture

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

- Interactive diagram: https://gitdiagram.com/asef69/ict_fest_hackathon_preliminary
- Repository: https://github.com/asef69/ict_fest_hackathon_preliminary

## Overview

1. **Overall shape**
   - This is a single-process FastAPI REST API, containerized as one service on port 8000.
   - It uses SQLite as the only database, with SQLAlchemy as the persistence layer. There are no external DB or queue services in the architecture.

2. **Application entrypoint**
   - `app/main.py` is the assembly point: it creates the FastAPI app, mounts routers, installs error handling, and likely triggers database initialization on startup.
   - `app/config.py` centralizes runtime settings such as secrets and environment-driven configuration.

3. **HTTP boundary and routing**
   - The API is split by concern into routers under `app/routers/`: `auth`, `rooms`, `bookings`, `admin`, and `health`.
   - Each router is a thin HTTP adapter: it validates request payloads, calls domain/services code, and returns response schemas with the exact contract the README specifies.

4. **Authentication and session lifecycle**
   - `app/auth.py` implements JWT creation and verification for access and refresh tokens.
   - The token claims and lifecycle rules are part of the architecture: org, role, subject, token type, unique JTI, expiration, logout invalidation, and single-use refresh rotation.
   - Auth is not just identity; it also carries tenancy and authorization context into every protected request.

5. **Domain model and persistence**
   - `app/models.py` contains the SQLAlchemy entities for the core business objects: organizations, users, rooms, bookings, and refund-related records.
   - `app/database.py` owns the engine/session wiring and is the bridge between FastAPI request handling and SQLite transactions.
   - The data model is the source of truth for invariants like booking status, room ownership, and refund history.

6. **Core booking workflow**
   - Booking creation, listing, and cancellation live in `app/routers/bookings.py` and are backed by domain logic in `app/services/`.
   - The service layer enforces the important business rules: future-start validation, duration limits, no-overlap booking conflicts, per-user quota, and cancellation refund calculation.
   - This is also where concurrency-sensitive rules are enforced so the API remains correct under simultaneous requests.

7. **Rooms, stats, and admin reporting**
   - `app/routers/rooms.py` exposes room listing, availability, and live stats for the caller’s organization.
   - `app/routers/admin.py` exposes organization-wide reporting and export endpoints for admins only.
   - Supporting services such as `stats.py`, `export.py`, and `reference.py` suggest the architecture separates read-model/report generation from the main booking commands.

8. **Cross-cutting state and rate limiting**
   - `app/cache.py` and `app/services/ratelimit.py` indicate a shared state layer used for things like request throttling, token blacklisting, or other short-lived coordination data.
   - This layer is important because the contract requires concurrency-safe rate limiting, logout invalidation, and uniqueness guarantees that cannot rely on plain stateless request handling.

9. **Serialization and API contract**
   - `app/schemas.py` defines the request/response shapes, while `app/serializers.py` converts internal models into the exact JSON fields required by the contract.
   - This separation keeps business logic independent from wire format and ensures the API can preserve field names, ordering expectations, and nested response shapes.

10. **Error and validation boundary**
   - `app/errors.py` standardizes application-level failures into the required `{"detail": ..., "code": ...}` format.
   - Framework validation remains separate, so FastAPI’s default 422 responses are preserved for malformed inputs, while business-rule failures are mapped to the contract-specific codes.

11. **Time handling and business rules**
   - `app/timeutils.py` centralizes UTC parsing, normalization, and date/window calculations.
   - This matters because booking overlap, quota windows, availability, and reports all depend on consistent UTC semantics and date-boundary behavior.

12. **Testing and delivery**
   - `tests/` contains smoke and exhaustive contract tests, which suggests the repository is built around black-box API correctness rather than internal unit boundaries alone.
   - `Dockerfile` and `docker-compose.yml` provide the deployment envelope; the application is meant to boot cleanly with schema creation on first startup and no manual provisioning.

13. **Key architectural boundaries to draw**
   - External clients talk only to FastAPI routers.
   - Routers delegate to auth/persistence/service layers rather than embedding business logic.
   - SQLAlchemy/SQLite holds durable state; cache/state utilities handle short-lived coordination.
   - Organization scoping is enforced everywhere, so cross-tenant access is treated as non-existent or forbidden depending on the operation.

Main entry points: [`app/main.py`](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/main.py) (App entry), [`app/services/__init__.py`](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/services/__init__.py) (Booking logic), [`app/routers/auth.py`](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/routers/auth.py) (Auth API), [`app/routers/bookings.py`](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/routers/bookings.py) (Bookings API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application"]
  node_main["App entry<br/>FastAPI bootstrap<br/>[main.py]"]
  node_config["Config<br/>runtime settings<br/>[config.py]"]
  node_errors["Errors<br/>api failures<br/>[errors.py]"]
  node_auth{{"Auth<br/>JWT lifecycle<br/>[auth.py]"}}
  node_database[("DB bridge<br/>SQLAlchemy wiring<br/>[database.py]")]
  node_models[("Data model<br/>SQLAlchemy entities<br/>[models.py]")]
  node_schemas["Schemas<br/>request/response shapes<br/>[schemas.py]"]
  node_serializers["Serializers<br/>wire mapping<br/>[serializers.py]"]
  node_timeutils["Time utils<br/>UTC rules<br/>[timeutils.py]"]
  node_cache[("Cache<br/>shared state<br/>[cache.py]")]
  node_health_router["Health<br/>liveness route<br/>[health.py]"]
  node_auth_router["Auth API<br/>HTTP auth<br/>[auth.py]"]
  node_rooms_router["Rooms API<br/>HTTP rooms<br/>[rooms.py]"]
  node_bookings_router["Bookings API<br/>HTTP bookings<br/>[bookings.py]"]
  node_admin_router["Admin API<br/>HTTP admin<br/>[admin.py]"]
end

subgraph group_services["Services"]
  node_booking_services{{"Booking logic<br/>domain workflow<br/>[__init__.py]"}}
  node_stats["Stats<br/>read model<br/>[stats.py]"]
  node_exports["Exports<br/>report output<br/>[export.py]"]
  node_refunds["Refunds<br/>policy<br/>[refunds.py]"]
  node_reference["Reference data<br/>lookup helper<br/>[reference.py]"]
  node_ratelimit["Rate limit<br/>coordination<br/>[ratelimit.py]"]
  node_notifications["Notifications<br/>side effect<br/>[notifications.py]"]
end

subgraph group_infra["Delivery"]
  node_dockerfile["Dockerfile<br/>container build"]
  node_compose["Compose<br/>service runtime<br/>[docker-compose.yml]"]
end

subgraph group_tests["Tests"]
  node_smoke_tests["Smoke tests<br/>contract test<br/>[test_smoke.py]"]
  node_bugs_tests["Bug tests<br/>regression test"]
  node_exhaustive_tests["Exhaustive tests<br/>contract test<br/>[test_exhaustive.py]"]
end

node_main -->|"reads"| node_config
node_main -->|"installs"| node_errors
node_main -->|"initializes"| node_database
node_main -->|"mounts"| node_auth_router
node_main -->|"mounts"| node_rooms_router
node_main -->|"mounts"| node_bookings_router
node_main -->|"mounts"| node_admin_router
node_main -->|"mounts"| node_health_router
node_auth_router -->|"uses"| node_auth
node_auth_router -->|"validates"| node_schemas
node_auth_router -->|"raises"| node_errors
node_rooms_router -->|"reads"| node_models
node_rooms_router -->|"uses"| node_stats
node_bookings_router -->|"delegates"| node_booking_services
node_bookings_router -->|"validates"| node_schemas
node_bookings_router -->|"raises"| node_errors
node_admin_router -->|"uses"| node_stats
node_admin_router -->|"uses"| node_exports
node_booking_services -->|"writes"| node_models
node_booking_services -->|"transactions"| node_database
node_booking_services -->|"normalizes"| node_timeutils
node_booking_services -->|"calculates"| node_refunds
node_booking_services -->|"looks up"| node_reference
node_booking_services -->|"coordinates"| node_ratelimit
node_booking_services -->|"notifies"| node_notifications
node_models -->|"mapped by"| node_database
node_serializers -->|"formats"| node_models
node_schemas -->|"shapes"| node_serializers
node_auth -->|"invalidates"| node_cache
node_ratelimit -->|"stores"| node_cache
node_dockerfile -->|"starts"| node_main
node_compose -->|"runs"| node_dockerfile
node_smoke_tests -.->|"exercises"| node_main
node_bugs_tests -.->|"exercises"| node_main
node_exhaustive_tests -.->|"exercises"| node_main

click node_main "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/main.py"
click node_config "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/config.py"
click node_errors "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/errors.py"
click node_auth "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/auth.py"
click node_database "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/database.py"
click node_models "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/models.py"
click node_schemas "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/schemas.py"
click node_serializers "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/serializers.py"
click node_timeutils "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/timeutils.py"
click node_cache "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/cache.py"
click node_health_router "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/routers/health.py"
click node_auth_router "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/routers/auth.py"
click node_rooms_router "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/routers/rooms.py"
click node_bookings_router "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/routers/bookings.py"
click node_admin_router "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/routers/admin.py"
click node_booking_services "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/services/__init__.py"
click node_stats "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/services/stats.py"
click node_exports "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/services/export.py"
click node_refunds "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/services/refunds.py"
click node_reference "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/services/reference.py"
click node_ratelimit "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/services/ratelimit.py"
click node_notifications "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/services/notifications.py"
click node_dockerfile "https://github.com/asef69/ict_fest_hackathon_preliminary/tree/main/Dockerfile"
click node_compose "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/docker-compose.yml"
click node_smoke_tests "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/tests/test_smoke.py"
click node_bugs_tests "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/tests/test_first_six_bugs.py"
click node_exhaustive_tests "https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/tests/test_exhaustive.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_main,node_config,node_errors,node_auth,node_database,node_models,node_schemas,node_serializers,node_timeutils,node_cache,node_health_router,node_auth_router,node_rooms_router,node_bookings_router,node_admin_router toneBlue
class node_booking_services,node_stats,node_exports,node_refunds,node_reference,node_ratelimit,node_notifications toneAmber
class node_dockerfile,node_compose toneMint
class node_smoke_tests,node_bugs_tests,node_exhaustive_tests toneRose
```

## Components

### Application

FastAPI API, domain logic, persistence, and shared utilities.

- [App entry](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/main.py): FastAPI bootstrap · Creates the app, wires routers, installs handlers, and initializes startup behavior. · `app/main.py`
- [Config](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/config.py): runtime settings · Centralized environment-driven settings and secrets. · `app/config.py`
- [Errors](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/errors.py): api failures · Normalizes application failures into API error responses. · `app/errors.py`
- [Auth](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/auth.py): JWT lifecycle · Creates and verifies access and refresh tokens, including claims and invalidation rules. · `app/auth.py`
- [DB bridge](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/database.py): SQLAlchemy wiring · Engine and session setup between FastAPI and SQLite transactions. · `app/database.py`
- [Data model](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/models.py): SQLAlchemy entities · Core persistence model for organizations, users, rooms, bookings, and refunds. · `app/models.py`
- [Schemas](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/schemas.py): request/response shapes · Defines the API contract objects used at the HTTP boundary. · `app/schemas.py`
- [Serializers](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/serializers.py): wire mapping · Converts internal models into the exact JSON response format. · `app/serializers.py`
- [Time utils](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/timeutils.py): UTC rules · Shared parsing and date-window handling for booking and reporting semantics. · `app/timeutils.py`
- [Cache](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/cache.py): shared state · Short-lived coordination store for throttling and invalidation-style state. · `app/cache.py`
- [Health](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/routers/health.py): liveness route · Basic health boundary for the service. · `app/routers/health.py`
- [Auth API](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/routers/auth.py): HTTP auth · Login and session endpoints for token issuance and lifecycle control. · `app/routers/auth.py`
- [Rooms API](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/routers/rooms.py): HTTP rooms · Room listing, availability, and organization-scoped stats endpoints. · `app/routers/rooms.py`
- [Bookings API](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/routers/bookings.py): HTTP bookings · Booking creation, listing, cancellation, and conflict-sensitive request handling. · `app/routers/bookings.py`
- [Admin API](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/routers/admin.py): HTTP admin · Organization-wide reporting and export endpoints for privileged users. · `app/routers/admin.py`

### Services

Business workflows and supporting read-model helpers.

- [Booking logic](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/services/__init__.py): domain workflow · Enforces booking rules such as future starts, quotas, overlaps, and cancellations. · `app/services/__init__.py`
- [Stats](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/services/stats.py): read model · Computes live room and organization reporting views. · `app/services/stats.py`
- [Exports](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/services/export.py): report output · Builds exportable admin reporting data. · `app/services/export.py`
- [Refunds](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/services/refunds.py): policy · Calculates cancellation refund behavior and related records. · `app/services/refunds.py`
- [Reference data](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/services/reference.py): lookup helper · Supports shared reference lookups for business workflows. · `app/services/reference.py`
- [Rate limit](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/services/ratelimit.py): coordination · Concurrency-sensitive throttling and short-lived access control state. · `app/services/ratelimit.py`
- [Notifications](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/app/services/notifications.py): side effect · Represents outbound or asynchronous notification handling hooks. · `app/services/notifications.py`

### Delivery

Container and runtime packaging.

- [Dockerfile](https://github.com/asef69/ict_fest_hackathon_preliminary/tree/main/Dockerfile): container build · Builds the single service image. · `Dockerfile`
- [Compose](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/docker-compose.yml): service runtime · Defines the containerized runtime envelope and exposed port. · `docker-compose.yml`

### Tests

Black-box contract and regression coverage.

- [Smoke tests](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/tests/test_smoke.py): contract test · Basic black-box API coverage. · `tests/test_smoke.py`
- [Bug tests](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/tests/test_first_six_bugs.py): regression test · Focused regression coverage for previously found issues. · `tests/test_first_six_bugs.py`
- [Exhaustive tests](https://github.com/asef69/ict_fest_hackathon_preliminary/blob/main/tests/test_exhaustive.py): contract test · Broad API contract and behavior verification. · `tests/test_exhaustive.py`

## Connections

- App entry → Config: reads · Loads runtime settings and environment configuration.
- App entry → Errors: installs · Registers application-level error handling.
- App entry → DB bridge: initializes · Creates or opens the persistence layer on startup.
- App entry → Auth API: mounts · Attaches auth endpoints to the FastAPI app.
- App entry → Rooms API: mounts · Attaches room-related endpoints.
- App entry → Bookings API: mounts · Attaches booking endpoints.
- App entry → Admin API: mounts · Attaches admin endpoints.
- App entry → Health: mounts · Attaches liveness and readiness endpoints.
- Auth API → Auth: uses · Delegates token creation and verification.
- Auth API → Schemas: validates · Uses request and response shapes.
- Auth API → Errors: raises · Maps auth failures to API error responses.
- Rooms API → Data model: reads · Queries room and organization data.
- Rooms API → Stats: uses · Serves live availability and stats views.
- Bookings API → Booking logic: delegates · Hands off booking commands to domain workflow logic.
- Bookings API → Schemas: validates · Uses request and response shapes.
- Bookings API → Errors: raises · Turns business-rule failures into API errors.
- Admin API → Stats: uses · Builds organization-level reporting.
- Admin API → Exports: uses · Produces export endpoints.
- Booking logic → Data model: writes · Persists bookings, status changes, and refund-related records.
- Booking logic → DB bridge: transactions · Runs concurrency-sensitive booking work in database sessions.
- Booking logic → Time utils: normalizes · Applies UTC and window logic consistently.
- Booking logic → Refunds: calculates · Computes cancellation refund behavior.
- Booking logic → Reference data: looks up · Uses shared reference data for business rules.
- Booking logic → Rate limit: coordinates · Applies request throttling and coordination rules.
- Booking logic → Notifications: notifies · Triggers outbound side effects when needed.
- Data model → DB bridge: mapped by · SQLAlchemy entities are bound through the engine/session layer.
- Serializers → Data model: formats · Converts persisted objects into response payloads.
- Schemas → Serializers: shapes · Keeps wire format separate from internal models.
- Auth → Cache: invalidates · Uses short-lived state for logout and token lifecycle rules.
- Rate limit → Cache: stores · Uses shared state for throttling and coordination.
- Dockerfile → App entry: starts · Builds an image that runs the API service.
- Compose → Dockerfile: runs · Defines the containerized deployment envelope.
- Smoke tests → App entry: exercises · Hits the assembled API from the outside.
- Bug tests → App entry: exercises · Regression coverage against the public contract.
- Exhaustive tests → App entry: exercises · Validates the full API behavior surface.
