# arjun-bhattarai/fleet-pulse architecture

> Architecture diagram of the GitHub repository arjun-bhattarai/fleet-pulse, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/arjun-bhattarai/fleet-pulse
- Repository: https://github.com/arjun-bhattarai/fleet-pulse

## Overview

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: [`app/core/dependency.py`](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/core/dependency.py) (Dependencies), [`app/main.py`](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/main.py) (App), [`app/core/db.py`](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/core/db.py) (DB), [`app/models/signal.py`](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/models/signal.py) (Signals)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API layer"]
  node_main["App<br/>FastAPI bootstrap<br/>[main.py]"]
  node_auth_route["Auth<br/>HTTP routes<br/>[auth.py]"]
  node_signal_route["Signals<br/>HTTP routes<br/>[signal_route.py]"]
  node_match_route["Matching<br/>HTTP routes<br/>[matching_route.py]"]
  node_driver_route["Drivers<br/>HTTP routes"]
  node_admin_route["Admin<br/>HTTP routes<br/>[admin_route.py]"]
  node_role_route["Roles<br/>HTTP routes<br/>[role_change.py]"]
  node_tracking_route["Tracking<br/>HTTP routes<br/>[tracking.py]"]
  node_vehicles_route["Vehicles<br/>HTTP routes<br/>[vehicles.py]"]
end

subgraph group_core["Core infra"]
  node_security["Security<br/>JWT + hashing<br/>[security.py]"]
  node_deps["Dependencies<br/>Auth/RBAC deps<br/>[dependency.py]"]
  node_redis[("Redis<br/>Token revocation<br/>[redis.py]")]
  node_db[("DB<br/>Async PostgreSQL<br/>[db.py]")]
end

subgraph group_domain["Domain logic"]
  node_signal_svc["Signal svc<br/>Use-case service<br/>[signal.py]"]
  node_match_svc["Match svc<br/>Matching service"]
  node_driver_svc["Driver svc<br/>Location service"]
  node_loc_util["Location util<br/>Geo helper<br/>[location.py]"]
end

subgraph group_data["Data layer"]
  node_user_model[("Users<br/>SQLModel entity<br/>[user.py]")]
  node_signal_model[("Signals<br/>SQLModel entity<br/>[signal.py]")]
  node_user_schema["User schema<br/>Pydantic contracts<br/>[user.py]"]
  node_signal_schema["Signal schema<br/>Pydantic contracts<br/>[signal.py]"]
  node_match_schema["Match schema<br/>Pydantic contracts<br/>[matching_schema.py]"]
end

subgraph group_ops["Schema ops"]
  node_migrations["Alembic<br/>Migration history"]
end

node_main -->|"mounts"| node_auth_route
node_main -->|"mounts"| node_signal_route
node_main -->|"mounts"| node_match_route
node_main -->|"mounts"| node_driver_route
node_main -->|"mounts"| node_admin_route
node_main -->|"mounts"| node_role_route
node_main -->|"mounts"| node_tracking_route
node_main -->|"mounts"| node_vehicles_route
node_auth_route -->|"hashes/tokens"| node_security
node_auth_route -->|"guards"| node_deps
node_signal_route -->|"guards"| node_deps
node_signal_route -->|"uses"| node_signal_svc
node_signal_route -->|"validates"| node_signal_schema
node_match_route -->|"guards"| node_deps
node_match_route -->|"uses"| node_match_svc
node_match_route -->|"validates"| node_match_schema
node_driver_route -->|"guards"| node_deps
node_driver_route -->|"uses"| node_driver_svc
node_admin_route -->|"guards"| node_deps
node_role_route -->|"guards"| node_deps
node_tracking_route -->|"guards"| node_deps
node_vehicles_route -->|"guards"| node_deps
node_signal_svc -->|"persists"| node_db
node_signal_svc -->|"maps"| node_signal_model
node_signal_svc -->|"geo logic"| node_loc_util
node_match_svc -->|"queries"| node_db
node_match_svc -->|"reads"| node_signal_model
node_match_svc -->|"geo logic"| node_loc_util
node_driver_svc -->|"persists"| node_db
node_driver_svc -->|"geo logic"| node_loc_util
node_security -->|"revokes"| node_redis
node_security -->|"auth data"| node_user_model
node_deps -->|"verifies"| node_security
node_deps -->|"loads"| node_user_model
node_user_model -->|"stored in"| node_db
node_signal_model -->|"stored in"| node_db
node_user_schema -->|"shapes"| node_user_model
node_signal_schema -->|"shapes"| node_signal_model
node_match_schema -->|"reads from"| node_signal_model
node_migrations -->|"evolves"| node_db

