How codesbyrohit/offline-first-incident-log works
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: js/app.js App and views · server/app.js HTTP routes · store.js Incident store · sync.js Sync engine
Components 19
Offline browser app
- App and views
public/js/app.js - UI rendering
public/js/ui.js - Shared validation
public/shared/validation.js - Incident store
public/js/store.js - IndexedDB
public/js/db.js - Connectivity monitor
public/js/connectivity.js - Offline shell cache
public/sw.js - Service worker registration
public/js/sw-register.js
Synchronization
- Sync engine
public/js/sync.js - HTTP API client
public/js/api.js
Incident server
- HTTP routes
server/app.js - Session authentication
server/auth.js - Incident repository
server/incidents-repo.js - SQLite database
server/db.js - Server startup
server/index.js
Optional AI summaries
- AI summary client
public/js/ai-client.js - AI summary service
server/ai.js
Other components
- Campus user
- AI provider
Connections 23
- Campus user → App and views: uses
README.md - App and views → UI rendering: renders
public/js/app.js - App and views → Incident store: manages reports
public/js/app.js - Incident store → Shared validation: validates
public/js/store.js - Incident store → IndexedDB: reads and writes
public/js/store.js - App and views → Connectivity monitor: monitors status
README.md - App and views → Service worker registration: registers
README.md - Service worker registration → Offline shell cache: registers
- App and views → Sync engine: triggers sync
README.md - Sync engine → Incident store: claims and updates outbox
public/js/sync.js - Sync engine → HTTP API client: sends requests
public/js/sync.js - HTTP API client → HTTP routes: HTTP requests
README.md - HTTP routes → Shared validation: validates payloads
server/app.js - HTTP routes → Session authentication: checks sessions
server/app.js - HTTP routes → Incident repository: handles incident routes
server/app.js - Incident repository → SQLite database: persists transactionally
server/incidents-repo.js - Server startup → HTTP routes: creates app
server/index.js - Server startup → SQLite database: opens database
server/index.js - App and views → AI summary client: requests on action
public/js/app.js - AI summary client → HTTP API client: posts summary request
public/js/ai-client.js - HTTP routes → AI summary service: routes summary request
server/app.js - AI summary service → AI provider: requests summary
- App and views → Incident store: stores summary separately
README.md