# sesuraja/aperture-people-tracking-in-construction architecture

> Architecture diagram of the GitHub repository sesuraja/aperture-people-tracking-in-construction, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sesuraja/aperture-people-tracking-in-construction
- Repository: https://github.com/sesuraja/aperture-people-tracking-in-construction

## Overview

#### Purpose and Entry Points
Aperture is an operations/tracking dashboard for workforce, assets, visitors, devices, incidents, maps, and external hardware/API integrations. It combines a Vite React client with a TypeScript server/API layer. Client bootstraps at `src/main.tsx` into `src/App.tsx`; deployment/server entry points are `server.ts` and `api/index.ts`.

#### Application Shell and Navigation
`src/App.tsx` owns the dashboard composition, tab-level navigation, and shared modal surfaces. `src/components/TopBar.tsx` and `src/components/CommandPaletteModal.tsx` provide global interaction controls. The main feature areas are independently rendered tab components, including `src/components/DashboardTab.tsx`, `src/components/LiveTrackingTab.tsx`, and `src/components/SettingsTab.tsx`.

#### Live Tracking State and Visualization
Tracking-centric UI state is centralized in `src/context/TrackingContext.tsx`. It feeds live map and inspection experiences in `src/components/LiveFloorMap.tsx`, `src/components/CustomMapPage.tsx`, and `src/components/LiveTrackingContextDrawer.tsx`. Spatial/display-layer transformation is separated in `src/lib/trackingLayers.ts`, creating a boundary between incoming location/tag data and map presentation.

#### Device, RFID, and Event Ingestion
The backend exposes dedicated integration surfaces for hardware, RFID, events, and real-time streams through `src/server/routes/hardware.ts`, `src/server/routes/rfid.ts`, `src/server/routes/events.ts`, and `src/server/routes/realtime.ts`. Ingestion and hardware-specific orchestration reside in `src/server/services/ingestionService.ts` and `src/server/services/hardwareIntegrationService.ts`. The client configures these sources through `src/components/HardwareIntegrationForm.tsx` and `src/components/RfidApiConfiguration.tsx`.

#### Real-Time Transport Boundary
WebSocket, SSE, and MQTT are first-class transport options. Server-side adapters are in `src/server/services/websocket.ts`, `src/server/services/sse.ts`, and `src/server/services/mqtt.ts`; browser-facing access is in `src/lib/webSocketService.ts`, `src/lib/useWebSocket.ts`, and `src/lib/mqttService.ts`. This separates live feed acquisition/distribution from the tracking UI and allows diagnostics through `src/components/StreamDiagnostics.tsx`.

#### Persistence and External Connections
MongoDB-oriented schemas distinguish historical and current tag records in `src/db/schemas/mongodb/history_records.ts` and `src/db/schemas/mongodb/real_time_tags.ts`; server DB access is organized in `src/server/services/db.ts`. Connection discovery/polling and third-party integration management are handled by `src/server/services/connectionsService.ts`, `src/server/services/connectionPoller.ts`, and `src/server/services/apiIntegrationService.ts`, exposed via `src/server/routes/connections.ts` and `src/server/routes/apiIntegrations.ts`.

#### AI, Authentication, and Operational APIs
Gemini is an explicit runtime dependency via `GEMINI_API_KEY`; AI request handling and pipeline logic are located in `src/server/routes/ai.ts` and `src/server/services/aiPipeline.ts`, with client outputs in `src/components/AIFeed.tsx` and `src/components/AIInsightsTab.tsx`. Authentication and authorization form a server boundary through `src/server/routes/auth.ts`, `src/server/middleware/auth.ts`, and `src/constants/permissions.ts`. Cross-cutting failures are handled by `src/server/middleware/errorHandler.ts` and `src/components/ErrorBoundary.tsx`.

#### Runtime and Deployment
The repository uses Node.js, TypeScript, React, and Vite, with built client/server artifacts under `dist/`. It includes Firebase/Firestore deployment or policy artifacts in `firebase-applet-config.json` and `firestore.rules`, Mongo runtime configuration in `.mongo_runtime.json`, and Vercel configuration in `vercel.json`.

Main entry points: [`src/App.tsx`](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/App.tsx) (Dashboard shell), [`src/server/routes/hardware.ts`](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/server/routes/hardware.ts) (Operational routes), [`src/server/services/ingestionService.ts`](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/server/services/ingestionService.ts) (Ingestion orchestration), [`src/lib/webSocketService.ts`](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/lib/webSocketService.ts) (Browser live transports)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React client"]
  node_client_bootstrap["Client bootstrap<br/>Vite entry<br/>[main.tsx]"]
  node_app_shell["Dashboard shell<br/>React composition<br/>[App.tsx]"]
  node_global_controls["Global controls<br/>React UI<br/>[TopBar.tsx]"]
  node_feature_tabs["Operational tabs<br/>React UI<br/>[DashboardTab.tsx]"]
  node_integration_config["Integration configuration<br/>React UI"]
  node_ai_ui["AI insights UI<br/>React UI<br/>[AIFeed.tsx]"]
