retellai-reference-architecture
1
总安装量
1
周安装量
#42989
全站排名
安装命令
npx skills add https://smithery.ai
Agent 安装分布
claude-code
1
Skill 文档
Retell AI Reference Architecture
Overview
Production-ready architecture patterns for Retell AI integrations.
Prerequisites
- Understanding of layered architecture
- Retell AI SDK knowledge
- TypeScript project setup
- Testing framework configured
Project Structure
my-retellai-project/
âââ src/
â âââ retellai/
â â âââ client.ts # Singleton client wrapper
â â âââ config.ts # Environment configuration
â â âââ types.ts # TypeScript types
â â âââ errors.ts # Custom error classes
â â âââ handlers/
â â âââ webhooks.ts # Webhook handlers
â â âââ events.ts # Event processing
â âââ services/
â â âââ retellai/
â â âââ index.ts # Service facade
â â âââ sync.ts # Data synchronization
â â âââ cache.ts # Caching layer
â âââ api/
â â âââ retellai/
â â âââ webhook.ts # Webhook endpoint
â âââ jobs/
â âââ retellai/
â âââ sync.ts # Background sync job
âââ tests/
â âââ unit/
â â âââ retellai/
â âââ integration/
â âââ retellai/
âââ config/
â âââ retellai.development.json
â âââ retellai.staging.json
â âââ retellai.production.json
âââ docs/
âââ retellai/
âââ SETUP.md
âââ RUNBOOK.md
Layer Architecture
âââââââââââââââââââââââââââââââââââââââââââ
â API Layer â
â (Controllers, Routes, Webhooks) â
âââââââââââââââââââââââââââââââââââââââââââ¤
â Service Layer â
â (Business Logic, Orchestration) â
âââââââââââââââââââââââââââââââââââââââââââ¤
â Retell AI Layer â
â (Client, Types, Error Handling) â
âââââââââââââââââââââââââââââââââââââââââââ¤
â Infrastructure Layer â
â (Cache, Queue, Monitoring) â
âââââââââââââââââââââââââââââââââââââââââââ
Key Components
Step 1: Client Wrapper
// src/retellai/client.ts
export class Retell AIService {
private client: RetellAIClient;
private cache: Cache;
private monitor: Monitor;
constructor(config: Retell AIConfig) {
this.client = new RetellAIClient(config);
this.cache = new Cache(config.cacheOptions);
this.monitor = new Monitor('retellai');
}
async get(id: string): Promise<Resource> {
return this.cache.getOrFetch(id, () =>
this.monitor.track('get', () => this.client.get(id))
);
}
}
Step 2: Error Boundary
// src/retellai/errors.ts
export class Retell AIServiceError extends Error {
constructor(
message: string,
public readonly code: string,
public readonly retryable: boolean,
public readonly originalError?: Error
) {
super(message);
this.name = 'Retell AIServiceError';
}
}
export function wrapRetell AIError(error: unknown): Retell AIServiceError {
// Transform SDK errors to application errors
}
Step 3: Health Check
// src/retellai/health.ts
export async function checkRetell AIHealth(): Promise<HealthStatus> {
try {
const start = Date.now();
await retellaiClient.ping();
return {
status: 'healthy',
latencyMs: Date.now() - start,
};
} catch (error) {
return { status: 'unhealthy', error: error.message };
}
}
Data Flow Diagram
User Request
â
â¼
âââââââââââââââ
â API â
â Gateway â
ââââââââ¬âââââââ
â
â¼
âââââââââââââââ âââââââââââââââ
â Service âââââ¶â Cache â
â Layer â â (Redis) â
ââââââââ¬âââââââ âââââââââââââââ
â
â¼
âââââââââââââââ
â Retell AI â
â Client â
ââââââââ¬âââââââ
â
â¼
âââââââââââââââ
â Retell AI â
â API â
âââââââââââââââ
Configuration Management
// config/retellai.ts
export interface Retell AIConfig {
apiKey: string;
environment: 'development' | 'staging' | 'production';
timeout: number;
retries: number;
cache: {
enabled: boolean;
ttlSeconds: number;
};
}
export function loadRetell AIConfig(): Retell AIConfig {
const env = process.env.NODE_ENV || 'development';
return require(`./retellai.${env}.json`);
}
Instructions
Step 1: Create Directory Structure
Set up the project layout following the reference structure above.
Step 2: Implement Client Wrapper
Create the singleton client with caching and monitoring.
Step 3: Add Error Handling
Implement custom error classes for Retell AI operations.
Step 4: Configure Health Checks
Add health check endpoint for Retell AI connectivity.
Output
- Structured project layout
- Client wrapper with caching
- Error boundary implemented
- Health checks configured
Error Handling
| Issue | Cause | Solution |
|---|---|---|
| Circular dependencies | Wrong layering | Separate concerns by layer |
| Config not loading | Wrong paths | Verify config file locations |
| Type errors | Missing types | Add Retell AI types |
| Test isolation | Shared state | Use dependency injection |
Examples
Quick Setup Script
# Create reference structure
mkdir -p src/retellai/{handlers} src/services/retellai src/api/retellai
touch src/retellai/{client,config,types,errors}.ts
touch src/services/retellai/{index,sync,cache}.ts
Resources
Flagship Skills
For multi-environment setup, see retellai-multi-env-setup.