|
| 1 | +# WARP.md |
| 2 | + |
| 3 | +This file provides guidance to WARP (warp.dev) when working with code in this repository. |
| 4 | + |
| 5 | +## Development Commands |
| 6 | + |
| 7 | +### Basic Development |
| 8 | +```bash |
| 9 | +# Start development server with file watching |
| 10 | +npm run dev |
| 11 | + |
| 12 | +# Start development with Docker (uses Neon Local for database) |
| 13 | +npm run dev:docker |
| 14 | + |
| 15 | +# Start production with Docker (connects to Neon Cloud) |
| 16 | +npm run prod:docker |
| 17 | +``` |
| 18 | + |
| 19 | +### Code Quality |
| 20 | +```bash |
| 21 | +# Lint code |
| 22 | +npm run lint |
| 23 | + |
| 24 | +# Fix linting issues automatically |
| 25 | +npm run lint:fix |
| 26 | + |
| 27 | +# Format code with Prettier |
| 28 | +npm run format |
| 29 | + |
| 30 | +# Check code formatting |
| 31 | +npm run format:check |
| 32 | +``` |
| 33 | + |
| 34 | +### Database Operations |
| 35 | +```bash |
| 36 | +# Generate new migration files from schema changes |
| 37 | +npm run db:generate |
| 38 | + |
| 39 | +# Apply migrations to database |
| 40 | +npm run db:migrate |
| 41 | + |
| 42 | +# Open Drizzle Studio (database GUI) |
| 43 | +npm run db:studio |
| 44 | +``` |
| 45 | + |
| 46 | +### Docker Development |
| 47 | +```bash |
| 48 | +# View development container logs |
| 49 | +docker logs acquisitions-app-dev |
| 50 | + |
| 51 | +# View production container logs |
| 52 | +docker logs acquisitions-app-prod |
| 53 | + |
| 54 | +# Execute commands inside running containers |
| 55 | +docker exec acquisitions-app-dev npm run db:migrate |
| 56 | +docker exec acquisitions-app-prod npm run db:studio |
| 57 | + |
| 58 | +# Stop and clean up containers |
| 59 | +docker-compose -f docker-compose.dev.yml down -v |
| 60 | +docker-compose -f docker-compose.prod.yml down -v |
| 61 | +``` |
| 62 | + |
| 63 | +### Testing Database Connections |
| 64 | +```bash |
| 65 | +# Connect to Neon Local database directly |
| 66 | +docker exec acquisitions-neon-local psql -U neon -d neondb |
| 67 | +``` |
| 68 | + |
| 69 | +## Architecture Overview |
| 70 | + |
| 71 | +### Core Structure |
| 72 | +This is a Node.js/Express REST API with a layered architecture: |
| 73 | + |
| 74 | +- **Routes** (`src/routes/`) - Express route definitions and HTTP endpoint handlers |
| 75 | +- **Controllers** (`src/controllers/`) - Request/response handling and validation |
| 76 | +- **Services** (`src/services/`) - Business logic and data processing |
| 77 | +- **Models** (`src/models/`) - Drizzle ORM database schema definitions |
| 78 | +- **Middleware** (`src/middleware/`) - Cross-cutting concerns (security, authentication) |
| 79 | +- **Utils** (`src/utils/`) - Shared utility functions (JWT, cookies, formatting) |
| 80 | +- **Validations** (`src/validations/`) - Zod schema validation |
| 81 | +- **Config** (`src/config/`) - Application configuration (database, logging, security) |
| 82 | + |
| 83 | +### Database Architecture |
| 84 | +- **ORM**: Drizzle ORM with PostgreSQL |
| 85 | +- **Provider**: Neon Database (serverless PostgreSQL) |
| 86 | +- **Development**: Uses Neon Local for ephemeral database branches |
| 87 | +- **Production**: Direct connection to Neon Cloud |
| 88 | + |
| 89 | +### Security Stack |
| 90 | +- **Arcjet**: Bot detection, rate limiting, and shield protection |
| 91 | +- **Helmet**: HTTP security headers |
| 92 | +- **CORS**: Cross-origin resource sharing configuration |
| 93 | +- **JWT**: Authentication tokens with role-based access |
| 94 | +- **bcrypt**: Password hashing |
| 95 | + |
| 96 | +### Path Imports |
| 97 | +The project uses Node.js path imports (defined in `package.json`): |
| 98 | +```javascript |
| 99 | +import logger from '#config/logger.js'; |
| 100 | +import { users } from '#models/user.model.js'; |
| 101 | +import { createUser } from '#services/auth.service.js'; |
| 102 | +``` |
| 103 | + |
| 104 | +### Environment Configuration |
| 105 | +- `.env.development` - Development environment (with Neon Local) |
| 106 | +- `.env.production` - Production environment (direct Neon Cloud connection) |
| 107 | +- `.env.example` - Template for environment variables |
| 108 | + |
| 109 | +### Key Features |
| 110 | +- User authentication (signup/signin/signout) with JWT tokens |
| 111 | +- Role-based access control (admin, user, guest) |
| 112 | +- Rate limiting based on user roles (admin: 20/min, user: 10/min, guest: 5/min) |
| 113 | +- Comprehensive logging with Winston |
| 114 | +- Request validation with Zod schemas |
| 115 | +- Database migrations with Drizzle Kit |
| 116 | + |
| 117 | +### Docker Setup |
| 118 | +Two environments available: |
| 119 | +- **Development**: Multi-container setup with Neon Local proxy for ephemeral databases |
| 120 | +- **Production**: Optimized single container connecting directly to Neon Cloud |
| 121 | + |
| 122 | +### Development Workflow |
| 123 | +1. Use Docker for consistent development environment |
| 124 | +2. Neon Local creates fresh database branches for each development session |
| 125 | +3. Hot reload enabled for code changes |
| 126 | +4. Use Drizzle Studio for database inspection |
| 127 | +5. ESLint enforces code style with 2-space indentation, single quotes, and semicolons |
| 128 | + |
| 129 | +### API Endpoints |
| 130 | +- `GET /` - Health check endpoint |
| 131 | +- `GET /health` - Detailed health status with uptime and memory usage |
| 132 | +- `GET /api` - API status endpoint |
| 133 | +- `POST /api/auth/sign-up` - User registration |
| 134 | +- `POST /api/auth/sign-in` - User authentication |
| 135 | +- `POST /api/auth/sign-out` - User logout |
| 136 | +- `GET /api/users` - Get all users |
| 137 | +- `GET /api/users/:id` - Get user by ID (placeholder) |
| 138 | +- `PUT /api/users/:id` - Update user (placeholder) |
| 139 | +- `DELETE /api/users/:id` - Delete user (placeholder) |
| 140 | + |
| 141 | +### Database Schema |
| 142 | +- **Users table**: id, name, email, password (hashed), role, created_at, updated_at |
| 143 | +- Default role: "user" |
| 144 | +- Supported roles: "user", "admin" |
0 commit comments