How nishantverse/topdock works
1. Repository shape
- This is a small, mostly single-module Python CLI application.
- The core runtime appears to live in topdock.py, with packaging metadata in pyproject.toml.
- install.sh and install.ps1 provide convenience installation paths for Unix-like shells and Windows PowerShell.
2. Primary purpose
- TopDock is a terminal dashboard for live Docker container metrics.
- It presents per-container CPU, memory, network, and block I/O statistics in real time, and can also emit one-shot snapshot output.
3. Runtime boundary
- The app runs locally on the user’s machine and talks to a Docker daemon.
- It can connect either to the local Docker socket or to a remote Docker host via the --host option, so the Docker daemon is the main external dependency and data source.
4. Core data flow
- Docker container statistics are collected from the daemon.
- Those stats are transformed into a tabular view model for the terminal.
- The view model is then rendered into a live dashboard, or serialized into snapshot output such as JSON/CSV.
5. Main functional subsystems
- CLI/command parsing: handles flags such as --sort, --refresh, --alert, --snapshot, --format, --host, and --version.
- Docker metrics acquisition: fetches live container stats from Docker.
- Ranking/sorting: orders containers by CPU, memory, network, or block I/O.
- Terminal dashboard UI: displays a continuously updating table and responds to keyboard input.
- Export/output path: supports snapshot mode and export of CSV/JSON.
- Alert handling: tracks threshold-based alerting, with a command to clear alerts.
6. Interactive control boundary
- The live dashboard is event-driven through keyboard shortcuts.
- Navigation keys scroll the table; letter keys change sort mode, export data, clear alerts, or quit.
- This makes the UI stateful: the same underlying metric set can be viewed with different sort order and scroll position.
7. Modes of operation
- Live mode: continuous refresh, interactive terminal UI, default behavior.
- Snapshot mode: one-shot capture intended for machine-readable output.
- These are distinct output paths, which is important for an architecture diagram because rendering and serialization are alternate sinks from the same metrics source.
8. Output and integration points
- Human-facing output is the terminal dashboard.
- Machine-facing output is JSON and CSV export/snapshot data.
- There are no signs of a database, web server, message queue, or background service; the application seems self-contained aside from Docker access.
9. Packaging and distribution
- pyproject.toml indicates standard Python packaging, likely exposing a console script entrypoint.
- The install scripts suggest the repo supports direct local installation in addition to package-manager-based installation via pipx or pip.
10. Platform considerations
- The README claims Linux, macOS, and Windows support.
- That implies the architecture is designed around cross-platform Python code and a terminal interface rather than OS-specific GUI components.
- Remote Docker host support also suggests the Docker communication layer is configurable, not hardwired to a local socket.
11. Likely diagram framing
- A good architecture diagram would place the user terminal at the center, with an interactive dashboard UI consuming data from a Docker daemon.
- Beside it, show an alternate snapshot/export path for JSON/CSV.
- Surround those with a thin CLI/configuration layer and packaging/install scripts as the entry and distribution boundary.
12. What is notably absent
- No evidence of backend services, persistence, authentication, or multi-process coordination.
- No signs of separate frontend/backend separation; this is a single-process CLI tool with a clear external dependency on Docker.
Main entry points: topdock.py Core CLI · pyproject.toml pyproject.toml · install.sh install.sh · install.ps1 install.ps1
Components 13
Runtime
Interactive CLI execution and Docker data flow
- Terminal · Where the dashboard is viewed and controlled
- Docker Daemon · Source of container metrics via local socket or remote host
- Core CLI · Main application module coordinating runtime behavior
topdock.py - CLI Parser · Handles flags, modes, sorting, refresh, host, and version
- Metrics Fetcher · Collects live CPU, memory, network, and block I/O stats
- Sorter · Orders containers by the selected metric
- Dashboard UI · Renders the live updating container view
- Keyboard Input · Processes navigation and command shortcuts
- Snapshot Export · Produces one-shot JSON or CSV output
- Alerts · Tracks and clears threshold-based alerts
Distribution
Packaging and install entry points
- pyproject.toml · Defines project metadata and console entrypoint
pyproject.toml - install.sh · Convenience install path for Unix-like shells
install.sh - install.ps1 · Convenience install path for PowerShell
install.ps1
Connections 18
- Terminal → Core CLI: launches · User starts the CLI in the terminal
- pyproject.toml → Core CLI: exposes · Packaging metadata points to the runnable entrypoint
- install.sh → pyproject.toml: installs · Unix helper installs the packaged CLI
- install.ps1 → pyproject.toml: installs · PowerShell helper installs the packaged CLI
- Core CLI → CLI Parser: parses · Reads command-line flags and mode selection
- CLI Parser → Metrics Fetcher: configures · Passes host, refresh, and snapshot settings
- Metrics Fetcher → Docker Daemon: queries · Fetches live container statistics from Docker
- Metrics Fetcher → Sorter: provides · Hands collected metrics to the ranking layer
- Sorter → Dashboard UI: orders · Supplies containers in the chosen sort order
- Sorter → Snapshot Export: orders · Formats ranked metrics for machine output
- Dashboard UI → Terminal: renders · Displays the live table in the terminal
- Keyboard Input → Dashboard UI: controls · Scrolls, changes sort, exports, clears alerts, and quits
- Dashboard UI → Keyboard Input: reads · Consumes interactive key events
- Core CLI → Dashboard UI: runs · Starts live dashboard mode
- Core CLI → Snapshot Export: runs · Starts snapshot mode for one-shot output
- Metrics Fetcher → Alerts: feeds · Threshold checks operate on incoming stats
- Alerts → Dashboard UI: annotates · Alerts are surfaced in the live view
- Alerts → Snapshot Export: annotates · Alert state can be included in exported output