# lokesh-gopinath/nightlink architecture

> Architecture diagram of the GitHub repository lokesh-gopinath/nightlink, 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/lokesh-gopinath/nightlink
- Repository: https://github.com/lokesh-gopinath/nightlink

## Overview

NightLink is a Tor-only, encrypted peer-to-peer chat application. The principal workflow is: a user initializes an identity and adds a contact, starts a chat, accepts or rejects incoming requests, then exchanges encrypted messages; group chat fans messages out to members’ peer sessions. The graph includes identity/configuration, Tor transport, chat security, groups, and terminal presentation. Some command-handler and persistence wiring is unsampled, so those links are omitted or marked unverified rather than inferred.

Main entry points: [`src/main.rs`](https://github.com/lokesh-gopinath/nightlink/blob/main/src/main.rs) (Command shell), [`src/chat.rs`](https://github.com/lokesh-gopinath/nightlink/blob/main/src/chat.rs) (Peer chat protocol), [`src/types.rs`](https://github.com/lokesh-gopinath/nightlink/blob/main/src/types.rs) (Runtime state), [`src/config.rs`](https://github.com/lokesh-gopinath/nightlink/blob/main/src/config.rs) (Config and contacts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_shell["CLI and state"]
  node_shell["Command shell<br/>[main.rs]"]
  node_state["Runtime state<br/>[types.rs]"]
  node_theme["Terminal themes<br/>[theme.rs]"]
end

subgraph group_identity["Identity and config"]
  node_config[("Config and contacts<br/>[config.rs]")]
  node_crypto["Identity and encryption<br/>[crypto.rs]"]
end

subgraph group_transport["Tor transport"]
  node_tor["Tor bootstrap<br/>[tor.rs]"]
  node_socks["SOCKS connections<br/>[tor.rs]"]
end

subgraph group_messaging["Chat and security"]
  node_chat["Peer chat protocol<br/>[chat.rs]"]
end

subgraph group_groups["Group chat"]
  node_groups["Group model<br/>[group.rs]"]
end

node_user(("Terminal user"))
node_tor_daemon["Tor daemon"]
node_peer(("Remote peer"))

node_user -->|"enters commands"| node_shell
node_shell -->|"starts listener"| node_chat
node_shell -->|"requests connection"| node_chat
node_shell -->|"uses runtime state"| node_state
node_shell -.->|"manages contacts"| node_config
node_shell -.->|"manages groups"| node_groups
node_shell -.->|"renders prompts"| node_theme
node_config -->|"creates identity"| node_crypto
node_config -->|"uses data types"| node_state
node_chat -->|"secures sessions"| node_crypto
node_chat -->|"opens Tor links"| node_socks
node_chat -->|"frames group messages"| node_groups
node_chat -->|"tracks sessions"| node_state
node_tor -->|"starts daemon"| node_tor_daemon
node_socks -->|"uses proxy"| node_tor_daemon
node_peer -.->|"exchanges messages"| node_chat
node_groups -->|"uses shared types"| node_state

click node_shell "https://github.com/lokesh-gopinath/nightlink/blob/main/src/main.rs"
click node_state "https://github.com/lokesh-gopinath/nightlink/blob/main/src/types.rs"
click node_theme "https://github.com/lokesh-gopinath/nightlink/blob/main/src/theme.rs"
click node_config "https://github.com/lokesh-gopinath/nightlink/blob/main/src/config.rs"
click node_crypto "https://github.com/lokesh-gopinath/nightlink/blob/main/src/crypto.rs"
click node_tor "https://github.com/lokesh-gopinath/nightlink/blob/main/src/tor.rs"
click node_socks "https://github.com/lokesh-gopinath/nightlink/blob/main/src/tor.rs"
click node_chat "https://github.com/lokesh-gopinath/nightlink/blob/main/src/chat.rs"
click node_groups "https://github.com/lokesh-gopinath/nightlink/blob/main/src/group.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_shell,node_state,node_theme,node_user toneBlue
class node_config,node_crypto toneAmber
class node_tor,node_socks toneMint
class node_chat toneRose
class node_groups,node_tor_daemon,node_peer toneIndigo
```

## Components

### CLI and state

- [Command shell](https://github.com/lokesh-gopinath/nightlink/blob/main/src/main.rs): `src/main.rs`
- [Runtime state](https://github.com/lokesh-gopinath/nightlink/blob/main/src/types.rs): `src/types.rs`
- [Terminal themes](https://github.com/lokesh-gopinath/nightlink/blob/main/src/theme.rs): `src/theme.rs`

### Identity and config

- [Config and contacts](https://github.com/lokesh-gopinath/nightlink/blob/main/src/config.rs): `src/config.rs`
- [Identity and encryption](https://github.com/lokesh-gopinath/nightlink/blob/main/src/crypto.rs): `src/crypto.rs`

### Tor transport

- [Tor bootstrap](https://github.com/lokesh-gopinath/nightlink/blob/main/src/tor.rs): `src/tor.rs`
- [SOCKS connections](https://github.com/lokesh-gopinath/nightlink/blob/main/src/tor.rs): `src/tor.rs`

### Chat and security

- [Peer chat protocol](https://github.com/lokesh-gopinath/nightlink/blob/main/src/chat.rs): `src/chat.rs`

### Group chat

- [Group model](https://github.com/lokesh-gopinath/nightlink/blob/main/src/group.rs): `src/group.rs`

### Other components

- **Terminal user**
- **Tor daemon**
- **Remote peer**

## Connections

- Terminal user → Command shell: enters commands (evidence: `README.md`)
- Command shell → Peer chat protocol: starts listener (evidence: `src/main.rs`)
- Command shell → Peer chat protocol: requests connection (evidence: `src/main.rs`)
- Command shell → Runtime state: uses runtime state (evidence: `src/main.rs`)
- Command shell → Config and contacts: manages contacts (evidence: `src/main.rs`)
- Command shell → Group model: manages groups (evidence: `src/main.rs`)
- Command shell → Terminal themes: renders prompts (evidence: `src/main.rs`)
- Config and contacts → Identity and encryption: creates identity (evidence: `src/config.rs`)
- Config and contacts → Runtime state: uses data types (evidence: `src/config.rs`)
- Peer chat protocol → Identity and encryption: secures sessions (evidence: `src/chat.rs`)
- Peer chat protocol → SOCKS connections: opens Tor links (evidence: `src/chat.rs`)
- Peer chat protocol → Group model: frames group messages (evidence: `src/chat.rs`)
- Peer chat protocol → Runtime state: tracks sessions (evidence: `src/chat.rs`)
- Tor bootstrap → Tor daemon: starts daemon (evidence: `src/tor.rs`)
- SOCKS connections → Tor daemon: uses proxy (evidence: `src/tor.rs`)
- Remote peer → Peer chat protocol: exchanges messages
- Group model → Runtime state: uses shared types (evidence: `src/group.rs`)
