This document explains how to run the production-like backend locally, run migrations, start workers, and test the system.
Prerequisites
- Docker & Docker Compose (for easy local Postgres + Redis)
- Python 3.11 (for local development/testing)
Environment variables (recommended)
DATABASE_URL— e.g.postgresql+asyncpg://postgres:password@db:5432/qrsREDIS_URL— e.g.redis://redis:6379/0JWT_SECRET— strong secret for signing tokensOUTPUT_DIR— where backtest results are written (defaultoutput/)
Quick start with Docker Compose
- Build and start services:
docker-compose up --build -d- Run migrations (inside the backend container):
docker-compose exec backend python scripts/run_migrations.py- Create a user and obtain a token (example using
curl):
curl -X POST http://localhost:8000/api/auth/register \
-H "Content-Type: application/json" \
-d '{"username":"alice","password":"secret"}'
curl -X POST http://localhost:8000/api/auth/token -F "username=alice" -F "password=secret"- Submit a backtest (authenticated):
curl -X POST http://localhost:8000/api/backtest/ \
-H "Authorization: Bearer <TOKEN>" \
-H "Content-Type: application/json" \
-d '{"initial_capital":100000, "weight_scheme":"rank"}'- Listen for progress via WebSocket (example using
wscat):
wscat -c ws://localhost:8000/api/backtest/ws/<JOB_ID>Local development without Docker (optional)
- Set
DATABASE_URLto a running Postgres server (or use SQLite for testing). - Install dependencies:
python -m pip install --upgrade pip
pip install .[dev]- Run migrations:
export DATABASE_URL="postgresql+asyncpg://postgres:password@localhost:5432/qrs"
python scripts/run_migrations.py- Run the backend (development):
uvicorn src.quant_research_starter.api.main:app --reload --port 8000Running tests
Unit and integration tests are configured via pytest.
pip install .[dev]
pytest -qCI
- A GitHub Actions workflow is included at
.github/workflows/ci.ymlwhich runs lint and tests using service containers for PostgreSQL and Redis.
Notes & next steps
- Use a secrets manager to provide
JWT_SECRETand DB credentials in production. - Add TLS, logging aggregation, metrics, and autoscaling for real deployments.