# java-mx/bitchat-python architecture

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

- Interactive diagram: https://gitdiagram.com/java-mx/bitchat-python
- Repository: https://github.com/java-mx/bitchat-python

## Overview

BitChat Python is an asynchronous terminal client for encrypted peer-to-peer chat over BLE and local networks. Users launch the terminal interface, discover peers, establish authenticated Noise sessions, and exchange messages; the mesh router supports multi-hop forwarding. The graph includes protocol encoding and fragmentation, persistent configuration, platform capability detection, and both transport families. Several internal links are based on documented capabilities rather than inspected call sites; those are marked dashed with no evidence path.

Main entry points: [`src/bitchat/app/session_coordinator.py`](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/app/session_coordinator.py) (Session coordinator), [`src/bitchat/tui/app.py`](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/tui/app.py) (Terminal interface), [`src/bitchat/ble/manager.py`](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/ble/manager.py) (BLE discovery and transport), [`src/bitchat/network/transport.py`](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/network/transport.py) (LAN transport)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Terminal client"]
  node_tui["Terminal interface<br/>[app.py]"]
  node_widgets["Chat widgets<br/>[chat_view.py]"]
  node_commands["Command parser<br/>[parser.py]"]
  node_coordinator["Session coordinator"]
  node_application["Application controller<br/>[application.py]"]
end

subgraph group_security["Identity and security"]
  node_identity["Peer identity<br/>[identity.py]"]
  node_noise["Noise handshake<br/>[noise.py]"]
  node_sessions["Secure sessions<br/>[sessions.py]"]
end

subgraph group_protocol["Protocol and mesh"]
  node_packet["Packet model<br/>[packet.py]"]
  node_fragmentation["Packet fragmentation<br/>[fragmentation.py]"]
  node_mesh["Mesh router<br/>[router.py]"]
end

subgraph group_connectivity["Peer connectivity"]
  node_ble["BLE discovery and transport<br/>[manager.py]"]
  node_ble_server["BLE GATT server<br/>[server.py]"]
  node_ble_adapter["BLE platform adapter<br/>[adapter.py]"]
  node_lan["LAN transport<br/>[transport.py]"]
  node_lan_server["LAN connection server<br/>[server.py]"]
end

subgraph group_platform["Platform and state"]
  node_capabilities["Hardware capabilities<br/>[capabilities.py]"]
  node_config[("Configuration storage<br/>[config.py]")]
  node_theme["Terminal themes<br/>[theme.py]"]
end

node_user(("Terminal user"))
node_peer(("Remote peer"))

node_user -->|"uses"| node_tui
node_tui -->|"coordinates sessions"| node_coordinator
node_tui -->|"parses commands"| node_commands
node_tui -->|"renders chat"| node_widgets
node_tui -->|"uses theme"| node_theme
node_application -->|"starts sessions"| node_coordinator
node_application -.->|"dispatches commands"| node_commands
node_application -->|"loads settings"| node_config
node_coordinator -->|"uses identity"| node_identity
node_coordinator -->|"manages sessions"| node_sessions
node_sessions -->|"uses handshake"| node_noise
node_coordinator -.->|"routes packets"| node_mesh
node_coordinator -.->|"selects transport"| node_ble
node_coordinator -.->|"selects transport"| node_lan
node_coordinator -.->|"persists settings"| node_config
node_ble -->|"uses adapter"| node_ble_adapter
node_ble -.->|"coordinates server"| node_ble_server
node_lan -->|"uses server"| node_lan_server
node_capabilities -.->|"detects support"| node_ble_adapter
node_ble -->|"discovers peers"| node_peer
node_lan -->|"discovers peers"| node_peer
node_ble -.->|"transfers packets"| node_packet
node_lan -.->|"transfers packets"| node_packet
node_coordinator -.->|"exchanges messages"| node_packet
node_packet -->|"fragments payloads"| node_fragmentation
node_mesh -->|"relays messages"| node_peer
node_coordinator -->|"sends encrypted chat"| node_peer

