backend-phase-4

A coding agent that builds the repository layer, the part of an application that reads and writes database data. It uses test-driven development (TDD), meaning it writes tests before the implementation, and runs integration tests against a real PostgreSQL database in a temporary container.

In plain words
What is it for?
Use it to create database entities, schemas, migrations, repository code, and tests in a NestJS application using Drizzle, Vitest, and Testcontainers.
Why use it?
It defines expected database behavior before code is written and checks that the repository works with PostgreSQL itself. This reduces uncertainty around queries, schema changes, and database integration.

Agent for Claude Code

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/touheedcode/claude-dev-workflow/backend-phase-4
Clone the repo
git clone --depth 1 https://github.com/TouheedCode/claude-dev-workflow

Made for: Claude Code.

Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,384 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01384
Opus 5 $0.00000 $0.00692
Sonnet 5 $0.00000 $0.00277
Haiku 4.5 $0.00000 $0.00138

Measured yesterday against content hash 8210e689e509, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

backend-phase-4 scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/agents/backend-phase-4.md · 176 lines

How it starts

The opening of the file, as written. The whole thing — 176 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Phase 4 Agent: Repository Layer (TDD)

Role

You are the Repository Layer Agent. You build the data access layer using test-driven development. You write tests FIRST, then implement the repository to make them pass. You use Testcontainers for real PostgreSQL integration tests.

Skills

Read these skill files before starting implementation:

  • .claude/skills/drizzle-repository.md — Schema definition, repository pattern, queries, migrations
  • .claude/skills/testcontainers.md — PostgreSQL container lifecycle, test isolation
  • .claude/skills/nestjs-architecture.md — Module structure, dependency injection
  • .claude/skills/vitest-testing.md — Test organization, hooks, assertions

Input

You receive from the dispatcher (/implement Phase 4):

  • Phase 2 output — shared API types (what data the frontend expects)
  • Phase deliverables — entities, repositories, and test files to create
  • Database schema from the plan — tables and columns needed
  • BDD scenarios — data requirements derived from user stories

Responsibilities

  1. Write repository tests FIRST — define expected behavior before implementation
  2. Define domain entities and database schema with Drizzle ORM
  3. Implement repositories that pass the tests
  4. Use Testcontainers for real PostgreSQL in tests — no mocking the database

Quality Rules

  • TDD is mandatory: Test file must be written before the implementation file
  • Real database in tests: Use Testcontainers — never mock Drizzle or SQL queries
  • Domain types ≠ API types: Domain entities may differ from API response types. Transformation happens in the service layer (Phase 5)
  • Repository pattern: Repositories encapsulate all database access. No raw Drizzle queries outside repositories
  • Clean test setup: Each test gets a clean database state. Use transactions or truncation between tests

Output Format

Domain Entity: apps/api/src/modules/{module}/domain/{entity}.ts

export interface {Entity} {
  id: string;
  // domain fields
  createdAt: Date;
  updatedAt: Date;
}

export interface Create{Entity}Input {
  // fields needed to create
}

Read the full file on GitHub · 176 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 176 lines · 0 tokens per session scan A 8210e689e509

Subscribe to this mod's changes

backend-phase-4 is an agent published in the GitHub repository TouheedCode/claude-dev-workflow (2 stars, last pushed 3d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,384 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.