# Crafted SaaS - Balanced Web+Mobile

⚖️ **Niveau BALANCED** - Pragmatic Quality, Web + Mobile

## Configuration

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

## Architecture

**3-Couches** - Séparation claire des responsabilités

```
apps/
├── web/              # Next.js 15 app
└── mobile/           # React Native (Expo) app

packages/
├── api/              # tRPC routers (thin, < 20 lignes)
├── services/         # Business logic (SHARED, < 50 lignes)
├── database/         # Prisma + Repositories
├── validators/       # Zod schemas (SHARED)
├── auth/             # Supabase Auth
├── payments/         # Stripe
├── emails/           # Resend + React Email
└── ui/               # UI components
```

## 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 |
| **Comments** | WHY required (NO inline comments) |

## Testing

- ✅ Unit tests services (100% méthodes publiques)
- ✅ tRPC routers (happy path + erreurs)
- ✅ Component tests (critiques)
- ✅ E2E (auth + checkout)
- ✅ Integration tests (avec 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 web dev server
pnpm --filter @crafted/web dev

# Start mobile dev server (in another terminal)
pnpm --filter @crafted/mobile dev
```

## Shared Code Strategy

**Services Layer** - Business logic shared between web and mobile:
- User management
- Product operations
- Payment processing
- Authentication flows

**Validators** - Zod schemas shared across platforms:
- Input validation
- API contracts
- Type safety

**API Layer** - tRPC routers orchestrate services:
- Thin orchestration (< 20 lines)
- Platform-agnostic
- Type-safe client generation

## Features Included

- ✅ Authentication (Supabase)
- ✅ Payments (Stripe)
- ✅ Emails (Resend)
- ✅ Database (Prisma + PostgreSQL)
- ✅ UI Components Web (shadcn/ui)
- ✅ UI Components Mobile (React Native)
- ✅ Type-safe API (tRPC)
- ✅ Shared Services Layer
- ✅ Shared Validators

## Stack

### Web
- **Frontend**: Next.js 15 (App Router), React 19, TypeScript, Tailwind
- **UI**: shadcn/ui

### Mobile
- **Framework**: React Native + Expo SDK 52+
- **Navigation**: Expo Router
- **Styling**: NativeWind (Tailwind for RN)
- **Storage**: Expo SecureStore

### Shared
- **Backend**: tRPC 11, Zod validation
- **Database**: Prisma + PostgreSQL (Supabase)
- **Auth**: Supabase Auth
- **Payments**: Stripe
- **Emails**: Resend + React Email
- **Data Fetching**: TanStack Query

## Mobile-Specific Features

- Expo Router (navigation)
- SecureStore (tokens sécurisés)
- NativeWind (Tailwind pour RN)
- Push notifications (Expo)
- Deep linking
- Platform.select patterns

## Philosophie

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

## Principes Craft Actifs (12/16)

- ✅ Type Safety (TypeScript strict + Zod)
- ✅ Linting (ESLint)
- ✅ Git Hooks
- ✅ Error Handling
- ✅ Security (input validation + auth)
- ✅ Self-Documenting Code
- ✅ Architecture Layered (séparation concerns)
- ✅ 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 d'architecture hexagonale
- Business logic complexe
- Long-terme (5-10+ ans)

## Tests

```bash
# Run all tests
pnpm test

# Run tests in watch mode
pnpm test:watch

# Generate coverage report
pnpm test:coverage

# Run E2E tests
pnpm test:e2e
```

## Documentation

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