---
description: Initialize a new SmartStack project with backend (.NET) and frontend (React)
args: [project_name]
---

# SmartStack Init - Project Scaffolding

You are an expert in SmartStack architecture. Initialize a new project based on the SmartStack template.

> **CLAUDE INSTRUCTION:** The `AskUserQuestion({...})` blocks below are instructions for using the `AskUserQuestion` tool **interactively**. You MUST execute the tool with these parameters to get the user's response BEFORE continuing. DO NOT display this code - WAIT for the response.

**Argument:** `$ARGUMENTS` = project name (required)

---

## ETAPE 0: VALIDATION PRE-INIT

### 0.1 Verification des serveurs MCP

> **CRITIQUE:** Les serveurs MCP SmartStack et Context7 sont requis pour le developpement optimal avec SmartStack.

**Verifier les MCP installes:**
```bash
# Lister les serveurs MCP actifs
claude mcp list
```

**MCP requis:**

| Serveur | Fonction | Installation |
|---------|----------|--------------|
| **SmartStack MCP** | Validation conventions, scaffolding, API docs | `claude mcp add smartstack` |
| **Context7 MCP** | Documentation libraries, exemples de code | `claude mcp add context7 -- npx @upstash/context7-mcp -- --api-key YOUR_API_KEY` |

**Si un MCP manque:**
```
┌──────────────────────────────────────────────────────────────────────────────┐
│  ⚠️  MCP SERVERS MISSING                                                      │
├──────────────────────────────────────────────────────────────────────────────┤
│  Les serveurs MCP suivants ne sont pas installes:                            │
│  • SmartStack MCP                                                            │
│  • Context7 MCP                                                              │
│                                                                              │
│  INSTALLATION:                                                               │
│  → SmartStack MCP: claude mcp add smartstack                                 │
│  → Context7 MCP:   claude mcp add context7                                   │
└──────────────────────────────────────────────────────────────────────────────┘
```

**Demander confirmation si MCP manquants:**
```javascript
if (mcpMissing.length > 0) {
  AskUserQuestion({
    questions: [{
      question: "Des serveurs MCP sont manquants. Continuer sans eux ?",
      header: "MCP",
      options: [
        { label: "Non, installer d'abord", description: "Recommande - installer les MCP avant de continuer" },
        { label: "Oui, continuer", description: "Le projet sera cree mais certaines fonctionnalites seront limitees" }
      ],
      multiSelect: false
    }]
  })
}
```

### 0.2 Verification des prerequis systeme

```bash
# Verifier .NET SDK
dotnet --version

# Verifier Node.js
node --version

# Verifier npm
npm --version
```

**Si un prerequis manque:**
```
PREREQUIS MANQUANTS
==========================================
[ ] .NET 10.0+ SDK
[ ] Node.js 18+
[ ] npm 9+

Installez les prerequis avant de continuer.
```

### 0.3 Verification du repertoire

```bash
# Verifier que le repertoire cible n'existe pas
if [ -d "$PROJECT_NAME" ]; then
  echo "Le repertoire '$PROJECT_NAME' existe deja."
  exit 1
fi
```

---

## ETAPE 1: CONFIGURATION DU PROJET

### 1.1 Collecter les informations

```javascript
AskUserQuestion({
  questions: [
    {
      question: "Quel type de projet voulez-vous creer ?",
      header: "Type",
      options: [
        { label: "Full Stack", description: "Backend .NET + Frontend React (Recommande)" },
        { label: "Backend Only", description: "API .NET uniquement" },
        { label: "Frontend Only", description: "Application React uniquement" }
      ],
      multiSelect: false
    },
    {
      question: "Quelle base de donnees utiliser ?",
      header: "Database",
      options: [
        { label: "SQL Server", description: "Microsoft SQL Server (Recommande)" },
        { label: "PostgreSQL", description: "PostgreSQL avec Npgsql" },
        { label: "SQLite", description: "SQLite pour developpement local" }
      ],
      multiSelect: false
    },
    {
      question: "Quels modules SmartStack activer ?",
      header: "Modules",
      options: [
        { label: "Auth", description: "Authentication JWT + OAuth (Google, Microsoft)" },
        { label: "Navigation", description: "Menu dynamique et navigation" },
        { label: "AI", description: "Integration OpenAI/Claude" },
        { label: "Notifications", description: "Notifications temps reel (SignalR)" }
      ],
      multiSelect: true
    }
  ]
})
```

