# mawidi-site

The main Next.js application for [Mawidi](https://mawidi.com). See the [root README](../README.md) for project overview.

---

## Setup

```bash
npm install
cp .env.example .env.local   # Configure your keys
npx prisma migrate dev
npx prisma generate
npm run dev                   # http://localhost:9000
```

## Commands

| Command | Description |
|---------|-------------|
| `npm run dev` | Development server (port 9000) |
| `npm run build` | Production build |
| `npm run test` | Jest unit tests |
| `npm run test:e2e` | Playwright E2E tests |
| `npm run lint` | ESLint |
| `npx tsc --noEmit` | Type check |
| `npx prisma studio` | Database browser |
| `npx prisma migrate dev` | Run migrations |

## Environment Variables

See `.env.example` for all required variables. Key ones:

```bash
DATABASE_URL=              # PostgreSQL connection string
NEXTAUTH_URL=http://localhost:9000
NEXTAUTH_SECRET=           # openssl rand -base64 32
STRIPE_SECRET_KEY=         # Stripe API key
UPSTASH_REDIS_REST_URL=    # Redis for rate limiting + OTP
```

## Structure

```
app/
├── [lang]/                # ar/ and en/ routes
│   ├── page.tsx           # Homepage
│   ├── dashboard/         # Protected dashboard (197 components)
│   ├── signup/            # Multi-step registration
│   ├── login/             # Auth pages
│   ├── pricing/           # Subscription plans
│   ├── blog/              # MDX blog
│   ├── industries/        # 17+ vertical pages
│   └── services/          # Feature pages
├── api/                   # 333 API routes
│   ├── auth/              # NextAuth + OTP
│   ├── stripe/            # Payments + webhooks
│   ├── dashboard/         # Protected endpoints
│   ├── bookings/          # Appointment management
│   ├── whatsapp/          # WhatsApp integration
│   └── voice-agent/       # AI voice agent
components/                # Shared React components
lib/                       # Services, hooks, validators, config
prisma/                    # Schema (93 models) + migrations
__tests__/                 # Jest unit tests
tests/                     # Playwright E2E tests
```

## Auth Stack

| Method | Used For |
|--------|----------|
| NextAuth v5 | Business owner login (email/password, Google OAuth) |
| Redis OTP | Staff login (phone-based, no password) |
| Staff JWT | API access for staff endpoints |
| CSRF tokens | All state-changing operations |

## i18n

- Routes: `/ar/...` (RTL) and `/en/...` (LTR)
- Middleware auto-detects browser language, defaults to Arabic
- Translations: `lib/config/translations/`

## Docker

```bash
# Dev with hot reload
docker compose -f ../docker-compose.dev.yml up

# Production (411MB image)
docker compose -f ../docker-compose.prod.yml up -d
```

## Contact

[mawidi.com](https://mawidi.com) | hello@mawidi.com | Doha, Qatar
