A production-ready FastAPI backend that orchestrates multiple AI agents with secure authentication, database persistence, and comprehensive monitoring.
- π Multi-Agent AI Orchestration: Support for PraisonAI, CrewAI, and AG2/AutoGen frameworks
- π Secure Authentication: Clerk JWT-based user authentication with RS256 verification
- ποΈ Database Persistence: Supabase PostgreSQL with SQLAlchemy ORM for session and execution tracking
- π Comprehensive Monitoring: Prometheus metrics with Grafana dashboards
- π³ Docker Ready: Multi-stage builds with production optimizations
- βοΈ Coolify Deployment: Pre-configured for seamless Coolify deployment
- β‘ High Performance: Async operations with connection pooling and health checks
- π§ͺ Testing: Unit tests and k6 load testing (targeting 20 RPS)
- π§ MindsDB Integration: Connect to MindsDB for machine learning capabilities
- π§ Gmail Integration: Send emails and access Gmail data through Google API
- βοΈ Admin Control Panel: Streamlit-based UI for easy configuration and setup
- π₯οΈ Tauri Integration: Connect to Tauri desktop applications with secure CORS configuration
- π Enhanced Supabase Connection: Direct connection and connection pooling for better performance
Internet β Traefik (HTTPS) β FastAPI Backend β AI Agents (PraisonAI/CrewAI/AG2)
β
Supabase Database
β
Prometheus β Grafana
β
MindsDB β β Gmail API
- FastAPI Application (
app/main.py
) - Main entry point with middleware configuration - AI Agent Orchestrator (
app/agents.py
) - Multi-agent system with graceful fallback - Authentication Layer (
app/auth.py
) - Clerk JWT verification and user management - Database Layer (
app/database.py
) - Async SQLAlchemy with Supabase backend - Monitoring System (
app/monitoring.py
) - Prometheus metrics and structured logging - MindsDB Integration (
app/integrations/mindsdb.py
) - Machine learning capabilities - Gmail Integration (
app/integrations/gmail.py
) - Email and Gmail data access
POST /v1/answer
- Execute AI agent tasksPOST /v1/sessions
- Create conversation sessionsGET /v1/agents
- List available agentsGET /v1/health
- Health check endpointGET /metrics
- Prometheus metrics (restricted)
- PraisonAI (
praisonai
) - Multi-agent orchestration with structured outputs - CrewAI (
crewai
) - Collaborative AI agents for complex tasks - AG2/AutoGen (
ag2
) - Conversation-based multi-agent system
The easiest way to deploy with automatic HTTPS, domain management, and monitoring:
# Use the Coolify-optimized configuration
# Simple version (FastAPI only)
cp docker-compose.coolify-simple.yml docker-compose.yml
# Full version (with monitoring)
cp docker-compose.coolify.yml docker-compose.yml
See COOLIFY_DEPLOYMENT_GUIDE.md for detailed instructions.
# Build and run with monitoring stack
docker-compose up -d
# Access the application
curl https://localhost/v1/health
# Authentication (Clerk)
CLERK_SECRET_KEY=your_clerk_secret_key
CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key
# Database (Supabase)
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key
DATABASE_URL=postgresql+asyncpg://user:pass@host:5432/dbname
# AI Services
OPENAI_API_KEY=your_openai_api_key
ANTHROPIC_API_KEY=your_anthropic_api_key
# Performance
DEBUG=false
LOG_LEVEL=info
GUNICORN_WORKERS=4
# CORS
CORS_ORIGINS=["https://your-frontend.com"]
- Python 3.11+
- Docker & Docker Compose
- Supabase account
- Clerk account
- OpenAI/Anthropic API keys
-
Clone the repository:
git clone <your-repo-url> cd fastapi-agent-backend
-
Create virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set environment variables:
cp env.example .env # Edit .env with your configuration
-
Run the application:
python -m uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
pytest tests/ -v
# Install k6
# Run load tests targeting 20 RPS
k6 run tests/load-test.js
- HTTP request/response metrics
- Agent execution performance
- Token usage tracking
- System resource utilization
- FastAPI performance dashboard
- AI agent execution metrics
- System health monitoring
Access Grafana at: https://grafana.your-domain.com
(with full deployment)
- JWT Authentication: Secure Clerk-based user authentication
- Environment Variables: All secrets stored securely outside code
- HTTPS Enforcement: Automatic SSL with Let's Encrypt (Coolify)
- Security Headers: Comprehensive security headers via reverse proxy
- Input Validation: Pydantic models for all API inputs
- Rate Limiting: Configurable rate limits (deployment-dependent)
- Target: 20 RPS sustained load
- P95 Latency: <200ms for agent endpoints
- Error Rate: <5% threshold
- Connection Pooling: Optimized database connections
- Async Operations: Non-blocking I/O throughout
The repository is configured for:
- Automatic deployments via Coolify on git push
- Health checks for zero-downtime deployments
- Rollback capability on deployment failures
- Load testing integration for performance validation
- Coolify Deployment Guide - Complete Coolify setup
- API Documentation - Interactive API docs (when running)
- Architecture Overview - Detailed system architecture
- Agent System - AI agent implementation details
- Supabase Connection Status - Guide for connecting to Supabase
- Tauri Integration - Guide for connecting to Tauri desktop apps
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: See the
/docs
directory and.cursor/rules/
files
The FastAPI Agent Backend includes a Streamlit-based admin control panel that allows you to configure the application through a user-friendly interface.
-
Install the required dependencies:
pip install -r requirements.txt
-
Run the admin panel using one of these methods:
Option 1: Using the startup script (recommended):
python admin/run_admin_panel.py
Option 2: Using Streamlit directly:
streamlit run admin/app.py
-
Access the admin panel in your web browser (typically at http://localhost:8501)
- Configure all application settings through a user-friendly UI
- Organized into logical sections for easy navigation
- Changes are saved directly to your
.env
file - Secure handling of sensitive information like API keys and passwords
For more details, see the Admin Panel Documentation.
- Clone this repository
- Set up external services (Supabase, Clerk, AI APIs)
- Choose deployment method:
- Coolify: Use
docker-compose.coolify-simple.yml
- Traditional: Use
docker-compose.yml
- Coolify: Use
- Configure environment variables (using the Admin Control Panel or manually)
- Set up integrations (if needed):
- Tauri Desktop App: Configure CORS and Tauri-specific settings
- Remote Supabase: Configure enhanced connection options
- Deploy and enjoy your AI agent backend!
Your FastAPI Agent Backend will be live with automatic HTTPS, monitoring, and enterprise-grade security! π