# craigsdennis/phoney-ai architecture

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

- Interactive diagram: https://gitdiagram.com/craigsdennis/phoney-ai
- Repository: https://github.com/craigsdennis/phoney-ai

## Overview

##### Project type and purpose
- This is a serverless telephony integration built on Cloudflare Workers AI.
- It accepts SMS or voice calls via Twilio, processes them through AssemblyAI and Cloudflare Workers AI, then responds back over Twilio to the user’s phone.

##### File structure
- Top‐level config files:
- wrangler.toml – Cloudflare Workers deployment settings
- .dev.vars.example – environment variable template for Twilio & AssemblyAI keys
- src/index.js – the single entry-point for all incoming webhooks (SMS or voice)
- package.json / package-lock.json – npm dependencies (Wrangler, Twilio SDK, AssemblyAI SDK, Cloudflare Workers AI)
- No frontend, no database directories – the entire logic lives in a single serverless function.

##### README for additional insights
- Dependencies: Twilio CLI for mapping phone numbers to your local tunnel or deployed Workers URL
- Dev workflow:
- npm install
- npx wrangler login & npm run dev (local Workers with tunnel)
- twilio phone-numbers:update → point SMS‐URL and voice‐URL at your tunnel
- Deploy workflow: npx wrangler deploy & repoint Twilio numbers.

a. Main components:
1. User’s Phone (SMS or Voice)
2. Twilio Telephony Platform (incoming webhook & outgoing API)
3. Cloudflare Workers Serverless Function (src/index.js + wrangler.toml)
4. AI Services:
– Cloudflare Workers AI (prompting, chat/completion)
– AssemblyAI (speech‐to‐text for voice messages)
b. Relationships and interactions:
- Phone → Twilio inbound
- Twilio → Cloudflare Workers webhook (/incoming-message or /incoming-voice)
- Workers → AssemblyAI for transcription (voice)
- Workers → Cloudflare Workers AI for generating responses
- Workers → Twilio outbound API (sms.messages.create or voice response)
- Twilio → Phone (delivers SMS or speaks response)
c. Architectural patterns and design principles:
- Event‐driven, serverless microservice (single function handles all events)
- Stateless processing — no on‐disk storage or database
- External service orchestration (Twilio as trigger & delivery, AssemblyAI for STT, Cloudflare AI for NLU/NLG)
d. Relevant technologies & libraries:
- Cloudflare Workers + Wrangler
- Twilio Node.js SDK + Twilio CLI
- AssemblyAI SDK
- Environment management via .dev.vars

## Diagram (Mermaid)

```mermaid
graph TB
    %% User Device
    Phone["User Phone\n(SMS/Voice)"]:::device

    %% Telephony Platform
    subgraph "Telephony Platform"
        TwilioIn["Twilio SMS/Voice Webhook"]:::cloud
        TwilioOut["Twilio SMS API / Voice Response"]:::cloud
    end

    %% Serverless Function on Edge
    subgraph "Cloudflare Edge (Serverless)"
        Worker["Cloudflare Worker\n(src/index.js)"]:::code
    end

    %% AI Services
    AssemblyAI["AssemblyAI STT"]:::cloud
    CF_AI["Cloudflare Workers AI"]:::cloud

    %% Configuration
    subgraph "Configuration & Deployment"
        Wrangler["wrangler.toml"]:::config
        DevVars[".dev.vars.example"]:::config
        Pkg["package.json"]:::config
        PkgLock["package-lock.json"]:::config
        Readme["README.md"]:::config
        Gitignore[".gitignore"]:::config
        Prettierrc[".prettierrc"]:::config
        Editorconfig[".editorconfig"]:::config
    end

    %% Flows
    Phone -->|"SMS/Voice" | TwilioIn
    TwilioIn -->|"HTTP POST /incoming-message\nor /incoming-voice"| Worker
    Worker -->|"transcribe voice"| AssemblyAI
    AssemblyAI -->|"transcript" | Worker
    Worker -->|"invoke AI completion"| CF_AI
    CF_AI -->|"response payload"| Worker
    Worker -->|"sms.messages.create\nor voice response"| TwilioOut
    TwilioOut -->|"SMS/Voice Delivery"| Phone

    %% Click Events
    click Worker "https://github.com/craigsdennis/phoney-ai/blob/main/src/index.js"
    click Wrangler "https://github.com/craigsdennis/phoney-ai/blob/main/wrangler.toml"
    click DevVars "https://github.com/craigsdennis/phoney-ai/blob/main/.dev.vars.example"
    click Pkg "https://github.com/craigsdennis/phoney-ai/blob/main/package.json"
    click PkgLock "https://github.com/craigsdennis/phoney-ai/blob/main/package-lock.json"
    click Readme "https://github.com/craigsdennis/phoney-ai/blob/main/README.md"
    click Gitignore "https://github.com/craigsdennis/phoney-ai/blob/main/.gitignore"
    click Prettierrc "https://github.com/craigsdennis/phoney-ai/blob/main/.prettierrc"
    click Editorconfig "https://github.com/craigsdennis/phoney-ai/blob/main/.editorconfig"

    %% Styles
    classDef device fill:#E8F0FE,stroke:#4A90E2,color:#0B3D91;
    classDef cloud fill:#E6F4EA,stroke:#34A853,color:#0F9D58;
    classDef code fill:#FFF4E5,stroke:#F2994A,color:#D35400;
    classDef config fill:#F2F2F2,stroke:#9B9B9B,color:#4A4A4A;
```
