# lemunozm/termchat architecture

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

- Interactive diagram: https://gitdiagram.com/lemunozm/termchat
- Repository: https://github.com/lemunozm/termchat

## Overview

Termchat is a serverless LAN chat application with a terminal UI. Its main workflow loads user settings, discovers peers over multicast, establishes TCP connections, and exchanges chat messages; commands add file transfer and video streaming. The sampled application code supports the core networking, state, and command relationships. Several listed modules were not sampled, so their internal wiring is omitted where it cannot be established.

Main entry points: [`src/application.rs`](https://github.com/lemunozm/termchat/blob/master/src/application.rs) (Application loop), [`src/action.rs`](https://github.com/lemunozm/termchat/blob/master/src/action.rs) (Action processing), [`src/main.rs`](https://github.com/lemunozm/termchat/blob/master/src/main.rs) (CLI entry), [`src/commands/send_file.rs`](https://github.com/lemunozm/termchat/blob/master/src/commands/send_file.rs) (File transfer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_startup["Startup and settings"]
  node_main["CLI entry<br/>[main.rs]"]
  node_config["Configuration<br/>[config.rs]"]
end

subgraph group_chat["Chat runtime"]
  node_application["Application loop<br/>[application.rs]"]
  node_events["Terminal events<br/>[terminal_events.rs]"]
  node_state["Chat state<br/>[state.rs]"]
  node_message["Wire messages<br/>[message.rs]"]
  node_encoder["Message encoding<br/>[encoder.rs]"]
end

subgraph group_commands["Commands and media"]
  node_command_manager["Command manager<br/>[commands.rs]"]
  node_action["Action processing<br/>[action.rs]"]
  node_send_file["File transfer<br/>[send_file.rs]"]
  node_stream["Video streaming"]
end

subgraph group_presentation["Terminal presentation"]
  node_renderer["Terminal renderer<br/>[renderer.rs]"]
  node_ui["Chat and video UI<br/>[ui.rs]"]
end

node_user(("User"))
node_peer(("LAN peers"))
node_network["UDP and TCP"]
node_filesystem[("Local files")]
node_camera["Video camera"]
node_terminal(("Terminal"))

node_user -->|"starts app"| node_main
node_main -->|"loads settings"| node_config
node_main -->|"starts runtime"| node_application
node_application -->|"collects input"| node_events
node_events -->|"reads events"| node_terminal
node_terminal -->|"shows interface"| node_user
node_application -->|"renders state"| node_renderer
node_renderer -->|"draws panels"| node_ui
node_ui -->|"reads view data"| node_state
node_application -->|"updates chat"| node_state
node_application -->|"encodes and decodes"| node_encoder
node_encoder -->|"serializes"| node_message
node_application -->|"discovers and connects"| node_network
node_application -->|"exchanges chat"| node_peer
node_network -->|"carries traffic"| node_peer
node_application -->|"dispatches input"| node_command_manager
node_command_manager -->|"creates actions"| node_action
node_application -->|"processes actions"| node_action
node_action -->|"runs transfer"| node_send_file
node_send_file -->|"reads file"| node_filesystem
node_send_file -->|"sends chunks"| node_network
node_application -->|"writes received files"| node_filesystem
node_action -->|"runs stream action"| node_stream
node_stream -.->|"captures frames"| node_camera
node_stream -.->|"sends video"| node_network
node_application -->|"stores received video"| node_state

click node_main "https://github.com/lemunozm/termchat/blob/master/src/main.rs"
click node_config "https://github.com/lemunozm/termchat/blob/master/src/config.rs"
click node_application "https://github.com/lemunozm/termchat/blob/master/src/application.rs"
click node_events "https://github.com/lemunozm/termchat/blob/master/src/terminal_events.rs"
click node_state "https://github.com/lemunozm/termchat/blob/master/src/state.rs"
click node_message "https://github.com/lemunozm/termchat/blob/master/src/message.rs"
click node_encoder "https://github.com/lemunozm/termchat/blob/master/src/encoder.rs"
click node_command_manager "https://github.com/lemunozm/termchat/blob/master/src/commands.rs"
click node_action "https://github.com/lemunozm/termchat/blob/master/src/action.rs"
click node_send_file "https://github.com/lemunozm/termchat/blob/master/src/commands/send_file.rs"
click node_stream "https://github.com/lemunozm/termchat/tree/master/src/commands/send_stream"
click node_renderer "https://github.com/lemunozm/termchat/blob/master/src/renderer.rs"
click node_ui "https://github.com/lemunozm/termchat/blob/master/src/ui.rs"

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_config,node_user toneBlue
class node_application,node_events,node_state,node_message,node_encoder,node_filesystem toneAmber
class node_command_manager,node_action,node_send_file,node_stream toneMint
class node_renderer,node_ui toneRose
class node_peer,node_network,node_camera,node_terminal toneIndigo
```

## Components

### Startup and settings

- [CLI entry](https://github.com/lemunozm/termchat/blob/master/src/main.rs): `src/main.rs`
- [Configuration](https://github.com/lemunozm/termchat/blob/master/src/config.rs): `src/config.rs`

### Chat runtime

- [Application loop](https://github.com/lemunozm/termchat/blob/master/src/application.rs): `src/application.rs`
- [Terminal events](https://github.com/lemunozm/termchat/blob/master/src/terminal_events.rs): `src/terminal_events.rs`
- [Chat state](https://github.com/lemunozm/termchat/blob/master/src/state.rs): `src/state.rs`
- [Wire messages](https://github.com/lemunozm/termchat/blob/master/src/message.rs): `src/message.rs`
- [Message encoding](https://github.com/lemunozm/termchat/blob/master/src/encoder.rs): `src/encoder.rs`

### Commands and media

- [Command manager](https://github.com/lemunozm/termchat/blob/master/src/commands.rs): `src/commands.rs`
- [Action processing](https://github.com/lemunozm/termchat/blob/master/src/action.rs): `src/action.rs`
- [File transfer](https://github.com/lemunozm/termchat/blob/master/src/commands/send_file.rs): `src/commands/send_file.rs`
- [Video streaming](https://github.com/lemunozm/termchat/tree/master/src/commands/send_stream): `src/commands/send_stream`

### Terminal presentation

- [Terminal renderer](https://github.com/lemunozm/termchat/blob/master/src/renderer.rs): `src/renderer.rs`
- [Chat and video UI](https://github.com/lemunozm/termchat/blob/master/src/ui.rs): `src/ui.rs`

### Other components

- **User**
- **LAN peers**
- **UDP and TCP**
- **Local files**
- **Video camera**
- **Terminal**

## Connections

- User → CLI entry: starts app
- CLI entry → Configuration: loads settings
- CLI entry → Application loop: starts runtime
- Application loop → Terminal events: collects input
- Terminal events → Terminal: reads events
- Terminal → User: shows interface
- Application loop → Terminal renderer: renders state
- Terminal renderer → Chat and video UI: draws panels
- Chat and video UI → Chat state: reads view data
- Application loop → Chat state: updates chat
- Application loop → Message encoding: encodes and decodes
- Message encoding → Wire messages: serializes
- Application loop → UDP and TCP: discovers and connects
- Application loop → LAN peers: exchanges chat
- UDP and TCP → LAN peers: carries traffic
- Application loop → Command manager: dispatches input
- Command manager → Action processing: creates actions
- Application loop → Action processing: processes actions
- Action processing → File transfer: runs transfer
- File transfer → Local files: reads file
- File transfer → UDP and TCP: sends chunks
- Application loop → Local files: writes received files
- Action processing → Video streaming: runs stream action
- Video streaming → Video camera: captures frames
- Video streaming → UDP and TCP: sends video
- Application loop → Chat state: stores received video
