# errordrive/harbor-chat architecture

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

- Interactive diagram: https://gitdiagram.com/errordrive/harbor-chat
- Repository: https://github.com/errordrive/harbor-chat

## Overview

Harbor Chat is a browser-based AI chat app backed by a Node server that keeps the Token Harbor key server-side. A user signs in, chooses a model, and streams a chat response; the server also enforces account-scoped usage budgets. The product includes chat history in browser storage, model discovery, settings, admin and usage features, and a user-scoped Skills Library. The graph focuses on these documented paths and sampled/indexed modules; unsampled wiring is omitted where evidence does not establish a call.

Main entry points: [`web/src/App.jsx`](https://github.com/errordrive/harbor-chat/blob/main/web/src/App.jsx) (Chat app), [`routes/chat.js`](https://github.com/errordrive/harbor-chat/blob/main/routes/chat.js) (Chat routes), [`web/src/lib/api.js`](https://github.com/errordrive/harbor-chat/blob/main/web/src/lib/api.js) (API client), [`server.js`](https://github.com/errordrive/harbor-chat/blob/main/server.js) (HTTP server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Chat client"]
  node_app["Chat app<br/>[App.jsx]"]
  node_auth_ui["Sign-in UI<br/>[AuthScreen.jsx]"]
  node_api_client["API client<br/>[api.js]"]
  node_chat_history[("Local chat history<br/>[store.js]")]
  node_model_picker["Model picker<br/>[ModelPicker.jsx]"]
  node_message_view["Message display<br/>[MessageList.jsx]"]
  node_skills_ui["Skills library UI<br/>[SkillsLibrary.jsx]"]
  node_admin_ui["Admin panel<br/>[AdminPanel.jsx]"]
end

subgraph group_routes["API routes"]
  node_auth_routes["Account routes<br/>[auth.js]"]
  node_chat_routes["Chat routes<br/>[chat.js]"]
  node_skills_routes["Skills routes<br/>[skills.js]"]
  node_misc_routes["Models and usage<br/>[misc.js]"]
  node_server["HTTP server<br/>[server.js]"]
  node_admin_routes["Admin routes<br/>[admin.js]"]
end

subgraph group_runtime["Chat runtime"]
  node_upstream["Provider client<br/>[upstream.js]"]
  node_ledger[("Usage ledger<br/>[ledger.js]")]
  node_accounting["Token accounting<br/>[accounting.js]"]
  node_agent["Agent orchestration<br/>[agent.js]"]
  node_tools["Agent tools<br/>[tools.js]"]
end

subgraph group_accounts["Accounts and skills"]
  node_auth["Session and auth<br/>[auth.js]"]
  node_skills_registry["Skills registry<br/>[skills-lib.js]"]
  node_database[("Postgres")]
end

node_user(("Chat user"))
node_provider{{"Token Harbor"}}

node_user -->|"uses"| node_app
node_app -->|"requests chat"| node_api_client
node_app -->|"persists chats"| node_chat_history
node_app -->|"renders"| node_model_picker
node_app -->|"renders"| node_message_view
node_user -->|"signs in"| node_auth_ui
node_auth_ui -->|"requests auth"| node_api_client
node_api_client -->|"calls auth API"| node_auth_routes
node_api_client -->|"streams chat"| node_chat_routes
node_api_client -->|"calls skills API"| node_skills_routes
node_app -->|"renders"| node_skills_ui
node_skills_ui -->|"requests skills"| node_api_client
node_server -->|"mounts"| node_auth_routes
node_server -->|"mounts"| node_chat_routes
node_server -->|"mounts"| node_skills_routes
node_server -->|"mounts"| node_admin_routes
node_chat_routes -->|"uses budgets"| node_accounting
node_chat_routes -->|"uses orchestration"| node_agent
node_chat_routes -->|"uses tools"| node_tools
node_chat_routes -->|"tracks usage"| node_ledger
node_upstream -->|"accounts tokens"| node_accounting
node_provider -->|"serves completions"| node_upstream
node_auth_routes -->|"queries accounts"| node_database
node_skills_routes -->|"stores skills"| node_database
node_skills_routes -->|"validates manifests"| node_skills_registry
node_admin_ui -.->|"uses admin API"| node_admin_routes
node_misc_routes -.->|"reports usage"| node_ledger
node_admin_ui -->|"shown for admins"| node_app

click node_app "https://github.com/errordrive/harbor-chat/blob/main/web/src/App.jsx"
click node_auth_ui "https://github.com/errordrive/harbor-chat/blob/main/web/src/components/AuthScreen.jsx"
click node_api_client "https://github.com/errordrive/harbor-chat/blob/main/web/src/lib/api.js"
click node_chat_history "https://github.com/errordrive/harbor-chat/blob/main/web/src/lib/store.js"
click node_model_picker "https://github.com/errordrive/harbor-chat/blob/main/web/src/components/ModelPicker.jsx"
click node_message_view "https://github.com/errordrive/harbor-chat/blob/main/web/src/components/MessageList.jsx"
click node_skills_ui "https://github.com/errordrive/harbor-chat/blob/main/web/src/components/SkillsLibrary.jsx"
click node_auth_routes "https://github.com/errordrive/harbor-chat/blob/main/routes/auth.js"
click node_chat_routes "https://github.com/errordrive/harbor-chat/blob/main/routes/chat.js"
click node_skills_routes "https://github.com/errordrive/harbor-chat/blob/main/routes/skills.js"
click node_misc_routes "https://github.com/errordrive/harbor-chat/blob/main/routes/misc.js"
click node_server "https://github.com/errordrive/harbor-chat/blob/main/server.js"
click node_upstream "https://github.com/errordrive/harbor-chat/blob/main/lib/upstream.js"
click node_ledger "https://github.com/errordrive/harbor-chat/blob/main/lib/ledger.js"
click node_accounting "https://github.com/errordrive/harbor-chat/blob/main/lib/accounting.js"
click node_agent "https://github.com/errordrive/harbor-chat/blob/main/lib/agent.js"
click node_tools "https://github.com/errordrive/harbor-chat/blob/main/lib/tools.js"
click node_auth "https://github.com/errordrive/harbor-chat/blob/main/lib/auth.js"
click node_skills_registry "https://github.com/errordrive/harbor-chat/blob/main/lib/skills-lib.js"
click node_admin_routes "https://github.com/errordrive/harbor-chat/blob/main/routes/admin.js"
click node_admin_ui "https://github.com/errordrive/harbor-chat/blob/main/web/src/components/AdminPanel.jsx"

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_auth_ui,node_api_client,node_chat_history,node_model_picker,node_message_view,node_skills_ui,node_admin_ui,node_user toneBlue
class node_auth_routes,node_chat_routes,node_skills_routes,node_misc_routes,node_server,node_admin_routes toneAmber
class node_upstream,node_ledger,node_accounting,node_agent,node_tools toneMint
class node_auth,node_skills_registry,node_database toneRose
class node_provider toneIndigo
```

## Components

### Chat client

- [Chat app](https://github.com/errordrive/harbor-chat/blob/main/web/src/App.jsx): `web/src/App.jsx`
- [Sign-in UI](https://github.com/errordrive/harbor-chat/blob/main/web/src/components/AuthScreen.jsx): `web/src/components/AuthScreen.jsx`
- [API client](https://github.com/errordrive/harbor-chat/blob/main/web/src/lib/api.js): `web/src/lib/api.js`
- [Local chat history](https://github.com/errordrive/harbor-chat/blob/main/web/src/lib/store.js): `web/src/lib/store.js`
- [Model picker](https://github.com/errordrive/harbor-chat/blob/main/web/src/components/ModelPicker.jsx): `web/src/components/ModelPicker.jsx`
- [Message display](https://github.com/errordrive/harbor-chat/blob/main/web/src/components/MessageList.jsx): `web/src/components/MessageList.jsx`
- [Skills library UI](https://github.com/errordrive/harbor-chat/blob/main/web/src/components/SkillsLibrary.jsx): `web/src/components/SkillsLibrary.jsx`
- [Admin panel](https://github.com/errordrive/harbor-chat/blob/main/web/src/components/AdminPanel.jsx): `web/src/components/AdminPanel.jsx`

### API routes

- [Account routes](https://github.com/errordrive/harbor-chat/blob/main/routes/auth.js): `routes/auth.js`
- [Chat routes](https://github.com/errordrive/harbor-chat/blob/main/routes/chat.js): `routes/chat.js`
- [Skills routes](https://github.com/errordrive/harbor-chat/blob/main/routes/skills.js): `routes/skills.js`
- [Models and usage](https://github.com/errordrive/harbor-chat/blob/main/routes/misc.js): `routes/misc.js`
- [HTTP server](https://github.com/errordrive/harbor-chat/blob/main/server.js): `server.js`
- [Admin routes](https://github.com/errordrive/harbor-chat/blob/main/routes/admin.js): `routes/admin.js`

### Chat runtime

- [Provider client](https://github.com/errordrive/harbor-chat/blob/main/lib/upstream.js): `lib/upstream.js`
- [Usage ledger](https://github.com/errordrive/harbor-chat/blob/main/lib/ledger.js): `lib/ledger.js`
- [Token accounting](https://github.com/errordrive/harbor-chat/blob/main/lib/accounting.js): `lib/accounting.js`
- [Agent orchestration](https://github.com/errordrive/harbor-chat/blob/main/lib/agent.js): `lib/agent.js`
- [Agent tools](https://github.com/errordrive/harbor-chat/blob/main/lib/tools.js): `lib/tools.js`

### Accounts and skills

- [Session and auth](https://github.com/errordrive/harbor-chat/blob/main/lib/auth.js): `lib/auth.js`
- [Skills registry](https://github.com/errordrive/harbor-chat/blob/main/lib/skills-lib.js): `lib/skills-lib.js`
- **Postgres**

### Other components

- **Chat user**
- **Token Harbor**

## Connections

- Chat user → Chat app: uses
- Chat app → API client: requests chat (evidence: `web/src/App.jsx`)
- Chat app → Local chat history: persists chats (evidence: `web/src/App.jsx`)
- Chat app → Model picker: renders (evidence: `web/src/App.jsx`)
- Chat app → Message display: renders (evidence: `web/src/App.jsx`)
- Chat user → Sign-in UI: signs in
- Sign-in UI → API client: requests auth (evidence: `web/src/components/AuthScreen.jsx`)
- API client → Account routes: calls auth API
- API client → Chat routes: streams chat
- API client → Skills routes: calls skills API (evidence: `web/src/lib/api.js`)
- Chat app → Skills library UI: renders (evidence: `web/src/App.jsx`)
- Skills library UI → API client: requests skills (evidence: `web/src/components/SkillsLibrary.jsx`)
- HTTP server → Account routes: mounts (evidence: `server.js`)
- HTTP server → Chat routes: mounts (evidence: `server.js`)
- HTTP server → Skills routes: mounts (evidence: `server.js`)
- HTTP server → Admin routes: mounts (evidence: `server.js`)
- Chat routes → Token accounting: uses budgets (evidence: `routes/chat.js`)
- Chat routes → Agent orchestration: uses orchestration (evidence: `routes/chat.js`)
- Chat routes → Agent tools: uses tools (evidence: `routes/chat.js`)
- Chat routes → Usage ledger: tracks usage (evidence: `routes/chat.js`)
- Provider client → Token accounting: accounts tokens (evidence: `lib/upstream.js`)
- Token Harbor → Provider client: serves completions
- Account routes → Postgres: queries accounts (evidence: `routes/auth.js`)
- Skills routes → Postgres: stores skills (evidence: `routes/skills.js`)
- Skills routes → Skills registry: validates manifests (evidence: `routes/skills.js`)
- Admin panel → Admin routes: uses admin API
- Models and usage → Usage ledger: reports usage
- Admin panel → Chat app: shown for admins (evidence: `web/src/App.jsx`)
