A production-ready, modular monolith backend for Lyo, an AI-powered multilingual social-learning application.
- Modular Monolith Architecture: Organized by domain functionality with clean separation of concerns
- Multilingual Support: Built-in internationalization for global audience
- AI Integration: Gemma 3 integration for personalized learning experiences
- Multiple Database Support: PostgreSQL for structured data, Firestore for flexible schema needs
- Caching Layer: Redis for performance optimization
- Real-time Capabilities: WebSocket support for instant notifications
- Comprehensive Security: JWT authentication, role-based access controls
- Observability: OpenTelemetry integration for monitoring and tracing
- Web Framework: FastAPI
- Relational Database: PostgreSQL with SQLModel
- NoSQL Database: Firestore
- Caching: Redis
- AI Platform: Gemma 3
- Authentication: JWT with OAuth2
- Internationalization: Babel
- Testing: Pytest with asyncio
- Containerization: Docker with docker-compose
- Observability: OpenTelemetry
lyo-backend/
├── api/
│ ├── core/ # Core application modules
│ ├── db/ # Database connectors and utilities
│ ├── middlewares/ # Custom middleware components
│ ├── models/ # Data models and entities
│ ├── routers/ # API endpoints and route definitions
│ ├── schemas/ # Pydantic schemas for request/response
│ └── services/ # Business logic and service layer
├── tests/ # Test suite
├── .env.example # Environment variable template
├── .env.test # Test environment variables
├── Dockerfile # Production Docker configuration
├── Dockerfile.test # Testing Docker configuration
├── docker-compose.yml # Development environment setup
├── docker-compose.test.yml # Testing environment setup
├── requirements.txt # Python dependencies
└── main.py # Application entry point
- Python 3.10+
- Docker and docker-compose
- PostgreSQL
- Redis
- Google Cloud account (for Firestore, Pub/Sub, Storage)
-
Clone the repository
git clone https://github.com/yourusername/lyo-backend.git cd lyo-backend -
Create a virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
cp .env.example .env # Edit .env with your configuration -
Run the application
uvicorn main:app --reload
-
Build and start the containers
docker-compose up --build
-
The API will be available at
http://localhost:8000
Run the test suite:
# Using pytest directly
pytest
# Using Docker
docker-compose -f docker-compose.test.yml up --buildOnce the application is running:
- Swagger UI: http://localhost:8000/api/v1/docs
- ReDoc: http://localhost:8000/api/v1/redoc
- OpenAPI JSON: http://localhost:8000/api/v1/openapi.json
- Update SECRET_KEY and other sensitive environment variables
- Set DEBUG=false
- Configure proper CORS settings
- Set up proper database credentials
- Configure telemetry endpoints
- Enable rate limiting for public endpoints