Skip to content

Latest commit

 

History

History
228 lines (163 loc) · 10 KB

react-implement-feature.workflow.md

File metadata and controls

228 lines (163 loc) · 10 KB
workflow_id WORKFLOW-REACT_IMPLEMENT_FEATURE_WORKFLOW
trigger manual
description Standard workflow for implementing React features using feature-based architecture

React Implement Feature Workflow

SDD Baseline

This workflow specializes WORKFLOW-COMMON_SDD_CHANGE_LIFECYCLE_WORKFLOW and applies RULE-COMMON_TEST_FIRST_DEVELOPMENT; the parent owns the single plan approval and technical Gate 3, the final evidence review, spec artifacts, routing, documentation, clean-up, security, coverage, and convergence. After the single plan approval, classify the lowest correct frontend test, create the smallest BDD-linked RED, apply the common test assertion/data rules, pass technical Gate 3, implement only the mapped minimum GREEN, and complete mandatory BLUE for production and tests while tests stay green. Do not duplicate or reorder the parent lifecycle here.

This workflow defines how an AI coding agent should implement or modify React frontend features.

Workflow Routing For REST Clients

When the feature consumes or changes a REST contract, invoke WORKFLOW-REACT_REST_API_CLIENT_WORKFLOW as supporting and WORKFLOW-COMMON_REST_API_DESIGN_WORKFLOW for the contract. Record both on the affected task; create workflow-routing.md only if multi-workflow ownership is ambiguous. Route Go/C# backend tasks to their backend workflow.

The workflow prioritizes:

  • Readability
  • Feature-based organization
  • Separation of UI and behavior
  • Good user experience
  • Maintainable React patterns
  • Avoiding unnecessary abstractions

This workflow intentionally does not force backend-style Clean Architecture into React.

For advanced reusable behavior, load languages/react/skills/react-advanced-patterns-skill.md and record the selected pattern and rejected simpler alternatives in the profile's design section/file.

It still enforces SDD for behavior changes:

  • User Stories before production code.
  • BDD Given/When/Then acceptance evidence.
  • Executable unit or component/page/route RED at the owning frontend boundary. Manual or visual QA is supplemental only and never unlocks production code.
  • Small vertical slices; add parallel-tracks.md ownership only for actual concurrent agent work.

Step 1 — Understand the Feature

Before writing code:

  • Locate the owning canonical capability and active risk-scaled change.
  • Confirm the BDD acceptance scenario and verification status.
  • When parallel execution is declared, check parallel-tracks.md before editing files.
  • Identify the user behavior.
  • Identify async interactions.
  • Identify REST/API-client boundaries and route them through WORKFLOW-REACT_REST_API_CLIENT_WORKFLOW before service or hook code.
  • Identify loading, error, and empty states.
  • Identify reusable UI vs feature-specific UI.
  • Identify whether URL state should be preserved.
  • Identify whether the feature belongs inside an existing feature folder.
  • Identify the current React/TypeScript version, compiler strictness, test runner, lint rules, styling system, and server-state approach before introducing APIs or dependencies.
  • Identify the state owner, external systems, accessibility contract, and error/recovery boundaries.
  • For every behavior partition, select test_type: unit | component | integration, the test path, standalone command, expected RED reason, and mapped production files before planning an implementation task.

Step 2 — Plan Feature Ownership

Prefer:

features/
└── crew-search/
    ├── components/
    ├── hooks/
    ├── services/
    ├── dto/
    └── types.ts

Avoid creating global shared code too early.

This step plans ownership and paths; it does not create production folders or files before RED.

Step 3 — Create The Correct RED First

Choose the lowest level that owns the next behavior:

  • unit for a pure reducer, parser, validator, mapper, or service policy;
  • component for a component, hook, page, route, accessibility state, or user interaction; or
  • integration for an owned real browser/network boundary when the repository defines that scope.

Record the stable TEST-*, behavior partition, standalone command, expected failure, and exact production files it may unlock. Write and run only that test plus behavior-free harness changes. Confirm RED for the intended missing behavior, prove the mapped production files are unchanged, and pass technical Gate 3. Manual QA, snapshots without behavioral assertions, typecheck, lint, or build output do not satisfy RED.

Step 4 — Implement The Smallest GREEN

Create only the types, service, hook, component, route, styles, or wiring required by the approved current RED. Do not build an entire feature stack ahead of its tests. If the next production responsibility is not mapped to the current test, stop and begin another RED cycle.

After the focused test is GREEN, complete BLUE before the next behavior partition. Refactor mapped production and test code, remove duplication/dead branches/inline lint suppression, improve feature ownership and test builders/fixtures, and keep every changed maintained source/test/configuration/CI/script file < 150 physical lines. Preserve React feature architecture; do not introduce backend-style Clean Architecture or ceremonial Value Objects. If BLUE needs new user-visible behavior, return to RED.

