# bernietv/elevenlabs-clone architecture

> Architecture diagram of the GitHub repository bernietv/elevenlabs-clone, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bernietv/elevenlabs-clone
- Repository: https://github.com/bernietv/elevenlabs-clone

## Overview

##### Project Type and Purpose
- This is a full-stack, self-hosted AI audio studio that clones ElevenLabs functionality.
- Frontend: Next.js (T3 stack) for UI & client-side routing.
- Backend/API: FastAPI micro-services (one per AI model: StyleTTS2, Seed-VC, Make-An-Audio) plus Next.js API routes (Auth.js, Inngest).
- Datastore: PostgreSQL (via Prisma) for user/credits, AWS S3 for audio file storage.
- Queueing: Inngest to throttle and sequence long-running audio jobs.

##### File Structure
- Top-level folders:
- elevenlabs-clone-frontend (Next.js + Prisma + Inngest + Auth.js)
- Make-An-Audio, StyleTTS2, seed-vc (each a Python FastAPI service with model code, configs, Dockerfiles)
- docker-compose.yml to orchestrate containers
- Config & infra:
- Dockerfile.api / Dockerfile.train in each AI folder
- configs/ for model hyperparameters
- README details AWS IAM & deployment
- Frontend specifics:
- /src/app/... – Next.js App Router with API routes in /app/api
- /src/server – database & auth setup
- /src/inngest – Inngest function definitions
- Backend specifics:
- api.py in each model folder – FastAPI entrypoints
- model code in subdirectories (ldm for Make-An-Audio, Modules for StyleTTS2, modules for seed-vc)
- scripts for inference & batch generation (gen_wav.py, train_*.py)

##### README Insights
- Confirms micro-services per model with FastAPI endpoints.
- Frontend handles auth, credits, queueing via Inngest.
- Uses AWS S3 for storage & EC2/ECR for container hosting.

a. Main Components:
- Client Browser (User UI)
- Next.js Frontend App (React + Tailwind + Auth.js + Prisma)
- Next.js API Routes
– /api/auth ([...nextauth]) for authentication
– /api/inngest for enqueuing jobs
- Inngest Queue (Task orchestration)
- Model Microservices (Docker containers):
– StyleTTS2 Service
– Seed-VC Service
– Make-An-Audio Service
- Database (PostgreSQL via Prisma)
- Object Storage (AWS S3)
b. Relationships & Data Flow:
1. User interacts with UI → fetch voices, submit text/audio
2. Frontend authenticates via NextAuth → session token
3. On “generate” action, frontend calls Next.js API → writes job request to Inngest
4. Inngest triggers a worker process that calls appropriate model microservice endpoint
5. Model service processes request, returns audio file URL or binary
6. Service uploads result to S3 → returns S3 URL
7. Worker writes metadata (user, credit usage, S3 link) into PostgreSQL
8. Frontend polls or receives webhook update → displays audio history & playback
c. Architectural Patterns & Principles:
- Microservices: one container per AI model for isolation & scalability
- Event-driven / queueing (Inngest) to handle asynchronous, long‐running tasks
- Separation of concerns: UI, API orchestration, model inference, storage, DB
- Infrastructure as code: Docker + docker-compose for local deploy
- Security: Auth.js (NextAuth), AWS IAM roles/policies for minimal S3 access
d. Key Technologies:
- Frontend: Next.js App Router, TypeScript, Tailwind CSS, Prisma ORM
- Orchestration: Inngest, NextAuth, Docker Compose
- Model APIs: FastAPI, Python 3.10, YAML config files
- Storage: AWS S3 (PutObject, GetObject)
- Database: PostgreSQL

