# Crafted SaaS - Balanced Web

⚖️ **Niveau BALANCED** - Pragmatic Quality, Web Only

## Configuration

- **Niveau**: Balanced (Pragmatic Quality)
- **Platform**: Web Only (Next.js)
- **Équipe**: 3-10 développeurs
- **Durée**: 1-3 ans (croissance)
- **Users**: 100-10K clients payants
- **Revenue**: $5K-100K MRR

## Architecture

**3-Layer Architecture** - Separation of Concerns

```
apps/
└── web/              # Next.js 15 app

packages/
├── api/              # tRPC routers (thin, max 20 lignes per procedure)
│   └── routers/      # Orchestration + validation only
├── services/         # Business logic (max 50 lignes per function)
│   └── *.service.ts  # Pure functions when possible
├── validators/       # Zod schemas (shared validation)
├── database/         # Prisma + repositories
│   └── repositories/ # Data access layer
├── auth/             # Supabase Auth
├── payments/         # Stripe
├── emails/           # Resend + React Email
└── ui/               # shadcn/ui components
```

### Layer Responsibilities

1. **Routers (API)**: Thin orchestration, validation only (max 20 lines)
2. **Services**: Business logic, platform-agnostic (max 50 lines)
3. **Repositories**: Data access, complex Prisma queries

## Règles de Code

| Aspect | Règle |
|--------|-------|
| **Max lignes/fonction** | 50 lignes |
| **Parameters** | Max 3 |
| **Duplication** | > 2 fois = extract obligatoire |
| **Cyclomatic complexity** | < 10 |
| **SOLID** | Full (tous les principes) |
| **Comments** | WHY required (NO inline WHAT/HOW) |

## Testing

**Test-After Generation (TAG)** - 70% coverage enforced

- ✅ Unit tests services (100% public methods)
- ✅ tRPC routers (happy path + errors)
- ✅ Component tests (critical components)
- ✅ E2E (auth + checkout)
- ✅ Integration tests (with MSW)

**Coverage**: 70% minimum enforced

## Quick Start

```bash
# Install dependencies
pnpm install

# Setup environment
cp .env.example .env.local
# Edit .env.local with your keys

# Generate Prisma client
pnpm --filter @crafted/database db:generate

# Start dev server
pnpm --filter @crafted/web dev
```

## Features Included

- ✅ Authentication (Supabase)
- ✅ Payments (Stripe)
- ✅ Emails (Resend)
- ✅ Database (Prisma + PostgreSQL)
- ✅ UI Components (shadcn/ui)
- ✅ Type-safe API (tRPC)

## Stack

- **Frontend**: Next.js 15 (App Router), React 19, TypeScript, Tailwind
- **Backend**: tRPC 11, Zod validation
- **Database**: Prisma + PostgreSQL (Supabase)
- **Auth**: Supabase Auth
- **Payments**: Stripe
- **Emails**: Resend + React Email

## Philosophie

> "Qualité où ça compte. Pragmatic engineering, pas de dogmatisme."

## Principes Craft Actifs (12/16)

### De Rapid (6/16)
- ✅ Type Safety (TypeScript strict + Zod)
- ✅ Linting (ESLint)
- ✅ Git Hooks (pre-commit)
- ✅ Error Handling
- ✅ Security (input validation + auth)
- ✅ Self-Documenting Code

### Nouveaux en Balanced (6/16)
- ✅ Architecture Layered (3 couches)
- ✅ Testing 70% coverage
- ✅ Code Review IA
- ✅ Documentation clés
- ✅ SOLID (tous principes appliqués)
- ✅ Performance basique

## Quand migrer vers Crafted ?

- Équipe > 10 développeurs
- Users > 10K
- MRR > $100K
- Besoin de longévité (5-10+ ans)
- Systèmes critiques nécessitant fiabilité maximale

## Documentation

- `CLAUDE.md` - Rules pour Claude Code
- `.cursorrules` - Rules pour Cursor
- `.clinerules` - Rules pour Cline
- `.windsurfrules` - Rules pour Windsurf
