c_agri_trade/process/.agents/skills/up-code-generate/SKILL.md

78 lines
6.8 KiB
Markdown

---
name: up-code-generate
description: Generate production-grade backend services, frontend views/screens, database migrations, API contracts, and integration adapters for the stories in the current iteration's backlog, with explicit delivery-surface coverage across portal/frontend, API, data, integration, infrastructure, and QA. Use this after up-wireframe-spec and up-test-model-generate have produced the iteration's screens, surface matrix, and test cases. Covers Stage 13 (Construction) of the UP-AI v1.0 Process (process/AI_Native_Unified_Process_v1.md).
---
# up-code-generate — Stage 13 (Construction, per iteration)
## Objective
Implement the current iteration's stories as production-grade code — backend services, frontend screens/views, database migrations, API contracts, and integration adapters — adhering to the technology stack configured in `tech-profile.yaml` and requirement-driven development principles.
## When to invoke
- After `up-wireframe-spec` and `up-test-model-generate` have produced this iteration's screens and test cases.
- Repeatedly within an iteration, once per story or logical group of related stories.
## Read first
- `tech-profile.yaml` (specifies backend language, framework, ORM, migrations, frontend framework, auth provider, and sandboxes)
- Current iteration's `04_generated_documentation/05_iteration_planning/iterations/iteration-NN/iteration_backlog.md` (STORY-xxx list)
- Current iteration's `iteration_surface_matrix.md` (required delivery surfaces and owners)
- Current iteration's `parallel_work_plan.md` (if parallel lanes are active)
- Owning `04_generated_documentation/04_architecture_design/lld/LLD-0xx_*.md` (API/table/event contracts)
- Owning use case's `functional-reqs.md` (acceptance criteria, validation, audit requirements)
- This iteration's wireframes (`04_generated_documentation/06_wireframes/`) and test cases (`04_generated_documentation/07_test_design/`)
- `04_generated_documentation/06_wireframes/DESIGN.md` or active design system tokens
- `architecture_spike_report.md` (service template conventions)
## Procedure
Pick the next `STORY-xxx` with status "Ready" from the iteration backlog. Implement only that story (or related group) per invocation:
Confirm every applicable surface in `iteration_surface_matrix.md` has an owner and repository path. If the story requires a frontend screen, frontend code is mandatory unless an approved `CR-xxx`/`DEC-xxx` explicitly defers it.
**Backend service generation:** Implement against the LLD API contract exactly — request/response shapes, status codes, error format, RBAC checks, tenant-context propagation, validation, and audit logging. Use the backend language/framework specified in `tech-profile.yaml`.
- When `framework: frappe`, organize code within the target Frappe App, authoring DocType controllers (`<doctype>.py`), whitelisted remote procedures (`@frappe.whitelist()`), server scripts, and event hooks (`hooks.py`).
- When `framework: django` or `fastapi` or `spring_boot`, implement service controllers, repositories, and API routers matching LLD endpoint contracts.
Write unit and integration tests covering the story's acceptance criteria. Add or update API collections (Bruno `.bru` or OpenAPI spec) for added/changed endpoints.
**Frontend screen generation:** Implement against the iteration's wireframe/field-level spec — fields, validation, navigation, error states.
- When `frontend.framework: frappe_desk`, configure DocType FormViews, ListViews, Workspaces, and client scripts (`<doctype>.js`), or custom Vue/React SPAs using `@frappe/ui`.
- When standard React/Vue/Angular, reuse `DESIGN.md` component library, tokens, and Tailwind/shadcn controls.
Write corresponding component and browser-E2E tests (e.g. Playwright) tagged with `UC-xxx`/`FR-xxx`/`STORY-xxx`.
**Database implementation:** Generate schema matching the LLD table definitions via the migration mechanism configured in `tech-profile.yaml`:
- When `framework: frappe`, author DocType schema JSON files (`<doctype>.json`) with fieldtypes, options, and permissions, synchronized into MariaDB/PostgreSQL via `bench migrate`.
- When SQLAlchemy/Django/Spring Boot/Prisma, generate migration files via Alembic, Django migrations, Flyway, or Prisma; do not hand-edit schema outside migrations.
**Integration adapters:** Implement external API triggers, requests, and failure handling against the contracts in `tech-profile.yaml`. Consume and verify against the Wave 0 Sandbox/Mock adapters so test suites run 100% deterministically and offline without external API dependencies.
Rules (apply to every story):
1. Do not introduce unrelated changes or refactor unrelated files.
2. Write unit/integration/contract/smoke/browser-E2E tests assigned to this story by `up-test-model-generate`.
3. Implement validation, error handling, structured logging, and audit trails where the FR requires it.
4. Enforce tenant isolation and authorization per the architecture spike's validated pattern.
5. Update `iteration_surface_matrix.md` with implementation status and verification evidence. In `traceability_graph.md`, transition requirement status to **`Implemented (Domain/Schema)`** upon code and unit test completion. DO NOT mark requirements as `Delivered` at this stage; `Delivered (E2E Verified)` is reserved for Gate 14.1 closure after all delivery surfaces, migrations, and dual QA assets pass.
6. Do not place secrets, live tokens, or production credentials in code, fixtures, logs, or commits.
7. **Strict Anti-Placeholder Rule:** Stub functions, mock controllers where real database logic was specified, and zero-coverage test stubs are strictly forbidden. All code must implement genuine business logic.
8. **Automated Test Coverage Budgets:** Ensure code meets the thresholds configured in `tech-profile.yaml`:
- Backend Domain & FSMs: **≥95.0%** statement and branch coverage.
- Integration Adapters: **≥90.0%** against Wave 0 sandboxes.
- Frontend UI Components: **≥80.0%** component branch coverage + mandatory Playwright browser-E2E tests for primary user journeys.
Exercise Happy Path, Alternate/Boundary, Failure, and FSM Invariant scenarios.
## Output expected
Source code changes; updated OpenAPI / Bruno specs in `docs/api/bruno/`; DB migrations; frontend portal artifacts; updated `iteration_surface_matrix.md`; requirement status transitioned to `Implemented (Domain/Schema)`; execution log.
## Exit criteria
Story implemented per LLD contract and screen spec across every applicable surface; API, data, integration, and frontend artifacts are synchronized; tests achieve configured coverage thresholds; requirements transitioned to `Implemented (Domain/Schema)`; ready for `up-defect-fix` and Gate 14.1.
## Related skills
Previous: `up-wireframe-spec`, `up-test-model-generate`. Next: `up-defect-fix` (code review, defect handling), then `up-traceability-gate` (Gate 14.1).