# kaizer-1/respondr architecture

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

- Interactive diagram: https://gitdiagram.com/kaizer-1/respondr
- Repository: https://github.com/kaizer-1/respondr

## Overview

1. **Top-level split:** The repo is divided into a Python backend (`backend/whisper_asr`) that ingests and analyzes emergency calls, and a Next.js frontend (`frontend/emergency-response-frontend`) that presents operator and station workflows. The architecture is centered on moving a phone call from raw audio into a structured incident record.

2. **Telephony ingress boundary:** `twilio_server/app.py` is the backend entrypoint for Twilio webhooks. Twilio posts call and recording events to this service, so the backend must be reachable over a public HTTPS URL in production; locally the README assumes `ngrok` in front of port `8080`.

3. **Call recording and storage:** Incoming recordings are kept on disk under `backend/whisper_asr/recordings/`, with temporary audio chunks in `tmp_chunks/`. Structured incident data is persisted in SQLite at `backend/whisper_asr/data/respondr.db`, making the backend both the processing engine and the system of record.

4. **Speech-to-text subsystem:** `src/asr/offline_transcriber.py` performs transcription using Whisper-based offline ASR. The README’s setup requirements (`torch`, `openai-whisper`, `ffmpeg`, `soundfile`, `numpy`, `scipy`) indicate audio decoding and model inference are local and compute-heavy, not SaaS-backed.

5. **Call analysis pipeline:** `src/pipeline/process_call.py` is the core orchestration layer. It likely coordinates audio normalization, transcription, NLP extraction, location inference, and database writes, turning one call recording into an incident object suitable for dashboards.

6. **Emergency triage logic:** The NLP layer (`src/nlp/emergency_classifier.py`, `keyword_sets.py`, `location_extractor.py`, `semantic_fallback.py`) classifies the incident into emergency type and priority, and extracts location cues from transcript text. This is the main intelligence boundary between raw transcript and dispatch-ready metadata.

7. **Location enrichment subsystem:** `src/location/geocoder.py`, `metadata_provider.py`, `semantic_location.py`, and `location_fusion.py` combine explicit place names with inferred or metadata-derived location context. This means location is not purely text extraction; it is fused from multiple signals before being shown to operators.

8. **Streaming/near-real-time path:** `src/streaming/` contains `live_pipeline.py`, `audio_chunker.py`, `transcript_buffer.py`, `state.py`, and `audio_utils.py`, which support incremental processing while a call is still active. This is the real-time path that complements the offline recording pipeline and enables “live incoming calls” behavior.

9. **Backend service boundaries:** `src/asr_service.py`, `src/db/call_repository.py`, and `src/db/database.py` form the service/data-access boundary. The repository abstraction isolates incident persistence from the processing logic, which is important for diagramming the system as “analysis engine” feeding a “durable incident store.”

10. **Frontend dashboards:** The frontend is a role-based operator/station client built with Next.js App Router (`app/operator/page.tsx`, `app/station/page.tsx`). `components/operator-dashboard.tsx`, `components/station-dashboard.tsx`, and `components/emergency-map.tsx` indicate the UI is organized around live incident lists, dispatch actions, and incident context rather than generic pages.

11. **Frontend-to-backend integration:** `lib/api.ts` is the client-side API boundary used by the dashboards to read incidents and issue dispatch/resolution actions. The frontend is a presentation and workflow layer; the backend owns transcription, analysis, and persistence.

12. **Operational scripts and test assets:** `migrate_database.py` handles schema evolution, while `run_call_analysis.py` suggests an offline/batch analysis mode for replaying audio. The `test_audio/` samples and stored `recordings/` show the repo supports both live call handling and repeatable local testing.