---

## ETAPE 2: CREATION DE LA STRUCTURE

### 2.1 Structure Backend (.NET)

```
{ProjectName}/
├── src/
│   ├── {ProjectName}.Domain/
│   │   ├── Entities/
│   │   ├── Interfaces/
│   │   └── {ProjectName}.Domain.csproj
│   ├── {ProjectName}.Application/
│   │   ├── Services/
│   │   ├── DTOs/
│   │   └── {ProjectName}.Application.csproj
│   ├── {ProjectName}.Infrastructure/
│   │   ├── Data/
│   │   │   └── {ProjectName}DbContext.cs
│   │   ├── Repositories/
│   │   └── {ProjectName}.Infrastructure.csproj
│   └── {ProjectName}.Api/
│       ├── Controllers/
│       ├── Program.cs
│       └── {ProjectName}.Api.csproj
├── tests/
│   └── {ProjectName}.Tests/
├── web/
│   └── {projectname}-web/
│       ├── src/
│       ├── package.json
│       └── vite.config.ts
├── {ProjectName}.sln
├── Directory.Build.props
└── README.md
```

### 2.2 Creer la solution .NET

```bash
# Creer le repertoire
mkdir -p "$PROJECT_NAME"
cd "$PROJECT_NAME"

# Creer la solution
dotnet new sln -n "$PROJECT_NAME"

# Creer les projets
dotnet new classlib -n "$PROJECT_NAME.Domain" -o "src/$PROJECT_NAME.Domain"
dotnet new classlib -n "$PROJECT_NAME.Application" -o "src/$PROJECT_NAME.Application"
dotnet new classlib -n "$PROJECT_NAME.Infrastructure" -o "src/$PROJECT_NAME.Infrastructure"
dotnet new webapi -n "$PROJECT_NAME.Api" -o "src/$PROJECT_NAME.Api"

# Ajouter a la solution
dotnet sln add "src/$PROJECT_NAME.Domain"
dotnet sln add "src/$PROJECT_NAME.Application"
dotnet sln add "src/$PROJECT_NAME.Infrastructure"
dotnet sln add "src/$PROJECT_NAME.Api"

# Ajouter les references entre projets
dotnet add "src/$PROJECT_NAME.Application" reference "src/$PROJECT_NAME.Domain"
dotnet add "src/$PROJECT_NAME.Infrastructure" reference "src/$PROJECT_NAME.Domain"
dotnet add "src/$PROJECT_NAME.Infrastructure" reference "src/$PROJECT_NAME.Application"
dotnet add "src/$PROJECT_NAME.Api" reference "src/$PROJECT_NAME.Application"
dotnet add "src/$PROJECT_NAME.Api" reference "src/$PROJECT_NAME.Infrastructure"
```

### 2.3 Installer les packages NuGet

```bash
# EF Core packages (Infrastructure)
dotnet add "src/$PROJECT_NAME.Infrastructure" package Microsoft.EntityFrameworkCore
dotnet add "src/$PROJECT_NAME.Infrastructure" package Microsoft.EntityFrameworkCore.Design

# Database provider (selon base de donnees selectionnee)
# SQL Server:
dotnet add "src/$PROJECT_NAME.Infrastructure" package Microsoft.EntityFrameworkCore.SqlServer

# PostgreSQL:
# dotnet add "src/$PROJECT_NAME.Infrastructure" package Npgsql.EntityFrameworkCore.PostgreSQL

# SQLite:
# dotnet add "src/$PROJECT_NAME.Infrastructure" package Microsoft.EntityFrameworkCore.Sqlite

# API packages
dotnet add "src/$PROJECT_NAME.Api" package Microsoft.AspNetCore.Authentication.JwtBearer
dotnet add "src/$PROJECT_NAME.Api" package Swashbuckle.AspNetCore
```

