FastAPI-based backend for the ALAE Multi-Cloud hackathon project.
- 🔐 Authentication & Authorization: JWT-based authentication with role-based access control
- ☁️ Multi-Cloud Management: Support for AWS and GCP instance management
- 🐳 Docker Swarm Clustering: Automated cluster creation and application deployment
- 📊 RESTful API: Comprehensive API with OpenAPI documentation
- 🗄️ Database Integration: Async SQLAlchemy with PostgreSQL
- 📈 Monitoring Ready: Integration points for Prometheus and Grafana
alae-backend/
├── app/
│ ├── api/
│ │ ├── endpoints/ # API endpoints
│ │ │ ├── auth.py # Authentication endpoints
│ │ │ ├── instances.py # Cloud instance management
│ │ │ └── clusters.py # Cluster management
│ │ └── dependencies.py # FastAPI dependencies
│ ├── core/ # Core functionality
│ │ ├── database.py # Database configuration
│ │ └── security.py # Security utilities
│ └── main.py # FastAPI application
├── models/ # SQLAlchemy models
├── schemas/ # Pydantic schemas
├── services/ # Business logic services
│ ├── cloud/ # Cloud provider integrations
│ │ ├── aws_service.py # AWS EC2 management
│ │ └── gcp_service.py # GCP Compute management
│ └── cluster/ # Cluster management
│ └── docker_swarm_service.py # Docker Swarm operations
├── config.py # Application configuration
├── requirements.txt # Python dependencies
└── .env.example # Environment variables template
# Copy environment template
cp .env.example .env
# Edit .env with your configuration
# - Set database URL
# - Add AWS/GCP credentials
# - Update security keys# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt# Create PostgreSQL database
createdb alae
# Run migrations (if using Alembic)
alembic upgrade head
# Or create tables directly
python -c "from app.core.database import Base, sync_engine; Base.metadata.create_all(bind=sync_engine)"# Development mode with auto-reload
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
# Production mode
uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 4- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- OpenAPI Schema: http://localhost:8000/openapi.json
POST /api/v1/auth/register- Register new userPOST /api/v1/auth/login- User loginGET /api/v1/auth/me- Get current user info
GET /api/v1/instances/- List user instancesPOST /api/v1/instances/- Create new instanceGET /api/v1/instances/{id}- Get instance detailsPUT /api/v1/instances/{id}- Update instanceDELETE /api/v1/instances/{id}- Delete instancePOST /api/v1/instances/{id}/start- Start instancePOST /api/v1/instances/{id}/stop- Stop instance
GET /api/v1/clusters/- List user clustersPOST /api/v1/clusters/- Create new clusterGET /api/v1/clusters/{id}- Get cluster detailsPUT /api/v1/clusters/{id}- Update clusterDELETE /api/v1/clusters/{id}- Delete clusterPOST /api/v1/clusters/{id}/deploy- Deploy applicationGET /api/v1/clusters/{id}/deployments- List deployments
GET /api/v1/dashboard- Get user dashboard info
Copy .env.example to .env and configure:
# Security
SECRET_KEY=your-super-secret-key
# Database
DATABASE_URL=postgresql+asyncpg://user:pass@localhost/alae
# AWS
AWS_ACCESS_KEY_ID=your-aws-key
AWS_SECRET_ACCESS_KEY=your-aws-secret
# GCP
GCP_PROJECT_ID=your-gcp-project
GCP_CREDENTIALS_PATH=/path/to/credentials.json- Create IAM user with EC2 permissions
- Generate access keys
- Add keys to
.env
- Create service account
- Download JSON credentials
- Set path in
.env
# Format code
black app/
isort app/
# Lint code
flake8 app/
mypy app/# Run tests
pytest tests/
# Run with coverage
pytest --cov=app tests/# Initialize Alembic
alembic init alembic
# Create migration
alembic revision --autogenerate -m "description"
# Apply migration
alembic upgrade head# Dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]# docker-compose.yml
version: '3.8'
services:
api:
build: .
ports:
- "8000:8000"
environment:
- DATABASE_URL=postgresql+asyncpg://user:pass@db:5432/alae
depends_on:
- db
- redis
db:
image: postgres:15
environment:
POSTGRES_DB: alae
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
volumes:
- postgres_data:/var/lib/postgresql/data
redis:
image: redis:7-alpine
volumes:
postgres_data:-
Database Connection
- Check PostgreSQL is running
- Verify connection string in
.env
-
Cloud Provider Errors
- Verify credentials are correct
- Check IAM permissions
- Ensure regions/zones are valid
-
SSH Connection Issues
- Verify SSH keys are properly configured
- Check firewall rules
- Ensure instances are running
-
Docker Swarm Issues
- Verify Docker is installed on instances
- Check network connectivity between nodes
- Ensure proper ports are open
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is created for the hackathon competition. Please check the hackathon rules for licensing terms.