---
name: step-03b-provider
description: Generate IClientSeedDataProvider implementation for client projects
prev_step: steps/step-03-roles.md
next_step: steps/step-04-backend.md
---

# Step 3b: Client Seed Data Provider (Client Projects Only)

## CONDITION D'EXECUTION

> This step executes ONLY if `{seeding_strategy}` = "provider" (client project).
> If `{seeding_strategy}` = "hasdata", skip directly to step-04-backend.md.

## MANDATORY EXECUTION RULES

- ONLY execute for client projects (`{seeding_strategy}` = "provider")
- ALWAYS use factory methods (`NavigationModule.Create(...)`, etc.) - NEVER `new Entity()`
- ALWAYS implement idempotence (check existence before inserting)
- ALWAYS register the provider in DI
- ALWAYS consume the SeedData classes created in steps 01-03

## YOUR TASK

Generate the `IClientSeedDataProvider` implementation that wires the SeedData files
created in steps 01, 02, 03 into the SmartStack Core seeding pipeline.

---

## AVAILABLE STATE

From previous steps:

| Variable | Description |
|----------|-------------|
| `{level}` | application, module, section, or resource |
| `{code}` | kebab-case identifier |
| `{full_path}` | Complete navigation path |
| `{labels}` | Object with fr, en, it, de |
| `{descriptions}` | Object with fr, en, it, de |
| `{icon}` | Lucide icon name |
| `{display_order}` | Numeric display order |
| `{navigation_guid}` | GUID of the navigation entity |
| `{permission_guids}` | GUIDs for generated permissions |
| `{project_type}` | "client" (guaranteed at this step) |
| `{seeding_strategy}` | "provider" (guaranteed at this step) |

---

## FILES TO GENERATE

See [references/provider-template.md](../references/provider-template.md) for the complete implementation:
- **ApplicationRolesSeedData.cs** (once per application) — defines application-scoped roles (Admin, Manager, Contributor, Viewer)
- **Provider class** (`{AppPascalName}SeedDataProvider.cs`) with 4 seed methods (Navigation, Roles, Permissions, RolePermissions)
- **DI registration** pattern for `Infrastructure/DependencyInjection.cs`
- **7 critical rules** (factory methods, idempotence, execution order, SaveChangesAsync order, deterministic GUIDs, FK by Code, Order property)

---

## EXECUTION SEQUENCE

### 1. Read SeedData files from steps 01-03

Identify all SeedData files created in previous steps:

```
Glob: **/Persistence/Seeding/Data/{Domain}/*SeedData.cs
Glob: **/Persistence/Seeding/Data/ApplicationRolesSeedData.cs
```

Expected files:
- `ApplicationRolesSeedData.cs` (application-level, once per app)
- `{Module}NavigationSeedData.cs` (from step 01)
- `{Module}NavigationTranslationSeedData.cs` (from step 01)
- `{Module}PermissionSeedData.cs` (from step 02)
- `{Module}RolePermissionSeedData.cs` (from step 03)

### 2. Generate Provider Class

Using the SeedData files as data sources, generate the `{AppPascalName}SeedDataProvider.cs` following the pattern above.

Adapt the template:
- Replace `{AppPascalName}` with the PascalCase application name
- Replace `{app_code}` with the kebab-case application code
- Fill in the actual navigation, permission, and role-permission creation logic
  using the helper methods from the SeedData classes
- **CRITICAL:** Follow the 7 critical rules: factory methods, idempotence, execution order, SaveChangesAsync order, random GUIDs via Guid.NewGuid(), FK by Code, Order property

### 3. Register in DI

Find and update `Infrastructure/DependencyInjection.cs`:

```
Glob: **/Infrastructure/DependencyInjection.cs
```

Add the `IClientSeedDataProvider` registration.

### 4. Verify

Before proceeding to step-04, verify:
- [ ] ApplicationRolesSeedData.cs created (once per application)
- [ ] Provider generated with 4 methods (SeedNavigationAsync, SeedRolesAsync, SeedPermissionsAsync, SeedRolePermissionsAsync)
- [ ] Execution order: Navigation → Roles → Permissions → RolePermissions
- [ ] Registered in DI (`services.AddScoped<IClientSeedDataProvider, ...>()`)
- [ ] Consumes SeedData classes from steps 01-03 + ApplicationRolesSeedData
- [ ] Idempotent (check existence before insert)
- [ ] Uses factory methods (no `new Entity()`)

---

## SUCCESS METRICS

- ApplicationRolesSeedData.cs created (application-level)
- Provider class generated with all 4 seed methods (Navigation, Roles, Permissions, RolePermissions)
- Correct execution order enforced
- DI registration added
- SeedData classes from steps 01-03 + ApplicationRolesSeedData properly consumed
- All methods are idempotent
- Factory methods used throughout
- Proceeded to step-04-backend.md

## FAILURE MODES

- SeedData files not found from previous steps (return to step-01)
- DependencyInjection.cs not found (ask user for DI registration location)
- Missing IClientSeedDataProvider interface (verify SmartStack.Application reference)

---

## NEXT STEP

After generating the provider and registering it in DI,
proceed to `./step-04-backend.md`
