# fahad2bhatti/fleetflow architecture

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

- Interactive diagram: https://gitdiagram.com/fahad2bhatti/fleetflow
- Repository: https://github.com/fahad2bhatti/fleetflow

## Overview

FleetFlow is a multi-company fleet and transportation management platform. Users sign in, then role-protected web pages call the REST API to manage fleet resources and progress delivery orders through trip assignment, transit, and delivery; the backend enforces business rules and persists company-scoped records. Separate capabilities cover finance, maintenance, analytics, audit, notifications, and expiry/service alerts. Relationships are based on the README and shown source/index references; unsampled implementation details are not treated as inspected.

Main entry points: [`backend/src/routes`](https://github.com/fahad2bhatti/fleetflow/tree/main/backend/src/routes) (API routers), [`backend/src/infra/database/data-source.ts`](https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/infra/database/data-source.ts) (PostgreSQL data source), [`backend/src/application/services/insights.service.ts`](https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/application/services/insights.service.ts) (Reports and analytics), [`frontend/src/App.tsx`](https://github.com/fahad2bhatti/fleetflow/blob/main/frontend/src/App.tsx) (Route application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_webapp["Route application<br/>[App.tsx]"]
  node_authpage["Login and register<br/>[Auth.tsx]"]
  node_authstate["Session state<br/>[authSlice.ts]"]
  node_pages["Fleet and trip pages"]
  node_analyticsui["Reports and dashboard"]
  node_permissions["Role permissions<br/>[permissions.ts]"]
  node_api_client["HTTP client<br/>[api.ts]"]
end

subgraph group_api["API and security"]
  node_express["Express app<br/>[app.ts]"]
  node_routers["API routers"]
  node_authmw["Request authentication<br/>[authenticate.ts]"]
  node_authorization["Permission checks<br/>[authorize.ts]"]
  node_validation["Request validation<br/>[schemas.ts]"]
end

subgraph group_usecases["Business services"]
  node_trips["Trip dispatch<br/>[trip.service.ts]"]
  node_assignment["Smart assignment"]
  node_operations["Fleet operations"]
  node_fleet["Fleet management<br/>[fleet.service.ts]"]
  node_insights["Reports and analytics"]
  node_authservice["Identity service<br/>[auth.service.ts]"]
  node_audit["Audit history<br/>[audit.service.ts]"]
  node_notifications["Notifications"]
end

subgraph group_platform["Persistence and alerts"]
  node_db[("PostgreSQL data source<br/>[data-source.ts]")]
  node_alerts["Scheduled alerts<br/>[alerts.job.ts]"]
end

node_user(("Fleet user"))
node_dbservice[("Database")]

node_user -->|"opens"| node_webapp
node_webapp -->|"routes to"| node_authpage
node_webapp -->|"routes to"| node_pages
node_webapp -->|"routes to"| node_analyticsui
node_authpage -->|"dispatches auth"| node_authstate
node_authstate -->|"sends requests"| node_api_client
node_pages -.->|"fetches resources"| node_api_client
node_permissions -.->|"guards routes"| node_webapp
node_api_client -.->|"calls REST API"| node_express
node_express -->|"mounts"| node_routers
node_routers -->|"dispatches trip calls"| node_trips
node_routers -->|"dispatches assignment"| node_assignment
node_routers -->|"dispatches operations"| node_operations
node_routers -->|"dispatches fleet calls"| node_fleet
node_routers -->|"dispatches analytics"| node_insights
node_routers -->|"dispatches notification calls"| node_notifications
node_routers -.->|"dispatches identity calls"| node_authservice
node_routers -->|"authenticates requests"| node_authmw
node_routers -->|"checks permissions"| node_authorization
node_routers -->|"validates input"| node_validation
node_trips -.->|"reads and writes"| node_db
node_assignment -.->|"reads availability"| node_db
node_operations -->|"reads and writes"| node_db
node_operations -.->|"records changes"| node_audit
node_operations -->|"notifies roles"| node_notifications
node_fleet -.->|"reads and writes"| node_db
node_insights -->|"queries metrics"| node_db
node_insights -->|"uses operations data"| node_operations
node_insights -->|"uses fleet data"| node_fleet
node_insights -->|"uses notifications"| node_notifications
node_authservice -->|"reads and writes"| node_db
node_authservice -->|"records auth events"| node_audit
node_audit -->|"stores audit logs"| node_db
node_notifications -.->|"stores notifications"| node_db
node_alerts -.->|"creates alerts"| node_notifications
node_db -->|"connects to"| node_dbservice

click node_webapp "https://github.com/fahad2bhatti/fleetflow/blob/main/frontend/src/App.tsx"
click node_authpage "https://github.com/fahad2bhatti/fleetflow/blob/main/frontend/src/pages/Auth.tsx"
click node_authstate "https://github.com/fahad2bhatti/fleetflow/blob/main/frontend/src/store/authSlice.ts"
click node_pages "https://github.com/fahad2bhatti/fleetflow/tree/main/frontend/src/pages"
click node_analyticsui "https://github.com/fahad2bhatti/fleetflow/tree/main/frontend/src/pages"
click node_permissions "https://github.com/fahad2bhatti/fleetflow/blob/main/frontend/src/lib/permissions.ts"
click node_api_client "https://github.com/fahad2bhatti/fleetflow/blob/main/frontend/src/lib/api.ts"
click node_express "https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/app.ts"
click node_routers "https://github.com/fahad2bhatti/fleetflow/tree/main/backend/src/routes"
click node_authmw "https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/infra/middleware/authenticate.ts"
click node_authorization "https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/infra/middleware/authorize.ts"
click node_validation "https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/application/dtos/schemas.ts"
click node_trips "https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/application/services/trip.service.ts"
click node_assignment "https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/application/services/assignment.service.ts"
click node_operations "https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/application/services/operations.service.ts"
click node_fleet "https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/application/services/fleet.service.ts"
click node_insights "https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/application/services/insights.service.ts"
click node_authservice "https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/application/services/auth.service.ts"
click node_audit "https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/application/services/audit.service.ts"
click node_notifications "https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/application/services/notification.service.ts"
click node_db "https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/infra/database/data-source.ts"
click node_alerts "https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/infra/jobs/alerts.job.ts"

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_webapp,node_authpage,node_authstate,node_pages,node_analyticsui,node_permissions,node_api_client,node_user toneBlue
class node_express,node_routers,node_authmw,node_authorization,node_validation,node_dbservice toneAmber
class node_trips,node_assignment,node_operations,node_fleet,node_insights,node_authservice,node_audit,node_notifications toneMint
class node_db,node_alerts toneRose
```

## Components

### Web application

- [Route application](https://github.com/fahad2bhatti/fleetflow/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Login and register](https://github.com/fahad2bhatti/fleetflow/blob/main/frontend/src/pages/Auth.tsx): `frontend/src/pages/Auth.tsx`
- [Session state](https://github.com/fahad2bhatti/fleetflow/blob/main/frontend/src/store/authSlice.ts): `frontend/src/store/authSlice.ts`
- [Fleet and trip pages](https://github.com/fahad2bhatti/fleetflow/tree/main/frontend/src/pages): `frontend/src/pages`
- [Reports and dashboard](https://github.com/fahad2bhatti/fleetflow/tree/main/frontend/src/pages): `frontend/src/pages`
- [Role permissions](https://github.com/fahad2bhatti/fleetflow/blob/main/frontend/src/lib/permissions.ts): `frontend/src/lib/permissions.ts`
- [HTTP client](https://github.com/fahad2bhatti/fleetflow/blob/main/frontend/src/lib/api.ts): `frontend/src/lib/api.ts`

### API and security

- [Express app](https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/app.ts): `backend/src/app.ts`
- [API routers](https://github.com/fahad2bhatti/fleetflow/tree/main/backend/src/routes): `backend/src/routes`
- [Request authentication](https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/infra/middleware/authenticate.ts): `backend/src/infra/middleware/authenticate.ts`
- [Permission checks](https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/infra/middleware/authorize.ts): `backend/src/infra/middleware/authorize.ts`
- [Request validation](https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/application/dtos/schemas.ts): `backend/src/application/dtos/schemas.ts`

### Business services

- [Trip dispatch](https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/application/services/trip.service.ts): `backend/src/application/services/trip.service.ts`
- [Smart assignment](https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/application/services/assignment.service.ts): `backend/src/application/services/assignment.service.ts`
- [Fleet operations](https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/application/services/operations.service.ts): `backend/src/application/services/operations.service.ts`
- [Fleet management](https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/application/services/fleet.service.ts): `backend/src/application/services/fleet.service.ts`
- [Reports and analytics](https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/application/services/insights.service.ts): `backend/src/application/services/insights.service.ts`
- [Identity service](https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/application/services/auth.service.ts): `backend/src/application/services/auth.service.ts`
- [Audit history](https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/application/services/audit.service.ts): `backend/src/application/services/audit.service.ts`
- [Notifications](https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/application/services/notification.service.ts): `backend/src/application/services/notification.service.ts`

### Persistence and alerts

- [PostgreSQL data source](https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/infra/database/data-source.ts): `backend/src/infra/database/data-source.ts`
- [Scheduled alerts](https://github.com/fahad2bhatti/fleetflow/blob/main/backend/src/infra/jobs/alerts.job.ts): `backend/src/infra/jobs/alerts.job.ts`

### Other components

- **Fleet user**
- **Database**

## Connections

- Fleet user → Route application: opens (evidence: `frontend/src/App.tsx`)
- Route application → Login and register: routes to (evidence: `frontend/src/App.tsx`)
- Route application → Fleet and trip pages: routes to (evidence: `frontend/src/App.tsx`)
- Route application → Reports and dashboard: routes to (evidence: `frontend/src/App.tsx`)
- Login and register → Session state: dispatches auth (evidence: `frontend/src/pages/Auth.tsx`)
- Session state → HTTP client: sends requests (evidence: `frontend/src/store/authSlice.ts`)
- Fleet and trip pages → HTTP client: fetches resources
- Role permissions → Route application: guards routes
- HTTP client → Express app: calls REST API
- Express app → API routers: mounts (evidence: `backend/src/app.ts`)
- API routers → Trip dispatch: dispatches trip calls (evidence: `backend/src/routes/trips.routes.ts`)
- API routers → Smart assignment: dispatches assignment (evidence: `backend/src/routes/trips.routes.ts`)
- API routers → Fleet operations: dispatches operations (evidence: `backend/src/routes/trips.routes.ts`)
- API routers → Fleet management: dispatches fleet calls (evidence: `backend/src/routes/fleet.routes.ts`)
- API routers → Reports and analytics: dispatches analytics (evidence: `backend/src/routes/insights.routes.ts`)
- API routers → Notifications: dispatches notification calls (evidence: `backend/src/routes/insights.routes.ts`)
- API routers → Identity service: dispatches identity calls
- API routers → Request authentication: authenticates requests (evidence: `backend/src/routes/helpers.ts`)
- API routers → Permission checks: checks permissions (evidence: `backend/src/routes/helpers.ts`)
- API routers → Request validation: validates input (evidence: `backend/src/routes/helpers.ts`)
- Trip dispatch → PostgreSQL data source: reads and writes
- Smart assignment → PostgreSQL data source: reads availability
- Fleet operations → PostgreSQL data source: reads and writes (evidence: `backend/src/application/services/operations.service.ts`)
- Fleet operations → Audit history: records changes (evidence: `backend/src/application/services/operations.service.ts`)
- Fleet operations → Notifications: notifies roles (evidence: `backend/src/application/services/operations.service.ts`)
- Fleet management → PostgreSQL data source: reads and writes
- Reports and analytics → PostgreSQL data source: queries metrics (evidence: `backend/src/application/services/insights.service.ts`)
- Reports and analytics → Fleet operations: uses operations data (evidence: `backend/src/application/services/insights.service.ts`)
- Reports and analytics → Fleet management: uses fleet data (evidence: `backend/src/application/services/insights.service.ts`)
- Reports and analytics → Notifications: uses notifications (evidence: `backend/src/application/services/insights.service.ts`)
- Identity service → PostgreSQL data source: reads and writes (evidence: `backend/src/application/services/auth.service.ts`)
- Identity service → Audit history: records auth events (evidence: `backend/src/application/services/auth.service.ts`)
- Audit history → PostgreSQL data source: stores audit logs (evidence: `backend/src/application/services/audit.service.ts`)
- Notifications → PostgreSQL data source: stores notifications (evidence: `backend/src/application/services/notification.service.ts`)
- Scheduled alerts → Notifications: creates alerts
- PostgreSQL data source → Database: connects to (evidence: `backend/src/infra/database/data-source.ts`)