click node_main "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/main.py"
click node_auth_route "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/routes/auth.py"
click node_signal_route "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/routes/signal_route.py"
click node_match_route "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/routes/matching_route.py"
click node_driver_route "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/routes/driver_location_route.py"
click node_admin_route "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/routes/admin_route.py"
click node_role_route "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/routes/role_change.py"
click node_tracking_route "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/routes/tracking.py"
click node_vehicles_route "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/routes/vehicles.py"
click node_security "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/core/security.py"
click node_deps "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/core/dependency.py"
click node_redis "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/core/redis.py"
click node_db "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/core/db.py"
click node_signal_svc "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/services/signal.py"
click node_match_svc "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/services/matching_service.py"
click node_driver_svc "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/services/driver_location_service.py"
click node_loc_util "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/utility/location.py"
click node_user_model "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/models/user.py"
click node_signal_model "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/models/signal.py"
click node_user_schema "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/schemas/user.py"
click node_signal_schema "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/schemas/signal.py"
click node_match_schema "https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/schemas/matching_schema.py"
click node_migrations "https://github.com/arjun-bhattarai/fleet-pulse/tree/main/alembic/versions"

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_auth_route,node_signal_route,node_match_route,node_driver_route,node_admin_route,node_role_route,node_tracking_route,node_vehicles_route toneBlue
class node_security,node_deps,node_redis,node_db toneAmber
class node_signal_svc,node_match_svc,node_driver_svc,node_loc_util toneMint
class node_user_model,node_signal_model,node_user_schema,node_signal_schema,node_match_schema toneRose
class node_migrations toneIndigo
```

## Components

### API layer

FastAPI entrypoint and HTTP route modules.

- [App](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/main.py): FastAPI bootstrap · Assembles the ASGI app and mounts routers. · `app/main.py`
- [Auth](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/routes/auth.py): HTTP routes · Login, token, and session endpoints. · `app/routes/auth.py`
- [Signals](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/routes/signal_route.py): HTTP routes · Passenger demand submission and retrieval endpoints. · `app/routes/signal_route.py`
- [Matching](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/routes/matching_route.py): HTTP routes · Endpoints for demand matching and ranking. · `app/routes/matching_route.py`
- [Drivers](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/routes/driver_location_route.py): HTTP routes · Driver location and availability endpoints. · `app/routes/driver_location_route.py`
- [Admin](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/routes/admin_route.py): HTTP routes · Administrative control endpoints. · `app/routes/admin_route.py`
- [Roles](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/routes/role_change.py): HTTP routes · Role change and permission management endpoints. · `app/routes/role_change.py`
- [Tracking](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/routes/tracking.py): HTTP routes · Operational tracking endpoints. · `app/routes/tracking.py`
- [Vehicles](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/routes/vehicles.py): HTTP routes · Vehicle-related operational endpoints. · `app/routes/vehicles.py`

### Core infra

Shared auth, database, Redis, and dependency wiring.

- [Security](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/core/security.py): JWT + hashing · Password hashing and token creation/verification. · `app/core/security.py`
- [Dependencies](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/core/dependency.py): Auth/RBAC deps · Shared FastAPI dependencies for current user and access checks. · `app/core/dependency.py`
- [Redis](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/core/redis.py): Token revocation · Blocklist store for JWT logout and invalidation. · `app/core/redis.py`
- [DB](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/core/db.py): Async PostgreSQL · Database connection and session access. · `app/core/db.py`

### Domain logic

Business services and transport-specific helpers.

- [Signal svc](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/services/signal.py): Use-case service · Creates and queries passenger demand signals. · `app/services/signal.py`
- [Match svc](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/services/matching_service.py): Matching service · Ranks or aggregates signals for transport matching. · `app/services/matching_service.py`
- [Driver svc](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/services/driver_location_service.py): Location service · Handles driver location updates and reads. · `app/services/driver_location_service.py`
- [Location util](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/utility/location.py): Geo helper · Reusable coordinate and distance utilities. · `app/utility/location.py`

### Data layer

Pydantic contracts and SQLModel persistence entities.

- [Users](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/models/user.py): SQLModel entity · Persistent user and role data. · `app/models/user.py`
- [Signals](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/models/signal.py): SQLModel entity · Persistent demand signal records. · `app/models/signal.py`
- [User schema](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/schemas/user.py): Pydantic contracts · Request and response shapes for auth and user data. · `app/schemas/user.py`
- [Signal schema](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/schemas/signal.py): Pydantic contracts · API contracts for demand signals. · `app/schemas/signal.py`
- [Match schema](https://github.com/arjun-bhattarai/fleet-pulse/blob/main/app/schemas/matching_schema.py): Pydantic contracts · API contracts for matching inputs and outputs. · `app/schemas/matching_schema.py`

### Schema ops

Alembic migrations and database evolution.

- [Alembic](https://github.com/arjun-bhattarai/fleet-pulse/tree/main/alembic/versions): Migration history · Versioned database schema evolution. · `alembic/versions`

## Connections

- 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.
