Skip to main content

Development Setup

How to set up a local development environment for the CRM platform.

Prerequisites

  • Node.js 22+
  • pnpm 9+
  • Docker (for PostgreSQL and Redis)
  • Access to monorepo

Initial Setup

1. Clone and Install

git clone <repo-url>
cd hub
pnpm install

2. Start Infrastructure

docker-compose up -d postgres redis

3. Configure Environment

Create .env in the workspace root or configure Infisical:

# Database
CRM_DATABASE_URL=postgresql://postgres:postgres@localhost:5432/crm

# Redis
REDIS_URL=redis://localhost:6379

# JWT
JWT_SECRET=dev-secret

# Social (optional for dev)
# FACEBOOK_APP_ID=...
# FACEBOOK_APP_SECRET=...

4. Run Migrations

cd libs/prisma/crm-client
npx prisma migrate dev
npx prisma generate

5. Start Backend

npx nx serve crm-backend

API available at http://localhost:3000

Project Structure

libs/
├── prisma/crm-client/ # Prisma schema and client
│ ├── prisma/
│ │ ├── schema.prisma
│ │ └── migrations/
│ └── src/
├── crm/
│ ├── core/ # Core services
│ ├── events/ # Event processing
│ ├── campaigns/ # Campaign management
│ ├── automation/ # Marketing automation
│ └── social/ # Social integration

apps/crm/
└── crm-backend/ # NestJS application

Common Commands

Running Services

# Backend API
npx nx serve crm-backend

# Worker (separate terminal)
npx nx serve crm-backend --configuration=worker

Running Tests

# Unit tests
npx nx test crm-core

# All CRM tests
npx nx run-many -t test -p crm-core crm-campaigns crm-backend

# With coverage
npx nx test crm-core --coverage

Database Operations

cd libs/prisma/crm-client

# Create migration
npx prisma migrate dev --name <name>

# Reset database
npx prisma migrate reset

# Open Prisma Studio
npx prisma studio

Code Generation

# Generate Prisma client after schema changes
npx prisma generate

# Generate NestJS module
npx nx g @nx/nest:module feature-name --project=crm-backend

# Generate service
npx nx g @nx/nest:service feature-name --project=crm-backend

Debugging

VS Code Launch Configuration

Add to .vscode/launch.json:

{
"version": "0.2.0",
"configurations": [
{
"name": "CRM Backend",
"type": "node",
"request": "launch",
"runtimeExecutable": "pnpm",
"runtimeArgs": ["nx", "serve", "crm-backend"],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal"
}
]
}

Debugging Events

Enable verbose logging:

DEBUG=bullmq:* npx nx serve crm-backend

Troubleshooting

Prisma Client Not Found

cd libs/prisma/crm-client
npx prisma generate

Database Connection Failed

Check Docker is running:

docker-compose ps
docker-compose logs postgres

Redis Connection Failed

Check Redis:

docker-compose logs redis
redis-cli ping

Port Already in Use

# Find process
lsof -i :3000

# Kill process
kill -9 <PID>