Skip to main content

Backend Local Setup

This guide walks through getting the Express API, PostgreSQL database, Redis, and BullMQ workers running locally.


Prerequisites

RequirementVersionPurpose
Node.js>= 20Runtime
npm>= 9Package manager (workspaces)
Docker & Docker ComposeLatestPostgreSQL 16 + Redis 7
GitLatestSource control

Step-by-Step Setup

1. Clone and Install

git clone <repo-url> Pulse
cd Pulse
npm install

This installs dependencies for all workspaces: apps/api, apps/web, and packages/shared.

2. Start Database Services

docker compose up -d

This starts two containers from docker-compose.yml:

ServiceImagePortPurpose
PostgreSQLpostgres:16-alpine5432Primary database (69+ models)
Redisredis:7-alpine6379BullMQ queues + rate limiting + caching
Verify Containers
docker compose ps
# Both should show "running" status

3. Configure Environment

cp apps/api/.env.example apps/api/.env

Edit apps/api/.env with the required values:

VariableExample ValueRequired
DATABASE_URLpostgresql://postgres:postgres@localhost:5432/unipulseYes
REDIS_URLredis://localhost:6379Yes
JWT_SECRETyour-secret-key-min-32-charsYes
JWT_REFRESH_SECRETyour-refresh-secret-keyYes
ENCRYPTION_KEY64-char hex stringYes
PORT3000No (default)
NODE_ENVdevelopmentNo (default)
FRONTEND_URLhttp://localhost:5173Yes
GEMINI_API_KEYYour Google AI API keyFor AI features
FACEBOOK_APP_IDYour Facebook app IDFor social features
FACEBOOK_APP_SECRETYour Facebook app secretFor social features
TIKTOK_CLIENT_KEYYour TikTok client keyFor social features
TIKTOK_CLIENT_SECRETYour TikTok client secretFor social features
AWS_S3_BUCKETYour S3 bucket nameFor media uploads
AWS_S3_REGIONus-east-1For media uploads
SMTP_HOSTsmtp.gmail.comFor email (OTP, notifications)
SMTP_PORT587For email

See Environment Variables for the complete reference.

4. Run Database Migrations

cd apps/api
npx prisma migrate dev
npx prisma generate

This creates all 69+ database tables and generates the Prisma client.

5. Build the Shared Package

# From root
npm run build --filter=shared

The API imports types and validators from @unipulse/shared, so this must be built before the API can run.

6. Start the API

# From root
npm run dev --filter=api

The API starts on http://localhost:3000. The base path for all routes is /api/v1.

Health Check

Verify the API is running:

curl http://localhost:3000/api/v1/health

Useful Commands

Database

cd apps/api

# Open Prisma Studio (visual DB browser)
npx prisma studio

# Reset database (drops all data, re-runs migrations)
npx prisma migrate reset

# Generate Prisma client after schema changes
npx prisma generate

# Create a new migration
npx prisma migrate dev --name describe_your_change

# View migration status
npx prisma migrate status

Development

# From root - start everything (API + Web + Shared watch)
npm run dev

# Type check all packages
npm run typecheck

# Run tests
npm run test --filter=api

Docker

# View container logs
docker compose logs -f postgres
docker compose logs -f redis

# Stop containers
docker compose down

# Stop and remove volumes (full reset)
docker compose down -v

Common Issues

IssueSolution
ECONNREFUSED on port 5432Docker containers not running. Run docker compose up -d
ECONNREFUSED on port 6379Redis container not running. Run docker compose up -d
Prisma client errorsRun npx prisma generate in apps/api
@unipulse/shared not foundBuild shared package: npm run build --filter=shared
Migration driftRun npx prisma migrate dev to apply pending migrations
Port 3000 already in useKill the existing process or set PORT in .env

Cross-Reference