# andreaswt/elevenlabs-clone architecture

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

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

## Overview

##### Project type and purpose
- This is a full-stack “ElevenLabs clone” for speech synthesis, voice conversion, and audio generation.
- Frontend: Next.js + T3 Stack (React, Tailwind CSS, Auth.js, Prisma).
- Backend: Next.js API routes + Inngest event queue calling Python microservices.
- AI Model services: three Dockerized FastAPI/PyTorch containers (StyleTTS2, Seed-VC, Make-An-Audio).
- Storage: AWS S3 for audio files.
- Database: PostgreSQL/MySQL (via Prisma) for users, credits, and history.

##### Main components
a. Users (Browser or Mobile App)
b. Next.js Frontend & API Layer
- Routes for UI pages
- NextAuth (Auth.js) for authentication
- Prisma client connecting to Database
- Inngest client triggering generation jobs
c. Inngest Queue
- Event-driven task queue that enforces sequential or rate-limited calls to AI services
d. AI Model Microservices (each in its own Docker container)
- StyleTTS2 API (text → speech)
- Seed-VC API (voice conversion)
- Make-An-Audio API (text → sound effects)
- Each exposes FastAPI endpoints and uploads results to S3
e. AWS S3 Bucket
- Stores generated audio files
- Read/write access granted to model services and frontend via IAM
f. Database (e.g., PostgreSQL)
- Stores user accounts, credit balances, and audio history records
g. AWS Infrastructure (optional)
- EC2 instances or ECS/EKS running Docker containers
- ECR for container registry
h. External/Auth services
- OAuth providers used by NextAuth (e.g., Google, GitHub)

##### Relationships and data flow
1. User interacts with Next.js UI (login, submit text, upload audio).
2. Next.js API route authenticates via NextAuth, queries/upserts user in Database, checks credits.
3. On generation request, Next.js calls Inngest client to enqueue a job.
4. Inngest worker dequeues job and calls the appropriate AI Model API endpoint.
5. Model API processes input, generates audio via PyTorch, uploads audio file to S3, returns S3 URL.
6. Inngest handler receives the response, updates Database with a new history record and decrements user credits.
7. Next.js frontend polls or listens for job completion, then fetches audio from S3 to play/download.

##### Architectural patterns and design principles
- Microservices: each AI model runs in an isolated container with its own FastAPI server.
- Event-driven: Inngest queue decouples request submission from heavy model inference.
- Separation of concerns: frontend/UI, API orchestration, AI compute layers, persistent storage.
- Containerization & CI/CD: Dockerfiles.api for each model and docker-compose or AWS ECS/EKS for deployment.
- Infrastructure as code: Dockerfiles, docker-compose.yml, ECR/ECS roles, IAM policies.

##### Technologies, frameworks, and libraries
- Frontend: Next.js (src/app), React, Tailwind CSS, Prisma ORM, NextAuth.js, Inngest JS.
- Backend orchestration: Next.js API routes, Inngest (Node.js).
- AI Services: Python 3.10, FastAPI, PyTorch models (StyleTTS2, Seed-VC, Make-An-Audio).
- Storage & deployment: AWS S3, AWS ECR/ECS or EC2, Docker, docker-compose, IAM roles.

