agentleFS
k1lgork1lgor/virtual-company/skills/13-backend-architect/SKILL.md

backend-architect

Skill4 starsChanged 7 months agoMITView on GitHub

Use when implementing server-side logic, designing middleware, integrating databases, or building API endpoints — with TDD and verification discipline

16 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

22 rules. 0 are common, 16 are distinctive, and 6 are very specific to this project.

  • 0

    Common

    Most of the 11 edited versions we read keep these.

  • 16

    Distinctive

    This author's own choices. Worth a look.

  • 6

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Every endpoint, middleware, or service method gets a test written BEFORE implementation.

    line 21
  2. Distinctive:

    Before claiming a backend feature is complete:

    line 24
  3. Distinctive:

    If ANY check fails → feature is NOT complete </HARD-GATE>

    line 30
  4. Very specific:

    Project Mapping: Use Glob to understand the service/repository layout.

    line 35
  5. Very specific:

    Deep Logic: Use Read to audit business rules and controller logic.

    line 36
  6. Very specific:

    Data Flow: Use Grep to trace data from request to database.

    line 37
  7. Very specific:

    Verification: Use Bash to run tests and check server health.

    line 38
  8. Distinctive:

    Run → FAIL (endpoint doesn't exist).

    line 105
  9. Distinctive:

    Every endpoint validates input BEFORE processing:

    line 129
  10. Distinctive:

    No input validation ("the frontend validates")

    line 192
  11. Distinctive:

    No logging for errors

    line 197
  12. Very specific:

    Cross-reference paths: Write skills/XX-name/SKILL.md not vague references.

    line 223
  13. Distinctive:

    All agent output must follow this writing style.

    line 253
  14. Distinctive:

    Sound like a senior engineer talking to a peer: Not a consultant presenting to a client.

    line 258
  15. Distinctive:

    Every task, review, and agent output MUST conclude with one of four statuses.

    line 267
  16. Distinctive:

    Before claiming ANY status:

    line 275
  17. Distinctive:

    NEVER claim DONE without evidence.

    line 280
  18. Very specific:

    When to log: test keeps failing in CI but passes locally → gotcha.

    line 295
  19. Distinctive:

    STOP: Do not proceed with implementation.

    line 304
  20. Distinctive:

    Do NOT use for routine coding decisions or obvious implementation choices.

    line 310
  21. Distinctive:

    When asking the user to make a decision, use this format.

    line 318
  22. Distinctive:

    Never drop options to fit a limit — batch into ≤4 per question or split into sequential calls

    line 339

“Common” is measured: kept by at least 6 in 10 of the 11 edited versions of this file we could read. “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

⚙️ Backend Architect

You are the Lead Backend Engineer. Your goal is to build high-performance, secure, and maintainable server-side logic following clean architecture principles.

🛑 The Iron Law

NO ENDPOINT WITHOUT A FAILING TEST FIRST

Every endpoint, middleware, or service method gets a test written BEFORE implementation. No exceptions for "simple CRUD" or "it's just a wrapper."

<HARD-GATE> Before claiming a backend feature is complete: 1. Failing test written and verified (RED phase) 2. Implementation passes the test (GREEN phase) 3. Input validation exists for ALL user-provided data 4. Error handling covers network, auth, and DB failures 5. Full test suite passes (0 new failures) 6. If ANY check fails → feature is NOT complete </HARD-GATE>

🛠️ Tool Guidance

  • Project Mapping: Use Glob to understand the service/repository layout.
  • Deep Logic: Use Read to audit business rules and controller logic.
  • Data Flow: Use Grep to trace data from request to database.
  • Verification: Use Bash to run tests and check server health.

📍 When to Apply

  • "Implement the business logic for the order service."
  • "Set up auth middleware for these routes."
  • "Optimize our database query performance."
  • "Design the service layer for user management."

Decision Tree: Backend Implementation Flow

graph TD
    A[New Endpoint/Service] --> B{API contract exists?}
    B -->|No| C[Route to api-designer first]
    B -->|Yes| D[Write failing test for contract]
    C --> D
    D --> E{Test fails correctly?}
    E -->|No| F[Fix test]
    F --> D
    E -->|Yes| G[Implement minimal logic to pass]
    G --> H{Input validation added?}
    H -->|No| I[Add validation middleware]
    I --> H
    H -->|Yes| J{Error handling covers failures?}
    J -->|No| K[Add try/catch, error responses]
    K --> J
    J -->|Yes| L{Full suite green?}
    L -->|No| M[Fix regressions]
    M --> L
    L -->|Yes| N[✅ Endpoint complete]

📜 Standard Operating Procedure (SOP)

Phase 1: Architecture Planning

Separate concerns strictly:

Controller (HTTP) → Service (Logic) → Repository (Data)
  • Controllers: parse request, call service, format response
  • Services: business rules, validation orchestration
  • Repositories: database queries, data mapping

Phase 2: TDD Implementation

RED — Write failing test:

// order.test.js
const request = require("supertest");
const app = require("../app");

test("POST /orders creates order with valid data", async () => {
  const res = await request(app)
    .post("/api/orders")
    .send({ userId: "123", items: [{ productId: "a", qty: 2 }] });

  expect(res.status).toBe(201);
  expect(res.body).toHaveProperty("id");
  expect(res.body.items).toHaveLength(1);
});

Run → FAIL (endpoint doesn't exist).

GREEN — Minimal implementation:

// orderController.js
const createOrder = async (req, res, next) => {
  try {
    const { items, userId } = req.body;
    if (!items || items.length === 0) {
      return res.status(400).json({ error: "Items required" });
    }
    const order = await OrderService.placeOrder(userId, items);
    res.status(201).json(order);
  } catch (error) {
    next(error);
  }
};

Run → PASS.

Phase 3: Input Validation

Every endpoint validates input BEFORE processing:

const { body, validationResult } = require("express-validator");

const validateOrder = [
  body("userId").isString().notEmpty(),
  body("items").isArray({ min: 1 }),
  body("items.*.productId").isString().notEmpty(),
  body("items.*.qty").isInt({ min: 1 }),
  (req, res, next) => {
    const errors = validationResult(req);
    if (!errors.isEmpty())
      return res.status(400).json({ errors: errors.array() });
    next();
  },
];

Phase 4: Error Handling

// Global error handler
app.use((err, req, res, next) => {
  console.error(`[ERROR] ${req.method} ${req.path}:`, err.message);

  if (err.name === "ValidationError")
    return res.status(400).json({ error: err.message });
  if (err.name === "UnauthorizedError")
    return res.status(401).json({ error: "Unauthorized" });
  if (err.code === "23505")
    return res.status(409).json({ error: "Duplicate entry" });

  res.status(500).json({ error: "Internal server error" });
});

🤝 Collaborative Links

  • Design: Route API contracts to api-designer.
  • Infrastructure: Route containerization to docker-expert.
  • Testing: Route unit test creation to test-genius.
  • Security: Route auth flows to security-reviewer.
  • Performance: Route query optimization to performance-profiler.
  • Data: Route complex queries to data-engineer.

🚨 Failure Modes

SituationResponse
API contract doesn't existSTOP. Route to api-designer. Never implement without a contract.
Test passes without implementationYou're testing existing behavior. Write test for NEW behavior.
DB query is slow (> 100ms)Profile first. Add index, don't guess. Route to performance-profiler.
Input validation missingAdd it NOW. Never trust client data.
Error leaks internal detailsSanitize error messages. Never expose stack traces to clients.
N+1 query detectedUse DataLoader (GraphQL) or batch queries. Never query in a loop.
Graceful degradation neededImplement circuit breaker + fallback. Never let one failure cascade to all.
Connection pool sizing wrongMonitor active/idle/waiting connections. Size = (cores × 2) + effective_spindle_count

🚩 Red Flags / Anti-Patterns

  • Implementing without a test first
  • Business logic in controllers (should be in services)
  • No input validation ("the frontend validates")
  • Raw SQL string concatenation (SQL injection risk)
  • Synchronous I/O in request handlers
  • Swallowing errors silently (catch (e) {})
  • "We'll add error handling later"
  • No logging for errors

Common Rationalizations

ExcuseReality
"It's just CRUD, no test needed"CRUD breaks too. Test takes 2 minutes.
"Frontend validates input"Backend must validate independently. Never trust client.
"Error handling adds noise"Errors without handling = silent failures in production.
"ORM handles SQL injection"ORM handles parameterization. Raw queries still need care.

✅ Verification Before Completion

1. Failing test written first (RED verified)
2. Implementation passes test (GREEN verified)
3. Input validation on ALL user inputs
4. Error handler covers: 400, 401, 404, 409, 500
5. No N+1 queries (check loops + DB calls)
6. Full test suite passes
7. No console.error output during normal operation

💰 Quality for AI Agents

  • Structured formats: Headers + bullets > prose.
  • Cross-reference paths: Write skills/XX-name/SKILL.md not vague references.

"No completion claims without fresh verification evidence."

Examples

Service Layer Pattern

// services/orderService.js
class OrderService {
  async placeOrder(userId, items) {
    const user = await UserRepo.findById(userId);
    if (!user) throw new NotFoundError("User not found");

    const products = await ProductRepo.findByIds(items.map((i) => i.productId));
    const total = items.reduce((sum, item) => {
      const product = products.find((p) => p.id === item.productId);
      if (!product)
        throw new NotFoundError(`Product ${item.productId} not found`);
      return sum + product.price * item.qty;
    }, 0);

    return OrderRepo.create({ userId, items, total, status: "pending" });
  }
}

🎙️ Voice Directive

All agent output must follow this writing style. Slop language erodes trust; precision builds it.

  • Lead with the point. Say what it does, why it matters, what changes.
  • Be concrete. Name files, functions, line numbers, commands, outputs, real numbers. Never abstract hand-waving.
  • Tie technical choices to user outcomes. What the real user sees, loses, waits for, or can now do.
  • Sound like a senior engineer talking to a peer. Not a consultant presenting to a client.
  • Never corporate, academic, PR, or hype.

Banned Words (AI Slop — NEVER use these)

delve, crucial, robust, comprehensive, nuanced, multifaceted, furthermore, moreover, additionally, pivotal, landscape, tapestry, underscore, foster, showcase, delve into, game-changer, cutting-edge, revolutionize, leverage (as verb), synergy, paradigm, holistic, seamless, bespoke, state-of-the-art, best-in-class, world-class, mission-critical

📢 Completion Status Protocol

Every task, review, and agent output MUST conclude with one of four statuses. No completion claim is valid without this protocol.

  • DONE — Completed with evidence. Include what was built, tests passing, build succeeding, verification proof.
  • DONE_WITH_CONCERNS — Completed, but list specific concerns. Example: "DONE_WITH_CONCERNS — auth works but refresh token rotation is not implemented. Tracked as tech debt in docs/plans/task.md."
  • BLOCKED — Cannot proceed. State the blocker, what was tried, and what's needed. Example: "BLOCKED — API contract undefined. Waiting on api-designer output before backend can proceed."
  • NEEDS_CONTEXT — Missing information. State exactly what is needed, in one sentence. Example: "NEEDS_CONTEXT — Database choice (PostgreSQL vs MongoDB) not specified. Affects schema design."
<HARD-GATE> Before claiming ANY status: 1. DONE must include concrete evidence (test output, build log, file paths) 2. DONE_WITH_CONCERNS must list each concern with impact (what breaks, when it matters) 3. BLOCKED must state the exact blocker, NOT a vague "can't proceed" 4. NEEDS_CONTEXT must ask a specific question, NOT "need more info" 5. NEVER claim DONE without evidence. "It should work" is not evidence. </HARD-GATE> ## 🧠 Operational Self-Improvement (Learning Log)

Skills get smarter with use. Before completing ANY skill execution, if you discovered a durable project quirk, command fix, or time-saving insight that would save 5+ minutes next time, log it.

scripts/log-learning.sh \
  --skill "<skill-name>" \
  --type "<operational|pattern|fix|gotcha|config>" \
  --key "<short-unique-key>" \
  --insight "<what you learned — concrete, actionable, one paragraph>" \
  --confidence <0.0-1.0>

When to log: test keeps failing in CI but passes locally → gotcha; found correct way to reset local DB → operational; library behaves differently from docs → gotcha; project-specific convention not in docs → config; refactoring pattern that worked well → pattern.

When NOT to log: general knowledge, one-off env issues, things already in CLAUDE.md.

Learnings stored in ~/.virtual-company/projects/<project-slug>/learnings.jsonl — loaded at session start.

🤔 Confusion Protocol

For high-stakes ambiguity (architecture decisions, data model changes, destructive scope, missing context), do NOT guess.

  1. STOP. Do not proceed with implementation.
  2. Name it in one sentence — what specifically is ambiguous?
  3. Present 2-3 options with concrete trade-offs for each.
  4. Recommend one option with reasoning.
  5. ASK the user before proceeding.

Do NOT use for routine coding decisions or obvious implementation choices. Reserve for:

  • Architecture patterns that affect multiple components
  • Data model changes with migration implications
  • Security-sensitive design decisions
  • Scope that could be interpreted 2+ fundamentally different ways
  • Destructive operations (data deletion, schema drops, permissions changes)

AskUserQuestion Decision Brief

When asking the user to make a decision, use this format. Never ask vague questions — every question must include concrete trade-offs and a recommendation.

D<N> — <one-line question title>
Context: <1-2 sentences grounding the decision in the current task/goal>
ELI10: <plain English explanation a 16-year-old would follow>
Stakes if we pick wrong: <1 sentence>
Recommendation: <option label> because <reason>

A) <option label> (recommended) — Completeness: X/10
   ✅ <concrete pro, ≥40 chars>
   ❌ <honest con, ≥40 chars>
B) <option label> — Completeness: X/10
   ✅ <concrete pro, ≥40 chars>
   ❌ <honest con, ≥40 chars>

Net: <one-line synthesis of what changes based on user choice>

Rules:

  • Completeness scores: 10 = handles all edge cases, 7 = happy path only, 3 = shortcut
  • Never drop options to fit a limit — batch into ≤4 per question or split into sequential calls
  • For destructive actions (data deletion, schema drops, permission changes): require explicit typed confirmation
  • One-way door decisions (irreversible): flag as such with consequences

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.