# tinode/chat architecture

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

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

## Overview

Tinode is a Go instant-messaging server with JSON/WebSocket, long-polling and gRPC client access, plus a Python command-line client and chatbot example. The main workflow is a client connection and session dispatch into messaging, presence and call handling, backed by persistence and optional integrations. The README documents broad chat capabilities, but the sampled excerpts do not expose all topic-level routing; the graph preserves those domain areas without guessing their internal call sequence.

Main entry points: [`server/store/store.go`](https://github.com/tinode/chat/blob/master/server/store/store.go) (Persistence facade), [`server/session.go`](https://github.com/tinode/chat/blob/master/server/session.go) (Sessions and dispatch), [`server/auth/auth.go`](https://github.com/tinode/chat/blob/master/server/auth/auth.go) (Authentication framework), [`tn-cli/client.py`](https://github.com/tinode/chat/blob/master/tn-cli/client.py) (CLI gRPC client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Messaging server"]
  node_server_main["Server startup<br/>[main.go]"]
  node_transport["Connection transports<br/>[hdl_websock.go]"]
  node_grpc["gRPC transport<br/>[hdl_grpc.go]"]
  node_session["Sessions and dispatch<br/>[session.go]"]
  node_topics["Topics and chat<br/>[topic.go]"]
  node_calls["Voice and video calls<br/>[calls.go]"]
  node_presence["Presence and delivery<br/>[pres.go]"]
  node_wire_model["Protocol model<br/>[model.proto]"]
end

subgraph group_data["Persistence"]
  node_store["Persistence facade<br/>[store.go]"]
  node_mysql["MySQL adapter<br/>[adapter.go]"]
  node_postgres["PostgreSQL adapter<br/>[adapter.go]"]
  node_rethink["RethinkDB adapter<br/>[adapter.go]"]
  node_mongodb["MongoDB adapter<br/>[adapter.go]"]
end

subgraph group_integrations["Auth and integrations"]
  node_auth["Authentication framework<br/>[auth.go]"]
  node_basic_auth["Basic authentication<br/>[auth_basic.go]"]
  node_rest_auth["REST authentication<br/>[auth_rest.go]"]
  node_media["Media storage<br/>[media.go]"]
  node_s3["S3 media backend<br/>[s3.go]"]
  node_push["Push notifications<br/>[push.go]"]
  node_push_types["Push payload model<br/>[typedef.go]"]
end

subgraph group_clients["Client tools"]
  node_cli_input["CLI input handling<br/>[input_handler.py]"]
  node_cli_client["CLI gRPC client<br/>[client.py]"]
  node_cli_commands["CLI commands<br/>[commands.py]"]
  node_chatbot["Chatbot example<br/>[chatbot.py]"]
  node_grpc_client["Python gRPC bindings<br/>[__init__.py]"]
end

node_user(("Messaging user"))
node_clients["Mobile and web clients"]

node_user -->|"uses"| node_clients
node_clients -->|"connects via WebSocket"| node_transport
node_clients -->|"connects via gRPC"| node_grpc
node_transport -.->|"dispatches"| node_session
node_grpc -.->|"dispatches"| node_session
node_server_main -->|"initializes"| node_auth
node_server_main -->|"configures"| node_media
node_session -->|"uses"| node_auth
node_session -->|"uses"| node_store
node_session -->|"handles messages"| node_wire_model
node_store -->|"adapts persistence"| node_mysql
node_store -->|"adapts persistence"| node_postgres
node_store -->|"adapts persistence"| node_rethink
node_store -.->|"adapts persistence"| node_mongodb
node_basic_auth -->|"registers scheme"| node_auth
node_rest_auth -->|"registers scheme"| node_auth
node_rest_auth -->|"calls external auth"| node_user
node_s3 -->|"implements backend"| node_media
node_push -->|"uses payload types"| node_push_types
node_cli_input -->|"feeds input"| node_cli_client
node_cli_client -->|"uses commands"| node_cli_commands
node_cli_client -->|"uses bindings"| node_grpc_client
node_chatbot -->|"uses bindings"| node_grpc_client

click node_server_main "https://github.com/tinode/chat/blob/master/server/main.go"
click node_transport "https://github.com/tinode/chat/blob/master/server/hdl_websock.go"
click node_grpc "https://github.com/tinode/chat/blob/master/server/hdl_grpc.go"
click node_session "https://github.com/tinode/chat/blob/master/server/session.go"
click node_topics "https://github.com/tinode/chat/blob/master/server/topic.go"
click node_calls "https://github.com/tinode/chat/blob/master/server/calls.go"
click node_presence "https://github.com/tinode/chat/blob/master/server/pres.go"
click node_wire_model "https://github.com/tinode/chat/blob/master/pbx/model.proto"
click node_store "https://github.com/tinode/chat/blob/master/server/store/store.go"
click node_mysql "https://github.com/tinode/chat/blob/master/server/db/mysql/adapter.go"
click node_postgres "https://github.com/tinode/chat/blob/master/server/db/postgres/adapter.go"
click node_rethink "https://github.com/tinode/chat/blob/master/server/db/rethinkdb/adapter.go"
click node_mongodb "https://github.com/tinode/chat/blob/master/server/db/mongodb/adapter.go"
click node_auth "https://github.com/tinode/chat/blob/master/server/auth/auth.go"
click node_basic_auth "https://github.com/tinode/chat/blob/master/server/auth/basic/auth_basic.go"
click node_rest_auth "https://github.com/tinode/chat/blob/master/server/auth/rest/auth_rest.go"
click node_media "https://github.com/tinode/chat/blob/master/server/media/media.go"
click node_s3 "https://github.com/tinode/chat/blob/master/server/media/s3/s3.go"
click node_push "https://github.com/tinode/chat/blob/master/server/push/push.go"
click node_push_types "https://github.com/tinode/chat/blob/master/server/push/common/typedef.go"
click node_cli_input "https://github.com/tinode/chat/blob/master/tn-cli/input_handler.py"
click node_cli_client "https://github.com/tinode/chat/blob/master/tn-cli/client.py"
click node_cli_commands "https://github.com/tinode/chat/blob/master/tn-cli/commands.py"
click node_chatbot "https://github.com/tinode/chat/blob/master/chatbot/python/chatbot.py"
click node_grpc_client "https://github.com/tinode/chat/blob/master/py_grpc/tinode_grpc/__init__.py"

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_server_main,node_transport,node_grpc,node_session,node_topics,node_calls,node_presence,node_wire_model,node_user,node_clients toneBlue
class node_store,node_mysql,node_postgres,node_rethink,node_mongodb toneAmber
class node_auth,node_basic_auth,node_rest_auth,node_media,node_s3,node_push,node_push_types toneMint
class node_cli_input,node_cli_client,node_cli_commands,node_chatbot,node_grpc_client toneRose
```

## Components

### Messaging server

- [Server startup](https://github.com/tinode/chat/blob/master/server/main.go): `server/main.go`
- [Connection transports](https://github.com/tinode/chat/blob/master/server/hdl_websock.go): `server/hdl_websock.go`
- [gRPC transport](https://github.com/tinode/chat/blob/master/server/hdl_grpc.go): `server/hdl_grpc.go`
- [Sessions and dispatch](https://github.com/tinode/chat/blob/master/server/session.go): `server/session.go`
- [Topics and chat](https://github.com/tinode/chat/blob/master/server/topic.go): `server/topic.go`
- [Voice and video calls](https://github.com/tinode/chat/blob/master/server/calls.go): `server/calls.go`
- [Presence and delivery](https://github.com/tinode/chat/blob/master/server/pres.go): `server/pres.go`
- [Protocol model](https://github.com/tinode/chat/blob/master/pbx/model.proto): `pbx/model.proto`

### Persistence

- [Persistence facade](https://github.com/tinode/chat/blob/master/server/store/store.go): `server/store/store.go`
- [MySQL adapter](https://github.com/tinode/chat/blob/master/server/db/mysql/adapter.go): `server/db/mysql/adapter.go`
- [PostgreSQL adapter](https://github.com/tinode/chat/blob/master/server/db/postgres/adapter.go): `server/db/postgres/adapter.go`
- [RethinkDB adapter](https://github.com/tinode/chat/blob/master/server/db/rethinkdb/adapter.go): `server/db/rethinkdb/adapter.go`
- [MongoDB adapter](https://github.com/tinode/chat/blob/master/server/db/mongodb/adapter.go): `server/db/mongodb/adapter.go`

### Auth and integrations

- [Authentication framework](https://github.com/tinode/chat/blob/master/server/auth/auth.go): `server/auth/auth.go`
- [Basic authentication](https://github.com/tinode/chat/blob/master/server/auth/basic/auth_basic.go): `server/auth/basic/auth_basic.go`
- [REST authentication](https://github.com/tinode/chat/blob/master/server/auth/rest/auth_rest.go): `server/auth/rest/auth_rest.go`
- [Media storage](https://github.com/tinode/chat/blob/master/server/media/media.go): `server/media/media.go`
- [S3 media backend](https://github.com/tinode/chat/blob/master/server/media/s3/s3.go): `server/media/s3/s3.go`
- [Push notifications](https://github.com/tinode/chat/blob/master/server/push/push.go): `server/push/push.go`
- [Push payload model](https://github.com/tinode/chat/blob/master/server/push/common/typedef.go): `server/push/common/typedef.go`

### Client tools

- [CLI input handling](https://github.com/tinode/chat/blob/master/tn-cli/input_handler.py): `tn-cli/input_handler.py`
- [CLI gRPC client](https://github.com/tinode/chat/blob/master/tn-cli/client.py): `tn-cli/client.py`
- [CLI commands](https://github.com/tinode/chat/blob/master/tn-cli/commands.py): `tn-cli/commands.py`
- [Chatbot example](https://github.com/tinode/chat/blob/master/chatbot/python/chatbot.py): `chatbot/python/chatbot.py`
- [Python gRPC bindings](https://github.com/tinode/chat/blob/master/py_grpc/tinode_grpc/__init__.py): `py_grpc/tinode_grpc/__init__.py`

### Other components

- **Messaging user**
- **Mobile and web clients**

## Connections

- Messaging user → Mobile and web clients: uses (evidence: `README.md`)
- Mobile and web clients → Connection transports: connects via WebSocket (evidence: `README.md`)
- Mobile and web clients → gRPC transport: connects via gRPC (evidence: `README.md`)
- Connection transports → Sessions and dispatch: dispatches
- gRPC transport → Sessions and dispatch: dispatches
- Server startup → Authentication framework: initializes (evidence: `server/main.go`)
- Server startup → Media storage: configures (evidence: `server/main.go`)
- Sessions and dispatch → Authentication framework: uses (evidence: `server/session.go`)
- Sessions and dispatch → Persistence facade: uses (evidence: `server/session.go`)
- Sessions and dispatch → Protocol model: handles messages (evidence: `server/session.go`)
- Persistence facade → MySQL adapter: adapts persistence (evidence: `server/db/mysql/adapter.go`)
- Persistence facade → PostgreSQL adapter: adapts persistence (evidence: `server/db/postgres/adapter.go`)
- Persistence facade → RethinkDB adapter: adapts persistence (evidence: `server/db/rethinkdb/adapter.go`)
- Persistence facade → MongoDB adapter: adapts persistence
- Basic authentication → Authentication framework: registers scheme (evidence: `server/auth/basic/auth_basic.go`)
- REST authentication → Authentication framework: registers scheme (evidence: `server/auth/rest/auth_rest.go`)
- REST authentication → Messaging user: calls external auth (evidence: `server/auth/rest/auth_rest.go`)
- S3 media backend → Media storage: implements backend (evidence: `server/media/s3/s3.go`)
- Push notifications → Push payload model: uses payload types (evidence: `server/push/push.go`)
- CLI input handling → CLI gRPC client: feeds input (evidence: `tn-cli/client.py`)
- CLI gRPC client → CLI commands: uses commands (evidence: `tn-cli/client.py`)
- CLI gRPC client → Python gRPC bindings: uses bindings (evidence: `tn-cli/client.py`)
- Chatbot example → Python gRPC bindings: uses bindings (evidence: `chatbot/python/chatbot.py`)
