# citadel-foss/portal architecture

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

- Interactive diagram: https://gitdiagram.com/citadel-foss/portal
- Repository: https://github.com/citadel-foss/portal

## Overview

Portal is a Bitcoin wallet and OpenSwap client/router, offered through desktop and headless-web hosts. Users connect or set up a wallet, then manage funds, discover offers, perform and recover swaps; router users configure liquidity, run routers, and review earnings. The React app calls a typed command boundary, while host-specific adapters provide desktop or web transport. The web host exposes authenticated HTTP routes and shared core operations. The README documents Tor, chain backends, backups, and updates; several implementation links remain unverified because their source was not excerpted.

Main entry points: [`src/App.tsx`](https://github.com/citadel-foss/portal/blob/main/src/App.tsx) (Application routes), [`core/src/ops`](https://github.com/citadel-foss/portal/tree/main/core/src/ops) (Wallet and swap operations), [`src/api/commands.ts`](https://github.com/citadel-foss/portal/blob/main/src/api/commands.ts) (Typed commands), [`src/pages/router/RouterWorkspacePage.tsx`](https://github.com/citadel-foss/portal/blob/main/src/pages/router/RouterWorkspacePage.tsx) (Router management)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["User interface"]
  node_app["Application routes<br/>[App.tsx]"]
  node_walletui["Wallet and setup<br/>[SetupPage.tsx]"]
  node_swapui["Swap and recovery<br/>[SwapPage.tsx]"]
  node_marketui["Market discovery<br/>[MarketPage.tsx]"]
  node_routerui["Router management"]
  node_reportsui["Router reports"]
  node_sharedui["Shared UI and formats<br/>[display.tsx]"]
  node_recoveryphrase["Phrase confirmation<br/>[RecoveryPhrase.tsx]"]
  node_stateui["Session and connection<br/>[connection.ts]"]
end

subgraph group_boundary["Host interfaces"]
  node_api["Typed commands<br/>[commands.ts]"]
  node_transport["Host transport<br/>[transport.ts]"]
  node_desktopadapter["Desktop adapter<br/>[desktop.ts]"]
  node_webadapter["Web adapter<br/>[web.ts]"]
end

subgraph group_core["Wallet and protocol core"]
  node_coreops["Wallet and swap operations"]
  node_corestate["Wallet state and types<br/>[state.rs]"]
  node_storage[("Wallet data storage<br/>[storage.rs]")]
  node_tor["Tor networking<br/>[tor.rs]"]
  node_chain["Chain backends<br/>[chain_backend.rs]"]
end

subgraph group_web["Web host"]
  node_webhost["HTTP routes<br/>[routes.rs]"]
  node_auth["Web authentication<br/>[auth.rs]"]
  node_webcommands["Web command dispatch<br/>[commands.rs]"]
  node_webstate["Web host state<br/>[state.rs]"]
  node_config["Web configuration<br/>[config.rs]"]
end

subgraph group_desktop["Desktop host"]
  node_desktopcommands["Desktop commands"]
end

node_user(("Portal user"))
node_electrum{{"Electrum or Bitcoin node"}}
node_nostr{{"Nostr market"}}
node_github{{"GitHub updates"}}

node_user -->|"uses"| node_app
node_app -->|"routes to"| node_walletui
node_app -->|"routes to"| node_swapui
node_app -->|"routes to"| node_marketui
node_app -->|"routes to"| node_routerui
node_routerui -.->|"opens reports"| node_reportsui
node_app -->|"gates routes"| node_recoveryphrase
node_walletui -.->|"requests commands"| node_api
node_swapui -.->|"requests commands"| node_api
node_marketui -.->|"requests commands"| node_api
node_routerui -->|"calls commands"| node_api
node_routerui -->|"renders"| node_sharedui
node_sharedui -.->|"uses commands"| node_api
node_stateui -->|"calls commands"| node_api
node_api -->|"invokes"| node_transport
node_transport -.->|"dispatches"| node_desktopadapter
node_transport -.->|"dispatches"| node_webadapter
node_webadapter -.->|"requests HTTP API"| node_webhost
node_desktopadapter -.->|"invokes commands"| node_desktopcommands
node_webhost -->|"routes authentication"| node_auth
node_webhost -->|"routes commands"| node_webcommands
node_webhost -->|"uses host state"| node_webstate
node_webstate -->|"uses config"| node_config
node_webcommands -.->|"dispatches operations"| node_coreops
node_coreops -.->|"uses state"| node_corestate
node_coreops -.->|"reads and writes"| node_storage
node_coreops -.->|"uses backend"| node_chain
node_coreops -.->|"uses Tor"| node_tor
node_coreops -.->|"discovers offers"| node_nostr
node_coreops -.->|"connects to chain"| node_electrum
node_user -.->|"configures backend"| node_electrum
node_user -.->|"discovers market"| node_nostr
node_app -.->|"checks updates"| node_github

click node_app "https://github.com/citadel-foss/portal/blob/main/src/App.tsx"
click node_walletui "https://github.com/citadel-foss/portal/blob/main/src/pages/setup/SetupPage.tsx"
click node_swapui "https://github.com/citadel-foss/portal/blob/main/src/pages/swap/SwapPage.tsx"
click node_marketui "https://github.com/citadel-foss/portal/blob/main/src/pages/market/MarketPage.tsx"
click node_routerui "https://github.com/citadel-foss/portal/blob/main/src/pages/router/RouterWorkspacePage.tsx"
click node_reportsui "https://github.com/citadel-foss/portal/blob/main/src/pages/router/RouterSwapReportPage.tsx"
click node_sharedui "https://github.com/citadel-foss/portal/blob/main/src/components/ui/display.tsx"
click node_recoveryphrase "https://github.com/citadel-foss/portal/blob/main/src/components/app/RecoveryPhrase.tsx"
click node_stateui "https://github.com/citadel-foss/portal/blob/main/src/store/connection.ts"
click node_api "https://github.com/citadel-foss/portal/blob/main/src/api/commands.ts"
click node_transport "https://github.com/citadel-foss/portal/blob/main/src/api/transport.ts"
click node_desktopadapter "https://github.com/citadel-foss/portal/blob/main/src/api/desktop.ts"
click node_webadapter "https://github.com/citadel-foss/portal/blob/main/src/api/web.ts"
click node_coreops "https://github.com/citadel-foss/portal/tree/main/core/src/ops"
click node_corestate "https://github.com/citadel-foss/portal/blob/main/core/src/state.rs"
click node_storage "https://github.com/citadel-foss/portal/blob/main/core/src/storage.rs"
click node_tor "https://github.com/citadel-foss/portal/blob/main/core/src/tor.rs"
click node_chain "https://github.com/citadel-foss/portal/blob/main/core/src/ops/chain_backend.rs"
click node_webhost "https://github.com/citadel-foss/portal/blob/main/src-web/src/routes.rs"
click node_auth "https://github.com/citadel-foss/portal/blob/main/src-web/src/auth.rs"
click node_webcommands "https://github.com/citadel-foss/portal/blob/main/src-web/src/commands.rs"
click node_webstate "https://github.com/citadel-foss/portal/blob/main/src-web/src/state.rs"
click node_config "https://github.com/citadel-foss/portal/blob/main/src-web/src/config.rs"
click node_desktopcommands "https://github.com/citadel-foss/portal/tree/main/src-tauri/src/commands"

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_app,node_walletui,node_swapui,node_marketui,node_routerui,node_reportsui,node_sharedui,node_recoveryphrase,node_stateui,node_user toneBlue
class node_api,node_transport,node_desktopadapter,node_webadapter toneAmber
class node_coreops,node_corestate,node_storage,node_tor,node_chain toneMint
class node_webhost,node_auth,node_webcommands,node_webstate,node_config toneRose
class node_desktopcommands,node_electrum,node_nostr,node_github toneIndigo
```

## Components

### User interface

- [Application routes](https://github.com/citadel-foss/portal/blob/main/src/App.tsx): `src/App.tsx`
- [Wallet and setup](https://github.com/citadel-foss/portal/blob/main/src/pages/setup/SetupPage.tsx): `src/pages/setup/SetupPage.tsx`
- [Swap and recovery](https://github.com/citadel-foss/portal/blob/main/src/pages/swap/SwapPage.tsx): `src/pages/swap/SwapPage.tsx`
- [Market discovery](https://github.com/citadel-foss/portal/blob/main/src/pages/market/MarketPage.tsx): `src/pages/market/MarketPage.tsx`
- [Router management](https://github.com/citadel-foss/portal/blob/main/src/pages/router/RouterWorkspacePage.tsx): `src/pages/router/RouterWorkspacePage.tsx`
- [Router reports](https://github.com/citadel-foss/portal/blob/main/src/pages/router/RouterSwapReportPage.tsx): `src/pages/router/RouterSwapReportPage.tsx`
- [Shared UI and formats](https://github.com/citadel-foss/portal/blob/main/src/components/ui/display.tsx): `src/components/ui/display.tsx`
- [Phrase confirmation](https://github.com/citadel-foss/portal/blob/main/src/components/app/RecoveryPhrase.tsx): `src/components/app/RecoveryPhrase.tsx`
- [Session and connection](https://github.com/citadel-foss/portal/blob/main/src/store/connection.ts): `src/store/connection.ts`

### Host interfaces

- [Typed commands](https://github.com/citadel-foss/portal/blob/main/src/api/commands.ts): `src/api/commands.ts`
- [Host transport](https://github.com/citadel-foss/portal/blob/main/src/api/transport.ts): `src/api/transport.ts`
- [Desktop adapter](https://github.com/citadel-foss/portal/blob/main/src/api/desktop.ts): `src/api/desktop.ts`
- [Web adapter](https://github.com/citadel-foss/portal/blob/main/src/api/web.ts): `src/api/web.ts`

### Wallet and protocol core

- [Wallet and swap operations](https://github.com/citadel-foss/portal/tree/main/core/src/ops): `core/src/ops`
- [Wallet state and types](https://github.com/citadel-foss/portal/blob/main/core/src/state.rs): `core/src/state.rs`
- [Wallet data storage](https://github.com/citadel-foss/portal/blob/main/core/src/storage.rs): `core/src/storage.rs`
- [Tor networking](https://github.com/citadel-foss/portal/blob/main/core/src/tor.rs): `core/src/tor.rs`
- [Chain backends](https://github.com/citadel-foss/portal/blob/main/core/src/ops/chain_backend.rs): `core/src/ops/chain_backend.rs`

### Web host

- [HTTP routes](https://github.com/citadel-foss/portal/blob/main/src-web/src/routes.rs): `src-web/src/routes.rs`
- [Web authentication](https://github.com/citadel-foss/portal/blob/main/src-web/src/auth.rs): `src-web/src/auth.rs`
- [Web command dispatch](https://github.com/citadel-foss/portal/blob/main/src-web/src/commands.rs): `src-web/src/commands.rs`
- [Web host state](https://github.com/citadel-foss/portal/blob/main/src-web/src/state.rs): `src-web/src/state.rs`
- [Web configuration](https://github.com/citadel-foss/portal/blob/main/src-web/src/config.rs): `src-web/src/config.rs`

### Desktop host

- [Desktop commands](https://github.com/citadel-foss/portal/tree/main/src-tauri/src/commands): `src-tauri/src/commands`

### Other components

- **Portal user**
- **Electrum or Bitcoin node**
- **Nostr market**
- **GitHub updates**

## Connections

- Portal user → Application routes: uses (evidence: `src/App.tsx`)
- Application routes → Wallet and setup: routes to (evidence: `src/App.tsx`)
- Application routes → Swap and recovery: routes to (evidence: `src/App.tsx`)
- Application routes → Market discovery: routes to (evidence: `src/App.tsx`)
- Application routes → Router management: routes to (evidence: `src/App.tsx`)
- Router management → Router reports: opens reports
- Application routes → Phrase confirmation: gates routes (evidence: `src/App.tsx`)
- Wallet and setup → Typed commands: requests commands
- Swap and recovery → Typed commands: requests commands
- Market discovery → Typed commands: requests commands
- Router management → Typed commands: calls commands (evidence: `src/pages/router/RouterWorkspacePage.tsx`)
- Router management → Shared UI and formats: renders (evidence: `src/pages/router/RouterWorkspacePage.tsx`)
- Shared UI and formats → Typed commands: uses commands (evidence: `src/components/ui/display.tsx`)
- Session and connection → Typed commands: calls commands (evidence: `src/store/connection.ts`)
- Typed commands → Host transport: invokes (evidence: `src/api/commands.ts`)
- Host transport → Desktop adapter: dispatches
- Host transport → Web adapter: dispatches
- Web adapter → HTTP routes: requests HTTP API
- Desktop adapter → Desktop commands: invokes commands
- HTTP routes → Web authentication: routes authentication (evidence: `src-web/src/routes.rs`)
- HTTP routes → Web command dispatch: routes commands (evidence: `src-web/src/routes.rs`)
- HTTP routes → Web host state: uses host state (evidence: `src-web/src/routes.rs`)
- Web host state → Web configuration: uses config (evidence: `src-web/src/state.rs`)
- Web command dispatch → Wallet and swap operations: dispatches operations
- Wallet and swap operations → Wallet state and types: uses state
- Wallet and swap operations → Wallet data storage: reads and writes
- Wallet and swap operations → Chain backends: uses backend
- Wallet and swap operations → Tor networking: uses Tor
- Wallet and swap operations → Nostr market: discovers offers
- Wallet and swap operations → Electrum or Bitcoin node: connects to chain
- Portal user → Electrum or Bitcoin node: configures backend
- Portal user → Nostr market: discovers market
- Application routes → GitHub updates: checks updates
