How talktolisten/talktolisten-backend works
Project Type and Purpose
• This is a standalone back‐end microservice (FastAPI/uvicorn) for the “Talk To Listen” project.
• It exposes a RESTful API (under app/api/api_v1) for chat, voice, image, text, group‐chat, explore, and bot functionality.
• It persists data in a relational database (Alembic migration scripts) and uses Azure Storage for blobs.
File Structure
• Top-level: Dockerfile, server.py (entrypoint), nginx/ (reverse‐proxy), dev (local scripts), .github (CI/CD).
• app/main.py boots the FastAPI application.
• app/api/api_v1: routes (controllers), dependency modules (utils, temp_audio/image, vad), engines (image, text, voice, storage).
• app/models.py + app/schemas: ORM models & Pydantic schemas.
• app/database.py + alembic/: DB connectivity & migrations.
• CI/CD workflows in .github/workflows for build, deploy on EC2.
README for Additional Insights
• Uses Uvicorn for dev server.
• Instructions for Alembic migrations (DB versioning).
• Docker build & run—service containerized.
• GitHub Actions deploy to EC2.
a. Main Components
– Client(s): mobile/web front‐ends or other services calling the REST API.
– API Gateway / Nginx: optional reverse‐proxy or ingress.
– Talk To Listen Microservice (FastAPI container)
• Controllers (app/api/api_v1/routes)
• Dependency Layer (temp_audio, temp_image, vad, utils)
• Engines (image processing, text processing, voice processing, storage/azure)
• Auth & Middleware (app/auth.py, app/middleware.py)
• Database Access (app/database.py, app/models.py, alembic)
– Relational Database (e.g., PostgreSQL)
– Azure Blob Storage (external storage for images/audio)
– CI/CD Pipeline (GitHub Actions) & Docker Registry
b. Relationships & Data Flows
– Client → Nginx/API Gateway → FastAPI (HTTP JSON)
– FastAPI → Database (SQLAlchemy via app/database.py)
– FastAPI → Azure Storage (via app/api/api_v1/engines/storage/azure.py)
– Internally: Controllers call Dependency modules, which call Engines
– CI/CD: GitHub Actions builds Docker image → pushes to registry → deploys to EC2 → Nginx routes traffic into container
c. Architectural Patterns & Principles
– Layered architecture: Routes (API) → Dependency/Service layer → Engine implementations → Data layer.
– Modular “engine” abstraction for pluggable text, voice, image, storage backends.
– Database migration versioning via Alembic.
– Containerization & immutable infrastructure (Docker).
– CI/CD with GitHub Actions and infrastructure‐as‐code principles.
d. Key Technologies & Frameworks
– FastAPI, Uvicorn
– SQLAlchemy + Alembic
– Pydantic Schemas
– Azure Blob SDK
– Docker, Nginx
– GitHub Actions (YAML pipelines)