# sajawalkhan01/civicpulse architecture

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

- Interactive diagram: https://gitdiagram.com/sajawalkhan01/civicpulse
- Repository: https://github.com/sajawalkhan01/civicpulse

## Overview

CivicPulse accepts free-text municipal complaints, classifies and prioritizes them, stores them for municipal follow-up, and exposes operational views. The main workflow runs from citizen intake through the frontend API client, complaint route, service, triage and persistence; separate branches cover status transitions, statistics, health/readiness, and provider observability. The graph uses source excerpts and the source index for backend relationships, plus README-documented product capabilities; some frontend internals and unsampled route wiring are therefore shown only at a broad level.

Main entry points: [`backend/app/main.py`](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/main.py) (FastAPI App), [`backend/app/services/triage_service.py`](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/services/triage_service.py) (Triage Orchestrator), [`backend/app/services/complaints.py`](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/services/complaints.py) (Complaint Service), [`backend/app/providers/triage/factory.py`](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/providers/triage/factory.py) (Provider Selection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_citizen_ui["Citizen and Operator UI"]
  node_web_app["Web Application<br/>[App.tsx]"]
  node_intake_page["Complaint Intake<br/>[submit-page.tsx]"]
  node_dashboard["Complaint Dashboard<br/>[dashboard-page.tsx]"]
  node_stats_page["Statistics View<br/>[stats-page.tsx]"]
  node_api_client["Frontend API Client<br/>[complaints.ts]"]
end

subgraph group_complaint_api["Complaint API"]
  node_complaint_route["Complaint Routes<br/>[complaints.py]"]
  node_complaint_service["Complaint Service<br/>[complaints.py]"]
  node_domain_models["Complaint and Triage Models<br/>[models.py]"]
  node_status_machine["Status State Machine<br/>[state_machine.py]"]
end

subgraph group_triage["Triage Providers"]
  node_triage_service["Triage Orchestrator<br/>[triage_service.py]"]
  node_provider_factory["Provider Selection<br/>[factory.py]"]
  node_provider_contract["Triage Provider Contract<br/>[protocols.py]"]
  node_groq_provider["Groq LLM Provider<br/>[llm.py]"]
  node_ollama_provider["Ollama Provider<br/>[ollama.py]"]
  node_rules_provider["Rules and Fallback<br/>[rules.py]"]
end

subgraph group_persistence["Persistence and Cache"]
  node_complaint_repo["Complaint Repository<br/>[complaints.py]"]
  node_orm_model["Complaint ORM Model<br/>[models.py]"]
  node_database[("PostgreSQL")]
  node_cache_factory["Cache Selection<br/>[factory.py]"]
  node_redis_cache["Redis Cache<br/>[redis_cache.py]"]
  node_memory_cache["In-Memory Cache<br/>[in_memory_cache.py]"]
  node_redis[("Redis")]
end

subgraph group_operations["Operations"]
  node_app_entry["FastAPI App<br/>[main.py]"]
  node_stats_route["Statistics Route<br/>[stats.py]"]
  node_meta_route["Provider Metadata Route<br/>[meta.py]"]
  node_health_routes["Health and Readiness<br/>[readiness.py]"]
  node_health_service["Readiness Checks<br/>[readiness.py]"]
  node_metrics_middleware["Metrics Middleware<br/>[metrics.py]"]
  node_rate_middleware["Rate Limit Middleware<br/>[rate_limit.py]"]
  node_rate_limiter["Rate Limiter<br/>[rate_limiter.py]"]
  node_observability_route["Metrics Endpoint<br/>[observability.py]"]
end

node_citizen(("Citizen / Operator"))
node_groq_service{{"Groq Cloud"}}
node_ollama_service{{"Ollama Runtime"}}

node_citizen -->|"uses"| node_web_app
node_web_app -->|"submits HTTP"| node_complaint_route
node_intake_page -.->|"submits through"| node_api_client
node_dashboard -.->|"loads records"| node_api_client
node_stats_page -.->|"loads statistics"| node_api_client
node_complaint_route -->|"delegates"| node_complaint_service
node_complaint_service -->|"requests triage"| node_triage_service
node_complaint_service -->|"persists and queries"| node_complaint_repo
node_complaint_service -->|"validates transitions"| node_status_machine
node_complaint_route -->|"validates payloads"| node_domain_models
node_triage_service -->|"selects provider"| node_provider_factory
node_triage_service -->|"falls back to"| node_rules_provider
node_triage_service -->|"gets cache"| node_cache_factory
node_provider_factory -->|"selects"| node_groq_provider
node_provider_factory -->|"selects"| node_ollama_provider
node_provider_factory -->|"selects"| node_rules_provider
node_groq_provider -->|"calls API"| node_groq_service
node_ollama_provider -.->|"calls model"| node_ollama_service
node_complaint_repo -->|"queries"| node_orm_model
node_orm_model -->|"stores complaints"| node_database
node_cache_factory -->|"chooses"| node_redis_cache
node_cache_factory -->|"chooses"| node_memory_cache
node_redis_cache -->|"reads and writes"| node_redis
node_app_entry -->|"registers"| node_complaint_route
node_app_entry -->|"registers"| node_stats_route
node_app_entry -->|"registers"| node_meta_route
node_app_entry -->|"registers"| node_health_routes
node_app_entry -->|"installs"| node_metrics_middleware
node_app_entry -->|"installs"| node_rate_middleware
node_rate_middleware -->|"uses"| node_rate_limiter
node_health_routes -->|"checks readiness"| node_health_service
node_meta_route -->|"reads provider status"| node_triage_service
node_stats_route -.->|"aggregates records"| node_complaint_repo
node_observability_route -.->|"exposes metrics"| node_metrics_middleware

click node_web_app "https://github.com/sajawalkhan01/civicpulse/blob/main/frontend/src/App.tsx"
click node_intake_page "https://github.com/sajawalkhan01/civicpulse/blob/main/frontend/src/pages/submit-page.tsx"
click node_dashboard "https://github.com/sajawalkhan01/civicpulse/blob/main/frontend/src/pages/dashboard-page.tsx"
click node_stats_page "https://github.com/sajawalkhan01/civicpulse/blob/main/frontend/src/pages/stats-page.tsx"
click node_api_client "https://github.com/sajawalkhan01/civicpulse/blob/main/frontend/src/api/complaints.ts"
click node_complaint_route "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/routes/complaints.py"
click node_complaint_service "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/services/complaints.py"
click node_domain_models "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/domain/models.py"
click node_status_machine "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/domain/state_machine.py"
click node_triage_service "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/services/triage_service.py"
click node_provider_factory "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/providers/triage/factory.py"
click node_provider_contract "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/domain/protocols.py"
click node_groq_provider "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/providers/triage/llm.py"
click node_ollama_provider "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/providers/triage/ollama.py"
click node_rules_provider "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/providers/triage/rules.py"
click node_complaint_repo "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/repositories/complaints.py"
click node_orm_model "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/models.py"
click node_cache_factory "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/providers/cache/factory.py"
click node_redis_cache "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/providers/cache/redis_cache.py"
click node_memory_cache "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/providers/cache/in_memory_cache.py"
click node_app_entry "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/main.py"
click node_stats_route "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/routes/stats.py"
click node_meta_route "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/routes/meta.py"
click node_health_routes "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/routes/readiness.py"
click node_health_service "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/services/readiness.py"
click node_metrics_middleware "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/middleware/metrics.py"
click node_rate_middleware "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/middleware/rate_limit.py"
click node_rate_limiter "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/providers/rate_limiter.py"
click node_observability_route "https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/routes/observability.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_web_app,node_intake_page,node_dashboard,node_stats_page,node_api_client toneBlue
class node_complaint_route,node_complaint_service,node_domain_models,node_status_machine toneAmber
class node_triage_service,node_provider_factory,node_provider_contract,node_groq_provider,node_ollama_provider,node_rules_provider toneMint
class node_complaint_repo,node_orm_model,node_database,node_cache_factory,node_redis_cache,node_memory_cache,node_redis toneRose
class node_app_entry,node_stats_route,node_meta_route,node_health_routes,node_health_service,node_metrics_middleware,node_rate_middleware,node_rate_limiter,node_observability_route,node_citizen,node_groq_service,node_ollama_service toneIndigo
```

## Components

### Citizen and Operator UI

- [Web Application](https://github.com/sajawalkhan01/civicpulse/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Complaint Intake](https://github.com/sajawalkhan01/civicpulse/blob/main/frontend/src/pages/submit-page.tsx): `frontend/src/pages/submit-page.tsx`
- [Complaint Dashboard](https://github.com/sajawalkhan01/civicpulse/blob/main/frontend/src/pages/dashboard-page.tsx): `frontend/src/pages/dashboard-page.tsx`
- [Statistics View](https://github.com/sajawalkhan01/civicpulse/blob/main/frontend/src/pages/stats-page.tsx): `frontend/src/pages/stats-page.tsx`
- [Frontend API Client](https://github.com/sajawalkhan01/civicpulse/blob/main/frontend/src/api/complaints.ts): `frontend/src/api/complaints.ts`

### Complaint API

- [Complaint Routes](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/routes/complaints.py): `backend/app/routes/complaints.py`
- [Complaint Service](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/services/complaints.py): `backend/app/services/complaints.py`
- [Complaint and Triage Models](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/domain/models.py): `backend/app/domain/models.py`
- [Status State Machine](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/domain/state_machine.py): `backend/app/domain/state_machine.py`

### Triage Providers

- [Triage Orchestrator](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/services/triage_service.py): `backend/app/services/triage_service.py`
- [Provider Selection](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/providers/triage/factory.py): `backend/app/providers/triage/factory.py`
- [Triage Provider Contract](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/domain/protocols.py): `backend/app/domain/protocols.py`
- [Groq LLM Provider](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/providers/triage/llm.py): `backend/app/providers/triage/llm.py`
- [Ollama Provider](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/providers/triage/ollama.py): `backend/app/providers/triage/ollama.py`
- [Rules and Fallback](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/providers/triage/rules.py): `backend/app/providers/triage/rules.py`

### Persistence and Cache

- [Complaint Repository](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/repositories/complaints.py): `backend/app/repositories/complaints.py`
- [Complaint ORM Model](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/models.py): `backend/app/models.py`
- **PostgreSQL**
- [Cache Selection](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/providers/cache/factory.py): `backend/app/providers/cache/factory.py`
- [Redis Cache](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/providers/cache/redis_cache.py): `backend/app/providers/cache/redis_cache.py`
- [In-Memory Cache](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/providers/cache/in_memory_cache.py): `backend/app/providers/cache/in_memory_cache.py`
- **Redis**

### Operations

- [FastAPI App](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/main.py): `backend/app/main.py`
- [Statistics Route](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/routes/stats.py): `backend/app/routes/stats.py`
- [Provider Metadata Route](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/routes/meta.py): `backend/app/routes/meta.py`
- [Health and Readiness](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/routes/readiness.py): `backend/app/routes/readiness.py`
- [Readiness Checks](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/services/readiness.py): `backend/app/services/readiness.py`
- [Metrics Middleware](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/middleware/metrics.py): `backend/app/middleware/metrics.py`
- [Rate Limit Middleware](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/middleware/rate_limit.py): `backend/app/middleware/rate_limit.py`
- [Rate Limiter](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/providers/rate_limiter.py): `backend/app/providers/rate_limiter.py`
- [Metrics Endpoint](https://github.com/sajawalkhan01/civicpulse/blob/main/backend/app/routes/observability.py): `backend/app/routes/observability.py`

### Other components

- **Citizen / Operator**
- **Groq Cloud**
- **Ollama Runtime**

## Connections

- Citizen / Operator → Web Application: uses (evidence: `README.md`)
- Web Application → Complaint Routes: submits HTTP (evidence: `README.md`)
- Complaint Intake → Frontend API Client: submits through
- Complaint Dashboard → Frontend API Client: loads records
- Statistics View → Frontend API Client: loads statistics
- Complaint Routes → Complaint Service: delegates (evidence: `backend/app/routes/complaints.py`)
- Complaint Service → Triage Orchestrator: requests triage (evidence: `backend/app/services/complaints.py`)
- Complaint Service → Complaint Repository: persists and queries (evidence: `backend/app/services/complaints.py`)
- Complaint Service → Status State Machine: validates transitions (evidence: `backend/app/services/complaints.py`)
- Complaint Routes → Complaint and Triage Models: validates payloads (evidence: `backend/app/routes/complaints.py`)
- Triage Orchestrator → Provider Selection: selects provider (evidence: `backend/app/services/triage_service.py`)
- Triage Orchestrator → Rules and Fallback: falls back to (evidence: `backend/app/services/triage_service.py`)
- Triage Orchestrator → Cache Selection: gets cache (evidence: `backend/app/services/triage_service.py`)
- Provider Selection → Groq LLM Provider: selects (evidence: `backend/app/providers/triage/factory.py`)
- Provider Selection → Ollama Provider: selects (evidence: `backend/app/providers/triage/factory.py`)
- Provider Selection → Rules and Fallback: selects (evidence: `backend/app/providers/triage/factory.py`)
- Groq LLM Provider → Groq Cloud: calls API (evidence: `backend/app/providers/triage/llm.py`)
- Ollama Provider → Ollama Runtime: calls model
- Complaint Repository → Complaint ORM Model: queries (evidence: `backend/app/repositories/complaints.py`)
- Complaint ORM Model → PostgreSQL: stores complaints (evidence: `README.md`)
- Cache Selection → Redis Cache: chooses (evidence: `backend/app/providers/cache/factory.py`)
- Cache Selection → In-Memory Cache: chooses (evidence: `backend/app/providers/cache/factory.py`)
- Redis Cache → Redis: reads and writes (evidence: `backend/app/providers/cache/redis_cache.py`)
- FastAPI App → Complaint Routes: registers (evidence: `backend/app/main.py`)
- FastAPI App → Statistics Route: registers (evidence: `backend/app/main.py`)
- FastAPI App → Provider Metadata Route: registers (evidence: `backend/app/main.py`)
- FastAPI App → Health and Readiness: registers (evidence: `backend/app/main.py`)
- FastAPI App → Metrics Middleware: installs (evidence: `backend/app/main.py`)
- FastAPI App → Rate Limit Middleware: installs (evidence: `backend/app/main.py`)
- Rate Limit Middleware → Rate Limiter: uses (evidence: `backend/app/middleware/rate_limit.py`)
- Health and Readiness → Readiness Checks: checks readiness (evidence: `backend/app/routes/readiness.py`)
- Provider Metadata Route → Triage Orchestrator: reads provider status (evidence: `backend/app/routes/meta.py`)
- Statistics Route → Complaint Repository: aggregates records
- Metrics Endpoint → Metrics Middleware: exposes metrics