click node_tui "https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/tui/app.py"
click node_widgets "https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/tui/widgets/chat_view.py"
click node_commands "https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/commands/parser.py"
click node_coordinator "https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/app/session_coordinator.py"
click node_application "https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/app/application.py"
click node_identity "https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/crypto/identity.py"
click node_noise "https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/crypto/noise.py"
click node_sessions "https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/crypto/sessions.py"
click node_packet "https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/protocol/packet.py"
click node_fragmentation "https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/protocol/fragmentation.py"
click node_mesh "https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/mesh/router.py"
click node_ble "https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/ble/manager.py"
click node_ble_server "https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/ble/server.py"
click node_ble_adapter "https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/ble/adapter.py"
click node_lan "https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/network/transport.py"
click node_lan_server "https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/network/server.py"
click node_capabilities "https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/platform/capabilities.py"
click node_config "https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/storage/config.py"
click node_theme "https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/tui/theme.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_tui,node_widgets,node_commands,node_coordinator,node_application,node_user toneBlue
class node_identity,node_noise,node_sessions toneAmber
class node_packet,node_fragmentation,node_mesh toneMint
class node_ble,node_ble_server,node_ble_adapter,node_lan,node_lan_server toneRose
class node_capabilities,node_config,node_theme,node_peer toneIndigo
```

## Components

### Terminal client

- [Terminal interface](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/tui/app.py): `src/bitchat/tui/app.py`
- [Chat widgets](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/tui/widgets/chat_view.py): `src/bitchat/tui/widgets/chat_view.py`
- [Command parser](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/commands/parser.py): `src/bitchat/commands/parser.py`
- [Session coordinator](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/app/session_coordinator.py): `src/bitchat/app/session_coordinator.py`
- [Application controller](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/app/application.py): `src/bitchat/app/application.py`

### Identity and security

- [Peer identity](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/crypto/identity.py): `src/bitchat/crypto/identity.py`
- [Noise handshake](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/crypto/noise.py): `src/bitchat/crypto/noise.py`
- [Secure sessions](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/crypto/sessions.py): `src/bitchat/crypto/sessions.py`

### Protocol and mesh

- [Packet model](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/protocol/packet.py): `src/bitchat/protocol/packet.py`
- [Packet fragmentation](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/protocol/fragmentation.py): `src/bitchat/protocol/fragmentation.py`
- [Mesh router](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/mesh/router.py): `src/bitchat/mesh/router.py`

### Peer connectivity

- [BLE discovery and transport](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/ble/manager.py): `src/bitchat/ble/manager.py`
- [BLE GATT server](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/ble/server.py): `src/bitchat/ble/server.py`
- [BLE platform adapter](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/ble/adapter.py): `src/bitchat/ble/adapter.py`
- [LAN transport](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/network/transport.py): `src/bitchat/network/transport.py`
- [LAN connection server](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/network/server.py): `src/bitchat/network/server.py`

### Platform and state

- [Hardware capabilities](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/platform/capabilities.py): `src/bitchat/platform/capabilities.py`
- [Configuration storage](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/storage/config.py): `src/bitchat/storage/config.py`
- [Terminal themes](https://github.com/java-mx/bitchat-python/blob/main/src/bitchat/tui/theme.py): `src/bitchat/tui/theme.py`

### Other components

- **Terminal user**
- **Remote peer**

## Connections

- Terminal user → Terminal interface: uses (evidence: `README.md`)
- Terminal interface → Session coordinator: coordinates sessions (evidence: `src/bitchat/tui/app.py`)
- Terminal interface → Command parser: parses commands (evidence: `src/bitchat/tui/app.py`)
- Terminal interface → Chat widgets: renders chat (evidence: `src/bitchat/tui/app.py`)
- Terminal interface → Terminal themes: uses theme (evidence: `src/bitchat/tui/app.py`)
- Application controller → Session coordinator: starts sessions (evidence: `src/bitchat/app/application.py`)
- Application controller → Command parser: dispatches commands (evidence: `src/bitchat/app/application.py`)
- Application controller → Configuration storage: loads settings (evidence: `src/bitchat/app/application.py`)
- Session coordinator → Peer identity: uses identity (evidence: `src/bitchat/app/session_coordinator.py`)
- Session coordinator → Secure sessions: manages sessions (evidence: `src/bitchat/app/session_coordinator.py`)
- Secure sessions → Noise handshake: uses handshake (evidence: `src/bitchat/crypto/sessions.py`)
- Session coordinator → Mesh router: routes packets (evidence: `src/bitchat/app/session_coordinator.py`)
- Session coordinator → BLE discovery and transport: selects transport (evidence: `src/bitchat/app/session_coordinator.py`)
- Session coordinator → LAN transport: selects transport (evidence: `src/bitchat/app/session_coordinator.py`)
- Session coordinator → Configuration storage: persists settings (evidence: `src/bitchat/app/session_coordinator.py`)
- BLE discovery and transport → BLE platform adapter: uses adapter (evidence: `src/bitchat/ble/manager.py`)
- BLE discovery and transport → BLE GATT server: coordinates server
- LAN transport → LAN connection server: uses server (evidence: `src/bitchat/network/transport.py`)
- Hardware capabilities → BLE platform adapter: detects support (evidence: `src/bitchat/ble/adapter.py`)
- BLE discovery and transport → Remote peer: discovers peers (evidence: `README.md`)
- LAN transport → Remote peer: discovers peers (evidence: `README.md`)
- BLE discovery and transport → Packet model: transfers packets (evidence: `src/bitchat/ble/manager.py`)
- LAN transport → Packet model: transfers packets (evidence: `src/bitchat/network/transport.py`)
- Session coordinator → Packet model: exchanges messages (evidence: `src/bitchat/app/session_coordinator.py`)
- Packet model → Packet fragmentation: fragments payloads (evidence: `src/bitchat/protocol/fragmentation.py`)
- Mesh router → Remote peer: relays messages (evidence: `README.md`)
- Session coordinator → Remote peer: sends encrypted chat (evidence: `README.md`)
