|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Development Commands |
| 6 | + |
| 7 | +- **Development server**: `pnpm run dev` - Starts both backend and email template development server |
| 8 | +- **Backend only**: `pnpm run start:dev` - Starts just the backend with hot reload |
| 9 | +- **Build**: `pnpm run build` - Builds the project using tsup |
| 10 | +- **Production start**: `pnpm run start:prod` - Starts production build with .env.production |
| 11 | +- **Local start**: `pnpm run start:local` - Starts production build with .env.local |
| 12 | +- **Database seeder**: `pnpm run seeder` - Runs database seeding scripts |
| 13 | +- **Linting**: `pnpm run lint` - Runs ESLint, `pnpm run lint:fix` - Auto-fixes linting issues |
| 14 | +- **Email templates**: `pnpm run email:dev` - Starts email template development server |
| 15 | + |
| 16 | +## Architecture Overview |
| 17 | + |
| 18 | +This is a TypeScript Express.js backend toolkit with the following key architectural components: |
| 19 | + |
| 20 | +### Core Architecture |
| 21 | +- **MagicRouter System**: Custom routing ([src/openapi/magic-router.ts](src/openapi/magic-router.ts)) that automatically generates OpenAPI/Swagger documentation from Zod schemas |
| 22 | +- **Module-based structure**: Features organized in modules under [src/modules/](src/modules/) (auth, user) |
| 23 | +- **Configuration management**: Type-safe config using Zod validation in [src/config/config.service.ts](src/config/config.service.ts) |
| 24 | +- **Database**: MongoDB with Mongoose ODM, connection managed in [src/lib/database.ts](src/lib/database.ts) |
| 25 | + |
| 26 | +### Key Features |
| 27 | +- **Authentication**: JWT-based with optional OTP verification, Google OAuth support |
| 28 | +- **File Uploads**: Multer with S3 integration via [src/lib/aws.service.ts](src/lib/aws.service.ts) |
| 29 | +- **Email System**: React Email templates with Mailgun provider, queue-based sending |
| 30 | +- **Real-time**: Socket.io integration with Redis adapter |
| 31 | +- **Background Jobs**: BullMQ with Redis for email queues and other background tasks |
| 32 | +- **API Documentation**: Auto-generated Swagger docs at `/api-docs` from MagicRouter |
| 33 | +- **Queue Dashboard**: BullMQ admin dashboard at `/admin/queues` |
| 34 | + |
| 35 | +### Middleware Stack |
| 36 | +- Request validation with Zod schemas ([src/middlewares/validate-zod-schema.middleware.ts](src/middlewares/validate-zod-schema.middleware.ts)) |
| 37 | +- JWT extraction and authorization ([src/middlewares/extract-jwt-schema.middleware.ts](src/middlewares/extract-jwt-schema.middleware.ts)) |
| 38 | +- File upload handling with S3 ([src/middlewares/multer-s3.middleware.ts](src/middlewares/multer-s3.middleware.ts)) |
| 39 | +- Access control middleware ([src/middlewares/can-access.middleware.ts](src/middlewares/can-access.middleware.ts)) |
| 40 | + |
| 41 | +### Environment Setup |
| 42 | +1. Start Docker services: `docker compose up -d` (MongoDB + Redis) |
| 43 | +2. Install dependencies: `pnpm i` |
| 44 | +3. Configure environment variables using `.env.sample` as template |
| 45 | + |
| 46 | +### Key Patterns |
| 47 | +- **MagicRouter**: All API routes use MagicRouter for automatic OpenAPI generation |
| 48 | +- **Zod Schemas**: Every route uses Zod for request/response validation |
| 49 | +- **Service Layer**: Business logic separated into service files |
| 50 | +- **Queue-based**: Email sending and background jobs use BullMQ queues |
| 51 | +- **Type Safety**: Full TypeScript coverage with Zod for runtime validation |
| 52 | + |
| 53 | +### File Upload & Storage |
| 54 | +- Multer middleware handles file uploads |
| 55 | +- AWS S3 integration for file storage |
| 56 | +- File upload routes in [src/upload/](src/upload/) |
| 57 | + |
| 58 | +### Email System |
| 59 | +- React Email for template development |
| 60 | +- Mailgun for email delivery |
| 61 | +- Queue-based sending system in [src/queues/email.queue.ts](src/queues/email.queue.ts) |
| 62 | + |
| 63 | +## Important Notes |
| 64 | +- All expiration times in config are in milliseconds (converted from strings) |
| 65 | +- The project uses pnpm as package manager |
| 66 | +- Database seeding is available via the seeder script |
| 67 | +- Global error handling in [src/utils/globalErrorHandler.ts](src/utils/globalErrorHandler.ts) |
| 68 | +- Logging uses Pino logger with pretty printing in development |
0 commit comments