end

subgraph group_tracking["Live tracking"]
  node_tracking_context["Tracking state<br/>React context"]
  node_tracking_layers["Spatial layer transform<br/>presentation mapping<br/>[trackingLayers.ts]"]
  node_map_views["Live map &amp; inspector<br/>React UI<br/>[LiveFloorMap.tsx]"]
  node_browser_transports["Browser live transports<br/>client adapters"]
  node_stream_diagnostics["Stream diagnostics<br/>React UI"]
end

subgraph group_server["Server API"]
  node_server_entry["Server entry<br/>Node entry<br/>[server.ts]"]
  node_api_routes["Operational routes<br/>API routes<br/>[hardware.ts]"]
  node_ingestion["Ingestion orchestration<br/>server service"]
  node_transport_adapters["Live transport adapters<br/>server adapters<br/>[websocket.ts]"]
  node_connections["External connection management<br/>server services"]
  node_ai_pipeline["Gemini AI pipeline<br/>server service<br/>[aiPipeline.ts]"]
  node_auth_boundary["Auth &amp; authorization<br/>middleware<br/>[auth.ts]"]
end

subgraph group_data["Data &amp; external services"]
  node_mongodb[("MongoDB tracking records<br/>database schemas<br/>[real_time_tags.ts]")]
  node_external_apis{{"Hardware &amp; third-party APIs<br/>external systems"}}
  node_gemini{{"Gemini<br/>AI provider"}}
end

node_client_bootstrap -->|"mounts"| node_app_shell
node_app_shell -->|"renders"| node_global_controls
node_app_shell -->|"navigates"| node_feature_tabs
node_app_shell -->|"provides"| node_tracking_context
node_app_shell -->|"renders"| node_integration_config
node_app_shell -->|"renders"| node_ai_ui
node_tracking_context -->|"supplies tag state"| node_tracking_layers
node_tracking_layers -->|"builds map display"| node_map_views
node_browser_transports -->|"updates live state"| node_tracking_context
node_browser_transports -->|"reports status"| node_stream_diagnostics
node_integration_config -->|"configures"| node_api_routes
node_server_entry -->|"serves"| node_api_routes
node_api_routes -->|"protected by"| node_auth_boundary
node_api_routes -->|"submits events"| node_ingestion
node_api_routes -->|"manages connections"| node_connections
node_ingestion -->|"publishes updates"| node_transport_adapters
node_transport_adapters -->|"streams live feeds"| node_browser_transports
node_ingestion -->|"stores tags and history"| node_mongodb
node_connections -->|"discovers and polls"| node_external_apis
node_external_apis -->|"sends hardware data"| node_ingestion
node_ai_ui -->|"requests insights"| node_ai_pipeline
node_ai_pipeline -->|"invokes"| node_gemini

