# Skills SmartStack - Shared Functions

## Model Strategy

| Task | Model | Reason |
|------|-------|--------|
| Code generation | **Sonnet** | Optimal quality/cost ratio |
| Security audit | **Opus** | Critical analysis required |
| Final validation | **Opus** | Architectural decisions |

## SmartStack Architecture

```
Domain → Application → Infrastructure → API → Web
```

### Layers
| Layer | Responsibility | Namespace |
|-------|-----------------|-----------|
| Domain | Entities, ValueObjects | `SmartStack.Domain.{Context}` |
| Application | Services, DTOs, Interfaces | `SmartStack.Application.{Context}` |
| Infrastructure | Implementations, EF Core | `SmartStack.Infrastructure.{Context}` |
| API | Controllers, Middleware | `SmartStack.Api.Controllers.{Area}` |
| Web | React components, pages | `src/pages/{context}/{app}/{module}` |

## Permissions (2 mandatory files)

### 1. Permissions.cs (Application layer)
```csharp
public static class {Module}
{
    public const string View = "{context}.{app}.{module}.view";
    public const string Create = "{context}.{app}.{module}.create";
    public const string Update = "{context}.{app}.{module}.update";
    public const string Delete = "{context}.{app}.{module}.delete";
}
```

### 2. PermissionConfiguration.cs (Infrastructure layer)
```csharp
builder.HasData(
    new { Id = nextId++, Path = Permissions.{Module}.View, ... },
    new { Id = nextId++, Path = Permissions.{Module}.Create, ... },
    ...
);
```

## i18n (4 mandatory languages)

| Language | File | Code |
|----------|------|------|
| French | `fr.json` | `fr` |
| English | `en.json` | `en` |
| Italian | `it.json` | `it` |
| German | `de.json` | `de` |

### i18n Structure
```json
{
  "{context}": {
    "{application}": {
      "{module}": {
        "title": "...",
        "fields": { ... },
        "actions": { ... },
        "messages": { ... }
      }
    }
  }
}
```

## Common Services to Inject

| Service | Usage |
|---------|-------|
| `IApplicationDbContext` | DB access |
| `ICurrentUserService` | Current user |
| `ILogger<T>` | Logging |
| `IMapper` | AutoMapper |
| `IPermissionService` | Permission cache |

## Security Validation

### Critical Logs
| Event | Level |
|-------|-------|
| Failed login | `Critical` |
| Permission denied | `Critical` |
| Account locked | `Critical` |
| Password change | `Warning` |
| Deletion | `Warning` |

### System Account Protection
```csharp
if (entity.UserType == UserType.System || entity.UserType == UserType.LocalAdmin)
    return BadRequest(new { message = "Cannot modify system accounts" });
```

## Common Validation Checklist

```
□ Permissions created (Permissions.cs + PermissionConfiguration.cs)
□ EF Core migration created
□ i18n 4 languages (fr, en, it, de)
□ Unit tests
□ API documentation (ProducesResponseType)
```

## MCP Tools References

### Outils Core

| Tool | Usage | Step APEX |
|------|-------|-----------|
| `mcp__smartstack__validate_conventions` | Valider conventions SmartStack (tables, migrations, services, namespaces, entities, tenants, controllers) | step-04-validate |
| `mcp__smartstack__scaffold_extension` | Génération code (feature, entity, service, controller, component, dto, validator, repository) | step-03-execute |
| `mcp__smartstack__check_migrations` | Analyser migrations EF Core (conflits, ordre, ModelSnapshot) | step-04-validate |
| `mcp__smartstack__api_docs` | Documentation API depuis Swagger/OpenAPI ou controllers | step-01-analyze |
| `mcp__smartstack__suggest_migration` | Suggérer nom migration ({context}_v{version}_{sequence}_{Description}) | step-03-execute |
| `mcp__smartstack__generate_permissions` | Générer permissions RBAC depuis NavRoute | step-03-execute |

### Outils Tests

| Tool | Usage | Step APEX |
|------|-------|-----------|
| `mcp__smartstack__scaffold_tests` | Générer tests unitaires/intégration/sécurité | step-07-tests |
| `mcp__smartstack__analyze_test_coverage` | Analyser couverture de tests du projet | step-07-tests |
| `mcp__smartstack__validate_test_conventions` | Valider conventions de nommage des tests | step-07-tests |
| `mcp__smartstack__suggest_test_scenarios` | Suggérer scénarios de test basés sur le code | step-07-tests |

### Outils Frontend

| Tool | Usage | Step APEX |
|------|-------|-----------|
| `mcp__smartstack__scaffold_api_client` | Générer client TypeScript avec NavRoute | step-03-execute |
| `mcp__smartstack__scaffold_routes` | Générer React Router depuis NavRoute backend | step-03-execute |
| `mcp__smartstack__validate_frontend_routes` | Valider synchronisation routes frontend/backend | step-04-validate |
| `mcp__smartstack__scaffold_frontend_extension` | Générer infrastructure extension frontend | step-03-execute |
| `mcp__smartstack__analyze_extension_points` | Analyser points d'extension dans les pages React | step-01-analyze |