##### Detailed Capture
- Don’t omit middleware (Auth.js), database calls, or S3 policies
- Docker-compose linking the containers and exposing ports

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser["Client Browser"]:::external

    subgraph "Frontend Layer"
        direction TB
        FrontendApp["Next.js Frontend App"]:::frontend
        AuthRoute["API: /api/auth/[...nextauth]"]:::frontend
        InngestRoute["API: /api/inngest"]:::frontend
        InngestClient["Inngest Client"]:::frontend
        InngestFunctions["Inngest Functions"]:::frontend
        AuthConfig["NextAuth Config"]:::frontend
        DBUtil["DB Utility"]:::frontend
        PrismaSchema["Prisma Schema"]:::frontend
        AudioStore["Audio Store"]:::frontend
        VoiceStore["Voice Store"]:::frontend
    end

    subgraph "Orchestration Layer"
        direction TB
        InngestQueue["Inngest Queue"]:::orchestration
    end

    subgraph "Model Microservices"
        direction TB
        MAA["Make-An-Audio Service"]:::microservice
        STTS2["StyleTTS2 Service"]:::microservice
        SVC["Seed-VC Service"]:::microservice
    end

    subgraph "Storage Layer"
        direction TB
        S3["AWS S3"]:::storage
        Postgres["PostgreSQL"]:::storage
    end

    Browser -->|"interact"| FrontendApp
    FrontendApp -->|"auth requests"| AuthRoute
    FrontendApp -->|"enqueue jobs"| InngestRoute
    InngestRoute -->|"push job"| InngestQueue
    InngestQueue -->|"trigger"| MAA
    InngestQueue -->|"trigger"| STTS2
    InngestQueue -->|"trigger"| SVC
    MAA -->|"upload audio"| S3
    STTS2 -->|"upload audio"| S3
    SVC -->|"upload audio"| S3
    MAA -->|"store metadata"| Postgres
    STTS2 -->|"store metadata"| Postgres
    SVC -->|"store metadata"| Postgres
    Postgres -->|"user data"| FrontendApp
    S3 -->|"audio URLs"| FrontendApp

    click FrontendApp "https://github.com/bernietv/elevenlabs-clone/tree/main/elevenlabs-clone-frontend/src/app"
    click AuthRoute "https://github.com/bernietv/elevenlabs-clone/blob/main/elevenlabs-clone-frontend/src/app/api/auth/[...nextauth]/route.ts"
    click InngestRoute "https://github.com/bernietv/elevenlabs-clone/blob/main/elevenlabs-clone-frontend/src/app/api/inngest/route.ts"
    click InngestClient "https://github.com/bernietv/elevenlabs-clone/blob/main/elevenlabs-clone-frontend/src/inngest/client.ts"
    click InngestFunctions "https://github.com/bernietv/elevenlabs-clone/blob/main/elevenlabs-clone-frontend/src/inngest/functions.ts"
    click AuthConfig "https://github.com/bernietv/elevenlabs-clone/blob/main/elevenlabs-clone-frontend/src/server/auth/config.ts"
    click DBUtil "https://github.com/bernietv/elevenlabs-clone/blob/main/elevenlabs-clone-frontend/src/server/db.ts"
    click PrismaSchema "https://github.com/bernietv/elevenlabs-clone/blob/main/elevenlabs-clone-frontend/prisma/schema.prisma"
    click AudioStore "https://github.com/bernietv/elevenlabs-clone/blob/main/elevenlabs-clone-frontend/src/stores/audio-store.ts"
    click VoiceStore "https://github.com/bernietv/elevenlabs-clone/blob/main/elevenlabs-clone-frontend/src/stores/voice-store.ts"
    click MAA "https://github.com/bernietv/elevenlabs-clone/tree/main/Make-An-Audio/"
    click STTS2 "https://github.com/bernietv/elevenlabs-clone/tree/main/StyleTTS2/"
    click SVC "https://github.com/bernietv/elevenlabs-clone/tree/main/seed-vc/"
    click S3 "https://github.com/bernietv/elevenlabs-clone/blob/main/README.md"

    classDef frontend fill:#D6EAF8,stroke:#1B4F72,color:#1B2631
    classDef orchestration fill:#D5F5E3,stroke:#145A32,color:#0E6251
    classDef microservice fill:#FAD7A0,stroke:#A04000,color:#4D1A00
    classDef storage fill:#E8DAEF,stroke:#6C3483,color:#1B0B2A
    classDef external fill:#F2F3F4,stroke:#566573,color:#1B2631
```
