# hrishabhkumarsingh/campus-safe architecture

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

- Interactive diagram: https://gitdiagram.com/hrishabhkumarsingh/campus-safe
- Repository: https://github.com/hrishabhkumarsingh/campus-safe

## Overview

Campus Safe is a campus emergency assistance and incident coordination platform with a public SOS experience and a role-based campus portal. The main workflow starts with an SOS alert or student complaint, routes it to appropriate staff, supports acknowledgement, assignment, updates and resolution, and delivers notifications and live incident changes. Admin capabilities include analytics, exports, user and routing configuration, escalation settings and audit review; simulations provide a separate practice workflow. The graph reflects documented capabilities and indexed imports; unsampled route details are not inferred.

Main entry points: [`server/src/index.js`](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/index.js) (API and socket server), [`server/src/db.js`](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/db.js) (PostgreSQL), [`client/src/App.jsx`](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/App.jsx) (Client routing), [`server/src/routes/incidents.js`](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/routes/incidents.js) (Incident operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Campus experiences"]
  node_home["Public SOS<br/>[Home.jsx]"]
  node_report["Complaint reporting<br/>[ReportIncident.jsx]"]
  node_dashboard["Staff dashboard<br/>[Dashboard.jsx]"]
  node_incident_list["Incident list<br/>[IncidentList.jsx]"]
  node_incident_detail["Incident detail<br/>[IncidentDetail.jsx]"]
  node_notifications_page["Notifications page<br/>[Notifications.jsx]"]
  node_safety["Safety guidance<br/>[Safety.jsx]"]
  node_app_routes["Client routing<br/>[App.jsx]"]
end

subgraph group_server["Incident coordination"]
  node_server_entry["API and socket server<br/>[index.js]"]
  node_auth_routes["Authentication<br/>[auth.js]"]
  node_auth_middleware["JWT and role checks<br/>[auth.js]"]
  node_public_routes["SOS intake<br/>[public.js]"]
  node_incident_routes["Incident operations<br/>[incidents.js]"]
  node_incident_rules["Visibility and status rules<br/>[services.js]"]
  node_notifications["Persist and push<br/>[notify.js]"]
  node_misc_routes["Responders and notifications<br/>[misc.js]"]
end

subgraph group_operations["Administration and practice"]
  node_admin["Admin and analytics<br/>[admin.js]"]
  node_simulation["Simulation workflow<br/>[simulations.js]"]
end

subgraph group_foundation["Shared platform"]
  node_app_context["Session and realtime<br/>[context.jsx]"]
  node_api_client["HTTP client<br/>[api.js]"]
  node_ui["Shared UI<br/>[ui.jsx]"]
  node_database[("PostgreSQL<br/>[db.js]")]
end

node_public_user(("Public reporter"))
node_portal_user(("Portal user"))

node_public_user -->|"opens SOS"| node_home
node_portal_user -->|"opens portal"| node_app_routes
node_app_routes -->|"routes to"| node_home
node_app_routes -->|"routes to"| node_dashboard
node_app_routes -->|"routes to"| node_incident_detail
node_app_routes -->|"routes to"| node_report
node_app_routes -->|"routes to"| node_notifications_page
node_app_routes -->|"routes to"| node_safety
node_dashboard -->|"renders"| node_incident_list
node_incident_detail -->|"uses"| node_ui
node_incident_list -->|"fetches incidents"| node_api_client
node_incident_list -->|"subscribes to events"| node_app_context
node_home -->|"submits SOS"| node_api_client
node_report -->|"submits complaint"| node_api_client
node_incident_detail -->|"loads and updates"| node_api_client
node_app_context -->|"authenticates and loads notes"| node_api_client
node_app_context -->|"connects by socket"| node_server_entry
node_home -.->|"calls backend"| node_server_entry
node_report -.->|"calls backend"| node_server_entry
node_server_entry -->|"mounts"| node_auth_routes
node_server_entry -->|"mounts"| node_public_routes
node_server_entry -->|"mounts"| node_incident_routes
node_server_entry -->|"mounts"| node_misc_routes
node_server_entry -->|"mounts"| node_admin
node_server_entry -->|"mounts"| node_simulation
node_auth_routes -->|"queries"| node_database
node_auth_middleware -->|"loads account"| node_database
node_public_routes -->|"stores alerts"| node_database
node_public_routes -->|"uses incident rules"| node_incident_rules
node_incident_routes -->|"queries and updates"| node_database
node_incident_routes -->|"checks access"| node_auth_middleware
node_incident_routes -->|"applies rules"| node_incident_rules
node_incident_routes -->|"notifies team"| node_notifications
node_incident_rules -->|"reads and writes"| node_database
node_incident_rules -->|"sends updates"| node_notifications
node_notifications -->|"persists notifications"| node_database
node_misc_routes -->|"queries"| node_database
node_admin -->|"queries and configures"| node_database
node_simulation -->|"records simulations"| node_database
node_server_entry -->|"configures socket delivery"| node_notifications
node_server_entry -->|"runs escalation sweep"| node_database

click node_home "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/pages/Home.jsx"
click node_report "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/pages/ReportIncident.jsx"
click node_dashboard "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/pages/Dashboard.jsx"
click node_incident_list "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/components/IncidentList.jsx"
click node_incident_detail "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/pages/IncidentDetail.jsx"
click node_notifications_page "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/pages/Notifications.jsx"
click node_safety "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/pages/Safety.jsx"
click node_app_routes "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/App.jsx"
click node_app_context "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/context.jsx"
click node_api_client "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/lib/api.js"
click node_ui "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/components/ui.jsx"
click node_server_entry "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/index.js"
click node_auth_routes "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/routes/auth.js"
click node_auth_middleware "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/auth.js"
click node_public_routes "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/routes/public.js"
click node_incident_routes "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/routes/incidents.js"
click node_incident_rules "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/services.js"
click node_notifications "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/notify.js"
click node_misc_routes "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/routes/misc.js"
click node_admin "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/routes/admin.js"
click node_simulation "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/routes/simulations.js"
click node_database "https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/db.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_home,node_report,node_dashboard,node_incident_list,node_incident_detail,node_notifications_page,node_safety,node_app_routes,node_portal_user toneBlue
class node_server_entry,node_auth_routes,node_auth_middleware,node_public_routes,node_incident_routes,node_incident_rules,node_notifications,node_misc_routes toneAmber
class node_admin,node_simulation toneMint
class node_app_context,node_api_client,node_ui,node_database toneRose
class node_public_user toneIndigo
```

## Components

### Campus experiences

- [Public SOS](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/pages/Home.jsx): `client/src/pages/Home.jsx`
- [Complaint reporting](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/pages/ReportIncident.jsx): `client/src/pages/ReportIncident.jsx`
- [Staff dashboard](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/pages/Dashboard.jsx): `client/src/pages/Dashboard.jsx`
- [Incident list](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/components/IncidentList.jsx): `client/src/components/IncidentList.jsx`
- [Incident detail](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/pages/IncidentDetail.jsx): `client/src/pages/IncidentDetail.jsx`
- [Notifications page](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/pages/Notifications.jsx): `client/src/pages/Notifications.jsx`
- [Safety guidance](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/pages/Safety.jsx): `client/src/pages/Safety.jsx`
- [Client routing](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/App.jsx): `client/src/App.jsx`

### Incident coordination

- [API and socket server](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/index.js): `server/src/index.js`
- [Authentication](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/routes/auth.js): `server/src/routes/auth.js`
- [JWT and role checks](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/auth.js): `server/src/auth.js`
- [SOS intake](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/routes/public.js): `server/src/routes/public.js`
- [Incident operations](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/routes/incidents.js): `server/src/routes/incidents.js`
- [Visibility and status rules](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/services.js): `server/src/services.js`
- [Persist and push](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/notify.js): `server/src/notify.js`
- [Responders and notifications](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/routes/misc.js): `server/src/routes/misc.js`

### Administration and practice

- [Admin and analytics](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/routes/admin.js): `server/src/routes/admin.js`
- [Simulation workflow](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/routes/simulations.js): `server/src/routes/simulations.js`

### Shared platform

- [Session and realtime](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/context.jsx): `client/src/context.jsx`
- [HTTP client](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/lib/api.js): `client/src/lib/api.js`
- [Shared UI](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/client/src/components/ui.jsx): `client/src/components/ui.jsx`
- [PostgreSQL](https://github.com/hrishabhkumarsingh/campus-safe/blob/main/server/src/db.js): `server/src/db.js`

### Other components

- **Public reporter**
- **Portal user**

## Connections

- Public reporter → Public SOS: opens SOS (evidence: `README.md`)
- Portal user → Client routing: opens portal (evidence: `README.md`)
- Client routing → Public SOS: routes to (evidence: `client/src/App.jsx`)
- Client routing → Staff dashboard: routes to (evidence: `client/src/App.jsx`)
- Client routing → Incident detail: routes to (evidence: `client/src/App.jsx`)
- Client routing → Complaint reporting: routes to (evidence: `client/src/App.jsx`)
- Client routing → Notifications page: routes to (evidence: `client/src/App.jsx`)
- Client routing → Safety guidance: routes to (evidence: `client/src/App.jsx`)
- Staff dashboard → Incident list: renders (evidence: `client/src/pages/Dashboard.jsx`)
- Incident detail → Shared UI: uses (evidence: `client/src/pages/IncidentDetail.jsx`)
- Incident list → HTTP client: fetches incidents (evidence: `client/src/components/IncidentList.jsx`)
- Incident list → Session and realtime: subscribes to events (evidence: `client/src/components/IncidentList.jsx`)
- Public SOS → HTTP client: submits SOS (evidence: `client/src/pages/Home.jsx`)
- Complaint reporting → HTTP client: submits complaint (evidence: `client/src/pages/ReportIncident.jsx`)
- Incident detail → HTTP client: loads and updates (evidence: `client/src/pages/IncidentDetail.jsx`)
- Session and realtime → HTTP client: authenticates and loads notes (evidence: `client/src/context.jsx`)
- Session and realtime → API and socket server: connects by socket (evidence: `client/src/context.jsx`)
- Public SOS → API and socket server: calls backend (evidence: `README.md`)
- Complaint reporting → API and socket server: calls backend (evidence: `README.md`)
- API and socket server → Authentication: mounts (evidence: `server/src/index.js`)
- API and socket server → SOS intake: mounts (evidence: `server/src/index.js`)
- API and socket server → Incident operations: mounts (evidence: `server/src/index.js`)
- API and socket server → Responders and notifications: mounts (evidence: `server/src/index.js`)
- API and socket server → Admin and analytics: mounts (evidence: `server/src/index.js`)
- API and socket server → Simulation workflow: mounts (evidence: `server/src/index.js`)
- Authentication → PostgreSQL: queries (evidence: `server/src/routes/auth.js`)
- JWT and role checks → PostgreSQL: loads account (evidence: `server/src/auth.js`)
- SOS intake → PostgreSQL: stores alerts (evidence: `server/src/routes/public.js`)
- SOS intake → Visibility and status rules: uses incident rules (evidence: `server/src/routes/public.js`)
- Incident operations → PostgreSQL: queries and updates (evidence: `server/src/routes/incidents.js`)
- Incident operations → JWT and role checks: checks access (evidence: `server/src/routes/incidents.js`)
- Incident operations → Visibility and status rules: applies rules (evidence: `server/src/routes/incidents.js`)
- Incident operations → Persist and push: notifies team (evidence: `server/src/routes/incidents.js`)
- Visibility and status rules → PostgreSQL: reads and writes (evidence: `server/src/services.js`)
- Visibility and status rules → Persist and push: sends updates (evidence: `server/src/services.js`)
- Persist and push → PostgreSQL: persists notifications (evidence: `server/src/notify.js`)
- Responders and notifications → PostgreSQL: queries (evidence: `server/src/routes/misc.js`)
- Admin and analytics → PostgreSQL: queries and configures (evidence: `server/src/routes/admin.js`)
- Simulation workflow → PostgreSQL: records simulations (evidence: `server/src/routes/simulations.js`)
- API and socket server → Persist and push: configures socket delivery (evidence: `server/src/index.js`)
- API and socket server → PostgreSQL: runs escalation sweep (evidence: `server/src/index.js`)
