This guide explains how to set up and run the QuPot Quantum Lottery Platform services for local development.
QuPot is a microservices-based quantum lottery platform that uses quantum random number generation for provably fair lottery draws. The platform consists of the following components:
- Quantum Service (Python/FastAPI): Generates quantum random numbers using Qiskit
- Lottery Service (NestJS): Manages lottery draws, tickets, and results
- Blockchain Service (NestJS/Hardhat): Handles blockchain interactions and smart contract operations
- Auth Service (NestJS): Manages user authentication and authorization
- API Gateway (NestJS): Routes requests to appropriate services
The project uses Turborepo for monorepo management and dependency orchestration.
- Node.js v18+ and npm
- Python 3.8+ for the quantum service
- Docker and Docker Compose (optional, for containerized development)
- Clone the repository and install dependencies:
git clone <repository-url>
cd qupot
npm install- Run the development environment:
To start all services in development mode:
npm run devThis command uses Turborepo to run all services in parallel, respecting dependencies between them.
To run only specific services:
# Run just the quantum service
npm run dev -- --filter=quantum-service
# Run multiple specific services
npm run dev -- --filter=quantum-service --filter=api-gatewayThe Quantum Service is a Python FastAPI application that generates random numbers using quantum computing principles.
# Navigate to the quantum service directory
cd apps/quantum-service
# Check environment and dependencies
npm run check-env
# Run the quantum service in development mode
npm run devWhen running, the Quantum Service will be available at http://localhost:8002 with:
- Interactive API documentation at http://localhost:8002/docs
- Custom HTML documentation at http://localhost:8002/
src/main.py: Main FastAPI application with endpointsscripts/check_env.py: Environment verification scriptclient.py: API testing clientvisualize_circuit.py: Quantum circuit visualization generator
The API Gateway routes requests to the appropriate microservices and provides a unified API.
cd apps/api-gateway
npm run devWhen running, the API Gateway will be available at http://localhost:8000
You can use Docker Compose to run all services in containers:
# Start all services
npm run docker:up
# Stop all services
npm run docker:downDocker development is especially useful for:
- Testing the entire system integration
- Ensuring consistent environments across developer machines
- Running services that require specific dependencies
-
Navigate to the quantum service directory:
cd apps/quantum-service -
Activate the virtual environment:
source venv/bin/activate # On Windows: venv\Scripts\activate
-
Implement your feature in
src/main.pyor create new modules as needed -
Test your implementation:
python client.py
-
Run the service to verify your changes:
npm run dev
Each service has its own testing configuration:
# Run tests for all services
npm run test
# Run tests for a specific service
npm run test -- --filter=quantum-serviceMaintain code quality with linting and formatting:
# Run linting for all services
npm run lint
# Format code
npm run formatqupot/
├── apps/ # Microservices
│ ├── api-gateway/ # API Gateway service (NestJS)
│ ├── quantum-service/ # Quantum random number service (FastAPI/Python)
│ │ ├── src/ # Service source code
│ │ ├── scripts/ # Utility scripts
│ │ └── venv/ # Python virtual environment (git-ignored)
│ ├── lottery-service/ # Lottery management service (NestJS)
│ ├── blockchain-service/ # Blockchain & smart contract service (NestJS/Solidity)
│ └── auth-service/ # Authentication service (NestJS)
├── packages/ # Shared libraries
│ └── common-lib/ # Common utilities & types (TypeScript)
├── docker/ # Docker configurations
└── docker-compose.yml # Docker Compose configuration
| Service | Port | Technologies |
|---|---|---|
| API Gateway | 8000 | NestJS |
| Auth Service | 8001 | NestJS/JWT |
| Quantum Service | 8002 | FastAPI/Python/Qiskit |
| Lottery Service | 8003 | NestJS/PostgreSQL |
| Blockchain Service | 8004 | NestJS/Hardhat/Solidity |
| PostgreSQL | 5432 | PostgreSQL |
If you encounter a "port already in use" error:
-
Check which process is using the port:
# On macOS/Linux lsof -i :<port> # On Windows netstat -ano | findstr :<port>
-
Either kill the existing process or change the port in the service's package.json file:
"dev": "if [ ! -d \"venv\" ]; then npm run setup; fi && . venv/bin/activate && uvicorn src.main:app --reload --host 0.0.0.0 --port 8002"
For the Quantum Service, run the environment check to verify the Python setup:
cd apps/quantum-service
npm run check-envCommon issues include:
- Missing Python dependencies
- Incorrect Python version
- Virtual environment not activated
If you encounter Docker issues, try:
# Stop and remove all containers
npm run docker:down
# Clean up Docker resources
docker system prune -a
# Restart services
npm run docker:upIf you encounter Node.js dependency issues:
# Clean npm cache
npm cache clean --force
# Reinstall dependencies
rm -rf node_modules
npm install- Quantum Service README: Detailed documentation for the Quantum Service
- SETUP_SUMMARY.md: Summary of the current setup
- QUANTUM_CONCEPTS.md: Explanation of quantum computing principles used
- FastAPI Documentation: Documentation for FastAPI
- Qiskit Documentation: Documentation for Qiskit
- IBM Quantum: IBM's quantum computing platform
- Turborepo Documentation: Documentation for Turborepo