How asef69/ict_fest_hackathon_preliminary works
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: main.py App entry · __init__.py Booking logic · auth.py Auth API · bookings.py Bookings API
Components 27
Application
FastAPI API, domain logic, persistence, and shared utilities.
- App entry · Creates the app, wires routers, installs handlers, and initializes startup behavior.
app/main.py - Config · Centralized environment-driven settings and secrets.
app/config.py - Errors · Normalizes application failures into API error responses.
app/errors.py - Auth · Creates and verifies access and refresh tokens, including claims and invalidation rules.
app/auth.py - DB bridge · Engine and session setup between FastAPI and SQLite transactions.
app/database.py - Data model · Core persistence model for organizations, users, rooms, bookings, and refunds.
app/models.py - Schemas · Defines the API contract objects used at the HTTP boundary.
app/schemas.py - Serializers · Converts internal models into the exact JSON response format.
app/serializers.py - Time utils · Shared parsing and date-window handling for booking and reporting semantics.
app/timeutils.py - Cache · Short-lived coordination store for throttling and invalidation-style state.
app/cache.py - Health · Basic health boundary for the service.
app/routers/health.py - Auth API · Login and session endpoints for token issuance and lifecycle control.
app/routers/auth.py - Rooms API · Room listing, availability, and organization-scoped stats endpoints.
app/routers/rooms.py - Bookings API · Booking creation, listing, cancellation, and conflict-sensitive request handling.
app/routers/bookings.py - Admin API · Organization-wide reporting and export endpoints for privileged users.
app/routers/admin.py
Services
Business workflows and supporting read-model helpers.
- Booking logic · Enforces booking rules such as future starts, quotas, overlaps, and cancellations.
app/services/__init__.py - Stats · Computes live room and organization reporting views.
app/services/stats.py - Exports · Builds exportable admin reporting data.
app/services/export.py - Refunds · Calculates cancellation refund behavior and related records.
app/services/refunds.py - Reference data · Supports shared reference lookups for business workflows.
app/services/reference.py - Rate limit · Concurrency-sensitive throttling and short-lived access control state.
app/services/ratelimit.py - Notifications · Represents outbound or asynchronous notification handling hooks.
app/services/notifications.py
Delivery
Container and runtime packaging.
- Dockerfile · Builds the single service image.
Dockerfile - Compose · Defines the containerized runtime envelope and exposed port.
docker-compose.yml
Tests
Black-box contract and regression coverage.
- Smoke tests · Basic black-box API coverage.
tests/test_smoke.py - Bug tests · Focused regression coverage for previously found issues.
tests/test_first_six_bugs.py - Exhaustive tests · Broad API contract and behavior verification.
tests/test_exhaustive.py
Connections 35
- 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.