8000 feat(router-cli): implement CLI control panel and live monitoring by MeGaNeKoS · Pull Request #46 · aula-id/mini-gateway-rs · GitHub
[go: up one dir, main page]

Skip to content
< 8000 div class="prc-PageLayout-VerticalDivider-9QRmK prc-PageLayout-SidebarVerticalDivider-0Rl0V" data-component="PageLayout.VerticalDivider" data-variant="line" data-position="end" style="--spacing:var(--spacing-none)">

feat(router-cli): implement CLI control panel and live monitoring - #46

Closed
MeGaNeKoS wants to merge 16 commits into
aula-id:mainfrom
MeGaNeKoS:feat/cli-control-panel-and-monitor
Closed

MeGaNeKoS wants to merge 16 commits into
aula-id:mainfrom
MeGaNeKoS:feat/cli-control-panel-and-monitor

Conversation

@MeGaNeKoS
@MeGaNeKoS MeGaNeKoS commented Mar 29, 2026 •
Copy link
Copy Markdown

Summary

Completes two roadmap items for the CLI crate:

  • CLI Control Panel: CRUD commands for proxy, domain, gwnode, gateway, user, cert, and sync resources
  • CLI Live Monitoring: Real-time TUI dashboard streaming gateway/proxy statistics via SSE

Development was guided by Architecture Decision Records (ADRs) documenting each design choice with Mermaid diagrams. See docs/adr/ for the full set:

  • ADR-0001: ADR Process
  • ADR-0002: CLI Architecture Redesign
  • ADR-0003: CLI Control Panel
  • ADR-0004: CLI Live Monitoring
  • ADR-0005: CLI Domain Separation

Changes

  • Architecture: Restructured CLI from a monolithic 405-line main.rs into domain-separated async modules with reqwest, token caching, and structured error types
  • Control Panel: 25+ commands (gwrs proxy list, gwrs user create, gwrs cert generate, etc.) with --format table|json|yaml output and --yes for non-interactive deletes
  • Live Monitoring: gwrs monitor launches a ratatui TUI showing per-second rates, traffic sparklines, status code bar charts, error rate badges, and a help overlay. Responsive layout adapts to terminal size.
  • Testing: 36 automated tests (25 unit + 11 integration with wiremock), plus a mock API server for manual TUI testing
  • Documentation: 5 ADRs with Mermaid architecture diagrams, updated CLI README with full command reference

AI Disclosure

AI tools (Claude) were used for code generation assistance. All code was reviewed, tested, and documented.

Test plan

  • cargo clippy -p router-cli --tests passes with zero warnings
  • cargo fmt -p router-cli --check passes clean
  • cargo test -p router-cli passes all 36 tests
  • Manual testing of CRUD commands against running API
  • Manual testing of TUI monitor against mock server (cd test-app && node mock-api.js)

Introduce Architecture Decision Records to document design choices
for upcoming CLI contributions. Includes ADR template with Mermaid
diagram sections and ADR-0001 establishing the process conventions.
Decompose monolithic main.rs into separate modules per ADR-0002.
Replace sync ureq with async reqwest, add token caching and
structured error types. Existing init/config/export commands
preserved with identical behavior.
Implement CLI management for all API resources per ADR-0003:
proxy, domain, gwnode, gateway, user, cert, and sync commands
with list/get/create/delete operations. Adds --format flag
(table/json/yaml) and --yes for non-interactive delete.
Implement real-time monitoring per ADR-0004 via `gwrs monitor`.
Connects to the SSE statistics stream and renders a ratatui-based
dashboard with gateway/proxy stats, traffic sparklines, and
status code distribution. Supports tab/1/2 panel switching,
auto-reconnect on disconnect, and 120-point history buffer.
The actix-web-lab SSE implementation uses \r\n\r\n message
boundaries. Update the parser to handle both \r\n\r\n and \n\n,
and skip comment lines (pings).
crossterm on Windows fires both Press and Release key events.
Without filtering, tab switches twice (flickering back). Only
process KeyEventKind::Press to match expected behavior.
Redesign the monitor TUI with responsive layout that adapts to
terminal size. Show per-second rates (req/s, bytes/s) instead of
raw totals. Add min/max/avg stats, bar chart for status codes,
and collapse sparklines on small terminals. Stack panels
vertically when terminal is narrow (<100 cols).
Add overview panel with aggregate totals, error/success rate
badges, and interval counts. Add request sparkline alongside
traffic sparklines. Add help overlay (?/Esc), uptime display,
and three-tier responsive layout (tall/mid/small). All computed
metrics from the API data are now displayed.
Read bytes min/max/avg directly from TargetStats reference instead
of copying into the Rates struct. Removes the intermediate fields
that the compiler could not track as used.
Express server mimicking router-api endpoints: login, CRUD for
proxies/gwnodes/gateways/domains/users, sync, certificates, and
SSE statistics stream with random data. Broadcasts every 5s with
30 pre-loaded history points for TUI testing.
Document the full CLI surface: CRUD operations for proxy, domain,
gwnode, gateway, user, cert, sync, and the monitor TUI dashboard.
Include authentication options, output formats, keybindings, and
mock server testing instructions.
25 unit tests covering app state (ring buffer, aggregates, error
rates, formatting, rates computation), auth (credential resolution,
token cache serialization), and output (table formatting).

