How arjun-bhattarai/fleet-pulse works
1. System shape: This is a backend-only FastAPI application for a public-transport demand signaling platform. The architecture is layered: HTTP routes at the edge, service modules for business rules, SQL-backed models for persistence, and shared core modules for auth/config/database concerns.
2. Application entrypoint: app/main.py is the FastAPI bootstrap and router composition point. It is the place where the API surface is assembled from the route modules under app/routes/.
3. API boundary / route grouping: The route files are split by concern rather than by CRUD boilerplate: auth, signal_route, matching_route, driver_location_route, admin_route, role_change, tracking, and vehicles. That suggests separate endpoint groups for login/session handling, user demand signals, driver-facing demand views, admin operations, and transport/role management.
4. Auth and security subsystem: app/core/security.py handles JWT creation/verification and password hashing with bcrypt. app/core/dependency.py likely centralizes FastAPI dependencies for authentication, current-user lookup, and RBAC checks. The README confirms access/refresh tokens and ownership checks for update/delete operations.
5. Redis-backed session invalidation: app/core/redis.py provides the Redis integration used for token blocklisting/logout support. This is an important architectural boundary because authentication is not purely stateless: Redis acts as the revocation store for JWTs.
6. Persistence layer: app/core/db.py is the database connection layer, and the README says the app uses async PostgreSQL with SQLModel. The domain data appears centered on at least user and signal models, with migrations indicating additional persisted concepts like driver locations and message/timestamp schema changes.
7. Domain models and schemas: app/models/ contains the persistence entities, while app/schemas/ contains Pydantic request/response contracts. This separation indicates the API does not expose database objects directly; route handlers translate between external payloads and internal models through schemas.
8. Business logic layer: app/services/ is where the core use cases live. The presence of signal.py, matching_service.py, and driver_location_service.py suggests the main domain operations are: record passenger demand, analyze or match demand to transport supply, and manage driver position data. service.py looks like a base/shared service abstraction.
9. Geo/location support: app/utility/location.py likely contains reusable coordinate or distance helpers used by matching and driver-location features. This is the main place where transport-domain spatial logic would sit outside the service layer.
10. Data flow for the main use case: A user sends a demand signal with latitude/longitude and passenger count through the signal route. The route validates input with schemas, applies auth/RBAC dependencies, then calls the signal service, which persists to PostgreSQL. Drivers and admins read those signals through their respective routes, while matching logic can aggregate or rank demand hotspots for routing decisions.
11. Operational/admin concerns: The extra route modules (admin_route, role_change, tracking, vehicles) indicate the system also manages user roles and transport operations, not just signal submission. These likely sit on top of the same core auth/database layers, with stricter dependencies for admin-only access.
12. Database evolution: The alembic/ directory is a first-class part of the architecture. The migration history shows the data model has evolved over time, including initial tables, name fields, a driver-location table, a message entity, and timestamp timezone fixes. That means schema evolution is managed explicitly rather than ad hoc.
13. Deployment/runtime boundary: The app runs as a standard ASGI service via uvicorn app.main:app --reload. There are no signs of a separate worker tier or frontend in this repo, so the main runtime boundary is the FastAPI server talking to PostgreSQL and Redis.
14. High-level dependency direction: The dependency flow is one-way: routes depend on schemas, dependencies, and services; services depend on models, DB, Redis, and utility helpers; core modules provide cross-cutting infrastructure. This makes the system easy to diagram as a clean layered backend with shared auth and persistence services underneath the transport-domain API.
Main entry points: dependency.py Dependencies · main.py App · db.py DB · signal.py Signals
Components 23
API layer
FastAPI entrypoint and HTTP route modules.
- App · Assembles the ASGI app and mounts routers.
app/main.py - Auth · Login, token, and session endpoints.
app/routes/auth.py - Signals · Passenger demand submission and retrieval endpoints.
app/routes/signal_route.py - Matching · Endpoints for demand matching and ranking.
app/routes/matching_route.py - Drivers · Driver location and availability endpoints.
app/routes/driver_location_route.py - Admin · Administrative control endpoints.
app/routes/admin_route.py - Roles · Role change and permission management endpoints.
app/routes/role_change.py - Tracking · Operational tracking endpoints.
app/routes/tracking.py - Vehicles · Vehicle-related operational endpoints.
app/routes/vehicles.py
Core infra
Shared auth, database, Redis, and dependency wiring.
- Security · Password hashing and token creation/verification.
app/core/security.py - Dependencies · Shared FastAPI dependencies for current user and access checks.
app/core/dependency.py - Redis · Blocklist store for JWT logout and invalidation.
app/core/redis.py - DB · Database connection and session access.
app/core/db.py
Domain logic
Business services and transport-specific helpers.
- Signal svc · Creates and queries passenger demand signals.
app/services/signal.py - Match svc · Ranks or aggregates signals for transport matching.
app/services/matching_service.py - Driver svc · Handles driver location updates and reads.
app/services/driver_location_service.py - Location util · Reusable coordinate and distance utilities.
app/utility/location.py
Data layer
Pydantic contracts and SQLModel persistence entities.
- Users · Persistent user and role data.
app/models/user.py - Signals · Persistent demand signal records.
app/models/signal.py - User schema · Request and response shapes for auth and user data.
app/schemas/user.py - Signal schema · API contracts for demand signals.
app/schemas/signal.py - Match schema · API contracts for matching inputs and outputs.
app/schemas/matching_schema.py
Schema ops
Alembic migrations and database evolution.
- Alembic · Versioned database schema evolution.
alembic/versions
Connections 40
- App → Auth: mounts · Registers auth endpoints on the API app.
- App → Signals: mounts · Registers signal endpoints on the API app.
- App → Matching: mounts · Registers matching endpoints on the API app.
- App → Drivers: mounts · Registers driver endpoints on the API app.
- App → Admin: mounts · Registers admin endpoints on the API app.
- App → Roles: mounts · Registers role management endpoints on the API app.
- App → Tracking: mounts · Registers tracking endpoints on the API app.
- App → Vehicles: mounts · Registers vehicle endpoints on the API app.
- Auth → Security: hashes/tokens · Uses JWT and password hashing primitives.
- Auth → Dependencies: guards · Applies auth and ownership dependencies.
- Signals → Dependencies: guards · Checks current user and access rules.
- Signals → Signal svc: uses · Delegates demand signal operations.
- Signals → Signal schema: validates · Parses request and response payloads.
- Matching → Dependencies: guards · Applies access control for matching endpoints.
- Matching → Match svc: uses · Delegates matching and ranking logic.
- Matching → Match schema: validates · Uses matching request and response contracts.
- Drivers → Dependencies: guards · Applies auth and role checks.
- Drivers → Driver svc: uses · Delegates driver location operations.
- Admin → Dependencies: guards · Restricts admin operations.
- Roles → Dependencies: guards · Restricts role changes to authorized users.
- Tracking → Dependencies: guards · Applies access control for tracking endpoints.
- Vehicles → Dependencies: guards · Applies access control for vehicle endpoints.
- Signal svc → DB: persists · Reads and writes signal records in PostgreSQL.
- Signal svc → Signals: maps · Uses domain entities for signal persistence.
- Signal svc → Location util: geo logic · Uses coordinate helpers for proximity logic.
- Match svc → DB: queries · Reads persisted signals and related data.
- Match svc → Signals: reads · Consumes signal entities for matching.
- Match svc → Location util: geo logic · Uses spatial helpers for ranking and grouping.
- Driver svc → DB: persists · Stores and reads driver location data.
- Driver svc → Location util: geo logic · Uses spatial helpers for location handling.
- Security → Redis: revokes · Supports token blocklisting and logout.
- Security → Users: auth data · Works with stored user credentials and identity.
- Dependencies → Security: verifies · Depends on token validation and identity lookup.
- Dependencies → Users: loads · Fetches current users and enforces ownership.
- Users → DB: stored in · Persisted through the async PostgreSQL layer.
- Signals → DB: stored in · Persisted through the async PostgreSQL layer.
- User schema → Users: shapes · Defines API contracts around user data.
- Signal schema → Signals: shapes · Defines API contracts around signal data.
- Match schema → Signals: reads from · Represents matching inputs derived from signals.
- Alembic → DB: evolves · Version-controls the database schema.