---
name: application
description: |
  Creates SmartStack full-stack applications/modules.
  Use this skill when:
  - User asks to create an application, module, or context
  - User mentions "new module", "new application", "add a feature"
  - User wants to extend navigation with new entries
  Scope: Context → Application → Module → Section (all levels)
---

# Skill Application SmartStack

**Reference:** [_shared.md](../_shared.md) for architecture, permissions, i18n

## ENTRY POINT

> **FIRST ACTION:** Load `steps/step-00-init.md`

This skill uses progressive step loading. Each step calls MCP tools for generation.

## STEP FILES

| Step | File | MCP Tool Called |
|------|------|-----------------|
| 00 | `steps/step-00-init.md` | `validate_conventions` (MCP check) |
| 01 | `steps/step-01-navigation.md` | `scaffold_navigation` |
| 02 | `steps/step-02-permissions.md` | `generate_permissions` |
| 03 | `steps/step-03-roles.md` | `scaffold_role_permissions` |
| 04 | `steps/step-04-backend.md` | `scaffold_extension` |
| 05 | `steps/step-05-frontend.md` | `scaffold_api_client`, `scaffold_routes` |
| 06 | `steps/step-06-migration.md` | `suggest_migration` |

## MCP INTEGRATION

> **CRITICAL:** This skill MUST use MCP tools for all generation.
> Templates in this folder are for REFERENCE ONLY - never use them directly.

| MCP Tool | Purpose |
|----------|---------|
| `mcp__smartstack__scaffold_navigation` | Navigation entity + translations |
| `mcp__smartstack__generate_permissions` | Permissions.cs + HasData |
| `mcp__smartstack__scaffold_role_permissions` | Role-permission mappings |
| `mcp__smartstack__scaffold_extension` | Entity, Service, Controller, DTOs |
| `mcp__smartstack__scaffold_api_client` | TypeScript API client |
| `mcp__smartstack__scaffold_routes` | React Router configuration |
| `mcp__smartstack__suggest_migration` | Migration name suggestion |

## WHEN THIS SKILL ACTIVATES

| Trigger | Example |
|---------|---------|
| Explicit request | "Create a module to manage products" |
| New feature | "We need to add order management" |
| Navigation extension | "Add a CRM application in business" |
| Keywords | "new module", "new application", "add a context" |

## FLOW ARCHITECTURE

```
WEB (React) → API (.NET) → Application → Infrastructure → Database
```

**FORBIDDEN:** WEB → Infrastructure (direct DB access), WEB → Domain

## WORKFLOW

### 1. Level Detection

| Hint | → Level |
|------|---------|
| "context", "workspace" | Context |
| "application", "app" | Application |
| "module", "feature" | Module |
| "section", "tab" | Section |

### 2. Parameter Extraction
`$LEVEL`, `$PARENT` (platform/business/personal), `$CODE` (kebab-case), `$LABEL_EN`, `$ICON` (Lucide)

### 3. Full-Stack Generation
```
1. DB SEED (Navigation + Translations 4 languages)
2. PERMISSIONS (Permissions.cs + PermissionConfiguration.cs) ← 2 files!
3. API (Controller + DTOs via /controller:create)
4. SERVICES (Interface + Implementation)
5. FRONTEND (Page + Components + Hooks)
6. I18N (fr, en, it, de)
7. ROUTES (nested routes mandatory)
8. PREFERENCES (Hook pattern)
9. MIGRATION (/efcore:migration)
```

### 4. Automatic Chaining
- `/controller:create` → API Controllers
- `/efcore:migration` → DB Migrations
- `/ui-components` → EntityCard, DataTable

## USER PREFERENCES

| Preference | Storage |
|------------|---------|
| pageSize | `user.preferences.{module}.pageSize` |
| sortColumn/Direction | `user.preferences.{module}.sort*` |
| filters | `user.preferences.{module}.filters` |
| visibleColumns | `user.preferences.{module}.visibleColumns` |
| viewMode | `user.preferences.{module}.viewMode` |

```typescript
export function use{Module}Preferences() {
  const { preferences, updatePreference } = useUserPreferences();
  return {
    pageSize: preferences.{module}?.pageSize ?? 10,
    setPageSize: (size: number) => updatePreference('{module}.pageSize', size),
    // ... others
  };
}
```

## ROUTING (React Router v7)

```tsx
// ✅ CORRECT - Nested routes
<Route path="$APPLICATION">
  <Route index element={<Navigate to="$DEFAULT_MODULE" replace />} />
  <Route path="$MODULE1" element={<Module1Page />} />
</Route>

// ❌ FORBIDDEN - Flat routes (cause redirect to Home)
<Route path="$APPLICATION" element={<Navigate ... />} />
<Route path="$APPLICATION/$MODULE1" element={...} />
```

## INTEGRATIONS

| Skill | When | Action |
|-------|------|--------|
| `/notification` | User alerts | INotificationService + SignalR |
| `/workflow` | Automated emails | IWorkflowService.TriggerAsync |
| `/ai-prompt` | AI assistance | IAiCompletionService |
| `/feature-full` | Complete feature | Orchestration all skills |

### Notification Integration Pattern
```csharp
await _notificationService.SendNotificationAsync(
    userId, NotificationType.{Entity}Created, title, message,
    relatedEntityType: nameof({Entity}), relatedEntityId: entity.Id);
```

### Workflow Integration Pattern
```csharp
await _workflowService.TriggerAsync("{entity}.created", new Dictionary<string, object>
{
    ["entityId"] = entity.Id,
    ["creatorEmail"] = _currentUser.Email
});
```

## ABSOLUTE RULES

| DO | DON'T |
|----|-------|
| 4 languages (FR, EN, IT, DE) | Import Infrastructure in frontend |
| Permissions: 2 files | Direct SQL in frontend |
| Nested routes | Flat routes (flat siblings) |
| EntityCard for cards | Manual cards with divs |
| DataTable for tables | Sequential GUIDs |

## ASSOCIATED FILES

### Step Files (ACTIVE - Use These)
- [steps/step-00-init.md](steps/step-00-init.md) - Initialize parameters
- [steps/step-01-navigation.md](steps/step-01-navigation.md) - Generate navigation
- [steps/step-02-permissions.md](steps/step-02-permissions.md) - Generate permissions
- [steps/step-03-roles.md](steps/step-03-roles.md) - Assign roles
- [steps/step-04-backend.md](steps/step-04-backend.md) - Generate backend
- [steps/step-05-frontend.md](steps/step-05-frontend.md) - Generate frontend
- [steps/step-06-migration.md](steps/step-06-migration.md) - Create migration

### Templates (REFERENCE ONLY - Do Not Use Directly)
> These templates are kept for documentation purposes.
> All generation is done via MCP tools in step files.

- [templates-backend.md](templates-backend.md) - Backend patterns reference
- [templates-frontend.md](templates-frontend.md) - Frontend patterns reference
- [templates-i18n.md](templates-i18n.md) - i18n structure reference
- [templates-seed.md](templates-seed.md) - Seed data patterns reference