##### Final recommendations
- Be very detailed: capture each service, queue, database, and external dependency.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        UI["User (Browser/Mobile)"]:::external
        UIRoutes["UI Routes (src/app/)"]:::frontend
        APIRoutes["API Routes (src/app/api/)"]:::frontend
        AuthRoute["NextAuth Route ([...nextauth])"]:::frontend
        OAuthConfig["Auth Config (config.ts)"]:::frontend
        Schema["Prisma Schema (schema.prisma)"]:::frontend
        DBServer["DB Client (db.ts)"]:::frontend
        ClientFiles["Inngest Client (client.ts)"]:::frontend
        FuncFiles["Inngest Functions (functions.ts)"]:::frontend

        UI -->|"accesses UI"| UIRoutes
        UIRoutes -->|"calls endpoints"| APIRoutes
        APIRoutes -->|"handles auth"| AuthRoute
        AuthRoute -->|"uses config"| OAuthConfig
        APIRoutes -->|"uses ORM"| Schema
        APIRoutes -->|"uses DB client"| DBServer
        APIRoutes -->|"enqueues jobs"| ClientFiles
        ClientFiles -->|"defines workflows"| FuncFiles
    end

    %% Orchestration Layer
    subgraph "Orchestration Layer"
        Queue["Inngest Queue"]:::queue
    end
    APIRoutes -->|"POST /inngest"| Queue

    %% AI Compute Layer
    subgraph "AI Compute Layer"
        StyleTTS2["StyleTTS2 FastAPI Service"]:::ai
        SeedVC["Seed-VC FastAPI Service"]:::ai
        MakeAudio["Make-An-Audio FastAPI Service"]:::ai
    end
    Queue -->|"HTTP POST /synthesize"| StyleTTS2
    Queue -->|"HTTP POST /convert"| SeedVC
    Queue -->|"HTTP POST /generate-effects"| MakeAudio
    StyleTTS2 -->|"uploads via SDK"| S3
    SeedVC -->|"uploads via SDK"| S3
    MakeAudio -->|"uploads via SDK"| S3

    %% Storage Layer
    subgraph "Storage Layer"
        S3["AWS S3 Bucket"]:::aws
    end

    %% Database Layer
    subgraph "Database Layer"
        DB["PostgreSQL/MySQL"]:::db
    end
    DBServer -->|"connects to"| DB
    FuncFiles -->|"updates history & credits"| DB

    %% External Services
    subgraph "External Services"
        OAuth["OAuth Providers"]:::aws
    end
    OAuthConfig -->|"OAuth flow"| OAuth

    %% Fetch Audio Flow
    UIRoutes -->|"fetch audio"| S3

    %% Infrastructure
    subgraph "Infrastructure"
        Compose["docker-compose.yml"]:::infra
    end
    Compose --> StyleTTS2
    Compose --> SeedVC
    Compose --> MakeAudio
    Compose --> UIRoutes
    Compose --> Queue
    Compose --> DB

    %% Click Events
    click UIRoutes "https://github.com/andreaswt/elevenlabs-clone/tree/main/elevenlabs-clone-frontend/src/app/"
    click AuthRoute "https://github.com/andreaswt/elevenlabs-clone/blob/main/elevenlabs-clone-frontend/src/app/api/auth/[...nextauth]/route.ts"
    click OAuthConfig "https://github.com/andreaswt/elevenlabs-clone/blob/main/elevenlabs-clone-frontend/src/server/auth/config.ts"
    click Schema "https://github.com/andreaswt/elevenlabs-clone/blob/main/elevenlabs-clone-frontend/prisma/schema.prisma"
    click DBServer "https://github.com/andreaswt/elevenlabs-clone/blob/main/elevenlabs-clone-frontend/src/server/db.ts"
    click ClientFiles "https://github.com/andreaswt/elevenlabs-clone/blob/main/elevenlabs-clone-frontend/src/inngest/client.ts"
    click FuncFiles "https://github.com/andreaswt/elevenlabs-clone/blob/main/elevenlabs-clone-frontend/src/inngest/functions.ts"
    click StyleTTS2 "https://github.com/andreaswt/elevenlabs-clone/blob/main/StyleTTS2/api.py"
    click StyleTTS2 "https://github.com/andreaswt/elevenlabs-clone/blob/main/StyleTTS2/Dockerfile.api"
    click SeedVC "https://github.com/andreaswt/elevenlabs-clone/blob/main/seed-vc/api.py"
    click SeedVC "https://github.com/andreaswt/elevenlabs-clone/blob/main/seed-vc/Dockerfile.api"
    click MakeAudio "https://github.com/andreaswt/elevenlabs-clone/blob/main/Make-An-Audio/api.py"
    click MakeAudio "https://github.com/andreaswt/elevenlabs-clone/blob/main/Make-An-Audio/Dockerfile.api"
    click Compose "https://github.com/andreaswt/elevenlabs-clone/blob/main/docker-compose.yml"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef db fill:#90EE90,stroke:#333,stroke-width:1px
    classDef aws fill:#FFA500,stroke:#333,stroke-width:1px
    classDef ai fill:#DDA0DD,stroke:#333,stroke-width:1px
    classDef queue stroke-dasharray: 5 5,fill:none,stroke:#333,stroke-width:1px
    classDef external fill:#CCCCCC,stroke:#333,stroke-width:1px
    classDef infra fill:#F0E68C,stroke:#333,stroke-width:1px
```
