# koanvi/cli-chat architecture

> Architecture diagram of the GitHub repository koanvi/cli-chat, 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/koanvi/cli-chat
- Repository: https://github.com/koanvi/cli-chat

## Overview

cli-chat is a small terminal chat application: a user enters a message and recipient in the CLI, the client sends a JSON request over TCP, and the server routes it to the recipient (or broadcasts to other connected clients). The client processes server responses and received messages and emits state events. The README describes the product only briefly; the sampled implementation shows no separate persistence or authentication layer. Edges reflect the displayed calls; the client/server wire interaction is evident from their implementations, though no shared protocol module is shown.

Main entry points: [`wsServer/src/server.ts`](https://github.com/koanvi/cli-chat/blob/main/wsServer/src/server.ts) (TCP server), [`wsClient/src/client.ts`](https://github.com/koanvi/cli-chat/blob/main/wsClient/src/client.ts) (TCP client), [`wsClient/src/index.ts`](https://github.com/koanvi/cli-chat/blob/main/wsClient/src/index.ts) (Prompt input), [`wsServer/src/index.ts`](https://github.com/koanvi/cli-chat/blob/main/wsServer/src/index.ts) (Server startup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["Terminal client"]
  node_cli_entry["CLI entry<br/>[index.ts]"]
  node_console_input["Prompt input<br/>[index.ts]"]
  node_client["TCP client<br/>[client.ts]"]
  node_client_events["Client events<br/>[client.ts]"]
end

subgraph group_server["Chat server"]
  node_server_entry["Server startup<br/>[index.ts]"]
  node_server["TCP server<br/>[server.ts]"]
  node_registry[("Client registry<br/>[server.ts]")]
  node_dispatch["Method dispatch<br/>[server.ts]"]
  node_message_route["Message routing<br/>[server.ts]"]
end

node_user(("Chat user"))

node_user -->|"enters message"| node_console_input
node_cli_entry -->|"creates client"| node_client
node_cli_entry -->|"starts prompts"| node_console_input
node_console_input -->|"sends request"| node_client
node_client -->|"emits events"| node_client_events
node_server_entry -->|"starts server"| node_server
node_client -.->|"sends TCP JSON"| node_server
node_server -->|"registers clients"| node_registry
node_server -->|"processes requests"| node_dispatch
node_dispatch -->|"invokes method"| node_message_route
node_message_route -->|"routes messages"| node_registry
node_server -.->|"returns responses"| node_client

click node_cli_entry "https://github.com/koanvi/cli-chat/blob/main/wsClient/src/index.ts"
click node_console_input "https://github.com/koanvi/cli-chat/blob/main/wsClient/src/index.ts"
click node_client "https://github.com/koanvi/cli-chat/blob/main/wsClient/src/client.ts"
click node_client_events "https://github.com/koanvi/cli-chat/blob/main/wsClient/src/client.ts"
click node_server_entry "https://github.com/koanvi/cli-chat/blob/main/wsServer/src/index.ts"
click node_server "https://github.com/koanvi/cli-chat/blob/main/wsServer/src/server.ts"
click node_registry "https://github.com/koanvi/cli-chat/blob/main/wsServer/src/server.ts"
click node_dispatch "https://github.com/koanvi/cli-chat/blob/main/wsServer/src/server.ts"
click node_message_route "https://github.com/koanvi/cli-chat/blob/main/wsServer/src/server.ts"

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_cli_entry,node_console_input,node_client,node_client_events,node_user toneBlue
class node_server_entry,node_server,node_registry,node_dispatch,node_message_route toneAmber
```

## Components

### Terminal client

- [CLI entry](https://github.com/koanvi/cli-chat/blob/main/wsClient/src/index.ts): `wsClient/src/index.ts`
- [Prompt input](https://github.com/koanvi/cli-chat/blob/main/wsClient/src/index.ts): `wsClient/src/index.ts`
- [TCP client](https://github.com/koanvi/cli-chat/blob/main/wsClient/src/client.ts): `wsClient/src/client.ts`
- [Client events](https://github.com/koanvi/cli-chat/blob/main/wsClient/src/client.ts): `wsClient/src/client.ts`

### Chat server

- [Server startup](https://github.com/koanvi/cli-chat/blob/main/wsServer/src/index.ts): `wsServer/src/index.ts`
- [TCP server](https://github.com/koanvi/cli-chat/blob/main/wsServer/src/server.ts): `wsServer/src/server.ts`
- [Client registry](https://github.com/koanvi/cli-chat/blob/main/wsServer/src/server.ts): `wsServer/src/server.ts`
- [Method dispatch](https://github.com/koanvi/cli-chat/blob/main/wsServer/src/server.ts): `wsServer/src/server.ts`
- [Message routing](https://github.com/koanvi/cli-chat/blob/main/wsServer/src/server.ts): `wsServer/src/server.ts`

### Other components

- **Chat user**

## Connections

- Chat user → Prompt input: enters message (evidence: `wsClient/src/index.ts`)
- CLI entry → TCP client: creates client (evidence: `wsClient/src/index.ts`)
- CLI entry → Prompt input: starts prompts (evidence: `wsClient/src/index.ts`)
- Prompt input → TCP client: sends request (evidence: `wsClient/src/index.ts`)
- TCP client → Client events: emits events (evidence: `wsClient/src/client.ts`)
- Server startup → TCP server: starts server (evidence: `wsServer/src/index.ts`)
- TCP client → TCP server: sends TCP JSON
- TCP server → Client registry: registers clients (evidence: `wsServer/src/server.ts`)
- TCP server → Method dispatch: processes requests (evidence: `wsServer/src/server.ts`)
- Method dispatch → Message routing: invokes method (evidence: `wsServer/src/server.ts`)
- Message routing → Client registry: routes messages (evidence: `wsServer/src/server.ts`)
- TCP server → TCP client: returns responses
