Open Source Feature Flag and A/B Testing Platform OptiFork is a production-ready, self-hosted feature flag and A/B testing platform designed for modern applications. Built with FastAPI and React, it provides enterprise-grade capabilities with the flexibility of open source.
- π― Feature Flags: Boolean flags with percentage rollouts and rule-based targeting
- π§ͺ A/B Testing: Multi-variant experiments with statistical analysis
- π₯ User Targeting: Advanced rule-based user segmentation
- π Real-time Analytics: Flag exposure tracking and experiment metrics
- π Snowflake Integration: Direct data warehouse connectivity
- ποΈ PostgreSQL Support: Production database with connection pooling
- β‘ Redis Caching: High-performance caching layer
- π‘οΈ Security Middleware: Rate limiting, CORS, security headers
- π Monitoring: Health checks, Prometheus metrics, system stats
- πΎ Backup & Restore: Automated backups with compression
- π³ Docker Support: Production-ready containerization
- π Fast Setup: One-command Docker deployment
- π API Documentation: Auto-generated OpenAPI/Swagger docs
- π§ Configuration: Environment-based config management
- π Logging: Structured logging with configurable levels
-
Clone the repository
git clone https://github.com/yourusername/optifork.git cd optifork -
Start with Docker Compose
# Development (SQLite) docker-compose up -d # Production (PostgreSQL + Redis) docker-compose -f docker-compose.prod.yml up -d
-
Access the application
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
- Python 3.8+
- Node.js 16+
- PostgreSQL (optional, defaults to SQLite)
- Redis (optional, for caching)
cd backend
pip install -r requirements.txt
# Configure environment (optional)
cp ../.env.example .env
# Edit .env with your settings
# Initialize database
python -c "from db import init_database; import asyncio; asyncio.run(init_database())"
# Start backend
uvicorn main:app --reload --host 0.0.0.0 --port 8000cd frontend
npm install
npm startAfter starting the services, verify everything is working:
# Check all containers are running
docker ps
# Expected output should show 3 running containers:
# optifork-frontend, optifork-backend, optifork-redis
# Test API endpoint
curl http://localhost:8000/flags
# Should return: []
# Open frontend in browser
open http://localhost:80If any step fails, check the Troubleshooting section below.
If the deploy script doesn't work, you can run Docker manually:
# Start all services
docker-compose up --build -d
# Check service status
docker ps
# View logs
docker-compose logs
# Stop services
docker-compose down# Quick start (SQLite)
./deploy.sh dev
# Production (PostgreSQL + Redis)
./deploy.sh prod-
Navigate to backend
cd backend -
Set up virtual environment
python3 -m venv venv source venv/bin/activate -
Install dependencies
pip install -r requirements.txt
-
Run the server
uvicorn main:app --reload
The API will be live at:
http://localhost:8000
-
Navigate to frontend
cd frontend -
Install dependencies
npm install
-
Run frontend
npm run dev
-
Open
http://localhost:5173in your browser.
| Endpoint | Method | Description |
|---|---|---|
/experiments |
POST |
Create a new experiment |
/experiments |
GET |
List all experiments |
/experiments/{experiment_name}/assign?user_id={id} |
GET |
Assign a user to a variant |
/experiments/{experiment_name}/exposure |
POST |
Log exposure for user |
/experiments/results |
GET |
View experiment results |
{
"name": "pricing_test",
"description": "A/B test on new pricing model",
"flag_id": 1,
"variants": [
{ "name": "control", "traffic_split": 0.5 },
{ "name": "variant_a", "traffic_split": 0.5 }
]
}
## π³ Docker Deployment
### Quick Commands
```bash
# Start development environment
./deploy.sh dev
# Start production environment
./deploy.sh prod
# View service status
./deploy.sh status
# View logs
./deploy.sh logs
# Create backup
./deploy.sh backup
# Stop all services
./deploy.sh stopCopy and customize environment:
cp .env.example .env
vim .envβββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Frontend β β Backend API β β Database β
β (React) β -> β (FastAPI) β -> β (SQLite/PG) β
β Port: 3000 β β Port: 8000 β β Port: 5432 β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
- π PostgreSQL for production database
- π Redis for caching and sessions
- π Health checks and monitoring
- π Automated backups
- π Horizontal scaling ready
- π‘οΈ Security hardened containers
For detailed deployment guide, see DEPLOYMENT.md
const isEnabled = await checkFeatureFlag(
'new_checkout',
'user123',
{ country: 'US', plan: 'premium' }
);client = OptiForkClient('http://localhost:8000')
enabled = client.check_flag('new_feature', 'user123')curl "http://localhost:8000/flags/new_feature?user_id=user123&country=US"| Endpoint | Method | Description |
|---|---|---|
/flags |
POST |
Create feature flag |
/flags |
GET |
List all flags |
/flags/{name} |
GET |
Check flag for user |
/flags/{name} |
PUT |
Update flag |
/flags/{name}/exposures |
GET |
Get flag exposures |
/experiments |
POST |
Create experiment |
/experiments/{name}/assign |
GET |
Assign user to variant |
Problem: Docker is not running
ERROR: Docker is not running. Please start Docker first.Solution:
- Start Docker Desktop application
- Wait for Docker to fully start (green whale icon)
- Run
docker --versionto verify
Problem: Port already in use
listen tcp 0.0.0.0:8000: bind: address already in useSolution:
# Find process using the port
lsof -i :8000
# Kill the process or use different port
kill -9 <PID>
# Or stop other services
docker-compose downProblem: Backend container keeps restarting
Container optifork-backend Restarting (1) 18 seconds agoSolution:
# Check backend logs for errors
docker logs optifork-backend
# Common fixes:
# 1. Module import errors - rebuilding usually fixes this
docker-compose down
docker-compose up --build
# 2. Database connection issues
docker-compose restart postgresProblem: Frontend shows nginx errors
nginx: [emerg] invalid value in nginx.confSolution: This should be auto-fixed in the latest version. If not:
# Rebuild frontend
docker-compose up --build frontendProblem: Cannot access http://localhost:80
Solution:
# Check if containers are running
docker ps
# Check container logs
docker logs optifork-frontend
docker logs optifork-backend
# Try alternative port
open http://localhost:3000Problem: API returns 404 or connection refused
Solution:
# Verify backend is running
curl http://localhost:8000/flags
# Check backend health
docker exec optifork-backend curl http://localhost:8000/flagsProblem: Database tables not created Solution:
# Restart backend (it creates tables on startup)
docker restart optifork-backend
# Check logs to verify table creation
docker logs optifork-backend | grep "CREATE TABLE"If you want to develop OptiFork:
# Clone and setup
git clone https://github.com/anupamprataps/optifork.git
cd optifork
# Backend development
cd backend
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
uvicorn main:app --reload
# Frontend development (in new terminal)
cd frontend
npm install
npm run devIf you encounter issues not covered here:
- Check logs:
docker-compose logsordocker logs <container-name> - Search issues: Look for similar problems in GitHub Issues
- Create issue: File a new issue with:
- Your OS and Docker version
- Complete error messages
- Steps to reproduce
- Docker logs output
A big thank you to everyone who has helped make OptiFork better β from code and design to docs, ideas, and testing.
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
- π» Contribute on GitHub
- πͺ² Report Issues
- π View All Contributors
- π Read Contributing Guide
OptiFork was originally released under the MIT License.
As of November 2025, the project has been relicensed under the
Apache License, Version 2.0, maintained by the Anshumat Foundation,
a registered nonprofit organization in India.
This change provides stronger patent protection and enterprise compatibility
while keeping OptiFork fully open source and free to use.
See the LICENSE file for the full text.
Built with β€οΈ by Anupam Singh
β Star this repo if you find OptiFork helpful!
