Overview
Opiinix Trade requires environment variables to be configured for multiple workspaces. Each service has its own.env.example file that should be copied and configured.
Quick Setup
Copy all example environment files:Database Configuration
- packages/db/.env
- Production
Configure the PostgreSQL database connection:
PostgreSQL connection string with format:
postgresql://[user]:[password]@[host]:[port]/[database]?schema=[schema]Connection String Components
| Component | Development Value | Description |
|---|---|---|
| User | dev | Database username |
| Password | dev | Database password |
| Host | localhost | Database host |
| Port | 5432 | PostgreSQL port |
| Database | repo | Database name |
| Schema | public | Schema name |
These values match the
docker-compose.yml configuration for local development.Client Configuration
- apps/client/.env
- Generate NEXTAUTH_SECRET
Configure the Next.js frontend application:
Environment Variables
The canonical URL of your site. Used for callbacks and redirects.
- Development:
http://localhost:3000 - Production: Your production domain (e.g.,
https://opinix.trade)
Secret key for NextAuth.js session encryption. Generate with:
Your Twilio Account SID for SMS authentication. Get from Twilio Console.
Your Twilio Auth Token for API authentication.
Your Twilio phone number with country code (e.g.,
+1234567890).Redis Configuration
- packages/order-queue/.env
Configure the Redis connection for the order queue:Or with TLS:
Redis connection URI with format:
redis://[host]:[port]- Development:
redis://localhost:6379 - Production: Your Redis server URL (with authentication if required)
Production Redis
For production with authentication:The
rediss:// protocol enables TLS encryption for Redis connections.WebSocket Service Configuration
- services/wss/.env
The WebSocket service currently has an empty
.env.example but may require:Check the WebSocket service source code for any additional required environment variables.
Prisma Configuration
After configuring the database URL, generate the Prisma client:Docker Environment Variables
When building with Docker, pass environment variables:.env file with Docker Compose:
docker-compose.yml
Verification
Verify your environment configuration:- Database
- Redis
- Application
Test database connection:
If successful, your database connection is working!
Environment Variables Reference
Complete Variable List
Complete Variable List
| Variable | Service | Required | Description |
|---|---|---|---|
DATABASE_URL | db | Yes | PostgreSQL connection string |
NEXTAUTH_URL | client | Yes | NextAuth canonical URL |
NEXTAUTH_SECRET | client | Yes | NextAuth session secret |
TWILIO_ACCOUNT_SID | client | Yes | Twilio account identifier |
TWILIO_AUTH_TOKEN | client | Yes | Twilio authentication token |
TWILIO_NUMBER | client | Yes | Twilio phone number |
REDIS_URI | order-queue | Yes | Redis connection URI |
Security Best Practices
Security Best Practices
- Never commit
.envfiles to Git - Use strong secrets - Generate with
openssl rand -base64 32 - Rotate secrets regularly in production
- Use different values for development and production
- Enable SSL/TLS for production databases and Redis
- Restrict database access to specific IP addresses
- Use environment-specific credentials
Troubleshooting
Database Connection Errors
Database Connection Errors
Error:
Can't reach database serverSolutions:- Ensure Docker containers are running:
docker-compose ps - Check DATABASE_URL format
- Verify PostgreSQL is listening on port 5432:
lsof -i :5432 - Restart Docker:
docker-compose restart timescaledb
Redis Connection Errors
Redis Connection Errors
Error:
Error: connect ECONNREFUSED 127.0.0.1:6379Solutions:- Ensure Redis is running:
docker-compose ps redis - Test connection:
redis-cli ping - Check REDIS_URI in your
.envfiles - Restart Redis:
docker-compose restart redis
Prisma Errors
Prisma Errors
Error:
Prisma schema file not foundSolutions:- Navigate to correct directory:
cd packages/db - Generate Prisma client:
npx prisma generate - Run migrations:
npx prisma migrate dev
NextAuth Errors
NextAuth Errors
Error:
[next-auth][error][MISSING_NEXTAUTH_SECRET]Solutions:- Ensure
NEXTAUTH_SECRETis set inapps/client/.env - Generate a new secret:
openssl rand -base64 32 - Restart the Next.js development server