# Consolidation Structural Schema Conformity Checks

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

## A. Required Sections Presence

| Section | Required | Check |
|---------|----------|-------|
| `metadata` | YES | Must have: app, module, language, featureDescription, featureType |
| `discovery` | YES | Must exist (even if minimal) |
| `analysis.entities[]` | YES | Must have >=1 entity |
| `analysis.businessRules[]` | YES | Must have >=1 BR |
| `analysis.objectives[]` | YES | Must have >=1 objective |
| `analysis.processFlow` | YES | Must have entryPoints, mainFlow, decisionPoints |
| `analysis.dataLifecycle` | YES | Must have retention, archival, deletion, gdprRelevant |
| `specification.useCases[]` | YES | Must have >=1 UC |
| `specification.functionalRequirements[]` | YES | Must have >=1 FR |
| `specification.permissionMatrix` | YES | Must be `{permissions[], roleAssignments[]}` (NOT flat array) |
| `specification.sections[]` | YES | Must have >=1 section with resources |
| `specification.wireframes[]` | YES | Must have >=1 wireframe with `layout` object |
| `specification.lifeCycles[]` | IF entities have status | States must be objects (NOT strings) |
| `specification.seedDataCore` | YES | Must have 9 arrays: navigationApplications, applicationRoles, navigationModules, navigationSections, navigationResources, navigationTranslations, permissions, rolePermissions, permissionConstants |
| `specification.seedDataBusiness` | NO (WARNING) | Business seed data is generated during implementation (business-analyse-develop), not during BA. If present, validates format. |
| `specification.gherkinScenarios` | YES | Must be `[{feature, scenarios[]}]` (array of objects, NOT single object or flat array) |
| `specification.navigation` | YES | Must have entries[] |
| `specification.i18nKeys[]` | YES | Must have >=1 key with fr, en, it, de |
| `validation` | YES | Must have completenessChecks, consistencyChecks, semanticChecks, decision |

## B. Field Name Conformity

> **Two-phase entity schema:** In the **analysis** phase (step-03), entity attributes use a business-friendly format WITHOUT `type`.
> In the **compilation** phase (step-03), `type` is auto-inferred and added to each attribute.
> Therefore `type` is FORBIDDEN in the raw analysis input but MANDATORY after compilation.

| Section | FORBIDDEN fields | Correct fields |
|---------|-----------------|----------------|
| `entities[].attributes[]` | `values`, `rules` | `type` (added by step-03 compilation), `description`, `unique`, `validation` |
| `businessRules[]` | `rule`, `condition` (singular) | `name`, `statement`, `conditions[]` |
| `useCases[]` | `actor`, `linkedBRs`, `linkedFRs` | `primaryActor`, `linkedRules` |
| `functionalRequirements[]` | `name`, `description`, `linkedUCs`, `linkedBRs` | `statement`, `linkedUseCases`, `linkedRules` |
| `permissionMatrix` | flat array with `resource`/`roles` | `{permissions[], roleAssignments[]}` |
| `lifeCycles[].states[]` | string values like `"Active"` | objects with `{id, displayName, color, isTerminal}` |
| `seedDataCore` | flat object, string values | 7 typed arrays |
| `gherkinScenarios` | flat scenario array | `{feature, scenarios[]}` nested |

## C. ID Pattern Conformity

| ID Type | Pattern | Example |
|---------|---------|---------|
| BR | `BR-(VAL\|CALC\|WF\|SEC\|DATA)-{PREFIX}-\d{3}` | BR-VAL-RM-001 |
| UC | `UC-{PREFIX}-\d{3}` | UC-RM-001 |
| FR | `FR-{PREFIX}-\d{3}` | FR-RM-001 |
| Permissions (module) | `{app}.{module}.{action}` | freebike.repairs.create |
| Permissions (section) | `{app}.{module}.{section}.{action}` | freebike.repairs.dashboard.read |

## D. Cross-Module ID Uniqueness

```
SET all_ids = {}
FOR each module:
  FOR each BR, UC, FR id:
    IF id IN all_ids -> ERROR: "Duplicate {id} in {module1} and {module2}"
    ADD id to all_ids
```

## E. Wireframe Layout Completeness

```
IF missing componentMapping[] -> ERROR
IF missing layout object -> ERROR
IF missing layout.regions[] -> ERROR
FOR each region: IF missing position or components[] -> ERROR
```

## F. SeedDataCore Translation Coverage

```
FOR each navigationModules[].code:
  FOR each language in [fr, en, it, de]:
    IF NOT EXISTS navigationTranslations[] with moduleCode AND language -> ERROR
```

## G. API Endpoint Coverage

```
FOR each entity in analysis.entities[]:
  endpoints = specification.apiEndpoints[].filter(e => e.path.includes(entity.name.toLowerCase()))
  IF endpoints.length < 5 -> WARNING: "Entity {entity.name} has <5 endpoints (expected: GET list, GET id, POST, PUT, DELETE)"
  IF endpoints.length === 0 -> ERROR: "Entity {entity.name} has NO endpoints — missing controller"
```

## H. Permission Granularity Check

> Validates that section permission modes are respected in the generated permission data.

```
FOR each module:
  FOR each section in anticipatedSections[]:
    IF section.sectionType == "view" OR section.permissionMode == "inherit":
      IF section has own permissions in seedDataCore.permissions[] -> WARNING: "Section '{code}' is type 'view' but has own permissions — should inherit from module"
    IF section.permissionMode == "read-only":
      IF section has create/update/delete permissions -> ERROR: "Section '{code}' is read-only but has write permissions"
    IF section.sectionType == "primary" AND NOT section.permissionMode:
      -> WARNING: "Primary section '{code}' missing explicit permissionMode — defaulting to 'crud'"
```

## Result Aggregation

```json
{
  "structuralChecks": [
    { "check": "required-sections", "module": "...", "status": "PASS|ERROR", "details": "..." },
    { "check": "field-names", "module": "...", "status": "PASS|ERROR", "details": "..." },
    { "check": "id-patterns", "module": "...", "status": "PASS|ERROR", "details": "..." },
    { "check": "id-uniqueness", "module": "...", "status": "PASS|ERROR", "details": "..." },
    { "check": "wireframe-layout", "module": "...", "status": "PASS|ERROR", "details": "..." },
    { "check": "seeddata-translations", "module": "...", "status": "PASS|ERROR", "details": "..." }
    ,
    { "check": "permission-granularity", "module": "...", "status": "PASS|WARNING|ERROR", "details": "..." }
  ]
}
```

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