This document is the primary operating model for AI-assisted design-to-code work in the Spring Design Library. It defines how agents classify outcomes, choose file targets, build pages, inject components, validate changes, and hand off work for review.
The workflow is outcome-first: every request must name the intended result before any implementation begins.
1. Operating Principles
- Outcome before code. Classify the work as a component, gallery page, AppFlow screen, static page, token change, icon change, or documentation change before touching files.
- Reuse before creation. Search existing package exports, gallery pages, tokens, and AppFlow registries before proposing new files.
- Plan before implementation. Stop for user approval when structure, file placement, new tokens, new components, or route behavior is uncertain.
- Gallery as source of truth. The design library route under
/library/*is the visual handoff surface for page and AppFlow work. - Tokens are mandatory. No raw hex, arbitrary spacing, or unregistered visual values unless a token gap is approved and synced.
- Validation closes the loop. Every output must name the commands or checks that prove the workflow succeeded.
- Rules stay executable. Long explanations belong in
docs/ai/;.cursor/rules/should stay short and enforceable.
2. Outcome Types
Outcome A: Reusable Design System Component
Use this when the result should be imported from @spring/ds-react.
Required structure:
| Artifact | Target |
|---|---|
| Component | packages/spring-ds-react/src/components/<category>/<ComponentName>.tsx |
| Public export | packages/spring-ds-react/src/index.ts |
| Optional category barrel | packages/spring-ds-react/src/components/<category>/index.ts |
| Optional Code Connect | Follow the decision tree in docs/ai/workflow-contracts.md: package-side by default, gallery-side only for legacy navigations, overlays, and SpringSearchBar |
| Optional gallery doc | apps/design-library/src/gallery/pages/components/<category>/<ComponentName>Page.tsx |
| Optional route shell | apps/design-library/src/app/library/components/<category>/<kebab-name>/page.tsx |
| Optional nav entry | apps/design-library/src/gallery/navigation/libraryNav.ts |
Validation:
npm run lintnpm run buildnpm run code-connect:parsewhen*.figma.tsxfiles are touched
Outcome B: Gallery Documentation Page
Use this when documenting or demonstrating existing design system behavior.
Required structure:
| Artifact | Target |
|---|---|
| Page implementation | apps/design-library/src/gallery/pages/ |
| Route shell | apps/design-library/src/app/library/ |
| Navigation | apps/design-library/src/gallery/navigation/libraryNav.ts when the page is live |
Rules:
- Import reusable UI from
@spring/ds-react. - Do not define product primitives inside gallery pages.
- Keep route files thin; page logic belongs in
src/gallery/. - Do not add placeholder-only pages to navigation.
Validation:
- Route shell exists and imports the gallery implementation.
libraryNav.tspoints to the route only when the page is live.npm run build
Outcome C: AppFlow Screen
Use this for personal loan flow screens and step previews.
Required structure:
| Artifact | Target |
|---|---|
| Screen body | apps/design-library/src/gallery/page/appflow/screens/AppFlow<Name>Screen.tsx |
| Registry injection | apps/design-library/src/gallery/page/appflow/personalLoanFlow.ts |
| Route | Existing dynamic route under apps/design-library/src/app/library/page/appflow/personal-loan/[slug]/ |
Rules:
- Keep screens presentational. No production API calls, analytics, database access, or third-party business logic.
- Chrome, progress, footer, and route framing belong to the existing AppFlow shell.
- Register
Body,status,slug,path,summary,progress, andsourcePathconsistently. - The final handoff must include the expected
/library/page/appflow/personal-loan/<slug>route.
Validation:
personalLoanFlow.tsimports and registers the screen.- The dynamic route can resolve the slug.
npm run build
Outcome D: Static Design Library Page
Use this for informational or foundation pages that are not reusable components and not AppFlow steps.
Required structure:
| Artifact | Target |
|---|---|
| Page implementation | apps/design-library/src/gallery/pages/ or a clearly named gallery subfolder |
| Route shell | apps/design-library/src/app/library/ |
| Navigation | apps/design-library/src/gallery/navigation/libraryNav.ts when live |
Rules:
- Prefer the existing gallery layout primitives.
- Keep routes thin and implementations in
src/gallery/. - Use a 1200px informational grid unless the request is explicitly an AppFlow-style page.
Validation:
- Route shell exists.
- Navigation is live only when content is complete.
npm run build
Outcome E: Token Or Foundation Change
Use this when the visual system itself changes.
Required structure:
| Artifact | Target |
|---|---|
| Token source | packages/spring-ds-react/src/tokens/design-tokens.mjs |
| Generated CSS | packages/spring-ds-react/src/tokens/generated/css-variables.css |
| Sync manifest | packages/spring-ds-react/src/tokens/generated/sync-manifest.json |
Rules:
- New visual values require an approved token gap.
- Run token sync after changing token source.
- Follow token names already used by the package and gallery.
- Restart any running dev server after token sync before trusting the local preview.
- Clear
apps/design-library/.nextbefore production build validation for token changes.
Validation:
npm run tokens:syncrm -rf apps/design-library/.nextnpm run lintandnpm run buildwhen consuming files also change
Outcome F: Icon Change
Use this when adding or regenerating Spring icon components.
Required structure:
| Artifact | Target |
|---|---|
| Icon components | packages/spring-ds-react/src/icons/ |
| Icon sync script | packages/spring-ds-react/scripts/sync-spring-icons-from-figma.mjs |
| Optional gallery manifest | apps/design-library/src/lib/iconManifest.ts |
Rules:
- Prefer
npm run icons:syncfor Figma-sourced icon changes. - Do not hand-edit large generated icon sets unless the change is intentionally scoped.
- Update gallery icon metadata only when the displayed categories or names change.
Validation:
npm run icons:syncwhen pulling from Figmanpm run buildwhen consumed by the gallery
Outcome G: Documentation Or Rule Change
Use this for repo guidance, AI workflow, onboarding, or rule updates.
Required structure:
| Artifact | Target |
|---|---|
| Long-form guidance | docs/ |
| Agent operating docs | docs/ai/ |
| Short executable rules | .cursor/rules/ |
Rules:
docs/ai/operational-manifesto.mdowns workflow narrative.docs/ai/workflow-contracts.mdowns file placement and output contracts.docs/ai/workflow-test-plan.mdowns validation strategy..cursor/rules/should summarize stable behavior, not duplicate long docs.
Validation:
- Docs are linked from
docs/README.mdanddocs/REPOSITORY_STRUCTURE.md. - No legacy stack or non-Spring UI library instructions remain in AI-facing workflow docs.
3. Multi-Agent Model
The workflow uses five roles. A single AI may play multiple roles, but the responsibilities must stay distinct.
1. Workflow Conductor
Owns intake, outcome classification, agent selection, user approval gates, loop limits, and final handoff.
Outputs:
WorkflowRunState- approved
BuildPlan - final handoff summary
Must not:
- Skip required user validation.
- Hide validation failures.
- Revert unrelated user changes.
2. Design & Token Analyst
Reads Figma/MCP context, screenshots, user instructions, existing token files, and visual examples. Maps raw design values to project tokens or reports gaps.
Outputs:
NormalizedDesignTreeTokenGapReport
Must not:
- Write component syntax.
- Add raw styling values without a token decision.
3. Structure & Reuse Architect
Determines whether the request should reuse, extend, create, or assemble. Audits public exports, route shells, navigation, and registries before recommending files.
Outputs:
AgenticImplementationPlan- file map
- registry injection plan
Must not:
- Create a new component when an existing exported component satisfies the outcome.
- Route AppFlow work into reserved package folders when the live implementation belongs in the gallery app.
4. Implementation Builder
Builds only the approved outcome and updates the required injection points.
Outputs:
- component/page/screen patch set
- route shell changes
- export, nav, registry, Code Connect, or token sync changes when required
Must not:
- Put page logic inside thin route shells.
- Put production API or database logic inside gallery or AppFlow previews.
- Modify unrelated files for cleanup.
5. Guardrail Critic
Runs validation, classifies failures, gives correction instructions, and blocks after three failed correction loops.
Outputs:
ValidationApprovalLogBlockedValidationReport
Must not:
- Mark work complete without naming validation coverage.
- Continue self-correction indefinitely.
4. Deterministic Workflow
flowchart TD
intake[InboundRequest] --> classify[ClassifyTaskType]
classify --> outcome[SelectOutcomeType]
outcome --> contextCheck[RequiredContextCheck]
contextCheck -->|"missing critical context"| askUser[AskUserForValidation]
contextCheck -->|"context complete"| investigate[InvestigateExistingStructure]
investigate --> normalize[TokenAndDesignNormalization]
normalize --> plan[BuildPlanAndFileMap]
plan --> planGate[HumanPlanValidation]
planGate -->|"changes requested"| plan
planGate -->|"approved"| build[BuildOutcomeFiles]
build --> inject[InjectRoutesRegistriesExports]
inject --> validate[GuardrailValidation]
validate -->|"fail under loop limit"| correct[CorrectionInstructions]
correct --> build
validate -->|"fail after loop limit"| blocked[UserEscalation]
validate -->|"pass"| handoff[DeveloperHandoff]
5. Investigation Order
Before building, inspect in this order:
docs/ai/project-context.md- classify the task and required intake.docs/ai/operational-manifesto.md- choose the workflow.docs/ai/workflow-contracts.md- confirm file targets and injection points.docs/REPOSITORY_STRUCTURE.md- use broader repo context when needed.- Nearby examples in
packages/spring-ds-react/src/components/orapps/design-library/src/gallery/. docs/ai/review-checklist.md- run the final quality gate before handoff.
6. Core Guardrails
- Human validation gate: Stop after structural planning when the implementation path, token additions, or new component creation needs user approval.
- Token guardrail: No raw hex, arbitrary spacing, or unregistered styling unless approved through a token gap.
- File boundary guardrail: Components stay in
packages/spring-ds-react; gallery docs and AppFlow screens stay inapps/design-library/src/gallery; routes stay underapps/design-library/src/app/library. - Reuse-first guardrail: Audit existing exports and nearby examples before adding files.
- Server-first guardrail: Default to Server Components. Add
'use client'only for hooks, events, lifecycle, or browser APIs. - Registry guardrail: Update all required injection points for the outcome:
src/index.ts, route shell,libraryNav.ts,personalLoanFlow.ts, Code Connect, or token generated artifacts. - Placeholder guardrail: Do not add placeholder-only pages to navigation.
- Self-correction guardrail: Run at most three correction loops before pausing with a blocker report.
- Dirty-tree guardrail: Do not revert unrelated user changes. Report any pre-existing modified files that affect validation confidence.
7. Self-Correction Protocol
When validation fails, the Guardrail Critic must produce a targeted correction instruction:
### System Intervention: Validation Failed
#### Failure Context
- Command: {COMMAND}
- File: {FILE_PATH}
- Error: {SUMMARY}
#### Required Correction
- Fix only the files related to the approved outcome.
- Preserve the functional and visual requirements.
- Do not introduce raw styling values or unrelated refactors.
- Re-run the failed validation command.
#### Loop Count
Attempt {CURRENT_ATTEMPT} of 3.
If the third attempt fails, stop and return a BlockedValidationReport with the command, error summary, affected files, and recommended user decision.
8. Developer Handoff
A completed workflow must provide:
- Outcome type.
- Current
WorkflowRunState, including phase, approval status, loop count, files changed, and next action if work is continuing. - Files changed.
- Route or import path to use.
- Registry/export/nav injection summary.
- Validation commands run and results.
- Known risks, skipped validations, or dirty-tree caveats.
If a workflow resumes after interruption, re-state the latest known WorkflowRunState and confirm user approval before continuing any implementation that depends on prior approval.
For gallery and AppFlow work, the /library/* route is the visual source of truth. Product developers should import verified presentational components and bind production data, tracking, and business logic outside the gallery.