# jorabarjomi/chatiks architecture

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

- Interactive diagram: https://gitdiagram.com/jorabarjomi/chatiks
- Repository: https://github.com/jorabarjomi/chatiks

## Overview

Chatiks is a browser-based, room-oriented chat application. A visitor opens the chat page, selects a room, and exchanges messages over WebSockets; the hub distributes messages and presence updates to clients in that room. When PostgreSQL is configured, the hub saves messages and loads recent room history for new connections. The excerpts show this runtime flow, but not the template contents or any authentication behavior; the auth module is empty.

Main entry points: [`internal/client.go`](https://github.com/jorabarjomi/chatiks/blob/main/internal/client.go) (WebSocket client), [`cmd/web/main.go`](https://github.com/jorabarjomi/chatiks/blob/main/cmd/web/main.go) (HTTP server), [`internal/hub.go`](https://github.com/jorabarjomi/chatiks/blob/main/internal/hub.go) (Room hub), [`internal/store.go`](https://github.com/jorabarjomi/chatiks/blob/main/internal/store.go) (Message store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web interface"]
  node_chatpage["Chat page handler<br/>[handlers.go]"]
  node_templates["Chat templates"]
  node_assets["Browser assets"]
  node_chatui["Room chat UI<br/>[script.js]"]
end

subgraph group_runtime["Chat runtime"]
  node_webserver["HTTP server<br/>[main.go]"]
  node_wsclient["WebSocket client<br/>[client.go]"]
  node_hub["Room hub<br/>[hub.go]"]
end

subgraph group_persistence["Message persistence"]
  node_storeinit["Store initialization<br/>[store.go]"]
  node_store[("Message store<br/>[store.go]")]
end

node_visitor(("Chat visitor"))
node_browser(("Browser"))
node_postgres[("PostgreSQL")]

node_visitor -->|"uses"| node_browser
node_browser -->|"requests page"| node_webserver
node_webserver -->|"routes GET"| node_chatpage
node_chatpage -->|"renders"| node_templates
node_webserver -->|"serves"| node_assets
node_browser -->|"runs"| node_chatui
node_chatui -->|"opens /ws"| node_wsclient
node_webserver -->|"routes /ws"| node_wsclient
node_wsclient -->|"registers"| node_hub
node_wsclient -->|"submits messages"| node_hub
node_hub -->|"queues room updates"| node_wsclient
node_wsclient -->|"sends WebSocket data"| node_browser
node_webserver -->|"initializes"| node_storeinit
node_storeinit -->|"opens database"| node_postgres
node_hub -->|"saves messages"| node_store
node_hub -->|"loads room history"| node_store
node_store -->|"reads and writes"| node_postgres

click node_webserver "https://github.com/jorabarjomi/chatiks/blob/main/cmd/web/main.go"
click node_chatpage "https://github.com/jorabarjomi/chatiks/blob/main/internal/handlers.go"
click node_templates "https://github.com/jorabarjomi/chatiks/tree/main/ui/templates"
click node_assets "https://github.com/jorabarjomi/chatiks/tree/main/ui/static"
click node_chatui "https://github.com/jorabarjomi/chatiks/blob/main/ui/static/script.js"
click node_wsclient "https://github.com/jorabarjomi/chatiks/blob/main/internal/client.go"
click node_hub "https://github.com/jorabarjomi/chatiks/blob/main/internal/hub.go"
click node_storeinit "https://github.com/jorabarjomi/chatiks/blob/main/internal/store.go"
click node_store "https://github.com/jorabarjomi/chatiks/blob/main/internal/store.go"

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_chatpage,node_templates,node_assets,node_chatui,node_browser toneBlue
class node_webserver,node_wsclient,node_hub,node_postgres toneAmber
class node_storeinit,node_store toneMint
class node_visitor toneIndigo
```

## Components

### Web interface

- [Chat page handler](https://github.com/jorabarjomi/chatiks/blob/main/internal/handlers.go): `internal/handlers.go`
- [Chat templates](https://github.com/jorabarjomi/chatiks/tree/main/ui/templates): `ui/templates`
- [Browser assets](https://github.com/jorabarjomi/chatiks/tree/main/ui/static): `ui/static`
- [Room chat UI](https://github.com/jorabarjomi/chatiks/blob/main/ui/static/script.js): `ui/static/script.js`

### Chat runtime

- [HTTP server](https://github.com/jorabarjomi/chatiks/blob/main/cmd/web/main.go): `cmd/web/main.go`
- [WebSocket client](https://github.com/jorabarjomi/chatiks/blob/main/internal/client.go): `internal/client.go`
- [Room hub](https://github.com/jorabarjomi/chatiks/blob/main/internal/hub.go): `internal/hub.go`

### Message persistence

- [Store initialization](https://github.com/jorabarjomi/chatiks/blob/main/internal/store.go): `internal/store.go`
- [Message store](https://github.com/jorabarjomi/chatiks/blob/main/internal/store.go): `internal/store.go`

### Other components

- **Chat visitor**
- **Browser**
- **PostgreSQL**

## Connections

- Chat visitor → Browser: uses
- Browser → HTTP server: requests page
- HTTP server → Chat page handler: routes GET (evidence: `cmd/web/main.go`)
- Chat page handler → Chat templates: renders (evidence: `internal/handlers.go`)
- HTTP server → Browser assets: serves (evidence: `cmd/web/main.go`)
- Browser → Room chat UI: runs
- Room chat UI → WebSocket client: opens /ws (evidence: `ui/static/script.js`)
- HTTP server → WebSocket client: routes /ws (evidence: `cmd/web/main.go`)
- WebSocket client → Room hub: registers (evidence: `internal/client.go`)
- WebSocket client → Room hub: submits messages (evidence: `internal/client.go`)
- Room hub → WebSocket client: queues room updates (evidence: `internal/hub.go`)
- WebSocket client → Browser: sends WebSocket data (evidence: `internal/client.go`)
- HTTP server → Store initialization: initializes (evidence: `cmd/web/main.go`)
- Store initialization → PostgreSQL: opens database (evidence: `internal/store.go`)
- Room hub → Message store: saves messages (evidence: `internal/hub.go`)
- Room hub → Message store: loads room history (evidence: `internal/hub.go`)
- Message store → PostgreSQL: reads and writes (evidence: `internal/store.go`)
