Sign in to create and edit playbooks. Sign In Register

Implement Backend

BPE-2 Order: #2 Construction Has Dependencies

Updated 4 weeks, 2 days ago

Guidance

Purpose

Implement backend services, models, and views following test-first development and small increments approach.

Steps

1. Create Skeletons

Create all class and method skeletons with full docstrings following your language's documentation conventions.

The core principle: the developer who has no knowledge of the system can implement methods/properties etc. following only documentation in the skeleton.

  • Create class and method/function stubs and document them
  • Include full docstrings, return types, and sample return values
  • Use appropriate placeholder (e.g., NotImplementedError, TODO, panic!, etc.)
  • Do not skip type hints or documentation
  • Add comments inside the methods pointing attention to the logic flow, exception handling, logging etc.

2. Write Behavior Tests Before Logic

Write unit tests before writing method logic using your test framework. Use real dependencies in integration scenarios - no mocking.

3. Implement Incrementally (behavior green)

Work method-by-method. Each method/property should be: implemented → behavior-tested → log-story tested (step 4) → agent-proof tested (step 4b when declared) → committed.

4. Log Story — Caplog in the Same Slice

For each footprint method covered by the plan's Log Story Script:

  1. Write test_*_log_story_happy and/or test_*_log_story_reject (red)
  2. Emit INFO logs that satisfy story beats (entry → config → validation → processing → branch → exit → error) per do-informative-logging
  3. Make log-story tests green using skill Pytest Log Story Assertions (tests/support/log_story.pyassert_log_story) once TFK-02 has bootstrapped the helper — per do-assert-log-story
  4. Never defer logging to a later "informative logging pass" slice

4b. Agent Proof — Same Slice (when SAO §17 / plan Section G in scope)

For each PRF row in the plan's Agent Proof Table:

  1. Write test_*_agent_story_happy and/or test_*_agent_story_reject marked @pytest.mark.agent_proof (red)
  2. Queue ordered LLM scripts from tests/fixtures/llm_scripts/<prf-id>/ via CAP-004 ScriptedLLM — only the LLM may be scripted; real DB, real tool registry
  3. Make agent-story tests green using skill Agent Integration Proof Patterns (tests/support/agent_story.pyassert_agent_story(...)) per do-assert-agent-story
  4. Assert control-plane trace beats (workflow, tools offered/called, domain effects, blackboard/plan state) — not assistant prose
  5. Never defer agent proofs to a later "agent testing pass" slice

5. Commit After Each Step

Write → run → test (behavior + log story + agent proof when declared) → evaluate → fix. Commit using Angular-style commit messages. Behavior, log-story, and agent-proof green in the same commit when declared.

Issue #N (when active): footer Refs #N on every slice commit; immediately gh issue comment N with `{short-sha}`, slice summary, next slice. Do not start the next plan slice until both are done. See rule do-github-issues.

6. Backend Architecture

  • Services Layer: Business logic shared between different interfaces (API, Web UI, CLI, etc.)
  • Repository Pattern: Data access abstraction (can be swapped)
  • Views/Controllers: Return appropriate responses for your framework
  • API Endpoints: Follow RESTful or your framework's conventions
  • Context/State: Always validate and document

7. Route Registration

Register new routes/endpoints with descriptive names. Follow your framework's conventions for URL/route structure.

8. Testing Views/Controllers

Use your framework's test client. Test responses, validate context/state, check templates/views used, test dynamic endpoints. Include caplog assertions for Log Story Script rows on those views.

9. Scan Skills

Query Playbook Skills where capability_domain in:
- BACKEND_FRAMEWORK — Backend implementation patterns for your tech stack
- TEST_FRAMEWORK — Testing patterns and best practices
- LOGGING_PATTERN — Logging implementation for your language
- LOG_STORY_TESTING — Pytest Log Story Assertions / caplog helpers
- AGENT_PROOF_TESTING — Agent Integration Proof Patterns / agent_story helpers
- DOCSTRING_FORMAT — Documentation format for your language

Apply reference implementations and patterns from matched Skills.

Rules

Before implementing, read each Rule below in this playbook (by slug), then apply it to every change in this activity's footprint. Do not rely on memory of the rule text; do not paraphrase the rule body into this activity.

Required:
- do-skeletons-first
- do-test-first
- do-not-mock-in-integration-tests
- do-informative-logging
- do-assert-log-story
- do-assert-agent-story (when plan Section G / SAO §17 PRF rows in scope)
- do-import-on-module-level
- do-write-concise-methods
- do-docstring-format
- do-follow-commit-convention
- do-small-increments
- pytest
- do-github-issues

Activity-specific (not a substitute for the rules above):
- Log-story tests (*_log_story_* / caplog) ship in the same red→green slice as behavior — no deferred logging pass.
- Agent-proof tests (*_agent_story_* / @agent_proof) ship in the same red→green slice as behavior when Section G declares PRF rows — no deferred agent-testing pass.

Success Criteria

  • All skeletons created with full documentation
  • Behavior tests written before implementation and passing
  • Log Story Script rows proven by passing *_log_story_* caplog tests in the same commit as behavior
  • Agent Proof Table rows proven by passing *_agent_story_* tests in the same commit as behavior (when Section G populated)
  • No deferred logging or agent-proof slice in the plan
  • Code committed with proper messages
  • Every slice commit for issue #N referenced in a GitHub issue comment with SHA
  • Routes/endpoints properly registered
  • Services layer properly structured
Details
Order:
#2
Phase:
Predecessor:
BPE-1 Plan Feature
Created:
Apr 12, 2026
Last Updated:
Aug 21, 2026
Workflow
Build Feature

Interactive, feature-by-feature AI-assisted development. Use BPE after ESM, DTA, DSP, and BSP are complete to build one feature spec at …

View Workflow
Assigned Agent
Dr. Dobbs v2

Cautious Developer Agent Guide Motto: "Code that's easy to prove correct is code that works" …

Rules
Input Artifacts 4
Output Artifacts

No output artifacts