---
name: step-02-build-data
description: Build FEATURE_DATA and EMBEDDED_ARTIFACTS objects from collected JSON data
model: opus
next_step: steps/step-03-render.md
---

> **Reference files:** `references/data-mapping.md` | `references/02-mapping-tables.md` | `references/02-normalization-helpers.md` | `references/02-screen-format-detection.md` | `references/02-feature-data-building.md` | `references/02-embedded-artifacts-building.md` | `references/02-self-check-validation.md`

# Step 2: Build Data Objects

## YOUR TASK

Build `FEATURE_DATA` and `EMBEDDED_ARTIFACTS` objects from `{collected_data}` collected in step-01.

---

## EXECUTION SEQUENCE

### 1. Build FEATURE_DATA

Construct the complete FEATURE_DATA object following the exact mapping in `references/data-mapping.md`:

> → **Load** `references/02-mapping-tables.md` for all field mappings (metadata, cadrage, stakeholders, scope, criteria, modules, dependencies, consolidation, handoff, moduleSpecs, wireframes, e2eFlows, dependencyGraph)
> → **Load** `references/02-normalization-helpers.md` for normalize* functions (normalizeColumn, normalizeField, normalizeFilter, normalizeSmartFilterField, normalizeAction, normalizeChart, normalizeKpi)
> → **Load** `references/02-screen-format-detection.md` for screens.json format detection and normalization (Format A/B-CANONICAL/B-LEGACY)

**Build moduleSpecs{} (ONE entry per module) + top-level fields:**

> → **Load** `references/02-feature-data-building.md` for complete moduleSpecs construction logic, screen building, anticipatedSections enrichment, and top-level fields (dependencies, consolidation, handoff)

### Post-Build Self-Check (MANDATORY — BLOCKING)

> → **Load** `references/02-self-check-validation.md` for complete self-check code and validation points.

After building FEATURE_DATA, run the self-check to detect data loss. This compares source file counts (useCases, businessRules, entities, screens) against built FEATURE_DATA counts to catch normalization bugs before rendering.

---

### 2. Build EMBEDDED_ARTIFACTS

**Build wireframes{}, e2eFlows[], and dependencyGraph:**

> → **Load** `references/02-embedded-artifacts-building.md` for complete construction logic: flat-file wireframe collection from screens.json (Sources A, B, C), field renaming (mockupFormat → format, mockup → content), e2eFlows, and dependencyGraph

---

### 3. Generate SVG Wireframes (Parallel, Optional)

This step is NEVER blocking — ASCII-only wireframes are acceptable.

1. Collect all wireframes where `content` exists and `svgContent` is null
2. Spawn parallel Task(sonnet) agents — ONE per wireframe
3. Validate results: strip markdown fences, verify SVG syntax
4. Inject valid SVGs into `EMBEDDED_ARTIFACTS.wireframes[moduleCode][index].svgContent`
5. Display: `"SVG wireframe generation: {successCount}/{total} generated, {failCount} fallback (ASCII)"`

---

## VALIDATION

- FEATURE_DATA.moduleSpecs must have ONE entry per module
- cadrage.scope uses HTML keys (inscope/outofscope)
- Wireframe fields use format/content (NOT mockupFormat/mockup)
- Per-module: useCases/businessRules/entities count must match source (empty when source has data = BUG)
- dependencies[] must be present (even if empty) to prevent HTML crashes
- **Permissions:** `buildPermissionKeys()` supports 4 formats:
  - **Format A:** `permissions.matrix[]` with `{role, permissions[]}`
  - **Format B:** `permissions.permissionMatrix.roleAssignments[]`
  - **Format C:** `permissions.roles[]` with `{role, permissions[]}`
  - **Format D:** `permissions.permissionMatrix.roleAssignments[]` with wildcard expansion
  - Pass optional `lang` parameter ('fr'|'en') for bilingual labels. Defaults to 'fr'.

## NEXT STEP

Load: `steps/step-03-render.md`
