# sanjeev0575/custody_band_backend architecture

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

- Interactive diagram: https://gitdiagram.com/sanjeev0575/custody_band_backend
- Repository: https://github.com/sanjeev0575/custody_band_backend

## Overview

Trackin360 is a FastAPI backend for a fleet-tracking dashboard. Authenticated users manage fleet records and view tracking, health, alarm, geofence, and reporting data; devices authenticate separately to submit normalized GPS, health, and alarm payloads. The API persists records in PostgreSQL/PostGIS and supports authenticated live tracking and Firebase push delivery. The sampled excerpts show the API, persistence, auth, and integration layers; some route behavior is documented only in the README, so those links cite the README.

Main entry points: [`app/main.py`](https://github.com/sanjeev0575/custody_band_backend/blob/main/app/main.py) (FastAPI routes), [`app/database.py`](https://github.com/sanjeev0575/custody_band_backend/blob/main/app/database.py) (PostgreSQL and PostGIS), [`app/firebase_auth.py`](https://github.com/sanjeev0575/custody_band_backend/blob/main/app/firebase_auth.py) (Firebase token verifier), [`app/models.py`](https://github.com/sanjeev0575/custody_band_backend/blob/main/app/models.py) (ORM data models)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API workflows"]
  node_api["FastAPI routes<br/>[main.py]"]
  node_fleet["Fleet and people<br/>[main.py]"]
  node_tracking["Location and trips<br/>[main.py]"]
  node_health["Health measurements<br/>[main.py]"]
  node_geofences["Geofences and alerts<br/>[main.py]"]
  node_reports["Dashboard and reports<br/>[main.py]"]
  node_schemas["Payload schemas<br/>[schemas.py]"]
end

subgraph group_identity["Identity and access"]
  node_auth["Firebase token verifier<br/>[firebase_auth.py]"]
  node_device_security["Device token security<br/>[security.py]"]
  node_config["Runtime settings<br/>[config.py]"]
end

subgraph group_persistence["Persistence"]
  node_orm["ORM data models<br/>[models.py]"]
  node_database[("PostgreSQL and PostGIS<br/>[database.py]")]
end

subgraph group_delivery["Live and push delivery"]
  node_connections["Tracking connections<br/>[realtime.py]"]
  node_push["Push notification sender<br/>[notifications.py]"]
end

node_dashboard(("React dashboard"))
node_devices(("GPS and wearable devices"))
node_firebase_auth{{"Firebase Authentication"}}
node_fcm{{"Firebase Cloud Messaging"}}

node_dashboard -->|"calls"| node_api
node_devices -->|"submits payloads"| node_api
node_api -->|"routes"| node_fleet
node_api -->|"routes"| node_tracking
node_api -->|"routes"| node_health
node_api -->|"routes"| node_geofences
node_api -->|"routes"| node_reports
node_api -->|"validates with"| node_schemas
node_api -->|"verifies tokens"| node_auth
node_auth -->|"verifies with"| node_firebase_auth
node_api -->|"checks device tokens"| node_device_security
node_api -->|"queries and writes"| node_database
node_api -->|"uses models"| node_orm
node_orm -->|"uses base"| node_database
node_database -->|"reads settings"| node_config
node_api -->|"broadcasts events"| node_connections
node_dashboard -->|"opens WebSocket"| node_connections
node_api -->|"sends notifications"| node_push
node_push -->|"delivers messages"| node_fcm

click node_api "https://github.com/sanjeev0575/custody_band_backend/blob/main/app/main.py"
click node_fleet "https://github.com/sanjeev0575/custody_band_backend/blob/main/app/main.py"
click node_tracking "https://github.com/sanjeev0575/custody_band_backend/blob/main/app/main.py"
click node_health "https://github.com/sanjeev0575/custody_band_backend/blob/main/app/main.py"
click node_geofences "https://github.com/sanjeev0575/custody_band_backend/blob/main/app/main.py"
click node_reports "https://github.com/sanjeev0575/custody_band_backend/blob/main/app/main.py"
click node_schemas "https://github.com/sanjeev0575/custody_band_backend/blob/main/app/schemas.py"
click node_auth "https://github.com/sanjeev0575/custody_band_backend/blob/main/app/firebase_auth.py"
click node_device_security "https://github.com/sanjeev0575/custody_band_backend/blob/main/app/security.py"
click node_config "https://github.com/sanjeev0575/custody_band_backend/blob/main/app/config.py"
click node_orm "https://github.com/sanjeev0575/custody_band_backend/blob/main/app/models.py"
click node_database "https://github.com/sanjeev0575/custody_band_backend/blob/main/app/database.py"
click node_connections "https://github.com/sanjeev0575/custody_band_backend/blob/main/app/realtime.py"
click node_push "https://github.com/sanjeev0575/custody_band_backend/blob/main/app/notifications.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_api,node_fleet,node_tracking,node_health,node_geofences,node_reports,node_schemas toneBlue
class node_auth,node_device_security,node_config toneAmber
class node_orm,node_database toneMint
class node_connections,node_push toneRose
class node_dashboard,node_devices,node_firebase_auth,node_fcm toneIndigo
```

## Components

### API workflows

- [FastAPI routes](https://github.com/sanjeev0575/custody_band_backend/blob/main/app/main.py): `app/main.py`
- [Fleet and people](https://github.com/sanjeev0575/custody_band_backend/blob/main/app/main.py): `app/main.py`
- [Location and trips](https://github.com/sanjeev0575/custody_band_backend/blob/main/app/main.py): `app/main.py`
- [Health measurements](https://github.com/sanjeev0575/custody_band_backend/blob/main/app/main.py): `app/main.py`
- [Geofences and alerts](https://github.com/sanjeev0575/custody_band_backend/blob/main/app/main.py): `app/main.py`
- [Dashboard and reports](https://github.com/sanjeev0575/custody_band_backend/blob/main/app/main.py): `app/main.py`
- [Payload schemas](https://github.com/sanjeev0575/custody_band_backend/blob/main/app/schemas.py): `app/schemas.py`

### Identity and access

- [Firebase token verifier](https://github.com/sanjeev0575/custody_band_backend/blob/main/app/firebase_auth.py): `app/firebase_auth.py`
- [Device token security](https://github.com/sanjeev0575/custody_band_backend/blob/main/app/security.py): `app/security.py`
- [Runtime settings](https://github.com/sanjeev0575/custody_band_backend/blob/main/app/config.py): `app/config.py`

### Persistence

- [ORM data models](https://github.com/sanjeev0575/custody_band_backend/blob/main/app/models.py): `app/models.py`
- [PostgreSQL and PostGIS](https://github.com/sanjeev0575/custody_band_backend/blob/main/app/database.py): `app/database.py`

### Live and push delivery

- [Tracking connections](https://github.com/sanjeev0575/custody_band_backend/blob/main/app/realtime.py): `app/realtime.py`
- [Push notification sender](https://github.com/sanjeev0575/custody_band_backend/blob/main/app/notifications.py): `app/notifications.py`

### Other components

- **React dashboard**
- **GPS and wearable devices**
- **Firebase Authentication**
- **Firebase Cloud Messaging**

## Connections

- React dashboard → FastAPI routes: calls (evidence: `README.md`)
- GPS and wearable devices → FastAPI routes: submits payloads (evidence: `README.md`)
- FastAPI routes → Fleet and people: routes (evidence: `README.md`)
- FastAPI routes → Location and trips: routes (evidence: `README.md`)
- FastAPI routes → Health measurements: routes (evidence: `README.md`)
- FastAPI routes → Geofences and alerts: routes (evidence: `README.md`)
- FastAPI routes → Dashboard and reports: routes (evidence: `README.md`)
- FastAPI routes → Payload schemas: validates with (evidence: `app/main.py`)
- FastAPI routes → Firebase token verifier: verifies tokens (evidence: `README.md`)
- Firebase token verifier → Firebase Authentication: verifies with (evidence: `app/firebase_auth.py`)
- FastAPI routes → Device token security: checks device tokens (evidence: `app/main.py`)
- FastAPI routes → PostgreSQL and PostGIS: queries and writes (evidence: `app/main.py`)
- FastAPI routes → ORM data models: uses models (evidence: `app/main.py`)
- ORM data models → PostgreSQL and PostGIS: uses base (evidence: `app/models.py`)
- PostgreSQL and PostGIS → Runtime settings: reads settings (evidence: `app/database.py`)
- FastAPI routes → Tracking connections: broadcasts events (evidence: `README.md`)
- React dashboard → Tracking connections: opens WebSocket (evidence: `README.md`)
- FastAPI routes → Push notification sender: sends notifications (evidence: `README.md`)
- Push notification sender → Firebase Cloud Messaging: delivers messages (evidence: `app/notifications.py`)
