# phantomxreborn/nexus-dispatch architecture

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

- Interactive diagram: https://gitdiagram.com/phantomxreborn/nexus-dispatch
- Repository: https://github.com/phantomxreborn/nexus-dispatch

## Overview

Nexus Dispatch is a browser-based CAD system for managing emergency incidents, field units, dispatch decisions, and operational history. The documented dispatcher workflow is to review active incidents and unit availability, identify a nearby available unit, assign it, update unit/incident status, and later close the incident; the API also exposes logs and dispatch statistics. The sampled server implements these workflows directly and queries PostgreSQL through a pooled database module. The README describes a dashboard and role-based access; the provided tree includes its HTML entry point, but no frontend implementation excerpt was available, so those links are documented rather than source-verified.

Main entry points: [`server/server.js`](https://github.com/phantomxreborn/nexus-dispatch/blob/main/server/server.js) (HTTP server), [`server/routes/incidents.js`](https://github.com/phantomxreborn/nexus-dispatch/blob/main/server/routes/incidents.js) (Incident management), [`server/routes/dispatch.js`](https://github.com/phantomxreborn/nexus-dispatch/blob/main/server/routes/dispatch.js) (Logs and statistics), [`server/models/database.js`](https://github.com/phantomxreborn/nexus-dispatch/blob/main/server/models/database.js) (Query pool)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_operations["Dispatch operations"]
  node_dashboard["CAD dashboard<br/>[index.html]"]
  node_incident_ops["Incident management<br/>[incidents.js]"]
  node_unit_ops["Unit tracking<br/>[units.js]"]
  node_dispatch_ops["Logs and statistics<br/>[dispatch.js]"]
end

subgraph group_service["Application service"]
  node_server["HTTP server<br/>[server.js]"]
end

subgraph group_persistence["Persistence"]
  node_database["Query pool<br/>[database.js]"]
  node_postgres[("PostgreSQL")]
  node_incidents_table[("Incidents")]
  node_units_table[("Units")]
  node_logs_table[("Dispatch logs")]
  node_users_table[("User accounts")]
end

subgraph group_identity["Authentication"]
  node_auth_middleware["Token validation<br/>[auth.js]"]
  node_login["Login endpoint<br/>[server.js]"]
end

node_dispatcher(("Dispatcher"))

node_dispatcher -.->|"uses"| node_dashboard
node_dashboard -.->|"requests API"| node_server
node_dispatcher -.->|"calls API"| node_server
node_server -.->|"handles incidents"| node_incident_ops
node_server -.->|"handles units"| node_unit_ops
node_server -.->|"handles dispatch"| node_dispatch_ops
node_server -->|"queries"| node_database
node_incident_ops -->|"queries"| node_database
node_unit_ops -->|"queries"| node_database
node_dispatch_ops -->|"queries"| node_database
node_database -->|"executes SQL"| node_postgres
node_server -->|"registers"| node_login
node_login -->|"checks credentials"| node_users_table
node_auth_middleware -.->|"validates tokens"| node_login
node_incident_ops -->|"reads and writes"| node_incidents_table
node_incident_ops -->|"assigns units"| node_units_table
node_incident_ops -->|"records actions"| node_logs_table
node_unit_ops -->|"reads and updates"| node_units_table
node_unit_ops -->|"records status"| node_logs_table
node_dispatch_ops -->|"aggregates"| node_incidents_table
node_dispatch_ops -->|"aggregates"| node_units_table
node_dispatch_ops -->|"reads history"| node_logs_table

click node_dashboard "https://github.com/phantomxreborn/nexus-dispatch/blob/main/public/index.html"
click node_incident_ops "https://github.com/phantomxreborn/nexus-dispatch/blob/main/server/routes/incidents.js"
click node_unit_ops "https://github.com/phantomxreborn/nexus-dispatch/blob/main/server/routes/units.js"
click node_dispatch_ops "https://github.com/phantomxreborn/nexus-dispatch/blob/main/server/routes/dispatch.js"
click node_server "https://github.com/phantomxreborn/nexus-dispatch/blob/main/server/server.js"
click node_auth_middleware "https://github.com/phantomxreborn/nexus-dispatch/blob/main/server/middleware/auth.js"
click node_login "https://github.com/phantomxreborn/nexus-dispatch/blob/main/server/server.js"
click node_database "https://github.com/phantomxreborn/nexus-dispatch/blob/main/server/models/database.js"
click node_incidents_table "https://github.com/phantomxreborn/nexus-dispatch/blob/main/migrations/001_initial_schema.sql"
click node_units_table "https://github.com/phantomxreborn/nexus-dispatch/blob/main/migrations/001_initial_schema.sql"
click node_logs_table "https://github.com/phantomxreborn/nexus-dispatch/blob/main/migrations/001_initial_schema.sql"
click node_users_table "https://github.com/phantomxreborn/nexus-dispatch/blob/main/migrations/001_initial_schema.sql"

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_dashboard,node_incident_ops,node_unit_ops,node_dispatch_ops toneBlue
class node_server toneAmber
class node_database,node_postgres,node_incidents_table,node_units_table,node_logs_table,node_users_table toneMint
class node_auth_middleware,node_login toneRose
class node_dispatcher toneIndigo
```

## Components

### Dispatch operations

- [CAD dashboard](https://github.com/phantomxreborn/nexus-dispatch/blob/main/public/index.html): `public/index.html`
- [Incident management](https://github.com/phantomxreborn/nexus-dispatch/blob/main/server/routes/incidents.js): `server/routes/incidents.js`
- [Unit tracking](https://github.com/phantomxreborn/nexus-dispatch/blob/main/server/routes/units.js): `server/routes/units.js`
- [Logs and statistics](https://github.com/phantomxreborn/nexus-dispatch/blob/main/server/routes/dispatch.js): `server/routes/dispatch.js`

### Application service

- [HTTP server](https://github.com/phantomxreborn/nexus-dispatch/blob/main/server/server.js): `server/server.js`

### Persistence

- [Query pool](https://github.com/phantomxreborn/nexus-dispatch/blob/main/server/models/database.js): `server/models/database.js`
- **PostgreSQL**
- [Incidents](https://github.com/phantomxreborn/nexus-dispatch/blob/main/migrations/001_initial_schema.sql): `migrations/001_initial_schema.sql`
- [Units](https://github.com/phantomxreborn/nexus-dispatch/blob/main/migrations/001_initial_schema.sql): `migrations/001_initial_schema.sql`
- [Dispatch logs](https://github.com/phantomxreborn/nexus-dispatch/blob/main/migrations/001_initial_schema.sql): `migrations/001_initial_schema.sql`
- [User accounts](https://github.com/phantomxreborn/nexus-dispatch/blob/main/migrations/001_initial_schema.sql): `migrations/001_initial_schema.sql`

### Authentication

- [Token validation](https://github.com/phantomxreborn/nexus-dispatch/blob/main/server/middleware/auth.js): `server/middleware/auth.js`
- [Login endpoint](https://github.com/phantomxreborn/nexus-dispatch/blob/main/server/server.js): `server/server.js`

### Other components

- **Dispatcher**

## Connections

- Dispatcher → CAD dashboard: uses (evidence: `README.md`)
- CAD dashboard → HTTP server: requests API (evidence: `README.md`)
- Dispatcher → HTTP server: calls API (evidence: `README.md`)
- HTTP server → Incident management: handles incidents (evidence: `README.md`)
- HTTP server → Unit tracking: handles units (evidence: `README.md`)
- HTTP server → Logs and statistics: handles dispatch (evidence: `README.md`)
- HTTP server → Query pool: queries (evidence: `server/server.js`)
- Incident management → Query pool: queries (evidence: `server/routes/incidents.js`)
- Unit tracking → Query pool: queries (evidence: `server/routes/units.js`)
- Logs and statistics → Query pool: queries (evidence: `server/routes/dispatch.js`)
- Query pool → PostgreSQL: executes SQL (evidence: `server/models/database.js`)
- HTTP server → Login endpoint: registers (evidence: `server/server.js`)
- Login endpoint → User accounts: checks credentials (evidence: `server/server.js`)
- Token validation → Login endpoint: validates tokens
- Incident management → Incidents: reads and writes (evidence: `server/routes/incidents.js`)
- Incident management → Units: assigns units (evidence: `server/routes/incidents.js`)
- Incident management → Dispatch logs: records actions (evidence: `server/routes/incidents.js`)
- Unit tracking → Units: reads and updates (evidence: `server/routes/units.js`)
- Unit tracking → Dispatch logs: records status (evidence: `server/routes/units.js`)
- Logs and statistics → Incidents: aggregates (evidence: `server/routes/dispatch.js`)
- Logs and statistics → Units: aggregates (evidence: `server/routes/dispatch.js`)
- Logs and statistics → Dispatch logs: reads history (evidence: `server/routes/dispatch.js`)
