# WGDashboard Rewrite – Roadmap This document is the single source of truth for the rewrite. It is written so that an agent (or contributor) can pick up **one workstream** and work on it independently. - Legacy code (read-only reference): `reference/` - New code: `src/` (backend + `src/web/` frontends), `docker/` - Goal: full feature parity with legacy, with an (almost) one-to-one Vue frontend, on a modern, readable, tested and secure codebase. --- ## 0. How to use this document (for agents) 1. Read **§1 Ground rules**, **§2 Coding style** and **§3 Architecture** – they apply to every workstream. 2. Pick a workstream from **§7 Workstreams**. Check its *Depends on* list is done. 3. Use the *Legacy reference* files only to understand behaviour. **Do not copy legacy code style** – re-implement following §2. 4. Satisfy every item in *Acceptance criteria* before marking the workstream done. 5. Update **§8 Parity checklist** and the endpoint table in **§5** when you finish. 6. Never modify anything inside `reference/`. Shared agent rules live in [AGENTS.md](../AGENTS.md), style rules in [.github/instructions/](../.github/instructions/) and role agents in [.github/agents/](../.github/agents/): | Agent | Workstreams | |---|---| | `wgd-orchestrator` | coordinates all, delegates, updates statuses | | `wgd-legacy-researcher` | read-only legacy behaviour lookups | | `wgd-reviewer` | read-only review + lint/tests | | `wgd-foundation` | WS-0 | | `wgd-wireguard` | WS-1, WS-2 | | `wgd-features` | WS-3, WS-4 | | `wgd-auth` | WS-5, WS-6 | | `wgd-migration` | WS-7 | | `wgd-devops` | WS-8 | | `wgd-frontend` | WS-9, WS-10, WS-11 | --- ## 1. Ground rules - Readability is the top priority. More lines of clear code beats fewer lines of clever code. - Routes are thin; business logic lives in services; SQL lives in the database layer; subprocess calls live only in `src/modules/wireguard/cli.py`. - Every new backend feature ships with pytest tests; every new frontend store/composable ships with Vitest tests. - Every schema change ships with an Alembic migration. - No secrets in logs. No `shell=True`. No raw SQL string formatting. - Keep the existing response envelope (`make_resp_obj`, see §4.1). --- ## 2. Coding style (mandatory) The legacy codebase often uses compact, dense constructs. The rewrite deliberately does the opposite. ### 2.1 Before / after Legacy (`reference/src/modules/WireguardConfiguration.py` ~L915): ```python "Total": sum(list(map(lambda x: x.cumu_data + x.total_data, self.Peers))), "ConnectedPeers": len(list(filter(lambda x: x.status == "running", self.Peers))), ``` Rewrite: ```python total_data_usage = 0.0 connected_peer_count = 0 for peer in peers: total_data_usage += peer.cumulative_data + peer.total_data if peer.status == PeerStatus.RUNNING: connected_peer_count += 1 ``` Legacy (`WireguardConfiguration.py` ~L1170): `list(islice(filter(lambda ip: ..., map(lambda iph: ..., network.hosts())), threshold))` Rewrite: a named helper `find_available_addresses(network, used_addresses, limit)` with a plain `for` loop and an early `break`. ### 2.2 Python rules 1. No `lambda`, `map()` or `filter()`. Use `for` loops, or a single-level comprehension with at most one simple `if`. 2. No nested ternaries; a ternary must fit comfortably on one short line. 3. One action per line. Use descriptively named intermediate variables instead of chained calls. 4. Early returns over nested `if/else`. Max ~3 indentation levels inside a function body. 5. Descriptive names: `peer`, `interface_name`, `allowed_ips` – never `p`, `ca`, `iph`, `x`. 6. Type hints on **every** parameter and return value. SQLAlchemy models use 2.0 `Mapped[...]` / `mapped_column`. 7. Error convention: functions return `tuple[bool, value]` (as already used in `config.py`). Be consistent. *(See decision D5.)* 8. Logging (from `GUIDELINES.md`): utility functions ALWAYS log at DEBUG. Services log INFO on state changes and ERROR on failure. Use `import logging as log` as existing modules do. 9. Never `subprocess` with `shell=True`. Arguments are lists. Only `wireguard/cli.py` may call `wg`/`awg`/`wg-quick`/`awg-quick`/`ip`/`iptables`. 10. Function ≲ 50 lines, file ≲ 400 lines. Split by responsibility. 11. Enums / constants instead of magic strings (`PeerStatus`, `Protocol`, `JobAction`, `JobOperator`). 12. Keep existing conventions: `#!/bin/env python3` header, snake_case functions, classes grouping `@staticmethod`s where already used, `'''docstring'''` one-liners. ### 2.3 Vue rules 1. `