Follow these steps to get the Order Matching Engine backend running locally.
Ensure you have these installed:
- Node.js v18+ (Download)
- PostgreSQL v14+ (Download)
- Redis v6+ (Download)
- Git (optional, for version control)
Open a terminal in the project directory and run:
npm installThis will install all required packages including TypeScript, Express, Prisma, Redis client, and more.
Copy the example environment file:
cp .env.example .envEdit the .env file with your configuration:
NODE_ENV=development
PORT=3000
# Update with your PostgreSQL credentials
DATABASE_URL="postgresql://postgres:your_password@localhost:5432/trading_engine?schema=public"
# Generate a secure random string for production
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
# Default is fine for local Redis
REDIS_URL=redis://localhost:6379Important: Change your_password to your actual PostgreSQL password.
Open PostgreSQL command line:
# Using psql
psql -U postgresCreate the database:
CREATE DATABASE trading_engine;
\qGenerate Prisma Client and create database tables:
npm run prisma:generate
npm run prisma:migrateYou should see output confirming the migration was successful and all tables were created.
On Windows (WSL or Redis for Windows):
redis-serverOn macOS (using Homebrew):
brew services start redisOn Linux:
sudo systemctl start redisVerify Redis is running:
redis-cli ping
# Should output: PONGnpm run devYou should see:
🚀 Server running on port 3000
📊 Environment: development
Redis connected successfully
🔗 Health check: http://localhost:3000/health
Open a new terminal and test the health endpoint:
curl http://localhost:3000/healthYou should get:
{
"status": "ok",
"timestamp": "2026-01-21T..."
}curl -X POST http://localhost:3000/auth/register \
-H "Content-Type: application/json" \
-d '{"email":"test@example.com","password":"password123"}'Save the accessToken from the response for making authenticated requests.
Replace YOUR_ACCESS_TOKEN with the token from step 9:
curl -X POST http://localhost:3000/orders \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-d '{
"symbol": "AAPL",
"side": "BUY",
"price": 150.00,
"quantity": 10
}'Change the PORT in your .env file to another port like 3001.
- Verify PostgreSQL is running:
pg_isready - Check your
DATABASE_URLin.env - Ensure the database
trading_engineexists
- Verify Redis is running:
redis-cli ping - Check your
REDIS_URLin.env
Run: npm run prisma:generate
Make sure all dependencies are installed: npm install
npm run prisma:studioOpens a web UI at http://localhost:5555 to view and edit database records.
npm run lint
npm run formatnpm run build
npm startNow that Phase 1 is running:
- ✅ You can register users and authenticate
- ✅ Create buy/sell orders
- ✅ View portfolios and open orders
- ✅ Orders are being queued in Redis
Coming in Phase 2:
- Order matching engine implementation
- Real-time trade execution
- WebSocket support for live updates
- Order cancellation
| Command | Description |
|---|---|
npm run dev |
Start development server with hot reload |
npm run build |
Compile TypeScript to JavaScript |
npm start |
Run production build |
npm run prisma:generate |
Generate Prisma Client |
npm run prisma:migrate |
Run database migrations |
npm run prisma:studio |
Open database GUI |
npm run lint |
Check code quality |
npm run format |
Format code with Prettier |
Congratulations! Your Phase 1 backend is now running. 🎉
Refer to README.md for full documentation and API_ROUTES.md for complete API reference.