click node_client_bootstrap "https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/main.tsx"
click node_app_shell "https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/App.tsx"
click node_global_controls "https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/components/TopBar.tsx"
click node_feature_tabs "https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/components/DashboardTab.tsx"
click node_integration_config "https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/components/HardwareIntegrationForm.tsx"
click node_ai_ui "https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/components/AIFeed.tsx"
click node_tracking_context "https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/context/TrackingContext.tsx"
click node_tracking_layers "https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/lib/trackingLayers.ts"
click node_map_views "https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/components/LiveFloorMap.tsx"
click node_browser_transports "https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/lib/webSocketService.ts"
click node_stream_diagnostics "https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/components/StreamDiagnostics.tsx"
click node_server_entry "https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/server.ts"
click node_api_routes "https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/server/routes/hardware.ts"
click node_ingestion "https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/server/services/ingestionService.ts"
click node_transport_adapters "https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/server/services/websocket.ts"
click node_connections "https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/server/services/connectionsService.ts"
click node_ai_pipeline "https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/server/services/aiPipeline.ts"
click node_auth_boundary "https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/server/middleware/auth.ts"
click node_mongodb "https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/db/schemas/mongodb/real_time_tags.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_client_bootstrap,node_app_shell,node_global_controls,node_feature_tabs,node_integration_config,node_ai_ui toneBlue
class node_tracking_context,node_tracking_layers,node_map_views,node_browser_transports,node_stream_diagnostics toneAmber
class node_server_entry,node_api_routes,node_ingestion,node_transport_adapters,node_connections,node_ai_pipeline,node_auth_boundary toneMint
class node_mongodb,node_external_apis,node_gemini toneRose
```

## Components

### React client

Dashboard shell and operational feature UI.

- [Client bootstrap](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/main.tsx): Vite entry · `src/main.tsx`
- [Dashboard shell](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/App.tsx): React composition · Owns navigation and shared modal surfaces. · `src/App.tsx`
- [Global controls](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/components/TopBar.tsx): React UI · Top bar and command palette interactions. · `src/components/TopBar.tsx`
- [Operational tabs](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/components/DashboardTab.tsx): React UI · Dashboard, live tracking, and settings feature areas. · `src/components/DashboardTab.tsx`
- [Integration configuration](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/components/HardwareIntegrationForm.tsx): React UI · Hardware and RFID source setup. · `src/components/HardwareIntegrationForm.tsx`
- [AI insights UI](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/components/AIFeed.tsx): React UI · AI feed and insights presentation. · `src/components/AIFeed.tsx`

### Live tracking

State, spatial transformation, and live map views.

- [Tracking state](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/context/TrackingContext.tsx): React context · Central client state for tracking UI. · `src/context/TrackingContext.tsx`
- [Spatial layer transform](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/lib/trackingLayers.ts): presentation mapping · Converts location and tag data into map layers. · `src/lib/trackingLayers.ts`
- [Live map & inspector](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/components/LiveFloorMap.tsx): React UI · Floor map, custom map, and context drawer. · `src/components/LiveFloorMap.tsx`
- [Browser live transports](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/lib/webSocketService.ts): client adapters · WebSocket, hook, and MQTT access. · `src/lib/webSocketService.ts`
- [Stream diagnostics](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/components/StreamDiagnostics.tsx): React UI · `src/components/StreamDiagnostics.tsx`

### Server API

Node/TypeScript API, integration, and transport boundaries.

- [Server entry](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/server.ts): Node entry · Deployment and API entry points. · `server.ts`
- [Operational routes](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/server/routes/hardware.ts): API routes · Hardware, RFID, event, and realtime endpoints. · `src/server/routes/hardware.ts`
- [Ingestion orchestration](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/server/services/ingestionService.ts): server service · Processes incoming events and hardware data. · `src/server/services/ingestionService.ts`
- [Live transport adapters](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/server/services/websocket.ts): server adapters · WebSocket, SSE, and MQTT distribution. · `src/server/services/websocket.ts`
- [External connection management](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/server/services/connectionsService.ts): server services · Discovery, polling, and API integration management. · `src/server/services/connectionsService.ts`
- [Gemini AI pipeline](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/server/services/aiPipeline.ts): server service · AI request processing through the Gemini runtime key. · `src/server/services/aiPipeline.ts`
- [Auth & authorization](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/server/middleware/auth.ts): middleware · Authentication and permission enforcement. · `src/server/middleware/auth.ts`

### Data & external services

Persistence and third-party runtime dependencies.

- [MongoDB tracking records](https://github.com/sesuraja/aperture-people-tracking-in-construction/blob/main/src/db/schemas/mongodb/real_time_tags.ts): database schemas · Historical records and current real-time tags. · `src/db/schemas/mongodb/real_time_tags.ts`
- **Hardware & third-party APIs**: external systems
- **Gemini**: AI provider · Configured with GEMINI_API_KEY.

## Connections

- Client bootstrap → Dashboard shell: mounts
- Dashboard shell → Global controls: renders
- Dashboard shell → Operational tabs: navigates
- Dashboard shell → Tracking state: provides
- Dashboard shell → Integration configuration: renders
- Dashboard shell → AI insights UI: renders
- Tracking state → Spatial layer transform: supplies tag state
- Spatial layer transform → Live map & inspector: builds map display
- Browser live transports → Tracking state: updates live state
- Browser live transports → Stream diagnostics: reports status
- Integration configuration → Operational routes: configures
- Server entry → Operational routes: serves
- Operational routes → Auth & authorization: protected by
- Operational routes → Ingestion orchestration: submits events
- Operational routes → External connection management: manages connections
- Ingestion orchestration → Live transport adapters: publishes updates
- Live transport adapters → Browser live transports: streams live feeds
- Ingestion orchestration → MongoDB tracking records: stores tags and history
- External connection management → Hardware & third-party APIs: discovers and polls
- Hardware & third-party APIs → Ingestion orchestration: sends hardware data
- AI insights UI → Gemini AI pipeline: requests insights
- Gemini AI pipeline → Gemini: invokes
