| name | elevenlabs-reference-architecture |
| description | Implement ElevenLabs reference architecture for production TTS/voice applications.
Use when designing new ElevenLabs integrations, reviewing project structure,
or building a scalable audio generation service.
Trigger: "elevenlabs architecture", "elevenlabs project structure",
"how to organize elevenlabs", "TTS service architecture",
"elevenlabs design patterns", "voice API architecture".
|
| allowed-tools | Read, Grep |
| version | 1.0.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","voice","ai","elevenlabs","architecture","patterns"] |
| compatible-with | claude-code |
ElevenLabs Reference Architecture
Overview
Production-ready architecture for ElevenLabs TTS/voice applications. Covers project layout, service layers, caching, streaming, and multi-model orchestration.
Prerequisites
- Understanding of layered architecture patterns
- ElevenLabs SDK knowledge (see
elevenlabs-sdk-patterns)
- TypeScript project with async patterns
- Redis (optional, for distributed caching)
Instructions
Step 1: Project Structure
my-elevenlabs-service/
├── src/
│ ├── elevenlabs/
│ │ ├── client.ts # Singleton client with retry config
│ │ ├── config.ts # Environment-aware configuration
│ │ ├── models.ts # Model selection logic
│ │ ├── errors.ts # Error classification (see sdk-patterns)
│ │ └── types.ts # TypeScript interfaces
│ ├── services/
│ │ ├── tts-service.ts # Text-to-Speech orchestration
│ │ ├── voice-service.ts # Voice management (clone, list, settings)
│ │ ├── audio-service.ts # SFX, isolation, transcription
│ │ └── cache-service.ts # Audio caching layer
│ ├── api/
│ │ ├── routes/
│ │ │ ├── tts.ts # POST /api/tts
│ │ │ ├── voices.ts # GET/POST /api/voices
│ │ │ ├── webhooks.ts # POST /webhooks/elevenlabs
│ │ │ └── health.ts # GET /health
│ │ └── middleware/
│ │ ├── rate-limit.ts # Request throttling
│ │ └── auth.ts # Your app's auth (not ElevenLabs auth)
│ ├── queue/
│ │ ├── tts-queue.ts # Async TTS job processing
│ │ └── workers.ts # Queue workers
│ └── monitoring/
│ ├── metrics.ts # Latency, error rate, quota tracking
│ └── alerts.ts # Budget and health alerts
├── tests/
│ ├── unit/
│ │ ├── tts-service.test.ts
│ │ └── cache-service.test.ts
│ └── integration/
│ └── tts-smoke.test.ts
├── config/
│ ├── development.json
│ ├── staging.json
│ └── production.json
└── .env.example
Step 2: Configuration Layer
export interface ElevenLabsConfig {
apiKey: string;
environment: "development" | "staging" | "production";
defaults: {
modelId: string;
: ;
: ;
: {
: ;
: ;
: ;
: ;
};
};
: {
: ;
: ;
: ;
};
: {
: ;
: ;
: ;
};
}
: <, <>> = {
: {
: {
: ,
: ,
: ,
: { : , : , : , : },
},
: { : , : , : },
: { : , : , : },
},
: {
: {
: ,
: ,
: ,
: { : , : , : , : },
},
: { : , : , : },
: { : , : , : },
},
};
(): {
env = process.. || ;
envConfig = [env] || .;
{
: process..!,
: env ,
...envConfig,
} ;
}