# mymirai-nikki/tor architecture

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

- Interactive diagram: https://gitdiagram.com/mymirai-nikki/tor
- Repository: https://github.com/mymirai-nikki/tor

## Overview

Tor is privacy software that routes users’ connections through a volunteer relay network, obscuring the link between their addresses and destinations. A client accepts proxy traffic, obtains network-directory information, selects relays, and builds circuits; relays forward traffic, while onion-service code supports private services. Configuration and the event loop provide an internal runtime layer, and the Control interface exposes management and events. The tree and README establish the product; edges are limited to relationships visible in the README or sampled source index, so unsampled integrations are not inferred.

Main entry points: [`src/core/or/circuitbuild.c`](https://github.com/mymirai-nikki/tor/blob/main/src/core/or/circuitbuild.c) (Circuit building), [`src/feature/nodelist/routerlist.c`](https://github.com/mymirai-nikki/tor/blob/main/src/feature/nodelist/routerlist.c) (Router descriptors), [`src/feature/dirclient/dirclient.c`](https://github.com/mymirai-nikki/tor/blob/main/src/feature/dirclient/dirclient.c) (Directory downloads), [`src/app/main/main.c`](https://github.com/mymirai-nikki/tor/blob/main/src/app/main/main.c) (Tor startup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime and config"]
  node_config["Configuration<br/>[config.c]"]
  node_main["Tor startup<br/>[main.c]"]
  node_eventloop["Event loop<br/>[mainloop.c]"]
  node_connections["Connection handling<br/>[connection.c]"]
end

subgraph group_client["Client access"]
  node_proxy["Proxy protocols<br/>[proxymode.c]"]
  node_edge["Client streams<br/>[connection_edge.c]"]
  node_guards["Entry selection<br/>[entrynodes.c]"]
end

subgraph group_network["Network directory"]
  node_directory_client["Directory downloads<br/>[dirclient.c]"]
  node_directory_server["Directory service<br/>[dirserv.c]"]
  node_routerparse["Descriptor parsing<br/>[routerparse.c]"]
  node_routerlist[("Router descriptors<br/>[routerlist.c]")]
  node_networkstatus[("Network consensus<br/>[networkstatus.c]")]
  node_nodelist[("Relay selection data<br/>[nodelist.c]")]
end

subgraph group_transport["Circuits and relays"]
  node_circuits["Circuit building<br/>[circuitbuild.c]"]
  node_circuitlist[("Circuit state<br/>[circuitlist.c]")]
  node_channels["Relay channels<br/>[channel.c]"]
  node_relay["Relay forwarding<br/>[relay.c]"]
  node_congestion["Congestion control"]
end

subgraph group_services["Onion services and control"]
  node_hsclient["Onion-service client<br/>[hs_client.c]"]
  node_hsservice["Onion-service host<br/>[hs_service.c]"]
  node_control["Control interface<br/>[control.c]"]
  node_control_events["Control events<br/>[control_events.c]"]
end

node_user(("Internet user"))

node_user -.->|"opens proxy"| node_proxy
node_main -->|"loads options"| node_config
node_main -->|"starts loop"| node_eventloop
node_main -->|"manages connections"| node_connections
node_proxy -.->|"accepts streams"| node_edge
node_edge -->|"attaches streams"| node_circuits
node_directory_client -->|"uses router data"| node_routerlist
node_routerparse -->|"adds descriptors"| node_routerlist
node_routerlist -->|"requests downloads"| node_directory_client
node_routerlist -->|"shares directory service"| node_directory_server
node_hsclient -->|"fetches descriptors"| node_directory_client
node_hsclient -->|"builds service circuits"| node_circuits
node_hsservice -->|"publishes descriptors"| node_directory_client
node_hsservice -->|"builds service circuits"| node_circuits
node_circuits -.->|"tracks circuits"| node_circuitlist
node_circuits -.->|"uses channels"| node_channels
node_relay -.->|"forwards cells"| node_channels
node_control -.->|"emits events"| node_control_events
node_networkstatus -.->|"updates relay data"| node_nodelist
node_circuits -.->|"applies congestion control"| node_congestion
node_guards -.->|"selects entry"| node_circuits

click node_config "https://github.com/mymirai-nikki/tor/blob/main/src/app/config/config.c"
click node_main "https://github.com/mymirai-nikki/tor/blob/main/src/app/main/main.c"
click node_eventloop "https://github.com/mymirai-nikki/tor/blob/main/src/core/mainloop/mainloop.c"
click node_connections "https://github.com/mymirai-nikki/tor/blob/main/src/core/mainloop/connection.c"
click node_proxy "https://github.com/mymirai-nikki/tor/blob/main/src/feature/client/proxymode.c"
click node_edge "https://github.com/mymirai-nikki/tor/blob/main/src/core/or/connection_edge.c"
click node_guards "https://github.com/mymirai-nikki/tor/blob/main/src/feature/client/entrynodes.c"
click node_directory_client "https://github.com/mymirai-nikki/tor/blob/main/src/feature/dirclient/dirclient.c"
click node_directory_server "https://github.com/mymirai-nikki/tor/blob/main/src/feature/dircache/dirserv.c"
click node_routerparse "https://github.com/mymirai-nikki/tor/blob/main/src/feature/dirparse/routerparse.c"
click node_routerlist "https://github.com/mymirai-nikki/tor/blob/main/src/feature/nodelist/routerlist.c"
click node_networkstatus "https://github.com/mymirai-nikki/tor/blob/main/src/feature/nodelist/networkstatus.c"
click node_nodelist "https://github.com/mymirai-nikki/tor/blob/main/src/feature/nodelist/nodelist.c"
click node_circuits "https://github.com/mymirai-nikki/tor/blob/main/src/core/or/circuitbuild.c"
click node_circuitlist "https://github.com/mymirai-nikki/tor/blob/main/src/core/or/circuitlist.c"
click node_channels "https://github.com/mymirai-nikki/tor/blob/main/src/core/or/channel.c"
click node_relay "https://github.com/mymirai-nikki/tor/blob/main/src/core/or/relay.c"
click node_congestion "https://github.com/mymirai-nikki/tor/blob/main/src/core/or/congestion_control_common.c"
click node_hsclient "https://github.com/mymirai-nikki/tor/blob/main/src/feature/hs/hs_client.c"
click node_hsservice "https://github.com/mymirai-nikki/tor/blob/main/src/feature/hs/hs_service.c"
click node_control "https://github.com/mymirai-nikki/tor/blob/main/src/feature/control/control.c"
click node_control_events "https://github.com/mymirai-nikki/tor/blob/main/src/feature/control/control_events.c"

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_config,node_main,node_eventloop,node_connections,node_user toneBlue
class node_proxy,node_edge,node_guards toneAmber
class node_directory_client,node_directory_server,node_routerparse,node_routerlist,node_networkstatus,node_nodelist toneMint
class node_circuits,node_circuitlist,node_channels,node_relay,node_congestion toneRose
class node_hsclient,node_hsservice,node_control,node_control_events toneIndigo
```

## Components

### Runtime and config

- [Configuration](https://github.com/mymirai-nikki/tor/blob/main/src/app/config/config.c): `src/app/config/config.c`
- [Tor startup](https://github.com/mymirai-nikki/tor/blob/main/src/app/main/main.c): `src/app/main/main.c`
- [Event loop](https://github.com/mymirai-nikki/tor/blob/main/src/core/mainloop/mainloop.c): `src/core/mainloop/mainloop.c`
- [Connection handling](https://github.com/mymirai-nikki/tor/blob/main/src/core/mainloop/connection.c): `src/core/mainloop/connection.c`

### Client access

- [Proxy protocols](https://github.com/mymirai-nikki/tor/blob/main/src/feature/client/proxymode.c): `src/feature/client/proxymode.c`
- [Client streams](https://github.com/mymirai-nikki/tor/blob/main/src/core/or/connection_edge.c): `src/core/or/connection_edge.c`
- [Entry selection](https://github.com/mymirai-nikki/tor/blob/main/src/feature/client/entrynodes.c): `src/feature/client/entrynodes.c`

### Network directory

- [Directory downloads](https://github.com/mymirai-nikki/tor/blob/main/src/feature/dirclient/dirclient.c): `src/feature/dirclient/dirclient.c`
- [Directory service](https://github.com/mymirai-nikki/tor/blob/main/src/feature/dircache/dirserv.c): `src/feature/dircache/dirserv.c`
- [Descriptor parsing](https://github.com/mymirai-nikki/tor/blob/main/src/feature/dirparse/routerparse.c): `src/feature/dirparse/routerparse.c`
- [Router descriptors](https://github.com/mymirai-nikki/tor/blob/main/src/feature/nodelist/routerlist.c): `src/feature/nodelist/routerlist.c`
- [Network consensus](https://github.com/mymirai-nikki/tor/blob/main/src/feature/nodelist/networkstatus.c): `src/feature/nodelist/networkstatus.c`
- [Relay selection data](https://github.com/mymirai-nikki/tor/blob/main/src/feature/nodelist/nodelist.c): `src/feature/nodelist/nodelist.c`

### Circuits and relays

- [Circuit building](https://github.com/mymirai-nikki/tor/blob/main/src/core/or/circuitbuild.c): `src/core/or/circuitbuild.c`
- [Circuit state](https://github.com/mymirai-nikki/tor/blob/main/src/core/or/circuitlist.c): `src/core/or/circuitlist.c`
- [Relay channels](https://github.com/mymirai-nikki/tor/blob/main/src/core/or/channel.c): `src/core/or/channel.c`
- [Relay forwarding](https://github.com/mymirai-nikki/tor/blob/main/src/core/or/relay.c): `src/core/or/relay.c`
- [Congestion control](https://github.com/mymirai-nikki/tor/blob/main/src/core/or/congestion_control_common.c): `src/core/or/congestion_control_common.c`

### Onion services and control

- [Onion-service client](https://github.com/mymirai-nikki/tor/blob/main/src/feature/hs/hs_client.c): `src/feature/hs/hs_client.c`
- [Onion-service host](https://github.com/mymirai-nikki/tor/blob/main/src/feature/hs/hs_service.c): `src/feature/hs/hs_service.c`
- [Control interface](https://github.com/mymirai-nikki/tor/blob/main/src/feature/control/control.c): `src/feature/control/control.c`
- [Control events](https://github.com/mymirai-nikki/tor/blob/main/src/feature/control/control_events.c): `src/feature/control/control_events.c`

### Other components

- **Internet user**

## Connections

- Internet user → Proxy protocols: opens proxy
- Tor startup → Configuration: loads options (evidence: `src/app/main/main.c`)
- Tor startup → Event loop: starts loop (evidence: `src/app/main/main.c`)
- Tor startup → Connection handling: manages connections (evidence: `src/app/main/main.c`)
- Proxy protocols → Client streams: accepts streams
- Client streams → Circuit building: attaches streams (evidence: `src/core/or/connection_edge.c`)
- Directory downloads → Router descriptors: uses router data (evidence: `src/feature/dirclient/dirclient.c`)
- Descriptor parsing → Router descriptors: adds descriptors (evidence: `src/feature/dirparse/routerparse.c`)
- Router descriptors → Directory downloads: requests downloads (evidence: `src/feature/nodelist/routerlist.c`)
- Router descriptors → Directory service: shares directory service (evidence: `src/feature/nodelist/routerlist.c`)
- Onion-service client → Directory downloads: fetches descriptors (evidence: `src/feature/hs/hs_client.c`)
- Onion-service client → Circuit building: builds service circuits (evidence: `src/feature/hs/hs_client.c`)
- Onion-service host → Directory downloads: publishes descriptors (evidence: `src/feature/hs/hs_service.c`)
- Onion-service host → Circuit building: builds service circuits (evidence: `src/feature/hs/hs_service.c`)
- Circuit building → Circuit state: tracks circuits
- Circuit building → Relay channels: uses channels
- Relay forwarding → Relay channels: forwards cells
- Control interface → Control events: emits events
- Network consensus → Relay selection data: updates relay data
- Circuit building → Congestion control: applies congestion control
- Entry selection → Circuit building: selects entry
