# mohithbs-stack/ksp-crime-ai architecture

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

- Interactive diagram: https://gitdiagram.com/mohithbs-stack/ksp-crime-ai
- Repository: https://github.com/mohithbs-stack/ksp-crime-ai

## Overview

KSP Crime Intelligence AI is a role-based police operations and crime-intelligence web application. Officers sign in, enter protected workspaces, and use case management or intelligence tools to inspect records and receive grounded query results; the README also describes dashboards, relationship graphs, GIS hotspots, analytics, and decision support. The UI is a React feature-page layer with shared layout and state, backed by crime and intelligence services plus demo data and an optional Catalyst datastore. Several capabilities are documented but their implementation was not sampled, so those branches show documented scope without speculative service links.

Main entry points: [`src/router/index.tsx`](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/router/index.tsx) (Protected routing), [`src/components/ui/PageShell.tsx`](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/components/ui/PageShell.tsx) (Shared page wrapper), [`src/features/cases/CasesPage.tsx`](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/cases/CasesPage.tsx) (Case management), [`src/features/intelligence/ChatbotPage.tsx`](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/intelligence/ChatbotPage.tsx) (Intelligence assistant)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and shell"]
  node_application["Application<br/>[App.tsx]"]
  node_router["Protected routing<br/>[index.tsx]"]
  node_authpage["Sign-in page<br/>[AuthPage.tsx]"]
  node_login["Login<br/>[Login.tsx]"]
  node_authstate["Session and roles<br/>[index.ts]"]
  node_shell["Application shell<br/>[AppShell.tsx]"]
  node_pageshell["Shared page wrapper<br/>[PageShell.tsx]"]
end

subgraph group_operations["Investigation tools"]
  node_dashboard["Operations dashboard<br/>[Dashboard.tsx]"]
  node_cases["Case management<br/>[CasesPage.tsx]"]
  node_relationships["Criminal relationship graph"]
  node_evidence["Evidence vault<br/>[EvidencePage.tsx]"]
  node_reports["Reports<br/>[ReportsPage.tsx]"]
end

subgraph group_insight["Analysis and intelligence"]
  node_analytics["Crime analytics<br/>[AnalyticsPage.tsx]"]
  node_hotspots["GIS hotspots<br/>[HotspotsPage.tsx]"]
  node_decision["Decision support"]
  node_chatbot["Intelligence assistant<br/>[ChatbotPage.tsx]"]
end

subgraph group_services["Services and data"]
  node_engine["Query and evidence engine"]
  node_crime["Crime service<br/>[crimeService.ts]"]
  node_mockdb[("Seeded crime records<br/>[mockDb.ts]")]
  node_catalyst[("Catalyst datastore")]
end

node_officer(("Police user"))
node_gemini["Google Gemini API"]

node_officer -->|"uses"| node_application
node_application -->|"renders"| node_router
node_router -->|"routes login"| node_authpage
node_authpage -->|"shows"| node_login
node_login -->|"authenticates"| node_authstate
node_router -->|"wraps protected pages"| node_shell
node_router -->|"routes"| node_dashboard
node_router -->|"routes"| node_cases
node_router -->|"routes"| node_relationships
node_router -->|"routes"| node_analytics
node_router -->|"routes"| node_hotspots
node_router -->|"routes"| node_chatbot
node_router -->|"routes"| node_evidence
node_router -->|"routes"| node_reports
node_cases -->|"queries cases"| node_crime
node_crime -->|"queries datastore"| node_catalyst
node_crime -->|"falls back to"| node_mockdb
node_chatbot -->|"submits query"| node_engine
node_engine -->|"executes grounded queries"| node_mockdb
node_engine -->|"requests generation"| node_gemini
node_cases -->|"uses wrapper"| node_pageshell
node_dashboard -.->|"uses wrapper"| node_pageshell
node_analytics -->|"uses wrapper"| node_pageshell
node_hotspots -->|"uses wrapper"| node_pageshell
node_chatbot -->|"uses wrapper"| node_pageshell
node_relationships -->|"uses wrapper"| node_pageshell
node_decision -.->|"supports investigation"| node_cases

