# sumeshpatva97/cctv-api architecture

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

- Interactive diagram: https://gitdiagram.com/sumeshpatva97/cctv-api
- Repository: https://github.com/sumeshpatva97/cctv-api

## Overview

cctv-api is a modular-monolith API for CCTV operations and workforce attendance. The documented request path is client → Express app/module registry → feature routers and services → PostgreSQL-backed results; authentication and authorization gate protected requests. The README identifies several feature areas as registered placeholders returning 501, so they are shown as product branches, not asserted as implemented workflows. Source excerpts show app setup, authentication, and streaming-session behavior; links for unsampled feature internals are limited to documented capabilities or left unverified.

Main entry points: [`src/modules/auth/auth.service.ts`](https://github.com/sumeshpatva97/cctv-api/blob/develop/src/modules/auth/auth.service.ts) (Auth service), [`src/modules/streaming/stream-sessions.service.ts`](https://github.com/sumeshpatva97/cctv-api/blob/develop/src/modules/streaming/stream-sessions.service.ts) (Live stream sessions), [`src/common/auth/authenticate.ts`](https://github.com/sumeshpatva97/cctv-api/blob/develop/src/common/auth/authenticate.ts) (Session authorization), [`src/app.ts`](https://github.com/sumeshpatva97/cctv-api/blob/develop/src/app.ts) (Express application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_platform["API platform"]
  node_app["Express application<br/>[app.ts]"]
  node_registry["Module registry<br/>[index.ts]"]
  node_config["Validated config<br/>[env.ts]"]
  node_database[("PostgreSQL")]
  node_realtime["Realtime hub<br/>[hub.ts]"]
end

subgraph group_identity["Identity and access"]
  node_auth_routes["Auth endpoints<br/>[auth.routes.ts]"]
  node_auth_service["Auth service<br/>[auth.service.ts]"]
  node_auth_middleware["Auth middleware<br/>[middleware.ts]"]
  node_auth_resolution["Session authorization<br/>[authenticate.ts]"]
  node_tokens["Token handling<br/>[tokens.ts]"]
  node_org_admin["Organization and access admin"]
end

subgraph group_workforce["Workforce operations"]
  node_people["Departments and employees"]
  node_shifts["Shift management"]
  node_attendance["Attendance and corrections"]
end

subgraph group_cctv["CCTV operations"]
  node_camera_admin["Camera management<br/>[cameras.service.ts]"]
  node_stream_sessions["Live stream sessions"]
  node_gateway["MediaMTX gateway"]
end

subgraph group_insights["Insights and audit"]
  node_dashboard["Dashboard"]
  node_reports["Reports and CSV<br/>[reports.service.ts]"]
  node_audit["Audit log"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_app
node_app -->|"mounts modules"| node_registry
node_app -->|"uses config"| node_config
node_client -->|"uses auth API"| node_auth_routes
node_auth_routes -.->|"dispatches"| node_auth_service
node_auth_service -->|"resolves session"| node_auth_resolution
node_auth_service -->|"issues tokens"| node_tokens
node_auth_middleware -->|"authenticates"| node_auth_resolution
node_auth_resolution -->|"verifies token"| node_tokens
node_auth_resolution -->|"loads session and grants"| node_database
node_auth_service -->|"updates identity state"| node_database
node_client -->|"manages organization access"| node_org_admin
node_client -->|"manages workforce"| node_people
node_client -->|"manages shifts"| node_shifts
node_client -->|"records attendance"| node_attendance
node_attendance -->|"uses employee schedules"| node_people
node_client -->|"manages cameras"| node_camera_admin
node_client -->|"requests live sessions"| node_stream_sessions
node_stream_sessions -.->|"checks gateway"| node_gateway
node_stream_sessions -->|"stores session state"| node_database
node_client -->|"views dashboard"| node_dashboard
node_client -->|"requests reports"| node_reports
node_client -->|"views audit log"| node_audit
node_stream_sessions -->|"records stream events"| node_audit
node_client -->|"connects live"| node_realtime

click node_app "https://github.com/sumeshpatva97/cctv-api/blob/develop/src/app.ts"
click node_registry "https://github.com/sumeshpatva97/cctv-api/blob/develop/src/modules/index.ts"
click node_config "https://github.com/sumeshpatva97/cctv-api/blob/develop/src/config/env.ts"
click node_auth_routes "https://github.com/sumeshpatva97/cctv-api/blob/develop/src/modules/auth/auth.routes.ts"
click node_auth_service "https://github.com/sumeshpatva97/cctv-api/blob/develop/src/modules/auth/auth.service.ts"
click node_auth_middleware "https://github.com/sumeshpatva97/cctv-api/blob/develop/src/common/auth/middleware.ts"
click node_auth_resolution "https://github.com/sumeshpatva97/cctv-api/blob/develop/src/common/auth/authenticate.ts"
click node_tokens "https://github.com/sumeshpatva97/cctv-api/blob/develop/src/common/auth/tokens.ts"
click node_org_admin "https://github.com/sumeshpatva97/cctv-api/tree/develop/src/modules/organization"
click node_people "https://github.com/sumeshpatva97/cctv-api/tree/develop/src/modules/employees"
click node_shifts "https://github.com/sumeshpatva97/cctv-api/tree/develop/src/modules/shifts"
click node_attendance "https://github.com/sumeshpatva97/cctv-api/tree/develop/src/modules/attendance"
click node_camera_admin "https://github.com/sumeshpatva97/cctv-api/blob/develop/src/modules/cameras/cameras.service.ts"
click node_stream_sessions "https://github.com/sumeshpatva97/cctv-api/blob/develop/src/modules/streaming/stream-sessions.service.ts"
click node_gateway "https://github.com/sumeshpatva97/cctv-api/blob/develop/src/integrations/streaming/mediamtx-gateway.ts"
click node_dashboard "https://github.com/sumeshpatva97/cctv-api/tree/develop/src/modules/dashboard"
click node_reports "https://github.com/sumeshpatva97/cctv-api/blob/develop/src/modules/reports/reports.service.ts"
click node_audit "https://github.com/sumeshpatva97/cctv-api/tree/develop/src/modules/audit"
click node_realtime "https://github.com/sumeshpatva97/cctv-api/blob/develop/src/realtime/hub.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_app,node_registry,node_config,node_database,node_realtime,node_client toneBlue
class node_auth_routes,node_auth_service,node_auth_middleware,node_auth_resolution,node_tokens,node_org_admin toneAmber
class node_people,node_shifts,node_attendance toneMint
class node_camera_admin,node_stream_sessions,node_gateway toneRose
class node_dashboard,node_reports,node_audit toneIndigo
```

## Components

### API platform

- [Express application](https://github.com/sumeshpatva97/cctv-api/blob/develop/src/app.ts): `src/app.ts`
- [Module registry](https://github.com/sumeshpatva97/cctv-api/blob/develop/src/modules/index.ts): `src/modules/index.ts`
- [Validated config](https://github.com/sumeshpatva97/cctv-api/blob/develop/src/config/env.ts): `src/config/env.ts`
- **PostgreSQL**
- [Realtime hub](https://github.com/sumeshpatva97/cctv-api/blob/develop/src/realtime/hub.ts): `src/realtime/hub.ts`

### Identity and access

- [Auth endpoints](https://github.com/sumeshpatva97/cctv-api/blob/develop/src/modules/auth/auth.routes.ts): `src/modules/auth/auth.routes.ts`
- [Auth service](https://github.com/sumeshpatva97/cctv-api/blob/develop/src/modules/auth/auth.service.ts): `src/modules/auth/auth.service.ts`
- [Auth middleware](https://github.com/sumeshpatva97/cctv-api/blob/develop/src/common/auth/middleware.ts): `src/common/auth/middleware.ts`
- [Session authorization](https://github.com/sumeshpatva97/cctv-api/blob/develop/src/common/auth/authenticate.ts): `src/common/auth/authenticate.ts`
- [Token handling](https://github.com/sumeshpatva97/cctv-api/blob/develop/src/common/auth/tokens.ts): `src/common/auth/tokens.ts`
- [Organization and access admin](https://github.com/sumeshpatva97/cctv-api/tree/develop/src/modules/organization): `src/modules/organization`

### Workforce operations

- [Departments and employees](https://github.com/sumeshpatva97/cctv-api/tree/develop/src/modules/employees): `src/modules/employees`
- [Shift management](https://github.com/sumeshpatva97/cctv-api/tree/develop/src/modules/shifts): `src/modules/shifts`
- [Attendance and corrections](https://github.com/sumeshpatva97/cctv-api/tree/develop/src/modules/attendance): `src/modules/attendance`

### CCTV operations

- [Camera management](https://github.com/sumeshpatva97/cctv-api/blob/develop/src/modules/cameras/cameras.service.ts): `src/modules/cameras/cameras.service.ts`
- [Live stream sessions](https://github.com/sumeshpatva97/cctv-api/blob/develop/src/modules/streaming/stream-sessions.service.ts): `src/modules/streaming/stream-sessions.service.ts`
- [MediaMTX gateway](https://github.com/sumeshpatva97/cctv-api/blob/develop/src/integrations/streaming/mediamtx-gateway.ts): `src/integrations/streaming/mediamtx-gateway.ts`

### Insights and audit

- [Dashboard](https://github.com/sumeshpatva97/cctv-api/tree/develop/src/modules/dashboard): `src/modules/dashboard`
- [Reports and CSV](https://github.com/sumeshpatva97/cctv-api/blob/develop/src/modules/reports/reports.service.ts): `src/modules/reports/reports.service.ts`
- [Audit log](https://github.com/sumeshpatva97/cctv-api/tree/develop/src/modules/audit): `src/modules/audit`

### Other components

- **API client**

## Connections

- API client → Express application: sends requests
- Express application → Module registry: mounts modules (evidence: `src/app.ts`)
- Express application → Validated config: uses config (evidence: `src/app.ts`)
- API client → Auth endpoints: uses auth API
- Auth endpoints → Auth service: dispatches
- Auth service → Session authorization: resolves session (evidence: `src/modules/auth/auth.service.ts`)
- Auth service → Token handling: issues tokens (evidence: `src/modules/auth/auth.service.ts`)
- Auth middleware → Session authorization: authenticates (evidence: `src/common/auth/middleware.ts`)
- Session authorization → Token handling: verifies token (evidence: `src/common/auth/authenticate.ts`)
- Session authorization → PostgreSQL: loads session and grants (evidence: `src/common/auth/authenticate.ts`)
- Auth service → PostgreSQL: updates identity state (evidence: `src/modules/auth/auth.service.ts`)
- API client → Organization and access admin: manages organization access
- API client → Departments and employees: manages workforce
- API client → Shift management: manages shifts
- API client → Attendance and corrections: records attendance
- Attendance and corrections → Departments and employees: uses employee schedules (evidence: `src/modules/attendance/attendance.engine.ts`)
- API client → Camera management: manages cameras
- API client → Live stream sessions: requests live sessions
- Live stream sessions → MediaMTX gateway: checks gateway
- Live stream sessions → PostgreSQL: stores session state (evidence: `src/modules/streaming/stream-sessions.service.ts`)
- API client → Dashboard: views dashboard
- API client → Reports and CSV: requests reports
- API client → Audit log: views audit log
- Live stream sessions → Audit log: records stream events (evidence: `src/modules/streaming/stream-sessions.service.ts`)
- API client → Realtime hub: connects live
