# ss-dev/fb-chat-emulator architecture

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

- Interactive diagram: https://gitdiagram.com/ss-dev/fb-chat-emulator
- Repository: https://github.com/ss-dev/fb-chat-emulator

## Overview

fb-chat-emulator is a lightweight Facebook-chat API stand-in for load-testing chatbot applications. A chatbot sends requests to the emulator; it applies configured timing, matches request rules, and may send templated responses back to the chatbot. Operators can inspect or reset live statistics. The graph follows the documented workflow and sampled handlers; the sample config represents the configuration format, not the runtime config file itself.

Main entry points: [`main.go`](https://github.com/ss-dev/fb-chat-emulator/blob/master/main.go) (HTTP server), [`chat.go`](https://github.com/ss-dev/fb-chat-emulator/blob/master/chat.go) (Request processing), [`stat.go`](https://github.com/ss-dev/fb-chat-emulator/blob/master/stat.go) (Stat update channel), [`config.go`](https://github.com/ss-dev/fb-chat-emulator/blob/master/config.go) (Load config)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Emulator runtime"]
  node_emulator["HTTP server<br/>[main.go]"]
  node_config["Load config<br/>[config.go]"]
  node_requesthandler["Request handler<br/>[main.go]"]
  node_statendpoint["Stats and reset handlers<br/>[main.go]"]
end

subgraph group_rules["Rule processing"]
  node_requestprocessing["Request processing<br/>[chat.go]"]
  node_rulematching["Rule matching<br/>[chat.go]"]
  node_response["Build and send response<br/>[chat.go]"]
end

subgraph group_stats["Statistics"]
  node_statupdates["Stat update channel<br/>[stat.go]"]
  node_statwriter["Stat accumulator<br/>[stat.go]"]
  node_statreset["Reset statistics<br/>[stat.go]"]
  node_statrender["Render statistics<br/>[stat.go]"]
end

node_chatbot(("Chatbot app"))
node_operator(("Operator browser"))
node_configfile["Rule config<br/>[config.sample.json]"]
node_botapp(("Configured chatbot endpoint"))

node_configfile -->|"configures"| node_config
node_emulator -->|"loads"| node_config
node_emulator -->|"starts"| node_statwriter
node_chatbot -->|"sends requests"| node_emulator
node_emulator -->|"dispatches"| node_requesthandler
node_requesthandler -->|"calls"| node_requestprocessing
node_requestprocessing -->|"matches rules"| node_rulematching
node_rulematching -->|"records unmatched"| node_statupdates
node_requestprocessing -->|"records no-response"| node_statupdates
node_requestprocessing -->|"starts asynchronously"| node_response
node_response -->|"records results"| node_statupdates
node_response -->|"posts response"| node_botapp
node_statupdates -->|"delivers updates"| node_statwriter
node_operator -->|"requests stats"| node_emulator
node_emulator -->|"dispatches"| node_statendpoint
node_statendpoint -->|"resets on request"| node_statreset
node_statendpoint -->|"renders table"| node_statrender
node_statreset -->|"renders table"| node_statrender
node_statwriter -->|"provides totals"| node_statrender

click node_emulator "https://github.com/ss-dev/fb-chat-emulator/blob/master/main.go"
click node_config "https://github.com/ss-dev/fb-chat-emulator/blob/master/config.go"
click node_configfile "https://github.com/ss-dev/fb-chat-emulator/blob/master/config.sample.json"
click node_requesthandler "https://github.com/ss-dev/fb-chat-emulator/blob/master/main.go"
click node_requestprocessing "https://github.com/ss-dev/fb-chat-emulator/blob/master/chat.go"
click node_rulematching "https://github.com/ss-dev/fb-chat-emulator/blob/master/chat.go"
click node_response "https://github.com/ss-dev/fb-chat-emulator/blob/master/chat.go"
click node_statupdates "https://github.com/ss-dev/fb-chat-emulator/blob/master/stat.go"
click node_statwriter "https://github.com/ss-dev/fb-chat-emulator/blob/master/stat.go"
click node_statreset "https://github.com/ss-dev/fb-chat-emulator/blob/master/stat.go"
click node_statrender "https://github.com/ss-dev/fb-chat-emulator/blob/master/stat.go"
click node_statendpoint "https://github.com/ss-dev/fb-chat-emulator/blob/master/main.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_emulator,node_config,node_requesthandler,node_statendpoint,node_operator toneBlue
class node_requestprocessing,node_rulematching,node_response toneAmber
class node_statupdates,node_statwriter,node_statreset,node_statrender toneMint
class node_chatbot,node_botapp toneIndigo
class node_configfile toneTeal
```

## Components

### Emulator runtime

- [HTTP server](https://github.com/ss-dev/fb-chat-emulator/blob/master/main.go): `main.go`
- [Load config](https://github.com/ss-dev/fb-chat-emulator/blob/master/config.go): `config.go`
- [Request handler](https://github.com/ss-dev/fb-chat-emulator/blob/master/main.go): `main.go`
- [Stats and reset handlers](https://github.com/ss-dev/fb-chat-emulator/blob/master/main.go): `main.go`

### Rule processing

- [Request processing](https://github.com/ss-dev/fb-chat-emulator/blob/master/chat.go): `chat.go`
- [Rule matching](https://github.com/ss-dev/fb-chat-emulator/blob/master/chat.go): `chat.go`
- [Build and send response](https://github.com/ss-dev/fb-chat-emulator/blob/master/chat.go): `chat.go`

### Statistics

- [Stat update channel](https://github.com/ss-dev/fb-chat-emulator/blob/master/stat.go): `stat.go`
- [Stat accumulator](https://github.com/ss-dev/fb-chat-emulator/blob/master/stat.go): `stat.go`
- [Reset statistics](https://github.com/ss-dev/fb-chat-emulator/blob/master/stat.go): `stat.go`
- [Render statistics](https://github.com/ss-dev/fb-chat-emulator/blob/master/stat.go): `stat.go`

### Other components

- **Chatbot app**
- **Operator browser**
- [Rule config](https://github.com/ss-dev/fb-chat-emulator/blob/master/config.sample.json): `config.sample.json`
- **Configured chatbot endpoint**

## Connections

- Rule config → Load config: configures
- HTTP server → Load config: loads
- HTTP server → Stat accumulator: starts
- Chatbot app → HTTP server: sends requests
- HTTP server → Request handler: dispatches
- Request handler → Request processing: calls
- Request processing → Rule matching: matches rules
- Rule matching → Stat update channel: records unmatched
- Request processing → Stat update channel: records no-response
- Request processing → Build and send response: starts asynchronously
- Build and send response → Stat update channel: records results
- Build and send response → Configured chatbot endpoint: posts response
- Stat update channel → Stat accumulator: delivers updates
- Operator browser → HTTP server: requests stats
- HTTP server → Stats and reset handlers: dispatches
- Stats and reset handlers → Reset statistics: resets on request
- Stats and reset handlers → Render statistics: renders table
- Reset statistics → Render statistics: renders table
- Stat accumulator → Render statistics: provides totals
