agentleFS
yerdaulet-damiryerdaulet-damir/vibe-coding-rules/.claude/skills/debug-backend/SKILL.md

debug-backend

Skill28 starsChanged 7 months agoMITView on GitHub

Systematic 5-step backend debugging flow for AI-coded FastAPI apps. Load this skill when a bug is reported, a test fails, or unexpected behavior appears in any backend layer. Forces layer isolation before touching code — prevents the "touch 8 files and make it worse" pattern.

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Stop. Do not edit any file yet.

    line 8
  2. Distinctive:

    Run these greps to find where the bug lives.

    line 14
  3. Distinctive:

    Before changing any production code, write a failing test that captures the exact bug.

    line 60
  4. Distinctive:

    After fixing: run the reproducing test.

    line 94
  5. Distinctive:

    Must exit 0. If a check fails, the fix introduced a new architecture violation — revert and fix properly.

    line 109

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

debug-backend

Stop. Do not edit any file yet. Work through these 5 steps in order.


Step 1 — Locate the layer

Run these greps to find where the bug lives. Check one layer at a time.

# Is it a routing problem? (wrong status code, missing auth, bad request parsing)
grep -n "HTTPException\|status_code\|Depends(" app/routers/<file>.py

# Is it a service logic problem? (wrong calculation, wrong state transition)
grep -n "def \|raise \|return " app/services/<file>.py

# Is it a repository problem? (wrong query, missing user_id scope, transaction issue)
grep -n "SELECT\|filter\|where\|FOR UPDATE" app/repositories/<file>.py

# Is it a provider problem? (timeout, wrong response shape, missing error handling)
grep -n "httpx\|raise\|return\|except" app/providers/<file>.py

Decision: fix only in the layer where the bug lives. Never fix a service bug in the router.


Step 2 — Check the 3 most common AI antipatterns

These cause 80% of production bugs in AI-coded backends. Grep for each:

# Antipattern 1: SQLAlchemy Session leaked into services
grep -rn "AsyncSession\|Session\|from sqlalchemy" app/services/

# Antipattern 2: Provider returning raw dict instead of domain type
grep -rn "return {" app/providers/

# Antipattern 3: Business logic in router (calculation, state change, external call)
grep -c "await.*service\|await.*repo\|if.*balance\|FOR UPDATE" app/routers/*.py
ResultRoot causePrinciple
Session in servicesHexagonal boundary brokenB1
return {} from providerMissing ACLB3
Logic in routerLayer violationA3 / code-standards
No user_id filter in queryMulti-tenancy gapsecurity-rules

Step 3 — Write a reproducing test first

Before changing any production code, write a failing test that captures the exact bug.

# Template: place in tests/unit/ or tests/integration/
async def test_<bug_description>():
    # Arrange: minimal setup that triggers the bug
    repo = FakeCreditsRepo()
    repo.seed_balance("user-1", Decimal("5.00"))
    service = CreditsUserService(repo=repo)

    # Act: call the exact code path that fails
    with pytest.raises(ValueError, match="Insufficient balance"):
        await service.charge("user-1", Decimal("10.00"), idempotency_key="idem-1")

    # Assert: prove the invariant that was violated
    assert await repo.get_balance("user-1") == Decimal("5.00")  # not negative

Run it: pytest tests/unit/test_<file>.py::test_<bug_description> -v It must be RED before you fix anything.


Step 4 — Fix in the correct layer

Minimum change. No opportunistic refactoring. No unrelated cleanup.

Router bug   → fix only app/routers/
Service bug  → fix only app/services/
Repo bug     → fix only app/repositories/
Provider bug → fix only app/providers/

After fixing: run the reproducing test. It must turn GREEN.

pytest tests/unit/test_<file>.py::test_<bug_description> -v
# Expected: PASSED

Step 5 — Run architecture lint

bash scripts/lint-architecture.sh

Must exit 0. If a check fails, the fix introduced a new architecture violation — revert and fix properly.


Common error → root cause table

ErrorWhere to look firstLikely cause
422 Unprocessable EntityRouter — Pydantic schemaWrong field type or missing required field
500 Internal Server ErrorService — exception not caughtProvider returned unexpected shape (dict not JobResult)
KeyError: 'url'Provider — ACL missingProvider response changed, parser not updated
InsufficientFunds on correct balanceRepo — concurrent holdTwo requests raced, no FOR UPDATE lock
401 on authenticated routeRouter — Depends(get_current_user_id) missingAuth dependency not wired
Test passes, prod failsRepo — fake vs real divergedFakeCreditsRepo doesn't match CreditsRepoProtocol
Logs silent on errorService — bare except:Exception swallowed, add logger.exception(...)

Verification

The skill was applied correctly when:

  • A failing test exists that reproduces the bug
  • Fix touches exactly one layer
  • bash scripts/lint-architecture.sh exits 0
  • No unrelated files were modified
  • The reproducing test is now green

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.