Skip to main content

Prerequisites

Before you begin, ensure you have the following installed:

Node.js

Version 18 or higher required

npm

Version 10.9.0 or higher

Docker

For running PostgreSQL and Redis

Git

For version control

Quick Start

1

Clone the repository

Clone the Opinix Trade repository to your local machine:
git clone https://github.com/Praashh/opinix-trade.git
cd opinix-trade
2

Start infrastructure services

Start PostgreSQL (TimescaleDB) and Redis using Docker Compose:
docker-compose up -d
This starts:
  • TimescaleDB on port 5432 (PostgreSQL)
  • Redis on port 6379
3

Install dependencies

Install all dependencies for the monorepo:
npm install
4

Configure environment variables

Set up environment variables for each workspace. See the Environment Configuration page for details.
# Database
cp packages/db/.env.example packages/db/.env

# Client
cp apps/client/.env.example apps/client/.env

# Order Queue
cp packages/order-queue/.env.example packages/order-queue/.env

# WebSocket Service
cp services/wss/.env.example services/wss/.env
5

Generate Prisma client

Generate the Prisma client for database access:
cd packages/db
npx prisma generate
cd ../..
6

Run database migrations

Apply database migrations:
cd packages/db
npx prisma migrate dev
cd ../..
7

Build the project

Build all packages and applications:
npm run build
8

Start development servers

Start all services in development mode:
npm run dev
This starts all workspaces concurrently using Turbo.
Your development environment is now ready!

Monorepo Structure

Opiinix Trade uses a Turborepo monorepo architecture:
opiinix-trade/
├── apps/
│   ├── client/          # Next.js frontend application
│   └── server/          # Express backend API
├── packages/
│   ├── db/              # Prisma database schema and client
│   ├── order-queue/     # Redis-based order queue
│   ├── types/           # Shared TypeScript types
│   ├── zod/             # Zod validation schemas
│   └── logger/          # Shared logging utility
├── services/
│   ├── engine/          # Order matching engine
│   └── wss/             # WebSocket server
├── docker-compose.yml   # Infrastructure services
├── turbo.json          # Turborepo configuration
└── package.json        # Root package.json

Workspaces

The client application built with Next.js 14, featuring:
  • Server-side rendering
  • NextAuth.js for authentication
  • Radix UI components
  • TanStack Query for data fetching
  • Real-time WebSocket connections
Scripts:
  • npm run dev - Start development server on port 3000
  • npm run build - Build for production
  • npm run start - Start production server
  • npm run lint - Lint code
The backend API server built with Express, handling:
  • Order placement and management
  • User authentication (JWT)
  • Event management
  • Portfolio tracking
Scripts:
  • npm run dev - Build and start server
  • npm run build - Build with esbuild
  • npm run start - Start production server
Prisma-based database package providing:
  • PostgreSQL schema definitions
  • Type-safe database client
  • Migration management
Scripts:
  • npm run build - Generate Prisma client
Redis-based queue for asynchronous order processing:
  • Order enqueueing
  • Worker management
  • Queue monitoring
Scripts:
  • npm run dev - Start with nodemon
  • npm run start - Start worker
The core order matching engine:
  • Order book management
  • Price-time priority matching
  • Real-time order execution
Scripts:
  • npm run dev - Build and start
  • npm run build - Build with esbuild
Real-time WebSocket server for:
  • Order book updates
  • Live price streaming
  • Event notifications
Scripts:
  • npm run dev - Build and start
  • npm run build - Build with esbuild

Available Scripts

Run these commands from the root directory:
# Start all services in development mode
npm run dev

# Start specific services
cd apps/client && npm run dev
cd apps/server && npm run dev

Turborepo Configuration

The project uses Turborepo for efficient monorepo management. Key configuration from turbo.json:
{
  "tasks": {
    "build": {
      "dependsOn": ["^build"],
      "outputs": [".next/**", "!.next/cache/**"]
    },
    "dev": {
      "cache": false,
      "persistent": true
    },
    "lint": {
      "dependsOn": ["^lint"]
    }
  }
}
Turborepo automatically handles task dependencies and caching for optimal build performance.

Port Configuration

Default ports used in development:
ServicePortDescription
Client (Next.js)3000Frontend application
Server (Express)3001Backend API
PostgreSQL5432Database
Redis6379Cache & Queue
WebSocket8080Real-time updates

Next Steps