# asknkitkr/phantom-messenger architecture

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

- Interactive diagram: https://gitdiagram.com/asknkitkr/phantom-messenger
- Repository: https://github.com/asknkitkr/phantom-messenger

## Overview

Phantom Messenger is an offline, terminal-based messenger for exchanging encrypted text with nearby peers over BLE. The main workflow starts in the CLI, opens the UI, establishes or selects a contact, encrypts and frames messages, sends them over BLE, then verifies and stores received messages and acknowledgements. The product also includes store-and-forward relaying, encrypted profile backups, expiry and blocking controls, and a loopback simulator. README descriptions establish several subsystem links; unsampled UI and mesh internals limit finer-grained call tracing.

Main entry points: [`src/messenger/ui/app.py`](https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/ui/app.py) (Terminal chat and controls), [`src/messenger/__main__.py`](https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/__main__.py) (CLI entry), [`src/messenger/transport/peripheral.py`](https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/transport/peripheral.py) (BLE central and peripheral), [`src/messenger/storage/database.py`](https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/storage/database.py) (Encrypted profile database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application"]
  node_entry["CLI entry<br/>[__main__.py]"]
  node_ui["Terminal chat and controls<br/>[app.py]"]
  node_config["Platform configuration<br/>[config.py]"]
  node_simulator["Loopback simulator<br/>[simulator.py]"]
end

subgraph group_crypto["Identity and cryptography"]
  node_keys["Identity and key exchange<br/>[keys.py]"]
  node_encryption["Message encryption<br/>[encryption.py]"]
end

subgraph group_transport["BLE and relaying"]
  node_protocol["Message framing<br/>[protocol.py]"]
  node_ble["BLE central and peripheral<br/>[peripheral.py]"]
  node_mesh["Store-forward relay<br/>[mesh.py]"]
end

subgraph group_storage["Encrypted local data"]
  node_database[("Encrypted profile database<br/>[database.py]")]
  node_models["Contacts and messages<br/>[models.py]"]
  node_backup["Encrypted backup<br/>[backup.py]"]
end

node_user(("Messenger user"))
node_peer(("Nearby peer"))

node_user -->|"launches"| node_entry
node_entry -->|"starts"| node_ui
node_entry -->|"creates"| node_keys
node_entry -->|"creates"| node_database
node_entry -->|"selects transport"| node_ble
node_ui -->|"manages identity"| node_keys
node_ui -->|"reads and writes"| node_database
node_ui -->|"encrypts messages"| node_encryption
node_ui -->|"frames messages"| node_protocol
node_ui -->|"exchanges packets"| node_ble
node_ui -->|"forwards queued relays"| node_mesh
node_ui -->|"backs up profiles"| node_backup
node_keys -->|"exchanges public keys"| node_peer
node_keys -->|"derives shared secret"| node_encryption
node_encryption -->|"sends signed ciphertext"| node_peer
node_ble -->|"transfers over BLE"| node_peer
node_protocol -->|"frames for transport"| node_ble
node_database -->|"persists"| node_models
node_ui -->|"displays conversations"| node_models
node_simulator -->|"uses loopback transport"| node_ble
node_simulator -->|"chunks messages"| node_protocol
node_simulator -->|"stores profiles"| node_database
node_config -.->|"configures paths"| node_database

click node_entry "https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/__main__.py"
click node_ui "https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/ui/app.py"
click node_config "https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/config.py"
click node_keys "https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/crypto/keys.py"
click node_encryption "https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/crypto/encryption.py"
click node_protocol "https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/transport/protocol.py"
click node_ble "https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/transport/peripheral.py"
click node_mesh "https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/transport/mesh.py"
click node_database "https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/storage/database.py"
click node_models "https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/storage/models.py"
click node_backup "https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/storage/backup.py"
click node_simulator "https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/simulator.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_entry,node_ui,node_config,node_simulator,node_user toneBlue
class node_keys,node_encryption toneAmber
class node_protocol,node_ble,node_mesh toneMint
class node_database,node_models,node_backup toneRose
class node_peer toneIndigo
```

## Components

### Application

- [CLI entry](https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/__main__.py): `src/messenger/__main__.py`
- [Terminal chat and controls](https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/ui/app.py): `src/messenger/ui/app.py`
- [Platform configuration](https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/config.py): `src/messenger/config.py`
- [Loopback simulator](https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/simulator.py): `src/messenger/simulator.py`

### Identity and cryptography

- [Identity and key exchange](https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/crypto/keys.py): `src/messenger/crypto/keys.py`
- [Message encryption](https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/crypto/encryption.py): `src/messenger/crypto/encryption.py`

### BLE and relaying

- [Message framing](https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/transport/protocol.py): `src/messenger/transport/protocol.py`
- [BLE central and peripheral](https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/transport/peripheral.py): `src/messenger/transport/peripheral.py`
- [Store-forward relay](https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/transport/mesh.py): `src/messenger/transport/mesh.py`

### Encrypted local data

- [Encrypted profile database](https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/storage/database.py): `src/messenger/storage/database.py`
- [Contacts and messages](https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/storage/models.py): `src/messenger/storage/models.py`
- [Encrypted backup](https://github.com/asknkitkr/phantom-messenger/blob/main/src/messenger/storage/backup.py): `src/messenger/storage/backup.py`

### Other components

- **Messenger user**
- **Nearby peer**

## Connections

- Messenger user → CLI entry: launches (evidence: `README.md`)
- CLI entry → Terminal chat and controls: starts (evidence: `src/messenger/__main__.py`)
- CLI entry → Identity and key exchange: creates (evidence: `src/messenger/__main__.py`)
- CLI entry → Encrypted profile database: creates (evidence: `src/messenger/__main__.py`)
- CLI entry → BLE central and peripheral: selects transport (evidence: `src/messenger/__main__.py`)
- Terminal chat and controls → Identity and key exchange: manages identity (evidence: `README.md`)
- Terminal chat and controls → Encrypted profile database: reads and writes (evidence: `README.md`)
- Terminal chat and controls → Message encryption: encrypts messages (evidence: `README.md`)
- Terminal chat and controls → Message framing: frames messages (evidence: `src/messenger/ui/app.py`)
- Terminal chat and controls → BLE central and peripheral: exchanges packets (evidence: `README.md`)
- Terminal chat and controls → Store-forward relay: forwards queued relays (evidence: `src/messenger/ui/app.py`)
- Terminal chat and controls → Encrypted backup: backs up profiles (evidence: `README.md`)
- Identity and key exchange → Nearby peer: exchanges public keys (evidence: `README.md`)
- Identity and key exchange → Message encryption: derives shared secret (evidence: `README.md`)
- Message encryption → Nearby peer: sends signed ciphertext (evidence: `README.md`)
- BLE central and peripheral → Nearby peer: transfers over BLE (evidence: `README.md`)
- Message framing → BLE central and peripheral: frames for transport (evidence: `README.md`)
- Encrypted profile database → Contacts and messages: persists (evidence: `src/messenger/storage/database.py`)
- Terminal chat and controls → Contacts and messages: displays conversations (evidence: `README.md`)
- Loopback simulator → BLE central and peripheral: uses loopback transport (evidence: `src/messenger/simulator.py`)
- Loopback simulator → Message framing: chunks messages (evidence: `src/messenger/simulator.py`)
- Loopback simulator → Encrypted profile database: stores profiles (evidence: `src/messenger/simulator.py`)
- Platform configuration → Encrypted profile database: configures paths (evidence: `src/messenger/storage/database.py`)