11 integration tests using wiremock: login success/failure, proxy
CRUD, gateway node list, user list, sync, 401 re-authentication,
and 404 error handling.
Move the hardcoded YAML config template from init.rs to
templates/router-config.yaml. Embedded at compile time via
include_str!, making the template easier to maintain and review
independently from the code.
Break ui.rs (482 lines) into tui/widgets/ with one file per
concern: header, overview, stats, sparklines, status_codes,
footer, help. Remove section comments. ui.rs is now a thin
layout orchestrator.
…d arg

Remove section dividers, obvious comments, and redundant doc
comments across all source files. Remove --gwnode-id from domain
create since the API does not accept it on that endpoint.
Colocate CLI definitions, models, and handlers per resource domain.
Each resource (proxy, domain, gwnode, gateway, user, cert, sync)
gets its own folder with mod.rs and models.rs. Shared types move
to common.rs. cli.rs shrinks to top-level Commands enum only.

Adding a new resource now means creating one folder with no
changes to existing files.
@zonblade
zonblade self-requested a review March 29, 2026 16:12
@zonblade
zonblade commented Mar 29, 2026 •
Copy link
Copy Markdown
Member

buat issue dulu ya, boleh baca Contribution guide sebelum nge PR.
khusus untuk mini-gateway ku sarankan untuk ngikutin contribution guide.

https://github.com/aula-id/mini-gateway-rs?tab=contributing-ov-file

Missing disclosure:

  • ❌ One PR per concern. Keep pull requests focused on a single change. Do not bundle unrelated changes.
  • ❌ Write a clear description. Explain what your PR does and why. Reference any related issues.
  • ❌ Disclose AI usage. If you used AI tools, state it clearly in the PR description (see AI-Assisted Code Policy).
  • ❌ Keep it reviewable. If your change is large, consider breaking it into smaller PRs.
  • ❌ Be responsive. Address review feedback in a timely manner.

@MeGaNeKoS
thanks

@zonblade zonblade added invalid This doesn't seem right question Further information is requested labels Mar 29, 2026
@MeGaNeKoS
Copy link
Copy Markdown
Author

Untuk feature CLI control panel dan live monitoringnya ku pisah aja ya?

dan untuk link proposal milestonenya nggak bisa di buka mas.

| Propose Milestone Work -- Want to tackle a larger piece of the roadmap? Open a Milestone Implementation proposal.

image

Untuk AI pakai ai buat auto completion code sama documentasi biar rapi. Nanti ku pecah lagi deh jadi beberapa branch.

@zonblade
Copy link
Copy Markdown
Member

@MeGaNeKoS itu cli nya breaking changes bgt cuy, sama reqwest gabisa dipake standalone makannya pake ureq, ini udah di riset dulu belum atau asal approve ai aja?

@zonblade
Copy link
Copy Markdown
Member

milestone buka yang di aula lewat issue

@MeGaNeKoS
Copy link
Copy Markdown
Author

@MeGaNeKoS itu cli nya breaking changes bgt cuy, sama reqwest gabisa dipake standalone makannya pake ureq, ini udah di riset dulu belum atau asal approve ai aja?

Aku request buat ganti, concern aku itu, karna kita ingin bikin seperti nginx, dimana itu I/O bound, dan, di nginx, dia itu menggunakan semacam async, tapi implementasi manual di C. Aku dokumentasikan semua decision ku di ADR. munkin untuk PR 1 ku ganti ke propose ADR dulu aja kali ya. Biar nanti orang lain gampang juga pahami kenapa kita milih approach tsb

@MeGaNeKoS MeGaNeKoS closed this Mar 30, 2026
@MeGaNeKoS
Copy link
Copy Markdown
Author

Opps, my initial though/reason was invalid. ku lupa CLI-nya nggak ngurusin proxy gateway. cuman ya, buat ui sih juga masih perlu async. karna butuh responsive. Nanti ku bikin lagi deh ADR yang benernya

@MeGaNeKoS
MeGaNeKoS deleted the feat/cli-control-panel-and-monitor branch March 30, 2026 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

invalid This doesn't seem right question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0