Skip to content

Installation

Prerequisites

DependencyVersionNotes
Node.js24+Required for manual install
pnpm9+Package manager
MongoDB7+Must run as a replica set
Redis7+Used for caching, queues, and sessions
Docker24+Required for Docker install only

Docker Compose starts all services including MongoDB and Redis.

Terminal window
# Clone the repository
git clone <repo-url> ai-gateway
cd ai-gateway
# Copy environment file
cp .env.example .env
# Start all services
docker compose -f docker/docker-compose.yml up -d

This starts five containers:

ContainerPortDescription
aigw-mongo-primary27017MongoDB with replica set auto-init
aigw-redis6379Redis with AOF persistence
aigw-server3000Gateway API server
aigw-workerBullMQ background worker
aigw-admin3001Admin dashboard

Option 2: Manual Install

1. Start Infrastructure

You need MongoDB running as a replica set and Redis. If you have them installed locally:

Terminal window
# Start MongoDB as a replica set
mongod --replSet rs0 --bind_ip_all
# In another terminal, initialize the replica set
mongosh --eval "rs.initiate({_id:'rs0', members:[{_id:0, host:'localhost:27017'}]})"
# Start Redis
redis-server --appendonly yes

Or start only the infrastructure via Docker:

Terminal window
docker compose -f docker/docker-compose.yml up -d mongodb-primary redis

2. Install Dependencies

Terminal window
git clone <repo-url> ai-gateway
cd ai-gateway
pnpm install

3. Configure Environment

Terminal window
cp .env.example .env

Edit .env and set at minimum:

  • JWT_SECRET — at least 16 characters, random string
  • JWT_REFRESH_SECRET — at least 16 characters, random string
  • ENCRYPTION_KEY — exactly 64 hex characters (256-bit key)

Generate secure values:

Terminal window
# Generate JWT secrets
node -e "console.log(require('crypto').randomBytes(48).toString('base64url'))"
# Generate encryption key
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

4. Build and Seed

Terminal window
# Build shared types (must be built first)
pnpm build:shared
# Build the server
pnpm build:server
# Seed the database with default roles and super admin
pnpm seed

5. Start Services

Terminal window
# Start all services (server + worker + admin)
pnpm dev
# Or start individually
pnpm dev:server # Gateway API on port 3000
pnpm dev:worker # Background worker
pnpm dev:admin # Admin dashboard on port 3001

Verify Installation

Check the health endpoint:

Terminal window
curl http://localhost:3000/health

You should receive a JSON response with "status": "ok".

Check the Swagger docs:

http://localhost:3000/docs

Check the admin dashboard:

http://localhost:3001

Troubleshooting

MongoDB replica set errors: MongoDB must run as a replica set for transaction support. If you see connection errors, verify the replica set is initialized with mongosh --eval "rs.status()".

Permission denied on Docker volumes: On Linux, ensure your user is in the docker group or run with sudo.

Port conflicts: If ports 3000, 3001, 27017, or 6379 are in use, update the port mappings in docker-compose.yml or your .env file.