---

## ETAPE 3: CREATION DU FRONTEND (si Full Stack)

### 3.1 Creer le projet React

```bash
mkdir -p "web/${PROJECT_NAME_LOWER}-web"
cd "web/${PROJECT_NAME_LOWER}-web"

# Initialiser avec Vite
npm create vite@latest . -- --template react-ts

# Installer les dependances
npm install

# Installer SmartStack React
npm install @atlashub/smartstack-react

# Installer les peer dependencies
npm install axios react-router-dom i18next react-i18next

# Installer Tailwind CSS
npm install -D tailwindcss @tailwindcss/vite
```

### 3.2 Configurer le projet React

Creer `vite.config.ts`:
```typescript
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'

export default defineConfig({
  plugins: [react(), tailwindcss()],
  server: {
    port: 5173,
    proxy: {
      '/api': {
        target: 'https://localhost:5001',
        changeOrigin: true,
        secure: false
      }
    }
  }
})
```

Creer `src/main.tsx`:
```tsx
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import { BrowserRouter } from 'react-router-dom'
import { SmartStackProvider } from '@atlashub/smartstack-react'
import '@atlashub/smartstack-react/styles'
import App from './App'

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <BrowserRouter>
      <SmartStackProvider apiUrl="https://localhost:5001/api">
        <App />
      </SmartStackProvider>
    </BrowserRouter>
  </StrictMode>
)
```

---

## ETAPE 4: CONFIGURATION

### 4.1 Creer Directory.Build.props

```xml
<Project>
  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
  </PropertyGroup>
</Project>
```

### 4.2 Configurer appsettings.json

```json
{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database={ProjectName};Trusted_Connection=True;MultipleActiveResultSets=true"
  },
  "SmartStack": {
    "Modules": {
      "Auth": true,
      "Navigation": true,
      "AI": false,
      "Notifications": true
    }
  },
  "Jwt": {
    "Secret": "CHANGE_THIS_SECRET_IN_PRODUCTION_MIN_32_CHARS",
    "Issuer": "{ProjectName}",
    "Audience": "{ProjectName}",
    "ExpirationMinutes": 60
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information"
    }
  }
}
```

### 4.3 Configurer Program.cs

```csharp
using SmartStack.Api.Core;
using SmartStack.Infrastructure;
using {ProjectName}.Infrastructure.Data;

var builder = WebApplication.CreateBuilder(args);

// SmartStack services
builder.Services.AddSmartStackCore(builder.Configuration);
builder.Services.AddSmartStackInfrastructure<{ProjectName}DbContext>(builder.Configuration);

// Add controllers
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddOpenApi();

var app = builder.Build();

// SmartStack middleware
app.UseSmartStackMiddleware();

if (app.Environment.IsDevelopment())
{
    app.MapOpenApi();
    app.UseScalar();
}

app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();

app.Run();
```

### 4.4 Creer le DbContext

```csharp
using Microsoft.EntityFrameworkCore;
using SmartStack.Infrastructure.Data;

namespace {ProjectName}.Infrastructure.Data;

public class {ProjectName}DbContext : SmartStackDbContext
{
    public {ProjectName}DbContext(DbContextOptions<{ProjectName}DbContext> options)
        : base(options)
    {
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        // Add your entity configurations here
    }
}
```

---

## ETAPE 5: INITIALISATION GIT

