# kawsaramin101/go-chatapp architecture

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

- Interactive diagram: https://gitdiagram.com/kawsaramin101/go-chatapp
- Repository: https://github.com/kawsaramin101/go-chatapp

## Overview

This is a browser-based chat application with account signup/login, private and group chats, connection requests, and live messaging. The main workflow is: a user authenticates, the browser opens a WebSocket and receives chat/request state, then chat actions and messages travel over that connection; messages are also cached in browser storage. The Go server coordinates WebSocket clients and rooms and persists account/chat data in SQLite. Several backend chat modules and frontend routes are present in the tree but were not sampled, so their detailed wiring is not inferred.

Main entry points: [`frontend/src/lib/stores/ws.ts`](https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/lib/stores/ws.ts) (WebSocket store), [`chat/client.go`](https://github.com/kawsaramin101/go-chatapp/blob/main/chat/client.go) (WebSocket client), [`main.go`](https://github.com/kawsaramin101/go-chatapp/blob/main/main.go) (HTTP server), [`frontend/src/routes/chat/[id]/+page.svelte`](https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/routes/chat/%5Bid%5D/%2Bpage.svelte) (Chat view)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Browser client"]
  node_signup_ui["Signup form<br/>[+page.svelte]"]
  node_login_ui["Login form<br/>[+page.svelte]"]
  node_layout["App shell<br/>[+layout.svelte]"]
  node_chat_ui["Chat view<br/>[+page.svelte]"]
  node_create_chat_ui["Create chat<br/>[+page.svelte]"]
  node_create_group_ui["Create group<br/>[+page.svelte]"]
  node_requests_ui["Message requests<br/>[+page.svelte]"]
  node_ws_store["WebSocket store<br/>[ws.ts]"]
  node_chat_store["Chat state<br/>[chats.ts]"]
  node_request_store["Request state"]
  node_message_store["Message state<br/>[messagesStore.ts]"]
  node_browser_cache[("Message cache<br/>[messages.ts]")]
end

subgraph group_server["Go server"]
  node_api["HTTP server<br/>[main.go]"]
  node_auth["Authentication<br/>[views.go]"]
end

subgraph group_chat["Chat runtime"]
  node_hub["WebSocket hub<br/>[hub.go]"]
  node_client["WebSocket client<br/>[client.go]"]
  node_actions["Chat actions<br/>[actions.go]"]
  node_rooms["Chat rooms<br/>[rooms.go]"]
  node_models["Chat messages<br/>[message_structs.go]"]
end

subgraph group_persistence["Persistence"]
  node_db_access["Database access<br/>[queries.go]"]
  node_sqlite[("SQLite data<br/>[db.go]")]
end

node_user(("User"))

node_user -->|"submits signup"| node_signup_ui
node_signup_ui -->|"POST signup"| node_api
node_user -->|"submits credentials"| node_login_ui
node_login_ui -->|"POST login"| node_api
node_api -->|"dispatches"| node_auth
node_auth -->|"queries users"| node_db_access
node_db_access -->|"reads/writes"| node_sqlite
node_api -->|"initializes"| node_sqlite
node_layout -->|"opens connection"| node_ws_store
node_ws_store -->|"opens WebSocket"| node_api
node_api -->|"starts and serves"| node_hub
node_hub -->|"registers clients"| node_client
node_client -->|"validates token"| node_auth
node_client -->|"loads user state"| node_db_access
node_client -->|"dispatches actions"| node_actions
node_actions -->|"chat operations"| node_rooms
node_client -->|"joins and leaves"| node_rooms
node_client -->|"decodes messages"| node_models
node_ws_store -->|"updates chat state"| node_chat_store
node_ws_store -->|"updates requests"| node_request_store
node_ws_store -->|"updates messages"| node_message_store
node_ws_store -->|"stores messages"| node_browser_cache
node_chat_ui -->|"sends chat actions"| node_ws_store
node_create_chat_ui -->|"sends chat actions"| node_ws_store
node_create_group_ui -->|"sends chat actions"| node_ws_store
node_requests_ui -->|"uses connection"| node_ws_store
node_chat_ui -->|"reads messages"| node_message_store
node_chat_ui -->|"loads cached messages"| node_browser_cache

click node_signup_ui "https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/routes/signup/%2Bpage.svelte"
click node_login_ui "https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/routes/login/%2Bpage.svelte"
click node_layout "https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/routes/%2Blayout.svelte"
click node_chat_ui "https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/routes/chat/%5Bid%5D/%2Bpage.svelte"
click node_create_chat_ui "https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/routes/create_chat/%2Bpage.svelte"
click node_create_group_ui "https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/routes/create_group_chat/%2Bpage.svelte"
click node_requests_ui "https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/routes/message_requests/%2Bpage.svelte"
click node_ws_store "https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/lib/stores/ws.ts"
click node_chat_store "https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/lib/stores/chats.ts"
click node_request_store "https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/lib/stores/connectionRequests.ts"
click node_message_store "https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/lib/stores/messagesStore.ts"
click node_browser_cache "https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/lib/storage/messages.ts"
click node_api "https://github.com/kawsaramin101/go-chatapp/blob/main/main.go"
click node_auth "https://github.com/kawsaramin101/go-chatapp/blob/main/auth/views.go"
click node_hub "https://github.com/kawsaramin101/go-chatapp/blob/main/chat/hub.go"
click node_client "https://github.com/kawsaramin101/go-chatapp/blob/main/chat/client.go"
click node_actions "https://github.com/kawsaramin101/go-chatapp/blob/main/chat/actions.go"
click node_rooms "https://github.com/kawsaramin101/go-chatapp/blob/main/chat/rooms.go"
click node_models "https://github.com/kawsaramin101/go-chatapp/blob/main/chat/message_structs.go"
click node_db_access "https://github.com/kawsaramin101/go-chatapp/blob/main/db/queries.go"
click node_sqlite "https://github.com/kawsaramin101/go-chatapp/blob/main/db/db.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_signup_ui,node_login_ui,node_layout,node_chat_ui,node_create_chat_ui,node_create_group_ui,node_requests_ui,node_ws_store,node_chat_store,node_request_store,node_message_store,node_browser_cache,node_user toneBlue
class node_api,node_auth toneAmber
class node_hub,node_client,node_actions,node_rooms,node_models toneMint
class node_db_access,node_sqlite toneRose
```

## Components

### Browser client

- [Signup form](https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/routes/signup/%2Bpage.svelte): `frontend/src/routes/signup/+page.svelte`
- [Login form](https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/routes/login/%2Bpage.svelte): `frontend/src/routes/login/+page.svelte`
- [App shell](https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/routes/%2Blayout.svelte): `frontend/src/routes/+layout.svelte`
- [Chat view](https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/routes/chat/%5Bid%5D/%2Bpage.svelte): `frontend/src/routes/chat/[id]/+page.svelte`
- [Create chat](https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/routes/create_chat/%2Bpage.svelte): `frontend/src/routes/create_chat/+page.svelte`
- [Create group](https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/routes/create_group_chat/%2Bpage.svelte): `frontend/src/routes/create_group_chat/+page.svelte`
- [Message requests](https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/routes/message_requests/%2Bpage.svelte): `frontend/src/routes/message_requests/+page.svelte`
- [WebSocket store](https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/lib/stores/ws.ts): `frontend/src/lib/stores/ws.ts`
- [Chat state](https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/lib/stores/chats.ts): `frontend/src/lib/stores/chats.ts`
- [Request state](https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/lib/stores/connectionRequests.ts): `frontend/src/lib/stores/connectionRequests.ts`
- [Message state](https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/lib/stores/messagesStore.ts): `frontend/src/lib/stores/messagesStore.ts`
- [Message cache](https://github.com/kawsaramin101/go-chatapp/blob/main/frontend/src/lib/storage/messages.ts): `frontend/src/lib/storage/messages.ts`

### Go server

- [HTTP server](https://github.com/kawsaramin101/go-chatapp/blob/main/main.go): `main.go`
- [Authentication](https://github.com/kawsaramin101/go-chatapp/blob/main/auth/views.go): `auth/views.go`

### Chat runtime

- [WebSocket hub](https://github.com/kawsaramin101/go-chatapp/blob/main/chat/hub.go): `chat/hub.go`
- [WebSocket client](https://github.com/kawsaramin101/go-chatapp/blob/main/chat/client.go): `chat/client.go`
- [Chat actions](https://github.com/kawsaramin101/go-chatapp/blob/main/chat/actions.go): `chat/actions.go`
- [Chat rooms](https://github.com/kawsaramin101/go-chatapp/blob/main/chat/rooms.go): `chat/rooms.go`
- [Chat messages](https://github.com/kawsaramin101/go-chatapp/blob/main/chat/message_structs.go): `chat/message_structs.go`

### Persistence

- [Database access](https://github.com/kawsaramin101/go-chatapp/blob/main/db/queries.go): `db/queries.go`
- [SQLite data](https://github.com/kawsaramin101/go-chatapp/blob/main/db/db.go): `db/db.go`

### Other components

- **User**

## Connections

- User → Signup form: submits signup
- Signup form → HTTP server: POST signup
- User → Login form: submits credentials
- Login form → HTTP server: POST login
- HTTP server → Authentication: dispatches
- Authentication → Database access: queries users
- Database access → SQLite data: reads/writes
- HTTP server → SQLite data: initializes
- App shell → WebSocket store: opens connection
- WebSocket store → HTTP server: opens WebSocket
- HTTP server → WebSocket hub: starts and serves
- WebSocket hub → WebSocket client: registers clients
- WebSocket client → Authentication: validates token
- WebSocket client → Database access: loads user state
- WebSocket client → Chat actions: dispatches actions
- Chat actions → Chat rooms: chat operations
- WebSocket client → Chat rooms: joins and leaves
- WebSocket client → Chat messages: decodes messages
- WebSocket store → Chat state: updates chat state
- WebSocket store → Request state: updates requests
- WebSocket store → Message state: updates messages
- WebSocket store → Message cache: stores messages
- Chat view → WebSocket store: sends chat actions
- Create chat → WebSocket store: sends chat actions
- Create group → WebSocket store: sends chat actions
- Message requests → WebSocket store: uses connection
- Chat view → Message state: reads messages
- Chat view → Message cache: loads cached messages
