# mmx233/bitsrunlogingo architecture

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

- Interactive diagram: https://gitdiagram.com/mmx233/bitsrunlogingo
- Repository: https://github.com/mmx233/bitsrunlogingo

## Overview

BitSrunLoginGo is a command-line campus-network login client, with a reusable `pkg/srun` login library. The main path loads configuration, optionally runs a guardian loop, selects interfaces, detects portal parameters, checks login status, and authenticates when needed; successful login can trigger DDNS. The README also documents multi-interface operation, automatic acid/enc detection, Reality requests, backoff, and three DNS providers. Links reflect the excerpted callers and explicit README behavior; provider-specific and several configuration details are indexed but not excerpted.

Main entry points: [`internal/login/login.go`](https://github.com/mmx233/bitsrunlogingo/blob/main/internal/login/login.go) (Login orchestration), [`cmd/bitsrun/main.go`](https://github.com/mmx233/bitsrunlogingo/blob/main/cmd/bitsrun/main.go) (CLI entry), [`internal/dns/dns.go`](https://github.com/mmx233/bitsrunlogingo/blob/main/internal/dns/dns.go) (DDNS dispatch), [`internal/config/config.go`](https://github.com/mmx233/bitsrunlogingo/blob/main/internal/config/config.go) (Configuration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Command and config"]
  node_cli["CLI entry<br/>[main.go]"]
  node_configuration["Configuration<br/>[config.go]"]
  node_defaults["Config defaults<br/>[default.go]"]
  node_logging["Logging<br/>[log.go]"]
end

subgraph group_runtime["Login orchestration"]
  node_guardian["Guardian loop<br/>[guardian.go]"]
  node_login["Login orchestration<br/>[login.go]"]
  node_interfaces["Interface selection<br/>[login.go]"]
  node_backoff["Retry backoff<br/>[backoff.go]"]
  node_interface["Network interfaces<br/>[eth.go]"]
end

subgraph group_protocol["Srun protocol"]
  node_srun["Srun client<br/>[srun.go]"]
  node_portal_api["Portal API<br/>[api.go]"]
  node_detection["Portal detection<br/>[detect.go]"]
  node_encoding["Protocol encoding<br/>[encode.go]"]
end

subgraph group_network["Network and DDNS"]
  node_http["HTTP client<br/>[http.go]"]
  node_ddns["DDNS dispatch<br/>[dns.go]"]
  node_cloudflare["Cloudflare provider<br/>[cloudflare.go]"]
  node_aliyun["Aliyun provider<br/>[aliyun.go]"]
  node_dnspod["DNSPod provider<br/>[dnspod.go]"]
end

node_user(("Operator"))
node_campus_portal(("Campus portal"))
node_dns_services(("DNS services"))

node_user -->|"runs"| node_cli
node_cli -->|"loads"| node_configuration
node_configuration -->|"initializes from"| node_defaults
node_configuration -.->|"configures"| node_logging
node_cli -->|"starts"| node_guardian
node_cli -->|"invokes"| node_login
node_guardian -->|"repeats"| node_login
node_login -->|"dispatches"| node_interfaces
node_interfaces -->|"runs per interface"| node_login
node_interfaces -->|"enumerates"| node_interface
node_login -->|"runs with retries"| node_backoff
node_login -->|"selects client"| node_http
node_login -->|"checks and authenticates"| node_srun
node_srun -.->|"uses"| node_portal_api
node_login -->|"detects parameters"| node_detection
node_srun -.->|"encodes requests"| node_encoding
node_portal_api -.->|"requests status and login"| node_campus_portal
node_login -->|"updates after login"| node_ddns
node_ddns -->|"dispatches"| node_aliyun
node_ddns -->|"dispatches"| node_cloudflare
node_ddns -->|"dispatches"| node_dnspod
node_aliyun -.->|"updates records"| node_dns_services
node_cloudflare -.->|"updates records"| node_dns_services
node_dnspod -.->|"updates records"| node_dns_services

click node_cli "https://github.com/mmx233/bitsrunlogingo/blob/main/cmd/bitsrun/main.go"
click node_configuration "https://github.com/mmx233/bitsrunlogingo/blob/main/internal/config/config.go"
click node_defaults "https://github.com/mmx233/bitsrunlogingo/blob/main/internal/config/default.go"
click node_logging "https://github.com/mmx233/bitsrunlogingo/blob/main/internal/config/log.go"
click node_guardian "https://github.com/mmx233/bitsrunlogingo/blob/main/internal/login/guardian.go"
click node_login "https://github.com/mmx233/bitsrunlogingo/blob/main/internal/login/login.go"
click node_interfaces "https://github.com/mmx233/bitsrunlogingo/blob/main/internal/login/login.go"
click node_backoff "https://github.com/mmx233/bitsrunlogingo/blob/main/internal/config/backoff.go"
click node_interface "https://github.com/mmx233/bitsrunlogingo/blob/main/tools/eth.go"
click node_srun "https://github.com/mmx233/bitsrunlogingo/blob/main/pkg/srun/srun.go"
click node_portal_api "https://github.com/mmx233/bitsrunlogingo/blob/main/pkg/srun/api.go"
click node_detection "https://github.com/mmx233/bitsrunlogingo/blob/main/pkg/srun/detect.go"
click node_encoding "https://github.com/mmx233/bitsrunlogingo/blob/main/pkg/srun/encode.go"
click node_http "https://github.com/mmx233/bitsrunlogingo/blob/main/internal/http_client/http.go"
click node_ddns "https://github.com/mmx233/bitsrunlogingo/blob/main/internal/dns/dns.go"
click node_cloudflare "https://github.com/mmx233/bitsrunlogingo/blob/main/internal/dns/cloudflare/cloudflare.go"
click node_aliyun "https://github.com/mmx233/bitsrunlogingo/blob/main/internal/dns/aliyun/aliyun.go"
click node_dnspod "https://github.com/mmx233/bitsrunlogingo/blob/main/internal/dns/dnspod/dnspod.go"

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_configuration,node_defaults,node_logging toneBlue
class node_guardian,node_login,node_interfaces,node_backoff,node_interface toneAmber
class node_srun,node_portal_api,node_detection,node_encoding toneMint
class node_http,node_ddns,node_cloudflare,node_aliyun,node_dnspod toneRose
class node_user,node_campus_portal,node_dns_services toneIndigo
```

## Components

### Command and config

- [CLI entry](https://github.com/mmx233/bitsrunlogingo/blob/main/cmd/bitsrun/main.go): `cmd/bitsrun/main.go`
- [Configuration](https://github.com/mmx233/bitsrunlogingo/blob/main/internal/config/config.go): `internal/config/config.go`
- [Config defaults](https://github.com/mmx233/bitsrunlogingo/blob/main/internal/config/default.go): `internal/config/default.go`
- [Logging](https://github.com/mmx233/bitsrunlogingo/blob/main/internal/config/log.go): `internal/config/log.go`

### Login orchestration

- [Guardian loop](https://github.com/mmx233/bitsrunlogingo/blob/main/internal/login/guardian.go): `internal/login/guardian.go`
- [Login orchestration](https://github.com/mmx233/bitsrunlogingo/blob/main/internal/login/login.go): `internal/login/login.go`
- [Interface selection](https://github.com/mmx233/bitsrunlogingo/blob/main/internal/login/login.go): `internal/login/login.go`
- [Retry backoff](https://github.com/mmx233/bitsrunlogingo/blob/main/internal/config/backoff.go): `internal/config/backoff.go`
- [Network interfaces](https://github.com/mmx233/bitsrunlogingo/blob/main/tools/eth.go): `tools/eth.go`

### Srun protocol

- [Srun client](https://github.com/mmx233/bitsrunlogingo/blob/main/pkg/srun/srun.go): `pkg/srun/srun.go`
- [Portal API](https://github.com/mmx233/bitsrunlogingo/blob/main/pkg/srun/api.go): `pkg/srun/api.go`
- [Portal detection](https://github.com/mmx233/bitsrunlogingo/blob/main/pkg/srun/detect.go): `pkg/srun/detect.go`
- [Protocol encoding](https://github.com/mmx233/bitsrunlogingo/blob/main/pkg/srun/encode.go): `pkg/srun/encode.go`

### Network and DDNS

- [HTTP client](https://github.com/mmx233/bitsrunlogingo/blob/main/internal/http_client/http.go): `internal/http_client/http.go`
- [DDNS dispatch](https://github.com/mmx233/bitsrunlogingo/blob/main/internal/dns/dns.go): `internal/dns/dns.go`
- [Cloudflare provider](https://github.com/mmx233/bitsrunlogingo/blob/main/internal/dns/cloudflare/cloudflare.go): `internal/dns/cloudflare/cloudflare.go`
- [Aliyun provider](https://github.com/mmx233/bitsrunlogingo/blob/main/internal/dns/aliyun/aliyun.go): `internal/dns/aliyun/aliyun.go`
- [DNSPod provider](https://github.com/mmx233/bitsrunlogingo/blob/main/internal/dns/dnspod/dnspod.go): `internal/dns/dnspod/dnspod.go`

### Other components

- **Operator**
- **Campus portal**
- **DNS services**

## Connections

- Operator → CLI entry: runs (evidence: `README.md`)
- CLI entry → Configuration: loads (evidence: `cmd/bitsrun/main.go`)
- Configuration → Config defaults: initializes from (evidence: `internal/config/config.go`)
- Configuration → Logging: configures
- CLI entry → Guardian loop: starts (evidence: `cmd/bitsrun/main.go`)
- CLI entry → Login orchestration: invokes (evidence: `cmd/bitsrun/main.go`)
- Guardian loop → Login orchestration: repeats (evidence: `internal/login/guardian.go`)
- Login orchestration → Interface selection: dispatches (evidence: `internal/login/login.go`)
- Interface selection → Login orchestration: runs per interface (evidence: `internal/login/login.go`)
- Interface selection → Network interfaces: enumerates (evidence: `internal/login/login.go`)
- Login orchestration → Retry backoff: runs with retries (evidence: `internal/login/login.go`)
- Login orchestration → HTTP client: selects client (evidence: `internal/login/login.go`)
- Login orchestration → Srun client: checks and authenticates (evidence: `internal/login/login.go`)
- Srun client → Portal API: uses
- Login orchestration → Portal detection: detects parameters (evidence: `internal/login/login.go`)
- Srun client → Protocol encoding: encodes requests
- Portal API → Campus portal: requests status and login
- Login orchestration → DDNS dispatch: updates after login (evidence: `internal/login/login.go`)
- DDNS dispatch → Aliyun provider: dispatches (evidence: `internal/dns/dns.go`)
- DDNS dispatch → Cloudflare provider: dispatches (evidence: `internal/dns/dns.go`)
- DDNS dispatch → DNSPod provider: dispatches (evidence: `internal/dns/dns.go`)
- Aliyun provider → DNS services: updates records
- Cloudflare provider → DNS services: updates records
- DNSPod provider → DNS services: updates records
