# Calendar API (Node.js)

Express + TypeScript MVC backend for the Calendar Booking Platform.

## Quick Start

```bash
cd node
cp .env.example .env   # configure DB, Redis, JWT, SMTP
npm install
npm run dev            # http://localhost:3000
```

## Scripts

| Command | Description |
|---------|-------------|
| `npm run dev` | Development server with hot reload |
| `npm run build` | Compile TypeScript |
| `npm start` | Run production build |
| `npm run worker` | BullMQ job worker (notifications + calendar sync) |
| `npm run scheduler` | Cron-style job enqueuer |
| `npm test` | Jest unit + integration tests |

## Architecture

MVC layout per [docs/node.md](../docs/node.md):

- **Models** — TypeORM entities + repositories (`src/models/`)
- **Views** — JSON serializers (`src/views/`)
- **Controllers** — HTTP handlers (`src/controllers/`)
- **Services** — Business logic (`src/services/`)

## API Endpoints

Base URL: `http://localhost:3000/v1`

| Group | Routes |
|-------|--------|
| Auth | `POST /auth/register`, `POST /auth/login` |
| Profile | `GET /me`, `PATCH /me` |
| Availability | `GET /me/availability`, `PUT /me/availability` |
| Event types | `GET/POST/PATCH/DELETE /me/event-types` |
| Bookings | `GET /me/bookings`, cancel, reschedule |
| Public | `GET /public/:user/:slug`, slots, bookings, cancel |
| Calendars | OAuth + Apple CalDAV under `/me/calendar-connections` |
| Embed | `GET /embed/config/:key`, CRUD `/me/embed-configs` |
| API keys | `GET/POST/DELETE /me/api-keys` |
| Health | `GET /health`, `GET /health/db` |

Full reference: [docs/API_REFERENCE.md](../docs/API_REFERENCE.md)

## Docker

```bash
docker build -t calendar-api .
docker run -p 3000:3000 --env-file .env calendar-api
```

Run worker and scheduler as separate containers with the same `.env`.

## Related Docs

- [Node Developer Guide](../docs/node.md)
- [MySQL Schema](../docs/mysql.md)
- [Calendar Integrations](../docs/CALENDAR_INTEGRATIONS.md)
