# Task 002 — App Foundation

## Objective

Scaffold the Next.js App Router application with TypeScript, Tailwind CSS, MongoDB connection utility, and project conventions under `/src`.

## Scope

- Next.js at repository root with `--src-dir` and `@/*` alias
- TypeScript strict configuration
- Tailwind CSS setup
- `lib/db.ts` MongoDB connection singleton
- `lib/env.ts` environment validation for core vars
- App layout shell (RTL Arabic root; no sidebar)
- Health API route `GET /api/health`
- shadcn/ui init — **deferred** (documented in decisions log)

**Out of scope:** Auth, CRM models, shadcn components, business pages.

## Requirements

1. `npm run dev` starts without errors.
2. `npm run build` succeeds.
3. MongoDB connection via `connectDB()` when `MONGODB_URI` set.
4. Folder structure matches `docs/01-architecture.md`.
5. ESLint configured (Next.js default).

## Files to create or modify

| Path | Action |
|------|--------|
| `package.json`, `tsconfig.json`, `next.config.ts` | Create |
| `src/app/layout.tsx`, `src/app/page.tsx` | Create |
| `src/app/api/health/route.ts` | Create |
| `src/lib/db.ts`, `src/lib/env.ts`, `src/lib/constants.ts` | Create |
| `src/types/index.ts` | Create |
| `postcss.config.mjs`, `eslint.config.mjs` | Create |
| `docs/01-architecture.md` | Update |
| `docs/03-api-specification.md` | Health route |
| `docs/04-ui-pages.md` | Home page |
| `docs/10-environment-variables.md` | Required now |
| `docs/12-deployment.md` | Local commands |
| `docs/16-changelog.md` | Task 002 entry |

## Acceptance criteria

- [x] Dev and build scripts work
- [x] Health endpoint returns JSON status
- [x] Env validation enforced for `MONGODB_URI`, `NEXTAUTH_*`, `APP_URL` on server `getEnv()`
- [x] README updated with setup commands
- [x] No CRM features implemented

## Documentation updates required

- [x] `docs/01-architecture.md`
- [x] `docs/03-api-specification.md`
- [x] `docs/04-ui-pages.md`
- [x] `docs/10-environment-variables.md`
- [x] `docs/12-deployment.md`
- [x] `docs/16-changelog.md`
- [x] `docs/13-decisions-log.md` (shadcn deferred)

**Status:** Complete