click node_application "https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/App.tsx"
click node_router "https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/router/index.tsx"
click node_authpage "https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/pages/AuthPage.tsx"
click node_login "https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/auth/Login.tsx"
click node_authstate "https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/store/index.ts"
click node_shell "https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/components/layout/AppShell.tsx"
click node_pageshell "https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/components/ui/PageShell.tsx"
click node_dashboard "https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/dashboard/Dashboard.tsx"
click node_cases "https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/cases/CasesPage.tsx"
click node_relationships "https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/suspects/RelationshipPage.tsx"
click node_evidence "https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/evidence/EvidencePage.tsx"
click node_reports "https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/reports/ReportsPage.tsx"
click node_analytics "https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/analytics/AnalyticsPage.tsx"
click node_hotspots "https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/hotspots/HotspotsPage.tsx"
click node_decision "https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/cases/DecisionSupportPage.tsx"
click node_chatbot "https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/intelligence/ChatbotPage.tsx"
click node_engine "https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/services/intelligenceEngine.ts"
click node_crime "https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/services/crimeService.ts"
click node_mockdb "https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/services/mockDb.ts"
click node_catalyst "https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/services/catalystDataStore.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_application,node_router,node_authpage,node_login,node_authstate,node_shell,node_pageshell,node_officer toneBlue
class node_dashboard,node_cases,node_relationships,node_evidence,node_reports toneAmber
class node_analytics,node_hotspots,node_decision,node_chatbot,node_gemini toneMint
class node_engine,node_crime,node_mockdb,node_catalyst toneRose
```

## Components

### Access and shell

- [Application](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/App.tsx): `src/App.tsx`
- [Protected routing](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/router/index.tsx): `src/router/index.tsx`
- [Sign-in page](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/pages/AuthPage.tsx): `src/pages/AuthPage.tsx`
- [Login](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/auth/Login.tsx): `src/features/auth/Login.tsx`
- [Session and roles](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/store/index.ts): `src/store/index.ts`
- [Application shell](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/components/layout/AppShell.tsx): `src/components/layout/AppShell.tsx`
- [Shared page wrapper](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/components/ui/PageShell.tsx): `src/components/ui/PageShell.tsx`

### Investigation tools

- [Operations dashboard](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/dashboard/Dashboard.tsx): `src/features/dashboard/Dashboard.tsx`
- [Case management](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/cases/CasesPage.tsx): `src/features/cases/CasesPage.tsx`
- [Criminal relationship graph](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/suspects/RelationshipPage.tsx): `src/features/suspects/RelationshipPage.tsx`
- [Evidence vault](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/evidence/EvidencePage.tsx): `src/features/evidence/EvidencePage.tsx`
- [Reports](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/reports/ReportsPage.tsx): `src/features/reports/ReportsPage.tsx`

### Analysis and intelligence

- [Crime analytics](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/analytics/AnalyticsPage.tsx): `src/features/analytics/AnalyticsPage.tsx`
- [GIS hotspots](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/hotspots/HotspotsPage.tsx): `src/features/hotspots/HotspotsPage.tsx`
- [Decision support](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/cases/DecisionSupportPage.tsx): `src/features/cases/DecisionSupportPage.tsx`
- [Intelligence assistant](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/features/intelligence/ChatbotPage.tsx): `src/features/intelligence/ChatbotPage.tsx`

### Services and data

- [Query and evidence engine](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/services/intelligenceEngine.ts): `src/services/intelligenceEngine.ts`
- [Crime service](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/services/crimeService.ts): `src/services/crimeService.ts`
- [Seeded crime records](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/services/mockDb.ts): `src/services/mockDb.ts`
- [Catalyst datastore](https://github.com/mohithbs-stack/ksp-crime-ai/blob/main/src/services/catalystDataStore.ts): `src/services/catalystDataStore.ts`

### Other components

- **Police user**
- **Google Gemini API**

## Connections

- Police user → Application: uses
- Application → Protected routing: renders (evidence: `src/App.tsx`)
- Protected routing → Sign-in page: routes login (evidence: `src/router/index.tsx`)
- Sign-in page → Login: shows (evidence: `src/pages/AuthPage.tsx`)
- Login → Session and roles: authenticates (evidence: `src/features/auth/Login.tsx`)
- Protected routing → Application shell: wraps protected pages (evidence: `src/router/index.tsx`)
- Protected routing → Operations dashboard: routes (evidence: `src/router/index.tsx`)
- Protected routing → Case management: routes (evidence: `src/router/index.tsx`)
- Protected routing → Criminal relationship graph: routes (evidence: `src/router/index.tsx`)
- Protected routing → Crime analytics: routes (evidence: `src/router/index.tsx`)
- Protected routing → GIS hotspots: routes (evidence: `src/router/index.tsx`)
- Protected routing → Intelligence assistant: routes (evidence: `src/router/index.tsx`)
- Protected routing → Evidence vault: routes (evidence: `src/router/index.tsx`)
- Protected routing → Reports: routes (evidence: `src/router/index.tsx`)
- Case management → Crime service: queries cases (evidence: `src/features/cases/CasesPage.tsx`)
- Crime service → Catalyst datastore: queries datastore (evidence: `src/services/crimeService.ts`)
- Crime service → Seeded crime records: falls back to (evidence: `src/services/crimeService.ts`)
- Intelligence assistant → Query and evidence engine: submits query (evidence: `src/features/intelligence/ChatbotPage.tsx`)
- Query and evidence engine → Seeded crime records: executes grounded queries (evidence: `src/services/intelligenceEngine.ts`)
- Query and evidence engine → Google Gemini API: requests generation (evidence: `src/services/intelligenceEngine.ts`)
- Case management → Shared page wrapper: uses wrapper (evidence: `src/features/cases/CasesPage.tsx`)
- Operations dashboard → Shared page wrapper: uses wrapper (evidence: `src/features/dashboard/Dashboard.tsx`)
- Crime analytics → Shared page wrapper: uses wrapper (evidence: `src/features/analytics/AnalyticsPage.tsx`)
- GIS hotspots → Shared page wrapper: uses wrapper (evidence: `src/features/hotspots/HotspotsPage.tsx`)
- Intelligence assistant → Shared page wrapper: uses wrapper (evidence: `src/features/intelligence/ChatbotPage.tsx`)
- Criminal relationship graph → Shared page wrapper: uses wrapper (evidence: `src/features/suspects/RelationshipPage.tsx`)
- Decision support → Case management: supports investigation
