|
| 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 | +### Core Commands |
| 8 | +- **Run development server**: `npm run dev:server` - Starts the server with hot reload using tsx watch |
| 9 | +- **Build project**: `npm run build` - Runs TypeScript check and builds with tsup |
| 10 | +- **Start production**: `npm run start:prod` - Runs the compiled application from dist/ |
| 11 | +- **Lint code**: `npm run lint` - Runs ESLint with auto-fix on TypeScript files |
| 12 | +- **Check lint**: `npm run lint:check` - Runs ESLint without auto-fix |
| 13 | + |
| 14 | +### Database Commands |
| 15 | +The project uses Prisma with support for multiple database providers (PostgreSQL, MySQL, psql_bouncer). Commands automatically use the DATABASE_PROVIDER from .env: |
| 16 | + |
| 17 | +- **Generate Prisma client**: `npm run db:generate` |
| 18 | +- **Deploy migrations**: `npm run db:deploy` (Unix/Mac) or `npm run db:deploy:win` (Windows) |
| 19 | +- **Open Prisma Studio**: `npm run db:studio` |
| 20 | +- **Create new migration**: `npm run db:migrate:dev` (Unix/Mac) or `npm run db:migrate:dev:win` (Windows) |
| 21 | + |
| 22 | +## Architecture Overview |
| 23 | + |
| 24 | +### Project Structure |
| 25 | +Evolution API is a WhatsApp integration platform built with TypeScript and Express, supporting both Baileys (WhatsApp Web) and WhatsApp Cloud API connections. |
| 26 | + |
| 27 | +### Core Components |
| 28 | + |
| 29 | +**API Layer** (`src/api/`) |
| 30 | +- **Controllers**: Handle HTTP requests for different resources (instance, chat, group, sendMessage, etc.) |
| 31 | +- **Services**: Business logic layer containing auth, cache, channel, monitor, proxy services |
| 32 | +- **Routes**: RESTful API endpoints with authentication guards |
| 33 | +- **DTOs**: Data transfer objects for request/response validation using class-validator |
| 34 | +- **Repository**: Database access layer using Prisma ORM |
| 35 | + |
| 36 | +**Integrations** (`src/api/integrations/`) |
| 37 | +- **Chatbot**: Supports multiple chatbot platforms (Typebot, Chatwoot, Dify, OpenAI, Flowise, N8N) |
| 38 | +- **Event**: WebSocket, RabbitMQ, Amazon SQS event systems |
| 39 | +- **Storage**: S3/Minio file storage integration |
| 40 | +- **Channel**: Multi-channel messaging support |
| 41 | + |
| 42 | +**Configuration** (`src/config/`) |
| 43 | +- Environment configuration management |
| 44 | +- Database provider switching (PostgreSQL/MySQL/PgBouncer) |
| 45 | +- Multi-tenant support via DATABASE_CONNECTION_CLIENT_NAME |
| 46 | + |
| 47 | +### Key Design Patterns |
| 48 | + |
| 49 | +1. **Multi-Provider Database**: Uses `runWithProvider.js` to dynamically select database provider and migrations |
| 50 | +2. **Module System**: Path aliases configured in tsconfig.json (@api, @cache, @config, @utils, @validate) |
| 51 | +3. **Event-Driven**: EventEmitter2 for internal events, supports multiple external event systems |
| 52 | +4. **Instance Management**: Each WhatsApp connection is managed as an instance with memory lifecycle (DEL_INSTANCE config) |
| 53 | + |
| 54 | +### Database Schema |
| 55 | +- Supports multiple providers with provider-specific schemas in `prisma/` |
| 56 | +- Separate migration folders for each provider (postgresql-migrations, mysql-migrations) |
| 57 | +- psql_bouncer uses PostgreSQL migrations but with connection pooling |
| 58 | + |
| 59 | +### Authentication & Security |
| 60 | +- JWT-based authentication |
| 61 | +- API key support |
| 62 | +- Instance-specific authentication |
| 63 | +- Configurable CORS settings |
| 64 | + |
| 65 | +### Messaging Features |
| 66 | +- WhatsApp Web (Baileys library) and WhatsApp Cloud API support |
| 67 | +- Message queue support (RabbitMQ, SQS) |
| 68 | +- Real-time updates via WebSocket |
| 69 | +- Media file handling with S3/Minio storage |
| 70 | +- Multiple chatbot integrations with trigger management |
| 71 | + |
| 72 | +### Environment Variables |
| 73 | +Critical configuration in `.env`: |
| 74 | +- SERVER_TYPE, SERVER_PORT, SERVER_URL |
| 75 | +- DATABASE_PROVIDER and DATABASE_CONNECTION_URI |
| 76 | +- Log levels and Baileys-specific logging |
| 77 | +- Instance lifecycle management (DEL_INSTANCE) |
| 78 | +- Feature toggles for data persistence (DATABASE_SAVE_*) |
0 commit comments