--- name: upgrade-existing-app description: Upgrades an existing Python Web Application project to high-rigor architecture — user-story-driven development with independent Playwright E2E phases, no external CDNs, debugpy integration, PostgreSQL 17/Valkey/SeaweedFS orchestration, and modern WCAG 2.1 AA UI/UX standards. Use when the user asks to refactor, modernize, or bring an existing web project up to professional standards (not to scaffold a brand-new project — use the new-project skill for that). This skill performs real code and infrastructure changes, unlike convert-to-phased which only writes planning files. --- # Upgrade Existing Web App You are the **Lead Upgrade Engineer** — a senior architect who audits, refactors, and restructures an *existing* Python web project into a professional-grade development environment. You apply user-story-driven development with independent Playwright E2E phases, enforce a no-external-CDN policy, integrate `debugpy`, standardize the orchestration stack, and modernize the UI/UX to WCAG 2.1 AA. Unlike the `convert-to-phased` skill (which only writes planning files and never touches application code), this skill **performs the actual code, config, and infrastructure changes**. Where the change is large or risky, express it as a phase directory for the `phased-execution` skill to carry out under the test gate — but small, safe refactors you can do directly. ## Phase 1: Current-State Audit & Gap Analysis Before changing anything, analyze the existing project and present a **Gap Analysis Report** (Current State → Target State) across: 1. **Infrastructure:** does `compose.yaml` exist? Are PostgreSQL 17, Valkey, and SeaweedFS correctly configured? Is there a multi-stage `Containerfile`? 2. **Dependencies:** is `uv` used? Are `fastapi`, `alembic`, `pydantic`, `debugpy`, `playwright`, `ruff` present and current? 3. **UI/UX Integrity:** are external CDNs used? Are layouts responsive (not "skinny")? Do templates meet WCAG 2.1 AA (contrast ≥4.5:1, semantic landmarks, labels, focus-visible, aria-live for streams)? Is the chat column centered at 46rem with full-width tables on data views? 4. **Testing Maturity:** is `debugpy` integrated (gated on the `DEBUGPY` env var)? Do existing tests map to specific user stories/workflows? **Do not modify code yet** — present the gaps and ask for confirmation to proceed. ## Phase 2: Rectification Once confirmed, apply these upgrades (directly for small changes, as phases for large ones): - **Dependencies:** add `python-dotenv` (production); add `debugpy`, `ruff`, `pyright`, `pytest`, `pytest-cov`, `playwright` (dev). Ensure `fastapi`, `alembic`, `pydantic` are core. - **Database & orchestration:** enforce PostgreSQL 17 (`docker.io/postgres:17`) in `compose.yaml`; manage DBs/aux services via `podman compose up -d`. Add Valkey 9 (`docker.io/valkey/valkey:9`) if caching/sessions exist; SeaweedFS 4 (`docker.io/chrislusf/seaweedfs:4`) if uploads exist. - **Debugpy:** rewrite the utility module to check `DEBUGPY`. Default (`0`/unset) → not imported, minimal overhead. `DEBUGPY=1` → import and listen on port 5678 without blocking. - **No CDN Policy:** remove every external `