When the current GREEN needs them, create explicit TypeScript types for:

  • UI models
  • API responses when needed
  • Component props
  • Async states
  • Discriminated component variants and mutually exclusive props
  • Runtime parsing/narrowing types for untrusted API, storage, or URL input

Keep each external DTO type and its fromApi/toViewModel or equivalent mapping functions in the same DTO module. Use a boundary-local companion only for generated DTOs or deliberate multi-source projections; do not create a global mapper folder.

Use strict TypeScript where supported. Avoid any; use unknown and narrow it with type guards or a runtime schema. Use satisfies for typed configuration maps and generic constraints for reusable components.

Services

Services should:

  • Encapsulate API access.
  • Keep HTTP details out of components.
  • Return predictable data.
  • Avoid leaking transport details to the UI.
  • Keep the configured client, cancellation, error normalization, runtime parsing, and DTO-owned mapping at the boundary defined by WORKFLOW-REACT_REST_API_CLIENT_WORKFLOW.

Hooks

Hooks orchestrate feature behavior.

Hooks may:

  • Fetch or mutate data.
  • Coordinate local state.
  • Expose UI event handlers.
  • Normalize async states.
  • Coordinate cancellation, stale-response protection, retry, and refresh behavior when requests overlap.

Hooks should not:

  • Render UI.
  • Become giant service layers.
  • Mix unrelated workflows.
  • Derive values through effects when they can be computed during render.

Select Advanced Patterns Deliberately

Use the simplest pattern that satisfies the current contract:

  1. Plain typed component.
  2. Composition with children or named slots.
  3. Custom hook.
  4. Reducer/state machine for explicit transitions.
  5. Compound component for private shared state.
  6. Render prop when the caller must own rendering.
  7. HOC for repeated cross-cutting wrappers such as permissions, auth, telemetry, or feature flags.
  8. Strategy for typed mode-dependent behavior.
  9. Provider for stable cross-cutting subtree state.

For patterns 5–9, document the state owner, public TypeScript contract, reason simpler composition was insufficient, and the focused test that protects the behavior. Preserve refs and wrapped props in HOCs, keep context private in compound components/providers, and avoid speculative registries or plugin systems.

Components

Components should:

  • Focus on rendering.
  • Receive simple props.
  • Avoid business orchestration.
  • Avoid direct API calls.
  • Keep JSX readable.

Extract components when JSX becomes difficult to scan.

Async States

Every async screen must intentionally support:

  • Initial state.
  • Loading state.
  • Empty state.
  • Error state.
  • Success state.
  • Retry behavior when appropriate.
  • Initial load versus refresh/mutation states when users need to distinguish them.
  • Cancellation, stale response protection, and recovery from errors.

Step 5 — Refactor And Review While GREEN

Verify:

  • Semantic HTML.
  • Keyboard navigation.
  • Accessible labels.
  • Proper button and link usage.
  • Dialog focus management.
  • Meaningful alt text.

Performance Review

Review:

  • Large unnecessary renders.
  • Unnecessary global state.
  • Large dependencies.
  • Heavy components that should be lazy-loaded.
  • Very large lists without virtualization.
  • Stable domain keys instead of array indexes for dynamic collections.
  • React DevTools Profiler evidence before broad memo, useMemo, or useCallback changes.
  • useTransition/useDeferredValue only for verified non-urgent rendering work.
  • Stable provider values and split contexts when update frequency differs.

Do not add memoization everywhere by default.

Step 6 — Final Verification

Before completing the task:

  • Remove unused code.
  • Remove dead state.
  • Remove unnecessary abstractions.
  • Remove duplicated logic.
  • Simplify props.
  • Keep files focused.
  • Verify feature organization remains understandable.
  • Search the changed handwritten frontend scope for eslint-disable, eslint-disable-next-line, and eslint-disable-line; remove every directive and resolve the underlying lint finding.
  • Run TypeScript, lint, build, focused tests, accessibility checks, and the repository's coverage command when available.
  • Confirm every changed production file maps to the TEST-* that was RED before that file changed, with the test type/layer, Gate 3 technical result, and GREEN command recorded.
  • Confirm the spec records pattern choices, architecture boundaries, verification evidence, and remaining risks.

Anti-Patterns

Avoid:

  • Huge page components.
  • API logic directly inside JSX files.
  • Global state for local behavior.
  • Deep prop drilling when composition solves the issue.
  • Premature abstractions.
  • Strict backend Clean Architecture layers in frontend code.
  • Overusing Context for frequently changing state.