The world's first mobile-native cloud IDE backend
DevPocket Server is a production-ready Python FastAPI backend that powers the DevPocket mobile-first cloud IDE. It provides secure, scalable development environments accessible from any mobile device.
- DevPocker Mobile App: https://github.com/mrgoonie/devpocket-app
- JWT Authentication with secure token management
- Google OAuth integration for seamless sign-in
- Role-based access control (Free, Starter, Pro, Admin)
- Rate limiting and DDoS protection
- Security headers and CORS configuration
- Account lockout after failed login attempts
- Multi-template support (Python, Node.js, Go, Rust, Ubuntu)
- Resource limits based on subscription plans
- Real-time monitoring (CPU, memory, storage usage)
- Environment lifecycle management (create, start, stop, delete)
- Persistent storage for development workspaces
- Real-time terminal access to environments
- Live log streaming from containers
- Connection management with automatic cleanup
- Rate limiting for WebSocket connections
- Structured logging with JSON output
- Health checks for Kubernetes deployments
- Metrics collection with Prometheus integration
- Database indexing for optimal performance
- Docker containerization with multi-stage builds
- Docker Compose setup with all dependencies
- Nginx reverse proxy with SSL termination
- MongoDB with replica set support
- Redis for caching and session management
βββββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββ
β Mobile App ββββββ Nginx Proxy ββββββ FastAPI App β
β (Flutter) β β (Load Balancer) β β (Python) β
βββββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββ
β
ββββββββββββββββββββ β
β Environment βββββββββββββ€
β Orchestrator β β
β (Kubernetes) β β
ββββββββββββββββββββ β
β
βββββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββ
β MongoDB ββββββ Redis ββββββ Prometheus β
β (Database) β β (Cache) β β (Metrics) β
βββββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββ
- Docker and Docker Compose
- Python 3.11+ (for local development)
- MongoDB 7.0+
- Redis 7.0+
git clone <repository-url>
cd devpocket-serverCopy the example environment file and configure your settings:
cp .env.example .envEdit .env with your configuration:
# Database
MONGODB_URL=mongodb://localhost:27017
DATABASE_NAME=devpocket
# Security
SECRET_KEY=your-super-secret-key-here
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
# Application
ENVIRONMENT=development
DEBUG=true
ALLOWED_ORIGINS=http://localhost:3000,http://localhost:3001# Add a default cluster credentials to database
export ENV_FILE=.env.prod
python3 scripts/add_default_ovh_cluster.py
# Show available default templates (no database required)
python3 scripts/show_default_templates.py
# Seed default environment templates (requires MongoDB)
python3 scripts/seed_templates.py
# Force reseed templates (removes existing ones first)
python3 scripts/seed_templates.py --force# Start all services
docker-compose up -d
# Check service status
docker-compose ps
# View logs
docker-compose logs -f devpocket-api# Check API health
curl http://localhost:8000/health
# Access API documentation
open http://localhost:8000/docs-
Install Dependencies
pip install -r requirements.txt
-
Start Database Services
docker-compose up -d mongo redis
-
Run the Application
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
-
Access the API
- API: http://localhost:8000
- Documentation: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
| Variable | Default | Description |
|---|---|---|
MONGODB_URL |
mongodb://localhost:27017 |
MongoDB connection string |
DATABASE_NAME |
devpocket |
Database name |
SECRET_KEY |
generated | JWT secret key |
GOOGLE_CLIENT_ID |
None |
Google OAuth client ID |
GOOGLE_CLIENT_SECRET |
None |
Google OAuth client secret |
DEBUG |
False |
Enable debug mode |
LOG_LEVEL |
INFO |
Logging level |
ALLOWED_ORIGINS |
["http://localhost:3000"] |
CORS allowed origins |
POST /api/v1/auth/register
POST /api/v1/auth/login
POST /api/v1/auth/google
GET /api/v1/auth/me
POST /api/v1/auth/logoutGET /api/v1/environments
POST /api/v1/environments
GET /api/v1/environments/{id}
DELETE /api/v1/environments/{id}
POST /api/v1/environments/{id}/start
POST /api/v1/environments/{id}/stop
GET /api/v1/environments/{id}/metricsWS /api/v1/ws/terminal/{environment_id}
WS /api/v1/ws/logs/{environment_id}curl -X POST http://localhost:8000/api/v1/auth/register \
-H "Content-Type: application/json" \
-d '{
"username": "developer",
"email": "dev@example.com",
"password": "SecurePass123!",
"full_name": "Developer User"
}'curl -X POST http://localhost:8000/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{
"username_or_email": "developer",
"password": "SecurePass123!"
}'curl -X POST http://localhost:8000/api/v1/environments \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{
"name": "my-python-env",
"template": "python"
}'const ws = new WebSocket('ws://localhost:8000/api/v1/ws/terminal/env-123?token=your-jwt-token');
ws.onmessage = function(event) {
const data = JSON.parse(event.data);
console.log('Terminal output:', data);
};
ws.send(JSON.stringify({
type: 'input',
data: 'ls -la\n'
}));# Build and start all services
docker-compose -f docker-compose.yaml up -d
# Scale API instances
docker-compose up -d --scale devpocket-api=3
# Update containers
docker-compose pull
docker-compose up -dThe project includes comprehensive Kubernetes manifests and automated CI/CD:
# Quick deployment
./scripts/deploy.sh
# Deploy specific version
./scripts/deploy.sh v1.2.3
# Update secrets
./scripts/update-secrets.sh- GitHub Actions: Automatic build and deploy on push to
main - Docker Registry:
digitop/devpocket-apion Docker Hub - Versioning: Semantic versioning with Git tags
- Health Checks: Automated readiness and liveness probes
- Scaling: Horizontal Pod Autoscaler (3-10 replicas)
See k8s/README.md for detailed Kubernetes deployment guide.
-
Authentication & Authorization
- JWT tokens with configurable expiration
- Google OAuth integration
- Role-based access control
- Account lockout after failed attempts
-
API Security
- Rate limiting (100 req/min global, 5 req/min auth)
- Request size limits (10MB)
- CORS configuration
- Security headers (CSP, HSTS, etc.)
-
Data Protection
- Password hashing with bcrypt
- Secure token generation
- Database input validation
- Environment variable secrets
-
Infrastructure Security
- Non-root container user
- Network isolation
- Health checks
- Graceful shutdown handling
-
Production Secrets
# Generate secure secret key python -c "import secrets; print(secrets.token_urlsafe(32))" # Use environment variables for all secrets export SECRET_KEY="your-secure-key" export GOOGLE_CLIENT_SECRET="your-oauth-secret"
-
Database Security
# Enable MongoDB authentication MONGODB_URL=mongodb://username:password@mongo:27017/devpocket?authSource=admin
-
SSL/TLS Configuration
server { listen 443 ssl http2; ssl_certificate /path/to/cert.pem; ssl_certificate_key /path/to/key.pem; # ... additional SSL configuration }
- Health:
GET /health- Basic service health - Readiness:
GET /health/ready- Database connectivity - Liveness:
GET /health/live- Service responsiveness
Structured logging with configurable formats:
# JSON logging for production
LOG_FORMAT=json
# Console logging for development
LOG_FORMAT=consoleBuilt-in metrics collection for:
- Request counts and latencies
- Database connection pools
- Environment resource usage
- WebSocket connections
- Error rates
# Add to docker-compose.yaml
services:
prometheus:
image: prom/prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml-
Indexes
// Automatically created indexes db.users.createIndex({ "email": 1 }, { unique: true }) db.environments.createIndex({ "user_id": 1, "status": 1 })
-
Connection Pooling
# MongoDB connection pool client = AsyncIOMotorClient( MONGODB_URL, maxPoolSize=10, minPoolSize=10 )
-
Async/Await
- All I/O operations are asynchronous
- Non-blocking database calls
- Concurrent request handling
-
Caching
- Redis for session storage
- In-memory rate limiting
- Connection pooling
-
Resource Limits
# Container resource limits resources: limits: memory: "512Mi" cpu: "500m" requests: memory: "256Mi" cpu: "250m"
# Install test dependencies
pip install pytest pytest-asyncio httpx
# Run all tests
pytest
# Run with coverage
pytest --cov=app --cov-report=html
# Run specific test file
pytest tests/test_auth.py -v- Unit Tests: Individual function testing
- Integration Tests: Database and service integration
- API Tests: HTTP endpoint testing
- WebSocket Tests: Real-time connection testing
import pytest
from httpx import AsyncClient
from app.main import app
@pytest.mark.asyncio
async def test_register_user():
async with AsyncClient(app=app, base_url="http://test") as ac:
response = await ac.post("/api/v1/auth/register", json={
"username": "testuser",
"email": "test@example.com",
"password": "TestPass123!"
})
assert response.status_code == 201
assert response.json()["username"] == "testuser"name: CI/CD Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install pytest pytest-asyncio httpx
- name: Run tests
run: pytest
deploy:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Deploy to production
run: |
# Your deployment script here
echo "Deploying to production..."-
Fork & Clone
git clone <your-fork-url> cd devpocket-server
-
Create Feature Branch
git checkout -b feature/amazing-feature
-
Install Development Dependencies
pip install -r requirements.txt pip install -r requirements-dev.txt
-
Make Changes & Test
pytest black app/ # Code formatting flake8 app/ # Linting
-
Commit & Push
git commit -m "Add amazing feature" git push origin feature/amazing-feature -
Create Pull Request
- Black for code formatting
- Flake8 for linting
- Type hints for all functions
- Docstrings for public methods
- Async/await for I/O operations
feat: add user authentication
fix: resolve database connection issue
docs: update API documentation
test: add environment tests
refactor: optimize database queries
This project is licensed under the MIT License - see the LICENSE file for details.
- API Docs: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- Architecture: See
docs/folder
- Issues: Create a GitHub issue for bugs
- Discussions: Use GitHub Discussions for questions
- Discord: Join our developer community
- Email: support@devpocket.io
-
Database Connection Failed
# Check MongoDB status docker-compose logs mongo # Verify connection string echo $MONGODB_URL
-
Import Errors
# Rebuild containers docker-compose build --no-cache # Check Python path python -c "import sys; print(sys.path)"
-
WebSocket Connection Issues
# Check nginx configuration docker-compose logs nginx # Verify WebSocket headers curl -H "Upgrade: websocket" http://localhost:8000/api/v1/ws/terminal/test
- JWT Authentication
- Google OAuth
- Environment Management
- WebSocket Terminal
- Docker Deployment
- Kubernetes Integration
- File Upload/Download
- Environment Sharing
- Usage Analytics
- API Rate Limiting Per User
- Multi-region Deployment
- Environment Templates Store
- AI-powered Code Assistance
- Team Collaboration Features
- Advanced Monitoring Dashboard
Built with β€οΈ for the mobile-first developer community
DevPocket - Code Anywhere, Build Everywhere π±π»