# codesbyrohit/offline-first-incident-log architecture

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

- Interactive diagram: https://gitdiagram.com/codesbyrohit/offline-first-incident-log
- Repository: https://github.com/codesbyrohit/offline-first-incident-log

## Overview

Campus Incident Log is an offline-first campus reporting app: users create, edit, search, and resolve reports locally, then synchronize queued changes when the server is reachable. Optional AI summaries are explicitly requested and kept separate from report data. The graph follows the documented browser-to-server workflow and includes authentication, shared validation, both storage layers, and the optional AI branch. Source excerpts establish key calls; some service-worker, UI, configuration, and backend details are documented only at a high level.

Main entry points: [`public/js/app.js`](https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/js/app.js) (App and views), [`server/app.js`](https://github.com/codesbyrohit/offline-first-incident-log/blob/main/server/app.js) (HTTP routes), [`public/js/store.js`](https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/js/store.js) (Incident store), [`public/js/sync.js`](https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/js/sync.js) (Sync engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Offline browser app"]
  node_app["App and views<br/>[app.js]"]
  node_ui["UI rendering<br/>[ui.js]"]
  node_validation["Shared validation<br/>[validation.js]"]
  node_localstore["Incident store<br/>[store.js]"]
  node_indexeddb[("IndexedDB<br/>[db.js]")]
  node_connectivity["Connectivity monitor<br/>[connectivity.js]"]
  node_serviceworker["Offline shell cache<br/>[sw.js]"]
  node_swregister["Service worker registration<br/>[sw-register.js]"]
end

subgraph group_sync["Synchronization"]
  node_syncengine["Sync engine<br/>[sync.js]"]
  node_apiclient["HTTP API client<br/>[api.js]"]
end

subgraph group_server["Incident server"]
  node_server["HTTP routes<br/>[app.js]"]
  node_auth["Session authentication<br/>[auth.js]"]
  node_repo["Incident repository<br/>[incidents-repo.js]"]
  node_sqlitedb[("SQLite database<br/>[db.js]")]
  node_serverentry["Server startup<br/>[index.js]"]
end

subgraph group_ai["Optional AI summaries"]
  node_ai_client["AI summary client<br/>[ai-client.js]"]
  node_ai_service["AI summary service<br/>[ai.js]"]
end

node_user(("Campus user"))
node_ai_provider["AI provider"]

node_user -->|"uses"| node_app
node_app -->|"renders"| node_ui
node_app -->|"manages reports"| node_localstore
node_localstore -->|"validates"| node_validation
node_localstore -->|"reads and writes"| node_indexeddb
node_app -->|"monitors status"| node_connectivity
node_app -->|"registers"| node_swregister
node_swregister -.->|"registers"| node_serviceworker
node_app -->|"triggers sync"| node_syncengine
node_syncengine -->|"claims and updates outbox"| node_localstore
node_syncengine -->|"sends requests"| node_apiclient
node_apiclient -->|"HTTP requests"| node_server
node_server -->|"validates payloads"| node_validation
node_server -->|"checks sessions"| node_auth
node_server -->|"handles incident routes"| node_repo
node_repo -->|"persists transactionally"| node_sqlitedb
node_serverentry -->|"creates app"| node_server
node_serverentry -->|"opens database"| node_sqlitedb
node_app -->|"requests on action"| node_ai_client
node_ai_client -->|"posts summary request"| node_apiclient
node_server -->|"routes summary request"| node_ai_service
node_ai_service -.->|"requests summary"| node_ai_provider
node_app -->|"stores summary separately"| node_localstore

click node_app "https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/js/app.js"
click node_ui "https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/js/ui.js"
click node_validation "https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/shared/validation.js"
click node_localstore "https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/js/store.js"
click node_indexeddb "https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/js/db.js"
click node_connectivity "https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/js/connectivity.js"
click node_serviceworker "https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/sw.js"
click node_swregister "https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/js/sw-register.js"
click node_syncengine "https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/js/sync.js"
click node_apiclient "https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/js/api.js"
click node_server "https://github.com/codesbyrohit/offline-first-incident-log/blob/main/server/app.js"
click node_auth "https://github.com/codesbyrohit/offline-first-incident-log/blob/main/server/auth.js"
click node_repo "https://github.com/codesbyrohit/offline-first-incident-log/blob/main/server/incidents-repo.js"
click node_sqlitedb "https://github.com/codesbyrohit/offline-first-incident-log/blob/main/server/db.js"
click node_serverentry "https://github.com/codesbyrohit/offline-first-incident-log/blob/main/server/index.js"
click node_ai_client "https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/js/ai-client.js"
click node_ai_service "https://github.com/codesbyrohit/offline-first-incident-log/blob/main/server/ai.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_app,node_ui,node_validation,node_localstore,node_indexeddb,node_connectivity,node_serviceworker,node_swregister,node_user toneBlue
class node_syncengine,node_apiclient toneAmber
class node_server,node_auth,node_repo,node_sqlitedb,node_serverentry toneMint
class node_ai_client,node_ai_service toneRose
class node_ai_provider toneIndigo
```

## Components

### Offline browser app

- [App and views](https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/js/app.js): `public/js/app.js`
- [UI rendering](https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/js/ui.js): `public/js/ui.js`
- [Shared validation](https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/shared/validation.js): `public/shared/validation.js`
- [Incident store](https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/js/store.js): `public/js/store.js`
- [IndexedDB](https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/js/db.js): `public/js/db.js`
- [Connectivity monitor](https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/js/connectivity.js): `public/js/connectivity.js`
- [Offline shell cache](https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/sw.js): `public/sw.js`
- [Service worker registration](https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/js/sw-register.js): `public/js/sw-register.js`

### Synchronization

- [Sync engine](https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/js/sync.js): `public/js/sync.js`
- [HTTP API client](https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/js/api.js): `public/js/api.js`

### Incident server

- [HTTP routes](https://github.com/codesbyrohit/offline-first-incident-log/blob/main/server/app.js): `server/app.js`
- [Session authentication](https://github.com/codesbyrohit/offline-first-incident-log/blob/main/server/auth.js): `server/auth.js`
- [Incident repository](https://github.com/codesbyrohit/offline-first-incident-log/blob/main/server/incidents-repo.js): `server/incidents-repo.js`
- [SQLite database](https://github.com/codesbyrohit/offline-first-incident-log/blob/main/server/db.js): `server/db.js`
- [Server startup](https://github.com/codesbyrohit/offline-first-incident-log/blob/main/server/index.js): `server/index.js`

### Optional AI summaries

- [AI summary client](https://github.com/codesbyrohit/offline-first-incident-log/blob/main/public/js/ai-client.js): `public/js/ai-client.js`
- [AI summary service](https://github.com/codesbyrohit/offline-first-incident-log/blob/main/server/ai.js): `server/ai.js`

### Other components

- **Campus user**
- **AI provider**

## Connections

- Campus user → App and views: uses (evidence: `README.md`)
- App and views → UI rendering: renders (evidence: `public/js/app.js`)
- App and views → Incident store: manages reports (evidence: `public/js/app.js`)
- Incident store → Shared validation: validates (evidence: `public/js/store.js`)
- Incident store → IndexedDB: reads and writes (evidence: `public/js/store.js`)
- App and views → Connectivity monitor: monitors status (evidence: `README.md`)
- App and views → Service worker registration: registers (evidence: `README.md`)
- Service worker registration → Offline shell cache: registers
- App and views → Sync engine: triggers sync (evidence: `README.md`)
- Sync engine → Incident store: claims and updates outbox (evidence: `public/js/sync.js`)
- Sync engine → HTTP API client: sends requests (evidence: `public/js/sync.js`)
- HTTP API client → HTTP routes: HTTP requests (evidence: `README.md`)
- HTTP routes → Shared validation: validates payloads (evidence: `server/app.js`)
- HTTP routes → Session authentication: checks sessions (evidence: `server/app.js`)
- HTTP routes → Incident repository: handles incident routes (evidence: `server/app.js`)
- Incident repository → SQLite database: persists transactionally (evidence: `server/incidents-repo.js`)
- Server startup → HTTP routes: creates app (evidence: `server/index.js`)
- Server startup → SQLite database: opens database (evidence: `server/index.js`)
- App and views → AI summary client: requests on action (evidence: `public/js/app.js`)
- AI summary client → HTTP API client: posts summary request (evidence: `public/js/ai-client.js`)
- HTTP routes → AI summary service: routes summary request (evidence: `server/app.js`)
- AI summary service → AI provider: requests summary
- App and views → Incident store: stores summary separately (evidence: `README.md`)