```bash
cd "$PROJECT_NAME"

# Initialiser Git
git init

# Creer .gitignore
cat > .gitignore << 'EOF'
## .NET
bin/
obj/
*.user
*.suo
.vs/

## Node
node_modules/
dist/

## IDE
.idea/
.vscode/

## Environment
*.env
*.env.local
appsettings.*.json
!appsettings.json
!appsettings.Development.json

## Build
*.log
EOF

# Premier commit
git add .
git commit -m "chore: initial SmartStack project setup"
```

---

## ETAPE 6: VERIFICATION

### 6.1 Build Backend

```bash
dotnet restore
dotnet build
```

### 6.2 Build Frontend (si applicable)

```bash
cd "web/${PROJECT_NAME_LOWER}-web"
npm run build
```

---

## RESUME FINAL

```
================================================================================
                    SMARTSTACK PROJECT INITIALIZED
================================================================================

Projet:       {ProjectName}
Type:         {Full Stack|Backend Only|Frontend Only}
Database:     {SQL Server|PostgreSQL|SQLite}
Modules:      {Auth, Navigation, ...}

STRUCTURE CREEE:
  src/
    ├── {ProjectName}.Domain/
    ├── {ProjectName}.Application/
    ├── {ProjectName}.Infrastructure/
    └── {ProjectName}.Api/
  web/
    └── {projectname}-web/

PACKAGES INSTALLES:
  NuGet:
    ✓ Microsoft.EntityFrameworkCore
    ✓ Microsoft.EntityFrameworkCore.Design
    ✓ Microsoft.EntityFrameworkCore.SqlServer (ou PostgreSQL/SQLite)
    ✓ Microsoft.AspNetCore.Authentication.JwtBearer
    ✓ Swashbuckle.AspNetCore
  npm:
    ✓ @atlashub/smartstack-react
    ✓ tailwindcss

PROCHAINES ETAPES:
  1. Configurer la connection string dans appsettings.json
  2. Creer la migration initiale:
     dotnet ef migrations add InitialCreate -p src/{ProjectName}.Infrastructure -s src/{ProjectName}.Api
  3. Appliquer la migration:
     dotnet ef database update -p src/{ProjectName}.Infrastructure -s src/{ProjectName}.Api
  4. Lancer le backend:
     dotnet run --project src/{ProjectName}.Api
  5. Lancer le frontend:
     cd web/{projectname}-web && npm run dev

DOCUMENTATION:
  - SmartStack: https://docs.smartstack.app
  - API Reference: https://localhost:5001/scalar

================================================================================
```

---

## MODES

| Commande | Action |
|----------|--------|
| `smartstack init {name}` | Creer projet avec wizard interactif |
| `smartstack init {name} --full-stack` | Full stack (defaut) |
| `smartstack init {name} --backend` | Backend .NET uniquement |
| `smartstack init {name} --frontend` | Frontend React uniquement |
| `smartstack init {name} --db sqlserver` | Specifier la DB |
| `smartstack init {name} --dry-run` | Simulation |
| `smartstack init {name} --skip-mcp-check` | Ignorer verification MCP |

---

## MCP SERVERS

Les projets SmartStack utilisent les serveurs MCP pour ameliorer l'experience de developpement:

### SmartStack MCP

Fournit:
- `validate_conventions` - Valide les conventions SQL, migrations, services, namespaces
- `check_migrations` - Analyse les conflits EF Core entre branches
- `scaffold_extension` - Genere du code (services, entites, controllers, components)
- `api_docs` - Documentation API Swagger/OpenAPI

### Context7 MCP

Fournit:
- `resolve-library-id` - Trouve l'ID Context7 d'une bibliotheque
- `query-docs` - Recupere la documentation et exemples de code a jour

**Installation:**
```bash
# SmartStack MCP
claude mcp add smartstack

# Context7 MCP (remplacez YOUR_API_KEY par votre cle)
claude mcp add context7 -- npx @upstash/context7-mcp -- --api-key YOUR_API_KEY
```

> **Note:** Obtenez votre cle API Context7 gratuite sur [context7.io](https://context7.io)
