# admirschwab/nexo architecture

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

- Interactive diagram: https://gitdiagram.com/admirschwab/nexo
- Repository: https://github.com/admirschwab/nexo

## Overview

Nexo is a terminal-based encrypted messenger. Its main workflow is register an identity, persist it encrypted, authenticate to a relay server, then use the terminal interface to discover online peers and exchange encrypted messages. Separate command paths support login, reconnect, password changes, server-address changes, and unregistering. The graph includes identity-file handling and the chat security layers. Some lifecycle calls and UI details are unsampled; those links are included only where the excerpts, source index, or README document them.

Main entry points: [`src/main.rs`](https://github.com/admirschwab/nexo/blob/main/src/main.rs) (Command dispatcher), [`src/overlay/mod.rs`](https://github.com/admirschwab/nexo/blob/main/src/overlay/mod.rs) (Overlay event loop), [`src/functions/connect.rs`](https://github.com/admirschwab/nexo/blob/main/src/functions/connect.rs) (Authenticate connection), [`src/overlay/app.rs`](https://github.com/admirschwab/nexo/blob/main/src/overlay/app.rs) (Chat application state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_commands["Commands and identity"]
  node_cli["Command dispatcher<br/>[main.rs]"]
  node_create_identity["Create identity<br/>[create_identity.rs]"]
  node_register_identity["Register identity"]
  node_unregister_identity["Unregister identity"]
  node_validate_nickname["Nickname validation"]
end

subgraph group_connection["Server connection"]
  node_connect["Authenticate connection<br/>[connect.rs]"]
  node_protocol["Wire protocol<br/>[protocol.rs]"]
end

subgraph group_interface["Terminal interface"]
  node_overlay_loop["Overlay event loop<br/>[mod.rs]"]
  node_app["Chat application state<br/>[app.rs]"]
  node_render["Terminal rendering<br/>[render.rs]"]
end

subgraph group_messaging["Encrypted messaging"]
  node_session["Chat sessions<br/>[session.rs]"]
  node_crypto["Crypto primitives<br/>[crypto.rs]"]
  node_peer_message["Peer messages<br/>[peer_message.rs]"]
end

subgraph group_identity_data["Identity data"]
  node_paths["Identity paths<br/>[paths.rs]"]
  node_config["Server config<br/>[config.rs]"]
  node_identity["Unlocked identity<br/>[identity.rs]"]
  node_encrypted_identity["Encrypted identity format"]
  node_derive_key["File key derivation<br/>[derive_file_key.rs]"]
  node_encrypt_identity["Encrypt identity"]
  node_decrypt_identity["Decrypt identity"]
  node_load_identity["Load identity file<br/>[load_identity.rs]"]
  node_save_identity["Save identity file<br/>[save_identity.rs]"]
end

node_user(("User"))
node_server{{"Nexo relay server"}}

node_user -->|"runs commands"| node_cli
node_cli -->|"initializes paths"| node_paths
node_cli -->|"creates identity"| node_create_identity
node_cli -->|"registers identity"| node_register_identity
node_cli -->|"saves identity"| node_save_identity
node_cli -->|"logs in"| node_connect
node_cli -->|"unregisters identity"| node_unregister_identity
node_cli -->|"rewrites identity"| node_encrypt_identity
node_cli -->|"unlocks identity"| node_decrypt_identity
node_cli -->|"validates nickname"| node_validate_nickname
node_create_identity -->|"creates"| node_identity
node_create_identity -->|"encrypts"| node_encrypt_identity
node_register_identity -->|"sends registration"| node_protocol
node_register_identity -->|"registers with"| node_server
node_unregister_identity -->|"sends removal"| node_protocol
node_unregister_identity -->|"removes identity"| node_server
node_connect -->|"reads address"| node_config
node_connect -->|"exchanges messages"| node_protocol
node_connect -->|"authenticates to"| node_server
node_overlay_loop -->|"reconnects through"| node_connect
node_overlay_loop -->|"dispatches events"| node_app
node_overlay_loop -->|"renders via"| node_render
node_overlay_loop -->|"decodes server messages"| node_protocol
node_overlay_loop -->|"exchanges websocket data"| node_server
node_app -->|"manages sessions"| node_session
node_app -->|"handles server messages"| node_protocol
node_app -->|"queues peer payloads"| node_peer_message
node_render -->|"renders state"| node_app
node_session -->|"uses primitives"| node_crypto
node_session -->|"builds messages"| node_peer_message
node_encrypt_identity -->|"derives key"| node_derive_key
node_decrypt_identity -->|"derives key"| node_derive_key
node_encrypt_identity -->|"encodes format"| node_encrypted_identity
node_decrypt_identity -->|"decodes format"| node_encrypted_identity
node_load_identity -->|"parses file"| node_encrypted_identity
node_save_identity -->|"serializes file"| node_encrypted_identity
node_decrypt_identity -->|"returns identity"| node_identity

click node_cli "https://github.com/admirschwab/nexo/blob/main/src/main.rs"
click node_paths "https://github.com/admirschwab/nexo/blob/main/src/paths.rs"
click node_config "https://github.com/admirschwab/nexo/blob/main/src/config.rs"
click node_create_identity "https://github.com/admirschwab/nexo/blob/main/src/functions/create_identity.rs"
click node_register_identity "https://github.com/admirschwab/nexo/blob/main/src/functions/register_identity.rs"
click node_unregister_identity "https://github.com/admirschwab/nexo/blob/main/src/functions/unregister_identity.rs"
click node_validate_nickname "https://github.com/admirschwab/nexo/blob/main/src/functions/validate_nickname.rs"
click node_connect "https://github.com/admirschwab/nexo/blob/main/src/functions/connect.rs"
click node_protocol "https://github.com/admirschwab/nexo/blob/main/src/models/protocol.rs"
click node_overlay_loop "https://github.com/admirschwab/nexo/blob/main/src/overlay/mod.rs"
click node_app "https://github.com/admirschwab/nexo/blob/main/src/overlay/app.rs"
click node_render "https://github.com/admirschwab/nexo/blob/main/src/overlay/render.rs"
click node_session "https://github.com/admirschwab/nexo/blob/main/src/chat/session.rs"
click node_crypto "https://github.com/admirschwab/nexo/blob/main/src/chat/crypto.rs"
click node_peer_message "https://github.com/admirschwab/nexo/blob/main/src/models/peer_message.rs"
click node_identity "https://github.com/admirschwab/nexo/blob/main/src/models/identity.rs"
click node_encrypted_identity "https://github.com/admirschwab/nexo/blob/main/src/models/encrypted_identity.rs"
click node_derive_key "https://github.com/admirschwab/nexo/blob/main/src/functions/derive_file_key.rs"
click node_encrypt_identity "https://github.com/admirschwab/nexo/blob/main/src/functions/encrypt_identity.rs"
click node_decrypt_identity "https://github.com/admirschwab/nexo/blob/main/src/functions/decrypt_identity.rs"
click node_load_identity "https://github.com/admirschwab/nexo/blob/main/src/functions/load_identity.rs"
click node_save_identity "https://github.com/admirschwab/nexo/blob/main/src/functions/save_identity.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_cli,node_create_identity,node_register_identity,node_unregister_identity,node_validate_nickname,node_user toneBlue
class node_connect,node_protocol toneAmber
class node_overlay_loop,node_app,node_render,node_server toneMint
class node_session,node_crypto,node_peer_message toneRose
class node_paths,node_config,node_identity,node_encrypted_identity,node_derive_key,node_encrypt_identity,node_decrypt_identity,node_load_identity,node_save_identity toneIndigo
```

## Components

### Commands and identity

- [Command dispatcher](https://github.com/admirschwab/nexo/blob/main/src/main.rs): `src/main.rs`
- [Create identity](https://github.com/admirschwab/nexo/blob/main/src/functions/create_identity.rs): `src/functions/create_identity.rs`
- [Register identity](https://github.com/admirschwab/nexo/blob/main/src/functions/register_identity.rs): `src/functions/register_identity.rs`
- [Unregister identity](https://github.com/admirschwab/nexo/blob/main/src/functions/unregister_identity.rs): `src/functions/unregister_identity.rs`
- [Nickname validation](https://github.com/admirschwab/nexo/blob/main/src/functions/validate_nickname.rs): `src/functions/validate_nickname.rs`

### Server connection

- [Authenticate connection](https://github.com/admirschwab/nexo/blob/main/src/functions/connect.rs): `src/functions/connect.rs`
- [Wire protocol](https://github.com/admirschwab/nexo/blob/main/src/models/protocol.rs): `src/models/protocol.rs`

### Terminal interface

- [Overlay event loop](https://github.com/admirschwab/nexo/blob/main/src/overlay/mod.rs): `src/overlay/mod.rs`
- [Chat application state](https://github.com/admirschwab/nexo/blob/main/src/overlay/app.rs): `src/overlay/app.rs`
- [Terminal rendering](https://github.com/admirschwab/nexo/blob/main/src/overlay/render.rs): `src/overlay/render.rs`

### Encrypted messaging

- [Chat sessions](https://github.com/admirschwab/nexo/blob/main/src/chat/session.rs): `src/chat/session.rs`
- [Crypto primitives](https://github.com/admirschwab/nexo/blob/main/src/chat/crypto.rs): `src/chat/crypto.rs`
- [Peer messages](https://github.com/admirschwab/nexo/blob/main/src/models/peer_message.rs): `src/models/peer_message.rs`

### Identity data

- [Identity paths](https://github.com/admirschwab/nexo/blob/main/src/paths.rs): `src/paths.rs`
- [Server config](https://github.com/admirschwab/nexo/blob/main/src/config.rs): `src/config.rs`
- [Unlocked identity](https://github.com/admirschwab/nexo/blob/main/src/models/identity.rs): `src/models/identity.rs`
- [Encrypted identity format](https://github.com/admirschwab/nexo/blob/main/src/models/encrypted_identity.rs): `src/models/encrypted_identity.rs`
- [File key derivation](https://github.com/admirschwab/nexo/blob/main/src/functions/derive_file_key.rs): `src/functions/derive_file_key.rs`
- [Encrypt identity](https://github.com/admirschwab/nexo/blob/main/src/functions/encrypt_identity.rs): `src/functions/encrypt_identity.rs`
- [Decrypt identity](https://github.com/admirschwab/nexo/blob/main/src/functions/decrypt_identity.rs): `src/functions/decrypt_identity.rs`
- [Load identity file](https://github.com/admirschwab/nexo/blob/main/src/functions/load_identity.rs): `src/functions/load_identity.rs`
- [Save identity file](https://github.com/admirschwab/nexo/blob/main/src/functions/save_identity.rs): `src/functions/save_identity.rs`

### Other components

- **User**
- **Nexo relay server**

## Connections

- User → Command dispatcher: runs commands (evidence: `README.md`)
- Command dispatcher → Identity paths: initializes paths (evidence: `src/main.rs`)
- Command dispatcher → Create identity: creates identity (evidence: `src/main.rs`)
- Command dispatcher → Register identity: registers identity (evidence: `src/main.rs`)
- Command dispatcher → Save identity file: saves identity (evidence: `src/main.rs`)
- Command dispatcher → Authenticate connection: logs in (evidence: `src/main.rs`)
- Command dispatcher → Unregister identity: unregisters identity (evidence: `README.md`)
- Command dispatcher → Encrypt identity: rewrites identity (evidence: `src/main.rs`)
- Command dispatcher → Decrypt identity: unlocks identity (evidence: `src/main.rs`)
- Command dispatcher → Nickname validation: validates nickname (evidence: `README.md`)
- Create identity → Unlocked identity: creates (evidence: `src/functions/create_identity.rs`)
- Create identity → Encrypt identity: encrypts (evidence: `src/functions/create_identity.rs`)
- Register identity → Wire protocol: sends registration (evidence: `src/functions/register_identity.rs`)
- Register identity → Nexo relay server: registers with (evidence: `README.md`)
- Unregister identity → Wire protocol: sends removal (evidence: `src/functions/unregister_identity.rs`)
- Unregister identity → Nexo relay server: removes identity (evidence: `README.md`)
- Authenticate connection → Server config: reads address (evidence: `src/functions/connect.rs`)
- Authenticate connection → Wire protocol: exchanges messages (evidence: `src/functions/connect.rs`)
- Authenticate connection → Nexo relay server: authenticates to (evidence: `src/functions/connect.rs`)
- Overlay event loop → Authenticate connection: reconnects through (evidence: `src/overlay/mod.rs`)
- Overlay event loop → Chat application state: dispatches events (evidence: `src/overlay/mod.rs`)
- Overlay event loop → Terminal rendering: renders via (evidence: `src/overlay/mod.rs`)
- Overlay event loop → Wire protocol: decodes server messages (evidence: `src/overlay/mod.rs`)
- Overlay event loop → Nexo relay server: exchanges websocket data (evidence: `src/overlay/mod.rs`)
- Chat application state → Chat sessions: manages sessions (evidence: `src/overlay/app.rs`)
- Chat application state → Wire protocol: handles server messages (evidence: `src/overlay/app.rs`)
- Chat application state → Peer messages: queues peer payloads (evidence: `src/overlay/app.rs`)
- Terminal rendering → Chat application state: renders state (evidence: `src/overlay/render.rs`)
- Chat sessions → Crypto primitives: uses primitives (evidence: `src/chat/session.rs`)
- Chat sessions → Peer messages: builds messages (evidence: `src/chat/session.rs`)
- Encrypt identity → File key derivation: derives key (evidence: `src/functions/encrypt_identity.rs`)
- Decrypt identity → File key derivation: derives key (evidence: `src/functions/decrypt_identity.rs`)
- Encrypt identity → Encrypted identity format: encodes format (evidence: `src/functions/encrypt_identity.rs`)
- Decrypt identity → Encrypted identity format: decodes format (evidence: `src/functions/decrypt_identity.rs`)
- Load identity file → Encrypted identity format: parses file (evidence: `src/functions/load_identity.rs`)
- Save identity file → Encrypted identity format: serializes file (evidence: `src/functions/save_identity.rs`)
- Decrypt identity → Unlocked identity: returns identity (evidence: `src/functions/decrypt_identity.rs`)
