AI-powered Python tutoring platform backend with FastAPI and multiple AI agents.
cd backend
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Copy environment file
cp .env.example .env
# Install dependencies
pip install -e ".[dev]"# Edit .env and add your OpenAI API key
export OPENAI_API_KEY="sk-your-key-here"python main.py
# Or with uvicorn directly
uvicorn main:app --reload --port 8000The API will be available at:
- API: http://localhost:8000
- Docs: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
POST /api/auth/register- Register new userPOST /api/auth/login- Login userGET /api/auth/me- Get current user
POST /api/chat- Chat (auto-routes to appropriate agent)POST /api/triage- Route query to specialistPOST /api/concepts- Explain Python conceptsPOST /api/code_review- Review Python codePOST /api/debug- Debug Python errorsPOST /api/exercise- Generate coding exercisesPOST /api/progress- Get learning progress
GET /health- Health checkGET /api/status- API status
backend/
├── main.py # Main FastAPI application
├── app/
│ ├── __init__.py
│ ├── config.py # Configuration settings
│ ├── schemas.py # Pydantic schemas
│ ├── auth.py # Authentication service
│ ├── models.py # SQLAlchemy models
│ ├── database.py # Database connection
│ ├── agents.py # AI agents
│ ├── triage_agent/ # Triage agent service
│ ├── concepts_agent/ # Concepts agent service
│ ├── code_review_agent/
│ ├── debug_agent/
│ ├── exercise_agent/
│ └── progress_agent/
├── tests/ # Test suite
├── pyproject.toml # Project dependencies
├── .env.example # Example environment variables
└── README.md # This file
Routes student queries to the most appropriate specialist agent.
Explains Python concepts with clear analogies and code examples.
Analyzes code for correctness, style (PEP 8), and efficiency.
Helps identify and fix Python errors, providing hints before solutions.
Generates coding challenges and practice problems at appropriate difficulty levels.
Tracks and reports student learning progress, mastery scores, and streaks.
Uses JWT tokens with HS256 signing.
# Get token from login
TOKEN=$(curl -X POST http://localhost:8000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com","password":"password123"}' \
| jq -r '.access_token')
# Use token in subsequent requests
curl -H "Authorization: Bearer $TOKEN" http://localhost:8000/api/auth/me# Run tests
pytest
# Run with coverage
pytest --cov=app tests/
# Run specific test
pytest tests/test_auth.py -v# Format code
black app/ main.py
# Lint
ruff check app/ main.py
# Type check
mypy app/ main.py# Use PostgreSQL instead of SQLite
DATABASE_URL=postgresql+asyncpg://user:password@hostname:5432/emberlearn
# Strong JWT secret
JWT_SECRET_KEY=generate-with-openssl-rand-hex-32
# Production mode
DEBUG=falseFROM python:3.11-slim
WORKDIR /app
COPY pyproject.toml .
RUN pip install -e .
COPY . .
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]docker build -t emberlearn-backend .
docker run -p 8000:8000 -e OPENAI_API_KEY="sk-..." emberlearn-backend- Make sure
OPENAI_API_KEYis set in.env - Check that your API key is valid on OpenAI dashboard
- Verify you have API credits available
- Delete
emberlearn.dbto reset local database - Run
python -c "from app.database import init_db; import asyncio; asyncio.run(init_db())"
- Check that frontend URL is in
CORS_ORIGINSin.env - Default allows
localhost:3000and127.0.0.1:3000
- Change
PORTin.env - Or kill process:
lsof -ti:8000 | xargs kill -9
- Implement Kafka integration for event streaming
- Add Dapr sidecar for distributed state management
- Deploy to Kubernetes with Kong API Gateway
- Add database migrations with Alembic
- Setup CI/CD with GitHub Actions
- Add monitoring and logging with Datadog/ELK
- Create a feature branch
- Make changes and add tests
- Run
pytestandruff check - Submit pull request
MIT