Main entry points: [`backend/whisper_asr/src/pipeline/process_call.py`](https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/pipeline/process_call.py) (Call pipeline), [`backend/whisper_asr/src/streaming/live_pipeline.py`](https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/streaming/live_pipeline.py) (Live pipeline), [`backend/whisper_asr/src/db/call_repository.py`](https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/db/call_repository.py) (Call repository), [`frontend/emergency-response-frontend/components/operator-dashboard.tsx`](https://github.com/kaizer-1/respondr/blob/main/frontend/emergency-response-frontend/components/operator-dashboard.tsx) (Operator dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend"]
  node_twilio_app["Twilio webhook<br/>HTTP ingress<br/>[app.py]"]
  node_call_pipeline["Call pipeline<br/>orchestration<br/>[process_call.py]"]
  node_asr_service["ASR service<br/>service boundary<br/>[asr_service.py]"]
  node_offline_transcriber["Offline ASR<br/>whisper transcriber"]
  node_normalizer["Normalizer<br/>audio prep<br/>[normalizer.py]"]
  node_streaming_pipeline["Live pipeline<br/>streaming pipeline<br/>[live_pipeline.py]"]
  node_chunker["Chunker<br/>audio chunking<br/>[audio_chunker.py]"]
  node_transcript_buffer["Transcript buffer<br/>stream state"]
  node_emergency_classifier["Emergency NLP<br/>triage classifier"]
  node_location_extractor["Location NLP<br/>text extraction"]
  node_location_fusion["Location fusion<br/>enrichment<br/>[location_fusion.py]"]
  node_geocoder["Geocoder<br/>location service<br/>[geocoder.py]"]
  node_call_repository["Call repository<br/>data access<br/>[call_repository.py]"]
  node_database[("SQLite DB<br/>system of record<br/>[database.py]")]
end

subgraph group_frontend["Frontend"]
  node_operator_page["Operator page<br/>Next.js route<br/>[page.tsx]"]
  node_station_page["Station page<br/>Next.js route<br/>[page.tsx]"]
  node_operator_dashboard["Operator dashboard<br/>ui workflow"]
  node_station_dashboard["Station dashboard<br/>ui workflow"]
  node_emergency_map["Incident map<br/>context view<br/>[emergency-map.tsx]"]
  node_api_client["API client<br/>frontend boundary<br/>[api.ts]"]
end

node_twilio_app -->|"starts analysis"| node_call_pipeline
node_twilio_app -->|"live calls"| node_streaming_pipeline
node_call_pipeline -->|"prepares audio"| node_normalizer
node_call_pipeline -->|"transcribes"| node_offline_transcriber
node_call_pipeline -->|"triages"| node_emergency_classifier
node_call_pipeline -->|"extracts location"| node_location_extractor
node_call_pipeline -->|"enriches location"| node_location_fusion
node_call_pipeline -->|"persists incident"| node_call_repository
node_asr_service -->|"uses ASR"| node_offline_transcriber
node_streaming_pipeline -->|"splits audio"| node_chunker
node_streaming_pipeline -->|"accumulates text"| node_transcript_buffer
node_streaming_pipeline -->|"incremental ASR"| node_offline_transcriber
node_location_fusion -->|"resolves places"| node_geocoder
node_location_extractor -->|"feeds cues"| node_location_fusion
node_emergency_classifier -->|"writes triage"| node_call_repository
node_call_repository -->|"stores in"| node_database
node_operator_page -->|"renders"| node_operator_dashboard
node_station_page -->|"renders"| node_station_dashboard
node_operator_dashboard -->|"reads/updates"| node_api_client
node_station_dashboard -->|"reads/updates"| node_api_client
node_operator_dashboard -->|"shows context"| node_emergency_map
node_api_client -.->|"backend calls"| node_call_repository

click node_twilio_app "https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/twilio_server/app.py"
click node_call_pipeline "https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/pipeline/process_call.py"
click node_asr_service "https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/asr_service.py"
click node_offline_transcriber "https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/asr/offline_transcriber.py"
click node_normalizer "https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/normalizer.py"
click node_streaming_pipeline "https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/streaming/live_pipeline.py"
click node_chunker "https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/streaming/audio_chunker.py"
click node_transcript_buffer "https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/streaming/transcript_buffer.py"
click node_emergency_classifier "https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/nlp/emergency_classifier.py"
click node_location_extractor "https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/nlp/location_extractor.py"
click node_location_fusion "https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/location/location_fusion.py"
click node_geocoder "https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/location/geocoder.py"
click node_call_repository "https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/db/call_repository.py"
click node_database "https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/db/database.py"
click node_operator_page "https://github.com/kaizer-1/respondr/blob/main/frontend/emergency-response-frontend/app/operator/page.tsx"
click node_station_page "https://github.com/kaizer-1/respondr/blob/main/frontend/emergency-response-frontend/app/station/page.tsx"
click node_operator_dashboard "https://github.com/kaizer-1/respondr/blob/main/frontend/emergency-response-frontend/components/operator-dashboard.tsx"
click node_station_dashboard "https://github.com/kaizer-1/respondr/blob/main/frontend/emergency-response-frontend/components/station-dashboard.tsx"
click node_emergency_map "https://github.com/kaizer-1/respondr/blob/main/frontend/emergency-response-frontend/components/emergency-map.tsx"
click node_api_client "https://github.com/kaizer-1/respondr/blob/main/frontend/emergency-response-frontend/lib/api.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_twilio_app,node_call_pipeline,node_asr_service,node_offline_transcriber,node_normalizer,node_streaming_pipeline,node_chunker,node_transcript_buffer,node_emergency_classifier,node_location_extractor,node_location_fusion,node_geocoder,node_call_repository,node_database toneBlue
class node_operator_page,node_station_page,node_operator_dashboard,node_station_dashboard,node_emergency_map,node_api_client toneAmber
```

## Components

### Backend

Twilio ingress, audio processing, analysis, and persistence.

- [Twilio webhook](https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/twilio_server/app.py): HTTP ingress · Receives call and recording events from Twilio and starts backend processing. · `backend/whisper_asr/twilio_server/app.py`
- [Call pipeline](https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/pipeline/process_call.py): orchestration · Coordinates normalization, transcription, analysis, and incident creation for a call. · `backend/whisper_asr/src/pipeline/process_call.py`
- [ASR service](https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/asr_service.py): service boundary · Backend service layer that exposes transcription and processing capabilities. · `backend/whisper_asr/src/asr_service.py`
- [Offline ASR](https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/asr/offline_transcriber.py): whisper transcriber · Local Whisper-based speech-to-text engine for recordings and chunks. · `backend/whisper_asr/src/asr/offline_transcriber.py`
- [Normalizer](https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/normalizer.py): audio prep · Prepares audio into a form suitable for transcription and downstream analysis. · `backend/whisper_asr/src/normalizer.py`
- [Live pipeline](https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/streaming/live_pipeline.py): streaming pipeline · Incrementally processes audio while a call is still active. · `backend/whisper_asr/src/streaming/live_pipeline.py`
- [Chunker](https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/streaming/audio_chunker.py): audio chunking · Splits live audio into smaller pieces for near-real-time handling. · `backend/whisper_asr/src/streaming/audio_chunker.py`
- [Transcript buffer](https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/streaming/transcript_buffer.py): stream state · Accumulates partial transcripts during live call handling. · `backend/whisper_asr/src/streaming/transcript_buffer.py`
- [Emergency NLP](https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/nlp/emergency_classifier.py): triage classifier · Classifies incident type and priority from transcript text. · `backend/whisper_asr/src/nlp/emergency_classifier.py`
- [Location NLP](https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/nlp/location_extractor.py): text extraction · Extracts place cues and location hints from the transcript. · `backend/whisper_asr/src/nlp/location_extractor.py`
- [Location fusion](https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/location/location_fusion.py): enrichment · Combines extracted, semantic, and metadata-based location signals. · `backend/whisper_asr/src/location/location_fusion.py`
- [Geocoder](https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/location/geocoder.py): location service · Resolves location text into geospatial or structured address context. · `backend/whisper_asr/src/location/geocoder.py`
- [Call repository](https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/db/call_repository.py): data access · Persistence abstraction for incident and call records. · `backend/whisper_asr/src/db/call_repository.py`
- [SQLite DB](https://github.com/kaizer-1/respondr/blob/main/backend/whisper_asr/src/db/database.py): system of record · Durable incident store backing the backend. · `backend/whisper_asr/src/db/database.py`

### Frontend

Next.js operator and station workflows.

- [Operator page](https://github.com/kaizer-1/respondr/blob/main/frontend/emergency-response-frontend/app/operator/page.tsx): Next.js route · Role-based dashboard entry for call handling and incident review. · `frontend/emergency-response-frontend/app/operator/page.tsx`
- [Station page](https://github.com/kaizer-1/respondr/blob/main/frontend/emergency-response-frontend/app/station/page.tsx): Next.js route · Role-based station workflow entry for dispatch and station operations. · `frontend/emergency-response-frontend/app/station/page.tsx`
- [Operator dashboard](https://github.com/kaizer-1/respondr/blob/main/frontend/emergency-response-frontend/components/operator-dashboard.tsx): ui workflow · Shows live incidents, triage context, and operator actions. · `frontend/emergency-response-frontend/components/operator-dashboard.tsx`
- [Station dashboard](https://github.com/kaizer-1/respondr/blob/main/frontend/emergency-response-frontend/components/station-dashboard.tsx): ui workflow · Supports station-facing dispatch and incident resolution workflows. · `frontend/emergency-response-frontend/components/station-dashboard.tsx`
- [Incident map](https://github.com/kaizer-1/respondr/blob/main/frontend/emergency-response-frontend/components/emergency-map.tsx): context view · Visualizes incident location context for operators. · `frontend/emergency-response-frontend/components/emergency-map.tsx`
- [API client](https://github.com/kaizer-1/respondr/blob/main/frontend/emergency-response-frontend/lib/api.ts): frontend boundary · Client-side interface used by dashboards to read and update backend state. · `frontend/emergency-response-frontend/lib/api.ts`

## Connections

- Twilio webhook → Call pipeline: starts analysis · Twilio webhook events enter the call processing pipeline.
- Twilio webhook → Live pipeline: live calls · Active call audio can be routed into the near-real-time pipeline.
- Call pipeline → Normalizer: prepares audio · Recorded call audio is normalized before transcription.
- Call pipeline → Offline ASR: transcribes · The pipeline invokes offline Whisper ASR on call audio.
- Call pipeline → Emergency NLP: triages · Transcript text is classified into emergency type and priority.
- Call pipeline → Location NLP: extracts location · The pipeline pulls location cues from transcript text.
- Call pipeline → Location fusion: enriches location · Location signals are fused before incident creation.
- Call pipeline → Call repository: persists incident · Processed call output is stored through the repository boundary.
- ASR service → Offline ASR: uses ASR · The service layer delegates speech-to-text work to the transcriber.
- Live pipeline → Chunker: splits audio · Live audio is divided into chunks for incremental processing.
- Live pipeline → Transcript buffer: accumulates text · Partial transcripts are buffered during the live session.
- Live pipeline → Offline ASR: incremental ASR · Chunked audio is transcribed as it arrives.
- Location fusion → Geocoder: resolves places · Fused location handling can call into geocoding resolution.
- Location NLP → Location fusion: feeds cues · Extracted place hints flow into location enrichment.
- Emergency NLP → Call repository: writes triage · Classification output contributes to the stored incident record.
- Call repository → SQLite DB: stores in · Repository operations persist to the SQLite database.
- Operator page → Operator dashboard: renders · The route loads the operator workflow component.
- Station page → Station dashboard: renders · The route loads the station workflow component.
- Operator dashboard → API client: reads/updates · Operator actions and incident views go through the API client.
- Station dashboard → API client: reads/updates · Station workflows use the same backend API boundary.
- Operator dashboard → Incident map: shows context · Operator UI includes mapped incident context.
- API client → Call repository: backend calls · Frontend API operations ultimately target incident persistence and workflow endpoints.
