Files
KArtSell.Aegis/docs/COMMON_WORKFLOWS.md
T
kjh2064 07ad98ec12 refactor(docs): Optimize CLAUDE.md structure (47KB→12KB) + expand AGENTS.md v16.0
## Summary
- **CLAUDE.md optimization:** Move engineering guidelines to AGENTS.md only (governance lock)
  - Removed: Governance, Testing Strategy, Observability details, Common Workflows, Guardrails
  - Kept: Project status, timeline, architecture high-level overview, quick reference
  - Result: 47KB → 12.1KB (75% reduction, well within 40KB limit)

- **AGENTS.md expansion:** Add 5 missing engineering procedure sections
  - v16.0 Testing Strategy (xUnit/Vitest/Playwright organization, commands, rules)
  - v16.0 Backend Architecture (Vertical Slice, Database/Migrations, Hangfire Job Design)
  - v16.0 Frontend Architecture (Registry-driven screens, KBX contracts, UI adapter boundary)
  - v16.0 Observability (Logging, Tracing, Dashboards, Metrics)
  - v16.0 Common Workflows (Adding Vertical Slices, Refactoring, Creating Jobs)

- **New companion docs** (no duplication, supplement AGENTS.md):
  - docs/ARCHITECTURE_DETAILED.md — Deep dive on backend/frontend patterns
  - docs/COMMON_WORKFLOWS.md — Workflow procedures with examples
  - docs/GITEA_API_REFERENCE.md — Gitea API + External data sources

## Governance (enforced)
- All engineering procedures now in AGENTS.md ONLY
- CLAUDE.md = project context only (status, timeline, overview)
- Companion docs reference AGENTS.md (no duplicate guidance)
- No conflicting guidance across multiple sources

## Result
- CLAUDE.md: 12.1KB  (within 40KB limit)
- AGENTS.md: 44.8KB (comprehensive procedures)
- Single source of truth for all engineering guidelines

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-08-16 14:47:41 +09:00

4.4 KiB

Common Workflows

Reference: For quick commands, see CLAUDE.md "Quick Start" section.
Governance: All work follows AGENTS.md v16.0 and VIBE Coding Guardrails.

Adding a New Vertical Slice

  1. Scaffold the structure:

    python tools/scaffold_vertical_slice.py --name MyFeature --module ModelOperations
    
  2. Define the contract (before code):

    • Request/Response DTOs in Contracts/
    • Event schema in Contracts/Events/ if async coupling needed
    • Validation rules (vee-validate schema on FE, Fluent on BE)
  3. Implement backend slice:

    • Handler.cs: Orchestration, transaction handling
    • Policy.cs: Pure business logic
    • Sql.cs: Dapper queries (schema-qualified, no SELECT *)
    • Endpoint.cs: HTTP routing & status codes
    • README.md: Traceability link to requirement/ADR
  4. Write tests:

    • Unit: Policy, Mapper logic
    • Integration: Handler + Dapper + real DB
    • Verify Outbox events are created if async
  5. Implement frontend feature:

    • Feature module under features/<feature>/
    • Use features/<feature>/pages/ for route-level components
    • Use shared/ui/adapter/ for any UI component usage
    • Form validation with vee-validate + Zod schema from BE contract
  6. Validation gates (pre-merge):

    • Architecture tests pass
    • DB migration is idempotent (fresh/upgrade test)
    • No SELECT *, no direct cross-module queries
    • Outbox/Inbox tests if async
    • Frontend typecheck + test + build
    • E2E smoke test (if user-facing)

Refactoring (Characterized, Isolated, Verified)

  1. Characterize: Lock current behavior with tests + perf baseline + Golden data.
  2. Isolate: Separate I/O (Dapper queries, HTTP) from logic (Policy).
  3. Transform: One small change at a time (rename, extract, move).
  4. Verify: All tests pass, no perf regression, backtest algorithm changes against Golden.
  5. Simplify: Delete dead abstractions, feature flags, branches.
  6. Observe: Post-release SLO/DQ/model drift monitoring.
  7. Close Debt: Update Debt ID, leave ADR for future maintainers.

Creating a Background Job

  1. Define the command:

    public class MyJobCommand : ICommand
    {
        public Guid IdempotencyKey { get; set; }
        public Guid CorrelationId { get; set; }
        public string InputData { get; set; }
    }
    
  2. Implement the handler:

    • Idempotent: Re-run should be safe and produce same result.
    • Classify failures: transient/permanent/dq/business-hold.
    • Emit events to Outbox for async notifications.
  3. Schedule via Hangfire:

    await backgroundJobClient.EnqueueAsync<MyJobHandler>(h => h.Handle(command));
    
  4. Test retry & replay scenarios:

    • Job runs successfully.
    • Job fails and is retried (verify idempotency).
    • Job is replayed from cold state (verify determinism).

Testing Strategy

xUnit Backend Tests

dotnet test KArtSell.sln -c Release
dotnet test --filter "Category=Integration" -c Release
dotnet test --filter "FullyQualifiedName~UnitTests" -c Release --verbosity quiet

Test Levels:

  1. Unit: Pure functions (Policy, Mapper), no I/O. Fast, deterministic.
  2. Integration: Handler + Dapper + real PostgreSQL. Validates transaction boundaries, Outbox/Inbox.
  3. Data: SQL query validation, schema conformance, index effectiveness.
  4. E2E: Full HTTP stack; used sparingly for critical paths.
  5. Golden/Frozen OOS: Before merging algorithm changes, lock baseline and diff against new run.

Vitest Frontend Tests

cd frontend
pnpm test                           # Run all tests
pnpm test -- --reporter=verbose     # Verbose output
pnpm test -- <test-file-pattern>    # Run subset
pnpm test -- --coverage             # Coverage report

Playwright E2E

cd frontend
pnpm e2e                            # Run all E2E tests headless
pnpm e2e -- --debug                 # Debug mode (browser stays open)
pnpm exec playwright test --headed  # Run with browser UI

Tools & Scripts

Scaffolding

python tools/scaffold_vertical_slice.py --name MyFeature --module ModelOperations
python tools/scaffold_ui_screen.py --name MyScreen --feature MyFeature

Validation

python tools/validate_v16.py          # Full v16 validation (contracts, migrations, Python tests)
python -m unittest discover           # Run all Python unit tests