# taoshihan1991/goflylivechat architecture

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

- Interactive diagram: https://gitdiagram.com/taoshihan1991/goflylivechat
- Repository: https://github.com/taoshihan1991/goflylivechat

## Overview

GOFLY LIVE CHAT is a customer-support chat service: visitors connect through the embedded chat or live-chat page, exchange real-time messages with support agents, and agents manage conversations and customer-service settings. The repository exposes HTTP routes and WebSocket handlers, with models backed by the documented MySQL database. The map also preserves documented installation, administration, and frontend capabilities. Source excerpts show routing and selected WebSocket/model interactions; many controller and frontend details are unsampled, so their internal links are omitted.

Main entry points: [`router`](https://github.com/taoshihan1991/goflylivechat/tree/master/router) (HTTP routes), [`static/js/chat-widget.js`](https://github.com/taoshihan1991/goflylivechat/blob/master/static/js/chat-widget.js) (Embedded chat widget), [`cmd`](https://github.com/taoshihan1991/goflylivechat/tree/master/cmd) (Server and install commands), [`ws/visitor.go`](https://github.com/taoshihan1991/goflylivechat/blob/master/ws/visitor.go) (Visitor WebSocket)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Service entry"]
  node_main["Application entry<br/>[main.go]"]
  node_commands["Server and install commands"]
  node_routes["HTTP routes"]
  node_middleware["Request middleware"]
  node_installer["Database installation<br/>[main.go]"]
end

subgraph group_chat["Live chat"]
  node_visitorws["Visitor WebSocket<br/>[visitor.go]"]
  node_agentws["Agent WebSocket<br/>[user.go]"]
  node_wsruntime["WebSocket runtime<br/>[ws.go]"]
  node_messageapi["Message endpoints<br/>[message.go]"]
  node_visitorapi["Visitor endpoints<br/>[visitor.go]"]
  node_message_store[("Message records<br/>[messages.go]")]
  node_visitor_store[("Visitor records<br/>[visitors.go]")]
end

subgraph group_admin["Support operations"]
  node_agent_admin["Agent accounts<br/>[kefu.go]"]
  node_settings["Support settings and roles"]
  node_replies["Automatic replies<br/>[reply.go]"]
end

subgraph group_client["Web client"]
  node_chat_widget["Embedded chat widget<br/>[chat-widget.js]"]
  node_chat_functions["Chat client functions<br/>[functions.js]"]
  node_layui["Layui UI library<br/>[layui.js]"]
  node_layer["Layer dialogs<br/>[layer.js]"]
  node_icons["Icon font<br/>[iconfont.js]"]
end

node_operator(("Visitor or agent"))
node_mysql[("MySQL")]

node_operator -->|"opens chat"| node_chat_widget
node_chat_widget -.->|"connects to"| node_visitorws
node_operator -->|"uses service"| node_routes
node_main -->|"executes"| node_commands
node_commands -->|"registers routes"| node_routes
node_commands -->|"installs middleware"| node_middleware
node_commands -->|"starts backend"| node_wsruntime
node_routes -->|"routes visitor socket"| node_visitorws
node_routes -->|"routes agent socket"| node_agentws
node_routes -->|"routes messages"| node_messageapi
node_routes -->|"routes visitors"| node_visitorapi
node_routes -->|"routes agent actions"| node_agent_admin
node_visitorws -->|"loads visitor"| node_visitor_store
node_visitorws -->|"loads last message"| node_message_store
node_installer -->|"checks connection"| node_mysql
node_installer -->|"uses models"| node_visitor_store
node_installer -->|"counts clients"| node_wsruntime
node_message_store -.->|"persists records"| node_mysql
node_visitor_store -.->|"persists records"| node_mysql
node_chat_functions -.->|"supports client"| node_chat_widget
node_chat_widget -.->|"uses UI library"| node_layui
node_chat_widget -.->|"uses dialogs"| node_layer

click node_main "https://github.com/taoshihan1991/goflylivechat/blob/master/main.go"
click node_commands "https://github.com/taoshihan1991/goflylivechat/tree/master/cmd"
click node_routes "https://github.com/taoshihan1991/goflylivechat/tree/master/router"
click node_middleware "https://github.com/taoshihan1991/goflylivechat/tree/master/middleware"
click node_installer "https://github.com/taoshihan1991/goflylivechat/blob/master/controller/main.go"
click node_visitorws "https://github.com/taoshihan1991/goflylivechat/blob/master/ws/visitor.go"
click node_agentws "https://github.com/taoshihan1991/goflylivechat/blob/master/ws/user.go"
click node_wsruntime "https://github.com/taoshihan1991/goflylivechat/blob/master/ws/ws.go"
click node_messageapi "https://github.com/taoshihan1991/goflylivechat/blob/master/controller/message.go"
click node_visitorapi "https://github.com/taoshihan1991/goflylivechat/blob/master/controller/visitor.go"
click node_message_store "https://github.com/taoshihan1991/goflylivechat/blob/master/models/messages.go"
click node_visitor_store "https://github.com/taoshihan1991/goflylivechat/blob/master/models/visitors.go"
click node_agent_admin "https://github.com/taoshihan1991/goflylivechat/blob/master/controller/kefu.go"
click node_settings "https://github.com/taoshihan1991/goflylivechat/tree/master/controller"
click node_replies "https://github.com/taoshihan1991/goflylivechat/blob/master/controller/reply.go"
click node_chat_widget "https://github.com/taoshihan1991/goflylivechat/blob/master/static/js/chat-widget.js"
click node_chat_functions "https://github.com/taoshihan1991/goflylivechat/blob/master/static/js/functions.js"
click node_layui "https://github.com/taoshihan1991/goflylivechat/blob/master/static/css/layui/layui.js"
click node_layer "https://github.com/taoshihan1991/goflylivechat/blob/master/static/js/layer/layer.js"
click node_icons "https://github.com/taoshihan1991/goflylivechat/blob/master/static/css/icon/iconfont.js"

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_main,node_commands,node_routes,node_middleware,node_installer toneBlue
class node_visitorws,node_agentws,node_wsruntime,node_messageapi,node_visitorapi,node_message_store,node_visitor_store,node_mysql toneAmber
class node_agent_admin,node_settings,node_replies toneMint
class node_chat_widget,node_chat_functions,node_layui,node_layer,node_icons toneRose
class node_operator toneIndigo
```

## Components

### Service entry

- [Application entry](https://github.com/taoshihan1991/goflylivechat/blob/master/main.go): `main.go`
- [Server and install commands](https://github.com/taoshihan1991/goflylivechat/tree/master/cmd): `cmd`
- [HTTP routes](https://github.com/taoshihan1991/goflylivechat/tree/master/router): `router`
- [Request middleware](https://github.com/taoshihan1991/goflylivechat/tree/master/middleware): `middleware`
- [Database installation](https://github.com/taoshihan1991/goflylivechat/blob/master/controller/main.go): `controller/main.go`

### Live chat

- [Visitor WebSocket](https://github.com/taoshihan1991/goflylivechat/blob/master/ws/visitor.go): `ws/visitor.go`
- [Agent WebSocket](https://github.com/taoshihan1991/goflylivechat/blob/master/ws/user.go): `ws/user.go`
- [WebSocket runtime](https://github.com/taoshihan1991/goflylivechat/blob/master/ws/ws.go): `ws/ws.go`
- [Message endpoints](https://github.com/taoshihan1991/goflylivechat/blob/master/controller/message.go): `controller/message.go`
- [Visitor endpoints](https://github.com/taoshihan1991/goflylivechat/blob/master/controller/visitor.go): `controller/visitor.go`
- [Message records](https://github.com/taoshihan1991/goflylivechat/blob/master/models/messages.go): `models/messages.go`
- [Visitor records](https://github.com/taoshihan1991/goflylivechat/blob/master/models/visitors.go): `models/visitors.go`

### Support operations

- [Agent accounts](https://github.com/taoshihan1991/goflylivechat/blob/master/controller/kefu.go): `controller/kefu.go`
- [Support settings and roles](https://github.com/taoshihan1991/goflylivechat/tree/master/controller): `controller`
- [Automatic replies](https://github.com/taoshihan1991/goflylivechat/blob/master/controller/reply.go): `controller/reply.go`

### Web client

- [Embedded chat widget](https://github.com/taoshihan1991/goflylivechat/blob/master/static/js/chat-widget.js): `static/js/chat-widget.js`
- [Chat client functions](https://github.com/taoshihan1991/goflylivechat/blob/master/static/js/functions.js): `static/js/functions.js`
- [Layui UI library](https://github.com/taoshihan1991/goflylivechat/blob/master/static/css/layui/layui.js): `static/css/layui/layui.js`
- [Layer dialogs](https://github.com/taoshihan1991/goflylivechat/blob/master/static/js/layer/layer.js): `static/js/layer/layer.js`
- [Icon font](https://github.com/taoshihan1991/goflylivechat/blob/master/static/css/icon/iconfont.js): `static/css/icon/iconfont.js`

### Other components

- **Visitor or agent**
- **MySQL**

## Connections

- Visitor or agent → Embedded chat widget: opens chat
- Embedded chat widget → Visitor WebSocket: connects to
- Visitor or agent → HTTP routes: uses service (evidence: `router/api.go`)
- Application entry → Server and install commands: executes (evidence: `main.go`)
- Server and install commands → HTTP routes: registers routes (evidence: `cmd/server.go`)
- Server and install commands → Request middleware: installs middleware (evidence: `cmd/server.go`)
- Server and install commands → WebSocket runtime: starts backend (evidence: `cmd/server.go`)
- HTTP routes → Visitor WebSocket: routes visitor socket (evidence: `router/api.go`)
- HTTP routes → Agent WebSocket: routes agent socket (evidence: `router/api.go`)
- HTTP routes → Message endpoints: routes messages (evidence: `router/api.go`)
- HTTP routes → Visitor endpoints: routes visitors (evidence: `router/api.go`)
- HTTP routes → Agent accounts: routes agent actions (evidence: `router/api.go`)
- Visitor WebSocket → Visitor records: loads visitor (evidence: `ws/visitor.go`)
- Visitor WebSocket → Message records: loads last message (evidence: `ws/visitor.go`)
- Database installation → MySQL: checks connection (evidence: `controller/main.go`)
- Database installation → Visitor records: uses models (evidence: `controller/main.go`)
- Database installation → WebSocket runtime: counts clients (evidence: `controller/main.go`)
- Message records → MySQL: persists records
- Visitor records → MySQL: persists records
- Chat client functions → Embedded chat widget: supports client
- Embedded chat widget → Layui UI library: uses UI library
- Embedded chat widget → Layer dialogs: uses dialogs
