---
name: step-04b-analyze
description: Analyze permission coherence, semantic validation, E2E flows, and global risks
model: opus
next_step: steps/step-04c-decide.md
---

> **Context files:** `_shared.md`

# Step 4b: Analyze - Permission Coherence & Validation

## MANDATORY EXECUTION RULES
- ALWAYS validate permission coherence across modules
- ALWAYS execute semantic validation checks
- E2E flows are OPTIONAL (informational only)

## YOUR TASK
Validate permission coherence, execute semantic checks, identify E2E business flows, and assess global application risks.

---

## EXECUTION SEQUENCE

### 3. Permission Coherence

> **Reference:** Load `references/analysis-semantic-checks.md` § "Permission Coherence Checks" for complete validation logic.

**All modules MUST use the same application-level roles.**

Execute these checks:

**3a. Role Consistency** — Verify all modules use the applicationRoles defined in cadrage

**3b. Permission Path Format** — Verify paths follow 3-segment (module-level) or 4-segment (section-level) patterns

**3c. Role Hierarchy Coherence** — Verify: Admin ⊃ Manager ⊃ Contributor ⊃ Viewer

**3d. Permission Conflicts** — Detect conflicts (e.g., Manager can approve in Orders but not Invoices)
- Present conflicts to user via AskUserQuestion for intentionality confirmation

**3e. Permission-Role Coherence Across Modules (WARNING)** — For each role, verify permission PATTERN is consistent across ALL modules
- Some permission differences may be intentional (store as WARNING, not ERROR)

### 4. Semantic Validation (MANDATORY)

> **Reference:** Load `references/analysis-semantic-checks.md` for complete semantic check definitions and blocking rules.

For EACH module feature.json, execute 13 checks:
- Permission orpheline (WARNING)
- UC sans FR (WARNING)
- Entity sans endpoint (WARNING)
- UC sans scenario (WARNING)
- Role sans permissions (WARNING)
- Navigation sans traduction (ERROR)
- LifeCycle terminal (WARNING)
- Schema conformity (ERROR)
- Wireframe coverage (ERROR)
- Doublon entity (ERROR)
- Permission fantome (ERROR)
- Dashboard coverage (WARNING)
- Permission-UC alignment (WARNING)

Store results in consolidation.semanticChecks[] with format: {check, module, status, details, autoFixed}

**Blocking rule:**
- 0 ERROR → PASS
- ≥1 ERROR → BLOCK (fix before handoff, ask user for each)
- WARNING only → PASS with user notification

### 4-bis. Structural Schema Conformity Check (MANDATORY)

> **Post-generation validation.** After semantic checks, verify ALL module feature.json files conform to JSON schema.

See [references/consolidation-structural-checks.md](../references/consolidation-structural-checks.md) for the full 6-category structural check:
- **A.** Required Sections Presence (18 sections)
- **B.** Field Name Conformity (forbidden vs correct fields)
- **C.** ID Pattern Conformity (BR, UC, FR, Permissions)
- **D.** Cross-Module ID Uniqueness
- **E.** Wireframe Layout Completeness
- **F.** SeedDataCore Translation Coverage

**Blocking rule:** 0 ERROR → PASS. ≥1 ERROR → BLOCK (attempt auto-fix, re-write, re-check).

### 5. End-to-End Flows

> **Reference:** Load `references/analysis-semantic-checks.md` § "E2E Flow Template" for the complete format.

Identify business processes that span multiple modules:
- Build flow with module → action → permission chain
- List actors involved and their roles
- Map data flow (entities referenced across modules)
- Display as diagrams for user understanding

### 6. Global Risk Assessment

> **Reference:** Load `references/analysis-semantic-checks.md` § "Global Risk Assessment Metrics" for complete evaluation.

Evaluate application-level risks using these metrics:
- Total entities (≤20)
- Total BRs (≤50)
- Cross-module dependencies (≤10)
- Shared entities (≤5)
- E2E flow length (≤8 steps max)
- Permission paths (≤100)

### 7. Consolidation Summary

Display comprehensive summary:
```
═══════════════════════════════════════════════════════════
  CONSOLIDATION - {application_name}
═══════════════════════════════════════════════════════════

### Modules ({count})
| Module | Entités | BRs | UCs | Complexité |
|--------|---------|-----|-----|------------|
{for each module}

### Interactions Cross-Module
- FK References: {count}
- Shared Entities: {count}
- Events: {count}
- Shared Data: {count}

### Permissions
- Roles: {count} (coherent: ✓/✗)
- Total paths: {count}
- Conflicts resolved: {count}

### E2E Flows
{for each flow: name, modules involved, actors}

### Risques Globaux
{risk assessment table}

═══════════════════════════════════════════════════════════
```

---

## SINGLE-MODULE MODE

When only 1 module:
1. Skip permission coherence check (only one module)
2. Skip E2E flows (single module)
3. Execute semantic validation (still required)
4. Auto-approve global risks (no cross-module complexity)

---

## CONTEXT MANAGEMENT

| Loaded | Not Loaded |
|--------|------------|
| _shared.md | Full module feature.json files |
| Module summaries | Questionnaires |
| consolidation section (from step-04a) | Templates |

---

## NEXT STEP

Load: `./step-04c-decide.md`
