# dr-lexus-dr/bproto architecture

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

- Interactive diagram: https://gitdiagram.com/dr-lexus-dr/bproto
- Repository: https://github.com/dr-lexus-dr/bproto

## Overview

bProto is a VPN product spanning client apps, a Rust UDP protocol and Linux server, and a web control panel. The main user path is importing or selecting a server profile, connecting a client tunnel, carrying IP traffic through the encrypted protocol and server TUN/NAT datapath, and managing clients and subscriptions through bUI. The graph also preserves routing, stealth, stats, and platform integration branches. Source excerpts are selective; unsampled subsystem relationships are omitted unless the README or source index establishes them.

Main entry points: [`panel/backend/src/main.rs`](https://github.com/dr-lexus-dr/bproto/blob/main/panel/backend/src/main.rs) (Panel backend), [`crates/vpn-core/src/session.rs`](https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-core/src/session.rs) (Encrypted sessions), [`crates/vpn-server/src/main.rs`](https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-server/src/main.rs) (Server process), [`apps/android/app/src/main/kotlin/dev/bproto/MainActivity.kt`](https://github.com/dr-lexus-dr/bproto/blob/main/apps/android/app/src/main/kotlin/dev/bproto/MainActivity.kt) (Android app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["VPN Clients"]
  node_android_ui["Android app<br/>[MainActivity.kt]"]
  node_android_profiles["Profiles and imports<br/>[ServerProfile.kt]"]
  node_android_subs["Subscription import"]
  node_android_routing["Android routing<br/>[RoutingPolicy.kt]"]
  node_android_tunnel["Android VPN service"]
  node_ios_tunnel["iOS tunnel provider"]
  node_cli["Linux CLI<br/>[main.rs]"]
  node_ffi["JNI bridge<br/>[jni.rs]"]
end

subgraph group_protocol["VPN Protocol"]
  node_core_config["Tunnel configuration<br/>[config.rs]"]
  node_handshake["Handshake and auth<br/>[handshake.rs]"]
  node_crypto["Key derivation<br/>[crypto.rs]"]
  node_wire["Datagram framing<br/>[packet.rs]"]
  node_session["Encrypted sessions<br/>[session.rs]"]
  node_ack["Acks and replay<br/>[ack.rs]"]
  node_congestion["Congestion control<br/>[congestion.rs]"]
  node_masquerade["TLS masquerade<br/>[mod.rs]"]
end

subgraph group_server["Linux Server"]
  node_server_bin["Server process<br/>[main.rs]"]
  node_server_config["Server configuration<br/>[config.rs]"]
  node_server_node["VPN session node<br/>[server.rs]"]
  node_tun["TUN and NAT<br/>[dev.rs]"]
  node_splicer["Traffic splicer<br/>[splicer.rs]"]
end

subgraph group_panel["bUI Panel"]
  node_panel_ui["Panel interface<br/>[App.tsx]"]
  node_panel_api["Panel API client<br/>[api.ts]"]
  node_routing_editor["Routing editor<br/>[RoutingEditor.tsx]"]
  node_panel_backend["Panel backend<br/>[main.rs]"]
  node_panel_auth["Admin authentication<br/>[auth.rs]"]
  node_inbounds["Inbounds and clients<br/>[inbounds.rs]"]
  node_panel_keys["Client keys<br/>[keys.rs]"]
  node_panel_subs["Subscriptions<br/>[subs.rs]"]
  node_panel_routing["Routing rules<br/>[routing.rs]"]
  node_panel_stats["Traffic statistics<br/>[stats.rs]"]
  node_panel_db[("SQLite database")]
end

node_user(("Client user"))
node_browser_admin(("Panel administrator"))

node_user -->|"configures"| node_android_ui
node_android_ui -->|"manages profiles"| node_android_profiles
node_android_ui -->|"fetches subscriptions"| node_android_subs
node_android_ui -->|"starts tunnel"| node_android_tunnel
node_android_tunnel -->|"applies policy"| node_android_routing
node_android_tunnel -.->|"calls native bridge"| node_ffi
node_ios_tunnel -.->|"uses protocol"| node_session
node_cli -->|"runs client tunnel"| node_session
node_ffi -->|"bridges client API"| node_session
node_core_config -->|"configures handshake"| node_handshake
node_handshake -->|"derives session keys"| node_crypto
node_session -->|"performs handshake"| node_handshake
node_session -->|"frames datagrams"| node_wire
node_session -->|"tracks acknowledgements"| node_ack
node_session -->|"controls sending"| node_congestion
node_masquerade -->|"wraps handshake"| node_handshake
node_server_bin -->|"loads configuration"| node_server_config
node_server_bin -->|"runs protocol node"| node_server_node
node_server_bin -->|"sets up datapath"| node_tun
node_server_node -->|"parses packets"| node_wire
node_server_node -->|"opens and seals"| node_session
node_server_bin -.->|"configures traffic handling"| node_splicer
node_browser_admin -->|"manages VPN"| node_panel_ui
node_panel_ui -->|"requests API"| node_panel_api
node_panel_ui -->|"edits routing"| node_routing_editor
node_panel_api -.->|"calls endpoints"| node_panel_backend
node_panel_backend -->|"routes authentication"| node_panel_auth
node_panel_backend -->|"routes client management"| node_inbounds
node_panel_backend -->|"routes key management"| node_panel_keys
node_panel_backend -->|"routes subscriptions"| node_panel_subs
node_panel_backend -->|"routes policy"| node_panel_routing
node_panel_backend -->|"routes traffic reports"| node_panel_stats
node_panel_backend -->|"stores panel state"| node_panel_db
node_panel_keys -->|"emits import config"| node_android_profiles
node_android_subs -.->|"retrieves subscription"| node_panel_subs

click node_android_ui "https://github.com/dr-lexus-dr/bproto/blob/main/apps/android/app/src/main/kotlin/dev/bproto/MainActivity.kt"
click node_android_profiles "https://github.com/dr-lexus-dr/bproto/blob/main/apps/android/app/src/main/kotlin/dev/bproto/ServerProfile.kt"
click node_android_subs "https://github.com/dr-lexus-dr/bproto/blob/main/apps/android/app/src/main/kotlin/dev/bproto/SubscriptionFetcher.kt"
click node_android_routing "https://github.com/dr-lexus-dr/bproto/blob/main/apps/android/app/src/main/kotlin/dev/bproto/RoutingPolicy.kt"
click node_android_tunnel "https://github.com/dr-lexus-dr/bproto/blob/main/apps/android/app/src/main/kotlin/dev/bproto/BprotoVpnService.kt"
click node_ios_tunnel "https://github.com/dr-lexus-dr/bproto/blob/main/apps/ios/BprotoTunnelProvider.swift"
click node_cli "https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-cli/src/main.rs"
click node_ffi "https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-ffi/src/jni.rs"
click node_core_config "https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-core/src/config.rs"
click node_handshake "https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-core/src/handshake.rs"
click node_crypto "https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-core/src/crypto.rs"
click node_wire "https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-core/src/packet.rs"
click node_session "https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-core/src/session.rs"
click node_ack "https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-core/src/ack.rs"
click node_congestion "https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-core/src/congestion.rs"
click node_masquerade "https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-core/src/masquerade/mod.rs"
click node_server_bin "https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-server/src/main.rs"
click node_server_config "https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-server/src/config.rs"
click node_server_node "https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-core/src/server.rs"
click node_tun "https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-tun/src/dev.rs"
click node_splicer "https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-server/src/splicer.rs"
click node_panel_ui "https://github.com/dr-lexus-dr/bproto/blob/main/panel/frontend/src/App.tsx"
click node_panel_api "https://github.com/dr-lexus-dr/bproto/blob/main/panel/frontend/src/api.ts"
click node_routing_editor "https://github.com/dr-lexus-dr/bproto/blob/main/panel/frontend/src/RoutingEditor.tsx"
click node_panel_backend "https://github.com/dr-lexus-dr/bproto/blob/main/panel/backend/src/main.rs"
click node_panel_auth "https://github.com/dr-lexus-dr/bproto/blob/main/panel/backend/src/auth.rs"
click node_inbounds "https://github.com/dr-lexus-dr/bproto/blob/main/panel/backend/src/inbounds.rs"
click node_panel_keys "https://github.com/dr-lexus-dr/bproto/blob/main/panel/backend/src/keys.rs"
click node_panel_subs "https://github.com/dr-lexus-dr/bproto/blob/main/panel/backend/src/subs.rs"
click node_panel_routing "https://github.com/dr-lexus-dr/bproto/blob/main/panel/backend/src/routing.rs"
click node_panel_stats "https://github.com/dr-lexus-dr/bproto/blob/main/panel/backend/src/stats.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_android_ui,node_android_profiles,node_android_subs,node_android_routing,node_android_tunnel,node_ios_tunnel,node_cli,node_ffi,node_user toneBlue
class node_core_config,node_handshake,node_crypto,node_wire,node_session,node_ack,node_congestion,node_masquerade toneAmber
class node_server_bin,node_server_config,node_server_node,node_tun,node_splicer toneMint
class node_panel_ui,node_panel_api,node_routing_editor,node_panel_backend,node_panel_auth,node_inbounds,node_panel_keys,node_panel_subs,node_panel_routing,node_panel_stats,node_panel_db toneRose
class node_browser_admin toneIndigo
```

## Components

### VPN Clients

- [Android app](https://github.com/dr-lexus-dr/bproto/blob/main/apps/android/app/src/main/kotlin/dev/bproto/MainActivity.kt): `apps/android/app/src/main/kotlin/dev/bproto/MainActivity.kt`
- [Profiles and imports](https://github.com/dr-lexus-dr/bproto/blob/main/apps/android/app/src/main/kotlin/dev/bproto/ServerProfile.kt): `apps/android/app/src/main/kotlin/dev/bproto/ServerProfile.kt`
- [Subscription import](https://github.com/dr-lexus-dr/bproto/blob/main/apps/android/app/src/main/kotlin/dev/bproto/SubscriptionFetcher.kt): `apps/android/app/src/main/kotlin/dev/bproto/SubscriptionFetcher.kt`
- [Android routing](https://github.com/dr-lexus-dr/bproto/blob/main/apps/android/app/src/main/kotlin/dev/bproto/RoutingPolicy.kt): `apps/android/app/src/main/kotlin/dev/bproto/RoutingPolicy.kt`
- [Android VPN service](https://github.com/dr-lexus-dr/bproto/blob/main/apps/android/app/src/main/kotlin/dev/bproto/BprotoVpnService.kt): `apps/android/app/src/main/kotlin/dev/bproto/BprotoVpnService.kt`
- [iOS tunnel provider](https://github.com/dr-lexus-dr/bproto/blob/main/apps/ios/BprotoTunnelProvider.swift): `apps/ios/BprotoTunnelProvider.swift`
- [Linux CLI](https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-cli/src/main.rs): `crates/vpn-cli/src/main.rs`
- [JNI bridge](https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-ffi/src/jni.rs): `crates/vpn-ffi/src/jni.rs`

### VPN Protocol

- [Tunnel configuration](https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-core/src/config.rs): `crates/vpn-core/src/config.rs`
- [Handshake and auth](https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-core/src/handshake.rs): `crates/vpn-core/src/handshake.rs`
- [Key derivation](https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-core/src/crypto.rs): `crates/vpn-core/src/crypto.rs`
- [Datagram framing](https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-core/src/packet.rs): `crates/vpn-core/src/packet.rs`
- [Encrypted sessions](https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-core/src/session.rs): `crates/vpn-core/src/session.rs`
- [Acks and replay](https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-core/src/ack.rs): `crates/vpn-core/src/ack.rs`
- [Congestion control](https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-core/src/congestion.rs): `crates/vpn-core/src/congestion.rs`
- [TLS masquerade](https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-core/src/masquerade/mod.rs): `crates/vpn-core/src/masquerade/mod.rs`

### Linux Server

- [Server process](https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-server/src/main.rs): `crates/vpn-server/src/main.rs`
- [Server configuration](https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-server/src/config.rs): `crates/vpn-server/src/config.rs`
- [VPN session node](https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-core/src/server.rs): `crates/vpn-core/src/server.rs`
- [TUN and NAT](https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-tun/src/dev.rs): `crates/vpn-tun/src/dev.rs`
- [Traffic splicer](https://github.com/dr-lexus-dr/bproto/blob/main/crates/vpn-server/src/splicer.rs): `crates/vpn-server/src/splicer.rs`

### bUI Panel

- [Panel interface](https://github.com/dr-lexus-dr/bproto/blob/main/panel/frontend/src/App.tsx): `panel/frontend/src/App.tsx`
- [Panel API client](https://github.com/dr-lexus-dr/bproto/blob/main/panel/frontend/src/api.ts): `panel/frontend/src/api.ts`
- [Routing editor](https://github.com/dr-lexus-dr/bproto/blob/main/panel/frontend/src/RoutingEditor.tsx): `panel/frontend/src/RoutingEditor.tsx`
- [Panel backend](https://github.com/dr-lexus-dr/bproto/blob/main/panel/backend/src/main.rs): `panel/backend/src/main.rs`
- [Admin authentication](https://github.com/dr-lexus-dr/bproto/blob/main/panel/backend/src/auth.rs): `panel/backend/src/auth.rs`
- [Inbounds and clients](https://github.com/dr-lexus-dr/bproto/blob/main/panel/backend/src/inbounds.rs): `panel/backend/src/inbounds.rs`
- [Client keys](https://github.com/dr-lexus-dr/bproto/blob/main/panel/backend/src/keys.rs): `panel/backend/src/keys.rs`
- [Subscriptions](https://github.com/dr-lexus-dr/bproto/blob/main/panel/backend/src/subs.rs): `panel/backend/src/subs.rs`
- [Routing rules](https://github.com/dr-lexus-dr/bproto/blob/main/panel/backend/src/routing.rs): `panel/backend/src/routing.rs`
- [Traffic statistics](https://github.com/dr-lexus-dr/bproto/blob/main/panel/backend/src/stats.rs): `panel/backend/src/stats.rs`
- **SQLite database**

### Other components

- **Client user**
- **Panel administrator**

## Connections

- Client user → Android app: configures (evidence: `README.md`)
- Android app → Profiles and imports: manages profiles (evidence: `apps/android/app/src/main/kotlin/dev/bproto/MainActivity.kt`)
- Android app → Subscription import: fetches subscriptions (evidence: `apps/android/app/src/main/kotlin/dev/bproto/MainActivity.kt`)
- Android app → Android VPN service: starts tunnel (evidence: `apps/android/app/src/main/kotlin/dev/bproto/MainActivity.kt`)
- Android VPN service → Android routing: applies policy (evidence: `apps/android/app/src/main/kotlin/dev/bproto/BprotoVpnService.kt`)
- Android VPN service → JNI bridge: calls native bridge
- iOS tunnel provider → Encrypted sessions: uses protocol
- Linux CLI → Encrypted sessions: runs client tunnel (evidence: `README.md`)
- JNI bridge → Encrypted sessions: bridges client API
- Tunnel configuration → Handshake and auth: configures handshake (evidence: `crates/vpn-core/src/handshake.rs`)
- Handshake and auth → Key derivation: derives session keys (evidence: `crates/vpn-core/src/handshake.rs`)
- Encrypted sessions → Handshake and auth: performs handshake (evidence: `crates/vpn-core/src/session.rs`)
- Encrypted sessions → Datagram framing: frames datagrams (evidence: `crates/vpn-core/src/session.rs`)
- Encrypted sessions → Acks and replay: tracks acknowledgements (evidence: `crates/vpn-core/src/session.rs`)
- Encrypted sessions → Congestion control: controls sending (evidence: `crates/vpn-core/src/session.rs`)
- TLS masquerade → Handshake and auth: wraps handshake (evidence: `crates/vpn-core/src/masquerade/mod.rs`)
- Server process → Server configuration: loads configuration (evidence: `crates/vpn-server/src/main.rs`)
- Server process → VPN session node: runs protocol node (evidence: `README.md`)
- Server process → TUN and NAT: sets up datapath (evidence: `README.md`)
- VPN session node → Datagram framing: parses packets (evidence: `crates/vpn-core/src/server.rs`)
- VPN session node → Encrypted sessions: opens and seals (evidence: `crates/vpn-core/src/server.rs`)
- Server process → Traffic splicer: configures traffic handling
- Panel administrator → Panel interface: manages VPN (evidence: `README.md`)
- Panel interface → Panel API client: requests API (evidence: `panel/frontend/src/App.tsx`)
- Panel interface → Routing editor: edits routing (evidence: `panel/frontend/src/App.tsx`)
- Panel API client → Panel backend: calls endpoints
- Panel backend → Admin authentication: routes authentication (evidence: `panel/backend/src/main.rs`)
- Panel backend → Inbounds and clients: routes client management (evidence: `panel/backend/src/main.rs`)
- Panel backend → Client keys: routes key management (evidence: `panel/backend/src/main.rs`)
- Panel backend → Subscriptions: routes subscriptions (evidence: `panel/backend/src/main.rs`)
- Panel backend → Routing rules: routes policy (evidence: `panel/backend/src/main.rs`)
- Panel backend → Traffic statistics: routes traffic reports (evidence: `panel/backend/src/main.rs`)
- Panel backend → SQLite database: stores panel state (evidence: `panel/backend/src/main.rs`)
- Client keys → Profiles and imports: emits import config
- Subscription import → Subscriptions: retrieves subscription
