# pallab-js/offgrid architecture

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

- Interactive diagram: https://gitdiagram.com/pallab-js/offgrid
- Repository: https://github.com/pallab-js/offgrid

## Overview

OffGrid is a LAN-hosted, local-first messaging and field-tools app: teammates join a room with a shared passphrase, then use browser features through a hub while keeping a local history mirror and queuing offline changes. The graph covers room setup, messaging and files, survival tools, browser sync, and hub persistence. Some capabilities are included from the README and source index even where their implementations were not excerpted; their internal wiring is omitted where evidence is insufficient.

Main entry points: [`src/stores/chat.ts`](https://github.com/pallab-js/offgrid/blob/main/src/stores/chat.ts) (Message state), [`src/stores/files.ts`](https://github.com/pallab-js/offgrid/blob/main/src/stores/files.ts) (File state), [`server/http/index.ts`](https://github.com/pallab-js/offgrid/blob/main/server/http/index.ts) (HTTP API), [`src/app/join/join-flow.tsx`](https://github.com/pallab-js/offgrid/blob/main/src/app/join/join-flow.tsx) (Join room)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Room entry"]
  node_join["Join room<br/>[join-flow.tsx]"]
  node_session["Device session<br/>[session.ts]"]
  node_roomcrypto["Room encryption<br/>[room.ts]"]
end

subgraph group_client["Browser messaging and sync"]
  node_chatui["Channels and chat<br/>[thread.tsx]"]
  node_chatstore["Message state<br/>[chat.ts]"]
  node_filesui["File sharing<br/>[files-page.tsx]"]
  node_filestore["File state<br/>[files.ts]"]
  node_fileapi["Transfer API<br/>[api.ts]"]
  node_wsclient["WebSocket client<br/>[client.ts]"]
  node_protocol["Frame protocol<br/>[frames.ts]"]
  node_localmirror["Local-first sync<br/>[outbox.ts]"]
end

subgraph group_field["Field tools"]
  node_checklists["Checklists and guides<br/>[checklist-page.tsx]"]
  node_map["Offline map and waypoints<br/>[map-page.tsx]"]
  node_beacon["Beacon signaling<br/>[beacon-page.tsx]"]
  node_sos["SOS distress<br/>[sos-overlay.tsx]"]
  node_notes["Shared notes<br/>[notes-page.tsx]"]
  node_status["Status board<br/>[status-page.tsx]"]
end

subgraph group_hub["Hub services"]
  node_hub["Hub startup<br/>[index.ts]"]
  node_http["HTTP API<br/>[index.ts]"]
  node_wsdispatch["WebSocket dispatch<br/>[dispatch.ts]"]
  node_registry["Live connections<br/>[registry.ts]"]
end

subgraph group_storage["Persistence"]
  node_repo["Domain repository<br/>[repo.ts]"]
  node_sqlite[("SQLite database<br/>[index.ts]")]
  node_browserdb[("Browser IndexedDB<br/>[db.ts]")]
  node_hubfiles[("Hub file storage<br/>[index.ts]")]
end

node_teammate(("Teammate"))

node_teammate -->|"joins room"| node_join
node_join -->|"derives key"| node_roomcrypto
node_join -->|"saves membership"| node_session
node_teammate -->|"uses channels"| node_chatui
node_chatui -->|"updates messages"| node_chatstore
node_chatstore -->|"sends frames"| node_wsclient
node_wsclient -->|"validates frames"| node_protocol
node_chatstore -->|"queues offline"| node_localmirror
node_chatstore -->|"stores history"| node_browserdb
node_teammate -->|"shares files"| node_filesui
node_filesui -->|"manages files"| node_filestore
node_filestore -->|"transfers bytes"| node_fileapi
node_fileapi -->|"encrypts frames"| node_roomcrypto
node_filestore -->|"syncs metadata"| node_wsclient
node_filestore -->|"caches files"| node_browserdb
node_teammate -->|"uses field kit"| node_checklists
node_teammate -->|"sets waypoints"| node_map
node_teammate -->|"signals beacon"| node_beacon
node_teammate -->|"raises distress"| node_sos
node_teammate -->|"shares notes"| node_notes
node_teammate -->|"checks status"| node_status
node_hub -->|"serves API"| node_http
node_hub -->|"attaches WebSocket"| node_wsdispatch
node_http -->|"handles room data"| node_repo
node_http -->|"reads presence"| node_registry
node_http -->|"stores uploads"| node_hubfiles
node_wsdispatch -->|"persists events"| node_repo
node_wsdispatch -->|"dispatches clients"| node_registry
node_repo -->|"reads and writes"| node_sqlite

click node_join "https://github.com/pallab-js/offgrid/blob/main/src/app/join/join-flow.tsx"
click node_session "https://github.com/pallab-js/offgrid/blob/main/src/stores/session.ts"
click node_roomcrypto "https://github.com/pallab-js/offgrid/blob/main/src/lib/crypto/room.ts"
click node_chatui "https://github.com/pallab-js/offgrid/blob/main/src/components/chat/thread.tsx"
click node_chatstore "https://github.com/pallab-js/offgrid/blob/main/src/stores/chat.ts"
click node_filesui "https://github.com/pallab-js/offgrid/blob/main/src/components/files/files-page.tsx"
click node_filestore "https://github.com/pallab-js/offgrid/blob/main/src/stores/files.ts"
click node_fileapi "https://github.com/pallab-js/offgrid/blob/main/src/lib/files/api.ts"
click node_wsclient "https://github.com/pallab-js/offgrid/blob/main/src/lib/ws/client.ts"
click node_protocol "https://github.com/pallab-js/offgrid/blob/main/src/lib/protocol/frames.ts"
click node_localmirror "https://github.com/pallab-js/offgrid/blob/main/src/lib/sync/outbox.ts"
click node_checklists "https://github.com/pallab-js/offgrid/blob/main/src/components/checklist/checklist-page.tsx"
click node_map "https://github.com/pallab-js/offgrid/blob/main/src/components/map/map-page.tsx"
click node_beacon "https://github.com/pallab-js/offgrid/blob/main/src/components/beacon/beacon-page.tsx"
click node_sos "https://github.com/pallab-js/offgrid/blob/main/src/components/sos/sos-overlay.tsx"
click node_notes "https://github.com/pallab-js/offgrid/blob/main/src/components/notes/notes-page.tsx"
click node_status "https://github.com/pallab-js/offgrid/blob/main/src/components/status/status-page.tsx"
click node_hub "https://github.com/pallab-js/offgrid/blob/main/server/index.ts"
click node_http "https://github.com/pallab-js/offgrid/blob/main/server/http/index.ts"
click node_wsdispatch "https://github.com/pallab-js/offgrid/blob/main/server/ws/dispatch.ts"
click node_registry "https://github.com/pallab-js/offgrid/blob/main/server/ws/registry.ts"
click node_repo "https://github.com/pallab-js/offgrid/blob/main/server/db/repo.ts"
click node_sqlite "https://github.com/pallab-js/offgrid/blob/main/server/db/index.ts"
click node_browserdb "https://github.com/pallab-js/offgrid/blob/main/src/lib/idb/db.ts"
click node_hubfiles "https://github.com/pallab-js/offgrid/blob/main/server/http/index.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_join,node_session,node_roomcrypto toneBlue
class node_chatui,node_chatstore,node_filesui,node_filestore,node_fileapi,node_wsclient,node_protocol,node_localmirror toneAmber
class node_checklists,node_map,node_beacon,node_sos,node_notes,node_status toneMint
class node_hub,node_http,node_wsdispatch,node_registry toneRose
class node_repo,node_sqlite,node_browserdb,node_hubfiles,node_teammate toneIndigo
```

## Components

### Room entry

- [Join room](https://github.com/pallab-js/offgrid/blob/main/src/app/join/join-flow.tsx): `src/app/join/join-flow.tsx`
- [Device session](https://github.com/pallab-js/offgrid/blob/main/src/stores/session.ts): `src/stores/session.ts`
- [Room encryption](https://github.com/pallab-js/offgrid/blob/main/src/lib/crypto/room.ts): `src/lib/crypto/room.ts`

### Browser messaging and sync

- [Channels and chat](https://github.com/pallab-js/offgrid/blob/main/src/components/chat/thread.tsx): `src/components/chat/thread.tsx`
- [Message state](https://github.com/pallab-js/offgrid/blob/main/src/stores/chat.ts): `src/stores/chat.ts`
- [File sharing](https://github.com/pallab-js/offgrid/blob/main/src/components/files/files-page.tsx): `src/components/files/files-page.tsx`
- [File state](https://github.com/pallab-js/offgrid/blob/main/src/stores/files.ts): `src/stores/files.ts`
- [Transfer API](https://github.com/pallab-js/offgrid/blob/main/src/lib/files/api.ts): `src/lib/files/api.ts`
- [WebSocket client](https://github.com/pallab-js/offgrid/blob/main/src/lib/ws/client.ts): `src/lib/ws/client.ts`
- [Frame protocol](https://github.com/pallab-js/offgrid/blob/main/src/lib/protocol/frames.ts): `src/lib/protocol/frames.ts`
- [Local-first sync](https://github.com/pallab-js/offgrid/blob/main/src/lib/sync/outbox.ts): `src/lib/sync/outbox.ts`

### Field tools

- [Checklists and guides](https://github.com/pallab-js/offgrid/blob/main/src/components/checklist/checklist-page.tsx): `src/components/checklist/checklist-page.tsx`
- [Offline map and waypoints](https://github.com/pallab-js/offgrid/blob/main/src/components/map/map-page.tsx): `src/components/map/map-page.tsx`
- [Beacon signaling](https://github.com/pallab-js/offgrid/blob/main/src/components/beacon/beacon-page.tsx): `src/components/beacon/beacon-page.tsx`
- [SOS distress](https://github.com/pallab-js/offgrid/blob/main/src/components/sos/sos-overlay.tsx): `src/components/sos/sos-overlay.tsx`
- [Shared notes](https://github.com/pallab-js/offgrid/blob/main/src/components/notes/notes-page.tsx): `src/components/notes/notes-page.tsx`
- [Status board](https://github.com/pallab-js/offgrid/blob/main/src/components/status/status-page.tsx): `src/components/status/status-page.tsx`

### Hub services

- [Hub startup](https://github.com/pallab-js/offgrid/blob/main/server/index.ts): `server/index.ts`
- [HTTP API](https://github.com/pallab-js/offgrid/blob/main/server/http/index.ts): `server/http/index.ts`
- [WebSocket dispatch](https://github.com/pallab-js/offgrid/blob/main/server/ws/dispatch.ts): `server/ws/dispatch.ts`
- [Live connections](https://github.com/pallab-js/offgrid/blob/main/server/ws/registry.ts): `server/ws/registry.ts`

### Persistence

- [Domain repository](https://github.com/pallab-js/offgrid/blob/main/server/db/repo.ts): `server/db/repo.ts`
- [SQLite database](https://github.com/pallab-js/offgrid/blob/main/server/db/index.ts): `server/db/index.ts`
- [Browser IndexedDB](https://github.com/pallab-js/offgrid/blob/main/src/lib/idb/db.ts): `src/lib/idb/db.ts`
- [Hub file storage](https://github.com/pallab-js/offgrid/blob/main/server/http/index.ts): `server/http/index.ts`

### Other components

- **Teammate**

## Connections

- Teammate → Join room: joins room (evidence: `README.md`)
- Join room → Room encryption: derives key (evidence: `src/app/join/join-flow.tsx`)
- Join room → Device session: saves membership (evidence: `src/app/join/join-flow.tsx`)
- Teammate → Channels and chat: uses channels (evidence: `README.md`)
- Channels and chat → Message state: updates messages (evidence: `src/components/chat/thread.tsx`)
- Message state → WebSocket client: sends frames (evidence: `src/stores/chat.ts`)
- WebSocket client → Frame protocol: validates frames (evidence: `src/lib/ws/client.ts`)
- Message state → Local-first sync: queues offline (evidence: `src/stores/chat.ts`)
- Message state → Browser IndexedDB: stores history (evidence: `src/stores/chat.ts`)
- Teammate → File sharing: shares files (evidence: `README.md`)
- File sharing → File state: manages files (evidence: `src/components/files/files-page.tsx`)
- File state → Transfer API: transfers bytes (evidence: `src/stores/files.ts`)
- Transfer API → Room encryption: encrypts frames (evidence: `src/lib/files/api.ts`)
- File state → WebSocket client: syncs metadata (evidence: `src/stores/files.ts`)
- File state → Browser IndexedDB: caches files (evidence: `src/stores/files.ts`)
- Teammate → Checklists and guides: uses field kit (evidence: `README.md`)
- Teammate → Offline map and waypoints: sets waypoints (evidence: `README.md`)
- Teammate → Beacon signaling: signals beacon (evidence: `README.md`)
- Teammate → SOS distress: raises distress (evidence: `README.md`)
- Teammate → Shared notes: shares notes (evidence: `README.md`)
- Teammate → Status board: checks status (evidence: `README.md`)
- Hub startup → HTTP API: serves API (evidence: `server/index.ts`)
- Hub startup → WebSocket dispatch: attaches WebSocket (evidence: `server/index.ts`)
- HTTP API → Domain repository: handles room data (evidence: `server/http/index.ts`)
- HTTP API → Live connections: reads presence (evidence: `server/http/index.ts`)
- HTTP API → Hub file storage: stores uploads (evidence: `server/http/index.ts`)
- WebSocket dispatch → Domain repository: persists events (evidence: `server/ws/dispatch.ts`)
- WebSocket dispatch → Live connections: dispatches clients (evidence: `server/ws/dispatch.ts`)
- Domain repository → SQLite database: reads and writes (evidence: `server/db/repo.ts`)
