Full-Stack Performance Optimizer — 4-Pillar CWV & TTFB Loop
Autonomous end-to-end Frontend, Backend, Edge Infra & Modularity optimization loop by Dương Phúc Khánh (khanhdp.com).
Free
Works with the AI Agents you already use
About this skill
When the user invokes /op-goal (or /goal /op-goal), execute this end-to-end autonomous loop across the 4-Pillar Performance & Modularity Quad (FE + BE + Infra + Refactor) without stopping until every target metric, modularity ceiling, deployment check, and skill distillation gate is 100% green.
- Load the 4-Pillar Performance & Modularity Quad Skills:
- Frontend:
frontend-performance-lighthouse - Backend:
backend-performance-optimization - Infra & Edge:
infra-performance-optimization - Structural Refactoring & Modularity:
code-simplification
- Frontend:
- Capture Live / Local Baseline Across All 4 Layers:
- Layer 1 — Edge CDN & Network Infra: Dissect cold vs. warm HTTP/2 connection timing (
Connect,TLS,TTFB) and inspectcf-cache-status,cf-ray,Cache-Control,CDN-Cache-Control, andVaryheaders. - Layer 2 — Backend App & Database: Measure server compute time (
Warm TTFB - 1 RTT), inspect Singleflight/Valkey cache hit rates, check DB connection pool settings, and runEXPLAIN (ANALYZE, BUFFERS)on slow queries. - Layer 3 — Frontend Browser & Bundles: Check HTML transfer size, hidden Suspense fallbacks (
grep -c 'id="S:0"'), RSC Flight payload bloat (self.__next_f.push), entry JS manifest chunks, and run headless Chrome Lighthouse (--form-factor=mobileSlow 4G +--preset=desktop). - Layer 4 — Codebase Modularity & Hygiene Audit: Scan source files (
find apps/ src/ -type f \( -name "*.ts" -o -name "*.tsx" \) ! -name "*.spec.*" ! -name "*.test.*" -exec wc -l {} + | sort -nr | head -n 20) to detect God-files (> 500 lines), duplicated business logic across components/services, scattered cross-cutting triggers, and dead/orphaned files.
- Layer 1 — Edge CDN & Network Infra: Dissect cold vs. warm HTTP/2 connection timing (
Apply root-cause fixes across Frontend, Backend, Infra, and Codebase Modularity following the 7-Rung Ladder:
- Frontend (
frontend-performance-lighthouse— Target 100/100 Mobile & Desktop, 0ms TBT, 0.000 CLS):- Eliminate RSC
<Suspense>div[hidden]#S:0traps around already-awaited Server Components and replaceuseSearchParams()in root client shells with Server Component prop passing +popstatelisteners. - Quarantine secondary tabs, modals, and heavy chart/table/export libraries (
React.lazy/next/dynamic) and bypass folder barrel (index.ts) imports so entry JS stays minimal (<50 KB). - Trim RSC Flight JSON payloads by pre-computing compact SSR summaries and fetching heavy time-series arrays on client interaction.
- Remove unused
next/font/googlepreloads or switchdisplay: 'swap'to'optional'on hero text to prevent Slow 4G LCP timer resets.
- Eliminate RSC
- Backend (
backend-performance-optimization— Target<10msServer Compute, 100% L1/L2 Cache Hit):- Wrap high-read SSR/API queries in Singleflight + Stale-While-Revalidate (
singleflight.execute/getOrSetCache). - Detach background SWR revalidation via
setTimeout(..., 0)so Server Component streaming never waits on background database promises. - Add a lightweight
.unref()background cache warmer (interval < ttlMs) with warm DB connection pooling (idle_timeout >= 120s) sonow < entry.expiresAtis permanently true. - Parallelize independent queries (
Promise.all), eliminate duplicate queries, and synthesize composite B-Tree indexes (Equality First, Range/Sort Second).
- Wrap high-read SSR/API queries in Singleflight + Stale-While-Revalidate (
- Infra & Edge (
infra-performance-optimization— Target<25msEdge HIT, Zero-Downtime Rollout):- Scope
Cache-ControlandCDN-Cache-Controlheaders withmissing: [{ type: 'header', key: 'rsc' }]so Cloudflare caches pure HTML document responses without poisoning RSC client navigations, while preserving browserbf-cache = 1.0(never emitno-storeon public pages). - Verify Reverse Proxy (Caddy/Nginx) Zstandard/Brotli compression and upstream
keepaliveconnection pooling. - Verify Linux VPS kernel
tcp_congestion_control = bbr, PostgreSQLshm_size&random_page_cost = 1.1, and Docker log rotation (max-size: 10m).
- Scope
- Structural Refactoring & Single-Source-of-Truth Consolidation (
code-simplification— Target<400 linesper file, Zero Duplication):- God-File Decomposition (
< 400 linestarget): Split bloated stores (Zustand/Redux), services (NestJS), and UI components into cohesive domain slices (types.ts,calculations.ts,storage.ts,actions/*.ts, focused sub-components) while preserving barrel re-exports for 100% backward compatibility. - Single-Source-of-Truth Consolidation: Deduplicate repeated state-merging logic, scattered auth/login triggers, and copy-pasted UI headers/modals into a single canonical hook or shared component.
- Dead Code & Legacy Shim Elimination: Delete unused components, unreachable fallback branches, and obsolete third-party SDK shims.
- God-File Decomposition (
- Mandatory Local Verification:
- Run the project's native build, linter, and test suites (
bun run build,bun run test,tsc --noEmit) and confirm zero errors before committing.
- Run the project's native build, linter, and test suites (
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Free forever
No account required to browse
Trust & safety
Security scan
Security scan passed 3 days ago
- Free with an Agensi account
Requires