# bragee7/cmfinal architecture

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

- Interactive diagram: https://gitdiagram.com/bragee7/cmfinal
- Repository: https://github.com/bragee7/cmfinal

## Overview

Women Safety Guardian is an emergency-response product spanning web and Android clients, a Node/Express API, and case-management dashboards. The main flow is a user-triggered SOS with location and media, followed by case storage and police review, status updates, and audit history. The README documents additional voice triggers, contacts, preferences, maps, sharing, and analytics. Some client pages, Android components, and server modules were not sampled; those are included where the tree or README establishes their role, while uncertain connections are omitted.

Main entry points: [`server/index.js`](https://github.com/bragee7/cmfinal/blob/main/server/index.js) (HTTP server), [`server/routes/sos.js`](https://github.com/bragee7/cmfinal/blob/main/server/routes/sos.js) (SOS case workflow), [`client/src/services/api.js`](https://github.com/bragee7/cmfinal/blob/main/client/src/services/api.js) (API client), [`server/db.js`](https://github.com/bragee7/cmfinal/blob/main/server/db.js) (Postgres data store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["User clients"]
  node_webapp["Web app routing<br/>[App.jsx]"]
  node_authstate["Web authentication<br/>[AuthContext.jsx]"]
  node_websos["Web SOS trigger"]
  node_casedetails["Case details<br/>[CaseDetails.jsx]"]
  node_mobileguard["Background voice guard"]
  node_mobilerecord["Mobile SOS recording"]
  node_clientapi["API client<br/>[api.js]"]
end

subgraph group_police["Police and admin"]
  node_policeui["Police case dashboard"]
  node_adminui["Admin analytics<br/>[AdminDashboard.jsx]"]
  node_adminpanels["Admin data panels"]
end

subgraph group_api["API services"]
  node_server["HTTP server<br/>[index.js]"]
  node_authroutes["Account and profile<br/>[auth.js]"]
  node_sosroutes["SOS case workflow<br/>[sos.js]"]
  node_contactroutes["Emergency contacts<br/>[contacts.js]"]
  node_preferences["Voice preferences<br/>[preferences.js]"]
  node_adminroutes["Admin statistics<br/>[admin.js]"]
  node_authmiddleware["JWT authorization<br/>[auth.js]"]
  node_socket["Live case updates<br/>[socket.js]"]
end

subgraph group_data["Case data"]
  node_database[("Postgres data store<br/>[db.js]")]
end

subgraph group_integrations["External services"]
  node_email["Alert email<br/>[email.js]"]
  node_station["Nearby police lookup"]
end

node_user(("Safety user"))
node_police(("Police responder"))
node_overpass(("OpenStreetMap Overpass"))

node_user -->|"uses"| node_webapp
node_webapp -->|"provides auth"| node_authstate
node_webapp -->|"routes to"| node_policeui
node_webapp -->|"routes to"| node_adminui
node_user -->|"triggers SOS"| node_websos
node_websos -->|"submits alert"| node_clientapi
node_user -->|"speaks trigger"| node_mobileguard
node_mobileguard -->|"starts recording"| node_mobilerecord
node_clientapi -->|"calls API"| node_server
node_server -->|"mounts routes"| node_authroutes
node_server -->|"mounts routes"| node_sosroutes
node_server -->|"mounts routes"| node_contactroutes
node_server -->|"mounts routes"| node_preferences
node_server -->|"mounts routes"| node_adminroutes
node_authroutes -->|"queries users"| node_database
node_sosroutes -->|"checks access"| node_authmiddleware
node_authroutes -->|"checks access"| node_authmiddleware
node_sosroutes -->|"reads and writes"| node_database
node_contactroutes -->|"reads and writes"| node_database
node_preferences -->|"reads and writes"| node_database
node_adminroutes -->|"queries statistics"| node_database
node_sosroutes -->|"sends alerts"| node_email
node_sosroutes -->|"publishes updates"| node_socket
node_sosroutes -->|"looks up station"| node_station
node_station -->|"queries nearby"| node_overpass
node_policeui -.->|"fetches cases"| node_clientapi
node_adminui -->|"fetches metrics"| node_clientapi
node_adminui -->|"renders panels"| node_adminpanels
node_police -->|"reviews cases"| node_policeui
node_police -->|"reviews analytics"| node_adminui
node_policeui -.->|"opens case"| node_casedetails
node_casedetails -->|"loads case"| node_clientapi

click node_webapp "https://github.com/bragee7/cmfinal/blob/main/client/src/App.jsx"
click node_authstate "https://github.com/bragee7/cmfinal/blob/main/client/src/context/AuthContext.jsx"
click node_websos "https://github.com/bragee7/cmfinal/blob/main/client/src/components/FloatingSosButton.jsx"
click node_casedetails "https://github.com/bragee7/cmfinal/blob/main/client/src/pages/CaseDetails.jsx"
click node_mobileguard "https://github.com/bragee7/cmfinal/blob/main/mobile/android/app/src/main/kotlin/com/zelda/zelda_guardian/PowerGuardService.kt"
click node_mobilerecord "https://github.com/bragee7/cmfinal/blob/main/mobile/android/app/src/main/kotlin/com/zelda/zelda_guardian/SosRecordingService.kt"
click node_policeui "https://github.com/bragee7/cmfinal/blob/main/client/src/pages/PoliceDashboard.jsx"
click node_adminui "https://github.com/bragee7/cmfinal/blob/main/client/src/pages/AdminDashboard.jsx"
click node_adminpanels "https://github.com/bragee7/cmfinal/tree/main/client/src/pages/admin"
click node_clientapi "https://github.com/bragee7/cmfinal/blob/main/client/src/services/api.js"
click node_server "https://github.com/bragee7/cmfinal/blob/main/server/index.js"
click node_authroutes "https://github.com/bragee7/cmfinal/blob/main/server/routes/auth.js"
click node_sosroutes "https://github.com/bragee7/cmfinal/blob/main/server/routes/sos.js"
click node_contactroutes "https://github.com/bragee7/cmfinal/blob/main/server/routes/contacts.js"
click node_preferences "https://github.com/bragee7/cmfinal/blob/main/server/routes/preferences.js"
click node_adminroutes "https://github.com/bragee7/cmfinal/blob/main/server/routes/admin.js"
click node_authmiddleware "https://github.com/bragee7/cmfinal/blob/main/server/middleware/auth.js"
click node_database "https://github.com/bragee7/cmfinal/blob/main/server/db.js"
click node_socket "https://github.com/bragee7/cmfinal/blob/main/server/socket.js"
click node_email "https://github.com/bragee7/cmfinal/blob/main/server/services/email.js"
click node_station "https://github.com/bragee7/cmfinal/blob/main/server/services/policeStationService.js"

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_webapp,node_authstate,node_websos,node_casedetails,node_mobileguard,node_mobilerecord,node_clientapi,node_user toneBlue
class node_policeui,node_adminui,node_adminpanels toneAmber
class node_server,node_authroutes,node_sosroutes,node_contactroutes,node_preferences,node_adminroutes,node_authmiddleware,node_socket toneMint
class node_database toneRose
class node_email,node_station,node_police,node_overpass toneIndigo
```

## Components

### User clients

- [Web app routing](https://github.com/bragee7/cmfinal/blob/main/client/src/App.jsx): `client/src/App.jsx`
- [Web authentication](https://github.com/bragee7/cmfinal/blob/main/client/src/context/AuthContext.jsx): `client/src/context/AuthContext.jsx`
- [Web SOS trigger](https://github.com/bragee7/cmfinal/blob/main/client/src/components/FloatingSosButton.jsx): `client/src/components/FloatingSosButton.jsx`
- [Case details](https://github.com/bragee7/cmfinal/blob/main/client/src/pages/CaseDetails.jsx): `client/src/pages/CaseDetails.jsx`
- [Background voice guard](https://github.com/bragee7/cmfinal/blob/main/mobile/android/app/src/main/kotlin/com/zelda/zelda_guardian/PowerGuardService.kt): `mobile/android/app/src/main/kotlin/com/zelda/zelda_guardian/PowerGuardService.kt`
- [Mobile SOS recording](https://github.com/bragee7/cmfinal/blob/main/mobile/android/app/src/main/kotlin/com/zelda/zelda_guardian/SosRecordingService.kt): `mobile/android/app/src/main/kotlin/com/zelda/zelda_guardian/SosRecordingService.kt`
- [API client](https://github.com/bragee7/cmfinal/blob/main/client/src/services/api.js): `client/src/services/api.js`

### Police and admin

- [Police case dashboard](https://github.com/bragee7/cmfinal/blob/main/client/src/pages/PoliceDashboard.jsx): `client/src/pages/PoliceDashboard.jsx`
- [Admin analytics](https://github.com/bragee7/cmfinal/blob/main/client/src/pages/AdminDashboard.jsx): `client/src/pages/AdminDashboard.jsx`
- [Admin data panels](https://github.com/bragee7/cmfinal/tree/main/client/src/pages/admin): `client/src/pages/admin`

### API services

- [HTTP server](https://github.com/bragee7/cmfinal/blob/main/server/index.js): `server/index.js`
- [Account and profile](https://github.com/bragee7/cmfinal/blob/main/server/routes/auth.js): `server/routes/auth.js`
- [SOS case workflow](https://github.com/bragee7/cmfinal/blob/main/server/routes/sos.js): `server/routes/sos.js`
- [Emergency contacts](https://github.com/bragee7/cmfinal/blob/main/server/routes/contacts.js): `server/routes/contacts.js`
- [Voice preferences](https://github.com/bragee7/cmfinal/blob/main/server/routes/preferences.js): `server/routes/preferences.js`
- [Admin statistics](https://github.com/bragee7/cmfinal/blob/main/server/routes/admin.js): `server/routes/admin.js`
- [JWT authorization](https://github.com/bragee7/cmfinal/blob/main/server/middleware/auth.js): `server/middleware/auth.js`
- [Live case updates](https://github.com/bragee7/cmfinal/blob/main/server/socket.js): `server/socket.js`

### Case data

- [Postgres data store](https://github.com/bragee7/cmfinal/blob/main/server/db.js): `server/db.js`

### External services

- [Alert email](https://github.com/bragee7/cmfinal/blob/main/server/services/email.js): `server/services/email.js`
- [Nearby police lookup](https://github.com/bragee7/cmfinal/blob/main/server/services/policeStationService.js): `server/services/policeStationService.js`

### Other components

- **Safety user**
- **Police responder**
- **OpenStreetMap Overpass**

## Connections

- Safety user → Web app routing: uses (evidence: `README.md`)
- Web app routing → Web authentication: provides auth (evidence: `client/src/App.jsx`)
- Web app routing → Police case dashboard: routes to (evidence: `client/src/App.jsx`)
- Web app routing → Admin analytics: routes to (evidence: `client/src/App.jsx`)
- Safety user → Web SOS trigger: triggers SOS (evidence: `README.md`)
- Web SOS trigger → API client: submits alert (evidence: `client/src/components/FloatingSosButton.jsx`)
- Safety user → Background voice guard: speaks trigger (evidence: `README.md`)
- Background voice guard → Mobile SOS recording: starts recording (evidence: `mobile/android/app/src/main/kotlin/com/zelda/zelda_guardian/PowerGuardService.kt`)
- API client → HTTP server: calls API (evidence: `client/src/services/api.js`)
- HTTP server → Account and profile: mounts routes (evidence: `server/index.js`)
- HTTP server → SOS case workflow: mounts routes (evidence: `server/index.js`)
- HTTP server → Emergency contacts: mounts routes (evidence: `server/index.js`)
- HTTP server → Voice preferences: mounts routes (evidence: `server/index.js`)
- HTTP server → Admin statistics: mounts routes (evidence: `server/index.js`)
- Account and profile → Postgres data store: queries users (evidence: `server/routes/auth.js`)
- SOS case workflow → JWT authorization: checks access (evidence: `server/routes/sos.js`)
- Account and profile → JWT authorization: checks access (evidence: `server/routes/auth.js`)
- SOS case workflow → Postgres data store: reads and writes (evidence: `server/routes/sos.js`)
- Emergency contacts → Postgres data store: reads and writes (evidence: `server/routes/contacts.js`)
- Voice preferences → Postgres data store: reads and writes (evidence: `server/routes/preferences.js`)
- Admin statistics → Postgres data store: queries statistics (evidence: `server/routes/admin.js`)
- SOS case workflow → Alert email: sends alerts (evidence: `server/routes/sos.js`)
- SOS case workflow → Live case updates: publishes updates (evidence: `server/routes/sos.js`)
- SOS case workflow → Nearby police lookup: looks up station (evidence: `server/routes/sos.js`)
- Nearby police lookup → OpenStreetMap Overpass: queries nearby (evidence: `server/services/policeStationService.js`)
- Police case dashboard → API client: fetches cases
- Admin analytics → API client: fetches metrics (evidence: `client/src/pages/AdminDashboard.jsx`)
- Admin analytics → Admin data panels: renders panels (evidence: `client/src/pages/AdminDashboard.jsx`)
- Police responder → Police case dashboard: reviews cases (evidence: `README.md`)
- Police responder → Admin analytics: reviews analytics (evidence: `README.md`)
- Police case dashboard → Case details: opens case
- Case details → API client: loads case (evidence: `client/src/pages/CaseDetails.jsx`)
