How mathis-lambert/api works
Project Type and Purpose
• This is a standalone, versioned backend API microservice built with Python 3.13 and FastAPI.
• It serves as the core API infrastructure under api.mathislambert.fr, exposing endpoints for health checks, LLM‐powered chat, data CRUD in MongoDB, and RAG queries in Qdrant.
• It is containerized (Docker, docker‑compose), reverse‑proxied by Nginx, and integrates with external LLM (MistralAI).
High‑Level Architecture Components
• Clients: browsers or other services calling REST endpoints.
• Nginx Reverse Proxy: routes incoming HTTP(S) traffic to the FastAPI service.
• FastAPI/Uvicorn Container: hosts the application code (src/api/...).
• Router layer (v1/routes)
• Service layer (v1/services, api/classes, api/utils)
• Database connectors (mongo_db_connector, qdrant_connector)
• Databases (each in its own container via docker‑compose):
• MongoDB (NoSQL document store)
• Qdrant (vector database for RAG)
• External Service: MistralAI API for text generation.
• Networking/Orchestration: docker‑compose, environment variables, init scripts (Mongo init‑db.js, Qdrant config.yaml).
Component Interactions and Data Flows
• Inside FastAPI:
• Request hits versioned router (e.g., /v1/chat).
• Router calls service layer (e.g., chat_service).
• Service may call:
– MongoDB connector for data I/O
– Qdrant connector for vector retrieval
– MistralAI (external HTTPS call) for text generation
• Responses bubble back through the same layers to the client.
Architectural Patterns and Principles
• Layered/Clean Architecture: routers (interface) → services (business) → connectors (persistence) → external integrations.
• Dependency Injection: connectors and services instantiated in main.py and injected via routers.
• Containerization & Infrastructure as Code: Dockerfiles, docker‑compose, Nginx config, DB init scripts.