# deeplegend/voicelink architecture

> Architecture diagram of the GitHub repository deeplegend/voicelink, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/deeplegend/voicelink
- Repository: https://github.com/deeplegend/voicelink

## Overview

1. This is a Next.js App Router application organized around two product areas: text-to-speech generation and voice management. The app shell lives under `src/app`, with dashboard pages in `src/app/(dashboard)` and dedicated auth/org-selection routes outside that shell.

2. The UI is split by feature, not by generic component type. `src/features/text-to-speech`, `src/features/voices`, and `src/features/dashboard` each contain their own views, components, data, and hooks. Shared primitives live in `src/components/ui`, which is a large design-system layer used across the app.

3. The main user flow is: sign in → select org → open dashboard → create or manage voices / generate speech. The dashboard entry points are `src/app/(dashboard)/page.tsx`, `voices/page.tsx`, and `text-to-speech/page.tsx`, each delegating to feature-specific view components.

4. Text-to-speech generation is the core subsystem. The TTS feature includes input forms, prompt suggestions, voice selection, settings/history panels, and audio playback visualization. Generation detail pages exist at `src/app/(dashboard)/text-to-speech/[generationId]`, indicating the app stores and reopens prior generations.

5. There is a backend API layer in `src/app/api` that mediates client actions. Key endpoints are `/api/create` for starting generation, `/api/audio/[generationId]` for retrieving generated audio, `/api/voices/[VoiceId]` for voice-specific operations, and `/api/trpc/[trpc]` for tRPC-based application queries and mutations.

6. Persistent application state is backed by Prisma. The schema and migrations under `prisma/` indicate a relational database is the source of truth for entities such as voices, generations, and related metadata. `src/lib/db.ts` is the DB access boundary.

7. Generated audio is stored separately from relational data. The presence of `src/lib/r2.ts` strongly suggests object storage, likely Cloudflare R2, is used for audio assets, while the DB stores references/metadata. This splits small metadata reads from large binary audio delivery.

8. Voice assets are treated as first-class data. The repository includes many bundled system voice WAV files in `scripts/system-voices/` plus a seeding script, which suggests there are built-in voices loaded into the database or storage at deploy/setup time. The voices feature also includes create dialogs, recording, category/scoping helpers, and list/card UI.

9. There is a distinct integration boundary around the speech engine itself. `src/lib/chatterbox-client.ts`, `src/types/chatterbox-api.d.ts`, and the top-level `chatterbox_tts.py` point to an external or separately runnable TTS service/client contract. The Next.js app appears to orchestrate generation requests rather than perform model inference directly in the browser.

10. Client-server state management is handled with tRPC for typed application data and route handlers for media transfer. `src/trpc/routers/generations.ts` and `voices.ts` expose domain operations, while `src/trpc/client.tsx`, `server.tsx`, and `query-client.ts` wire the React app to those routers. This keeps interactive data fetching separate from binary audio delivery.

11. The `src/features/text-to-speech/hooks/use-wavesurfer.ts` and `src/hooks/use-audio-playback.ts` indicate browser-side playback and waveform visualization happen in the client, consuming audio retrieved from the backend rather than embedding audio processing into the server.

12. Deployment/runtime-wise, this is a TypeScript-heavy Next.js app with Prisma migrations, custom scripts, and API routes. The architecture centers on a web frontend, a relational database, object storage for audio, and a TTS service boundary, with auth/session and org context layered around the dashboard experience.

Main entry points: [`src/app/api/create/route.ts`](https://github.com/deeplegend/voicelink/blob/main/src/app/api/create/route.ts) (API routes), [`src/app/(dashboard)/layout.tsx`](https://github.com/deeplegend/voicelink/blob/main/src/app/(dashboard)/layout.tsx) (Dashboard shell), [`src/app/layout.tsx`](https://github.com/deeplegend/voicelink/blob/main/src/app/layout.tsx) (App layout), [`src/features/text-to-speech/views/text-to-speech-view.tsx`](https://github.com/deeplegend/voicelink/blob/main/src/features/text-to-speech/views/text-to-speech-view.tsx) (TTS view)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App shell"]
  node_app_layout["App layout<br/>nextjs layout<br/>[layout.tsx]"]
  node_dashboard_layout["Dashboard shell<br/>route shell<br/>[layout.tsx]"]
  node_dashboard_home["Dashboard home<br/>route page<br/>[page.tsx]"]
  node_tts_route["TTS page<br/>route page<br/>[page.tsx]"]
  node_tts_detail_route["TTS detail<br/>route page<br/>[page.tsx]"]
  node_voices_route["Voices page<br/>route page<br/>[page.tsx]"]
  node_sign_in["Sign in<br/>auth route<br/>[page.tsx]"]
  node_org_select["Org select<br/>access route<br/>[page.tsx]"]
end

subgraph group_features["Features"]
  node_dashboard_view["Dashboard view<br/>feature view<br/>[dashboard-view.tsx]"]
  node_tts_view["TTS view<br/>feature view"]
  node_tts_detail_view["TTS detail view<br/>feature view"]
  node_voices_view["Voices view<br/>feature view<br/>[voices-view.tsx]"]
  node_tts_components["TTS controls<br/>feature components"]
  node_voices_components["Voice tools<br/>feature components<br/>[voices-list.tsx]"]
  node_tts_state["TTS state<br/>feature state"]
  node_voices_audio["Voice audio<br/>feature hook"]
end

subgraph group_backend["Backend"]
  node_api_routes["API routes<br/>route handlers<br/>[route.ts]"]
  node_trpc_layer["tRPC layer<br/>rpc boundary<br/>[_app.ts]"]
  node_db_layer[("Database<br/>prisma boundary<br/>[db.ts]")]
  node_storage_layer[("Audio storage<br/>object storage<br/>[r2.ts]")]
  node_speech_engine["Speech engine<br/>tts service<br/>[chatterbox_tts.py]"]
end

subgraph group_shared["Shared"]
  node_ui_kit["UI kit<br/>design system<br/>[button.tsx]"]
  node_app_trpc_client["tRPC client<br/>client wiring<br/>[client.tsx]"]
end

node_app_layout -->|"wraps"| node_dashboard_layout
node_app_layout -->|"routes"| node_sign_in
node_app_layout -->|"routes"| node_org_select
node_dashboard_layout -->|"shows"| node_dashboard_home
node_dashboard_layout -->|"contains"| node_tts_route
node_dashboard_layout -->|"contains"| node_voices_route
node_tts_route -->|"delegates"| node_tts_view
node_tts_detail_route -->|"delegates"| node_tts_detail_view
node_voices_route -->|"delegates"| node_voices_view
node_dashboard_home -->|"delegates"| node_dashboard_view
node_tts_view -->|"composes"| node_tts_components
node_tts_view -->|"uses"| node_tts_state
node_tts_detail_view -->|"uses"| node_tts_state
node_voices_view -->|"composes"| node_voices_components
node_voices_view -->|"uses"| node_voices_audio
node_tts_components -->|"builds on"| node_ui_kit
node_voices_components -->|"builds on"| node_ui_kit
node_dashboard_view -->|"builds on"| node_ui_kit
node_tts_components -->|"starts generation"| node_api_routes
node_voices_components -->|"manages voices"| node_api_routes
node_api_routes -->|"reads/writes"| node_db_layer
node_api_routes -->|"streams audio"| node_storage_layer
node_api_routes -->|"orchestrates"| node_speech_engine
node_trpc_layer -->|"queries"| node_db_layer
node_trpc_layer -->|"served by"| node_app_trpc_client
node_tts_state -->|"fetches data"| node_app_trpc_client
node_voices_audio -->|"uploads/records"| node_api_routes

click node_app_layout "https://github.com/deeplegend/voicelink/blob/main/src/app/layout.tsx"
click node_dashboard_layout "https://github.com/deeplegend/voicelink/blob/main/src/app/(dashboard)/layout.tsx"
click node_dashboard_home "https://github.com/deeplegend/voicelink/blob/main/src/app/(dashboard)/page.tsx"
click node_tts_route "https://github.com/deeplegend/voicelink/blob/main/src/app/(dashboard)/text-to-speech/page.tsx"
click node_tts_detail_route "https://github.com/deeplegend/voicelink/blob/main/src/app/(dashboard)/text-to-speech/[generationId]/page.tsx"
click node_voices_route "https://github.com/deeplegend/voicelink/blob/main/src/app/(dashboard)/voices/page.tsx"
click node_sign_in "https://github.com/deeplegend/voicelink/blob/main/src/app/sign-in/[[...sign-in]]/page.tsx"
click node_org_select "https://github.com/deeplegend/voicelink/blob/main/src/app/org-selection/page.tsx"
click node_dashboard_view "https://github.com/deeplegend/voicelink/blob/main/src/features/dashboard/views/dashboard-view.tsx"
click node_tts_view "https://github.com/deeplegend/voicelink/blob/main/src/features/text-to-speech/views/text-to-speech-view.tsx"
click node_tts_detail_view "https://github.com/deeplegend/voicelink/blob/main/src/features/text-to-speech/views/text-to-speech-detail-view.tsx"
click node_voices_view "https://github.com/deeplegend/voicelink/blob/main/src/features/voices/views/voices-view.tsx"
click node_tts_components "https://github.com/deeplegend/voicelink/blob/main/src/features/text-to-speech/components/text-to-speech-form.tsx"
click node_voices_components "https://github.com/deeplegend/voicelink/blob/main/src/features/voices/components/voices-list.tsx"
click node_tts_state "https://github.com/deeplegend/voicelink/blob/main/src/features/text-to-speech/contexts/tts-voices-context.tsx"
click node_voices_audio "https://github.com/deeplegend/voicelink/blob/main/src/features/voices/hooks/use-audio-recorder.ts"
click node_api_routes "https://github.com/deeplegend/voicelink/blob/main/src/app/api/create/route.ts"
click node_trpc_layer "https://github.com/deeplegend/voicelink/blob/main/src/trpc/routers/_app.ts"
click node_db_layer "https://github.com/deeplegend/voicelink/blob/main/src/lib/db.ts"
click node_storage_layer "https://github.com/deeplegend/voicelink/blob/main/src/lib/r2.ts"
click node_speech_engine "https://github.com/deeplegend/voicelink/blob/main/chatterbox_tts.py"
click node_ui_kit "https://github.com/deeplegend/voicelink/blob/main/src/components/ui/button.tsx"
click node_app_trpc_client "https://github.com/deeplegend/voicelink/blob/main/src/trpc/client.tsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app_layout,node_dashboard_layout,node_dashboard_home,node_tts_route,node_tts_detail_route,node_voices_route,node_sign_in,node_org_select toneBlue
class node_dashboard_view,node_tts_view,node_tts_detail_view,node_voices_view,node_tts_components,node_voices_components,node_tts_state,node_voices_audio toneAmber
class node_api_routes,node_trpc_layer,node_db_layer,node_storage_layer,node_speech_engine toneMint
class node_ui_kit,node_app_trpc_client toneRose
```

## Components

### App shell

Next.js routes, layout, and access entrypoints

- [App layout](https://github.com/deeplegend/voicelink/blob/main/src/app/layout.tsx): nextjs layout · Root application shell and global providers · `src/app/layout.tsx`
- [Dashboard shell](https://github.com/deeplegend/voicelink/blob/main/src/app/(dashboard)/layout.tsx): route shell · Authenticated dashboard layout wrapper · `src/app/(dashboard)/layout.tsx`
- [Dashboard home](https://github.com/deeplegend/voicelink/blob/main/src/app/(dashboard)/page.tsx): route page · Main dashboard entry page · `src/app/(dashboard)/page.tsx`
- [TTS page](https://github.com/deeplegend/voicelink/blob/main/src/app/(dashboard)/text-to-speech/page.tsx): route page · Text-to-speech entry page · `src/app/(dashboard)/text-to-speech/page.tsx`
- [TTS detail](https://github.com/deeplegend/voicelink/blob/main/src/app/(dashboard)/text-to-speech/[generationId]/page.tsx): route page · Reopens a prior generation by id · `src/app/(dashboard)/text-to-speech/[generationId]/page.tsx`
- [Voices page](https://github.com/deeplegend/voicelink/blob/main/src/app/(dashboard)/voices/page.tsx): route page · Voice management entry page · `src/app/(dashboard)/voices/page.tsx`
- [Sign in](https://github.com/deeplegend/voicelink/blob/main/src/app/sign-in/[[...sign-in]]/page.tsx): auth route · Authentication entry route · `src/app/sign-in/[[...sign-in]]/page.tsx`
- [Org select](https://github.com/deeplegend/voicelink/blob/main/src/app/org-selection/page.tsx): access route · Organization selection flow after auth · `src/app/org-selection/page.tsx`

### Features

Product-area modules with their own views and UI

- [Dashboard view](https://github.com/deeplegend/voicelink/blob/main/src/features/dashboard/views/dashboard-view.tsx): feature view · Dashboard landing experience and quick actions · `src/features/dashboard/views/dashboard-view.tsx`
- [TTS view](https://github.com/deeplegend/voicelink/blob/main/src/features/text-to-speech/views/text-to-speech-view.tsx): feature view · Primary speech generation workspace · `src/features/text-to-speech/views/text-to-speech-view.tsx`
- [TTS detail view](https://github.com/deeplegend/voicelink/blob/main/src/features/text-to-speech/views/text-to-speech-detail-view.tsx): feature view · Generation playback and detail workspace · `src/features/text-to-speech/views/text-to-speech-detail-view.tsx`
- [Voices view](https://github.com/deeplegend/voicelink/blob/main/src/features/voices/views/voices-view.tsx): feature view · Voice catalog and management workspace · `src/features/voices/views/voices-view.tsx`
- [TTS controls](https://github.com/deeplegend/voicelink/blob/main/src/features/text-to-speech/components/text-to-speech-form.tsx): feature components · Forms, settings, voice preview, history, and generation controls · `src/features/text-to-speech/components/text-to-speech-form.tsx`
- [Voice tools](https://github.com/deeplegend/voicelink/blob/main/src/features/voices/components/voices-list.tsx): feature components · Voice cards, creation, recorder, and toolbar UI · `src/features/voices/components/voices-list.tsx`
- [TTS state](https://github.com/deeplegend/voicelink/blob/main/src/features/text-to-speech/contexts/tts-voices-context.tsx): feature state · Voice context and playback waveform hook · `src/features/text-to-speech/contexts/tts-voices-context.tsx`
- [Voice audio](https://github.com/deeplegend/voicelink/blob/main/src/features/voices/hooks/use-audio-recorder.ts): feature hook · Audio recording and playback helpers for voice assets · `src/features/voices/hooks/use-audio-recorder.ts`

### Backend

API, database, storage, and external engine boundaries

- [API routes](https://github.com/deeplegend/voicelink/blob/main/src/app/api/create/route.ts): route handlers · Create, audio delivery, voice operations, and tRPC transport · `src/app/api/create/route.ts`
- [tRPC layer](https://github.com/deeplegend/voicelink/blob/main/src/trpc/routers/_app.ts): rpc boundary · Typed client/server wiring and domain routers · `src/trpc/routers/_app.ts`
- [Database](https://github.com/deeplegend/voicelink/blob/main/src/lib/db.ts): prisma boundary · Relational persistence for voices, generations, and metadata · `src/lib/db.ts`
- [Audio storage](https://github.com/deeplegend/voicelink/blob/main/src/lib/r2.ts): object storage · Binary audio asset storage boundary · `src/lib/r2.ts`
- [Speech engine](https://github.com/deeplegend/voicelink/blob/main/chatterbox_tts.py): tts service · External or separately runnable TTS client/service contract · `chatterbox_tts.py`

### Shared

Reusable UI and cross-cutting client helpers

- [UI kit](https://github.com/deeplegend/voicelink/blob/main/src/components/ui/button.tsx): design system · Shared reusable primitives across the app · `src/components/ui/button.tsx`
- [tRPC client](https://github.com/deeplegend/voicelink/blob/main/src/trpc/client.tsx): client wiring · React client, server helpers, and query client setup · `src/trpc/client.tsx`

## Connections

- App layout → Dashboard shell: wraps · Root shell contains authenticated dashboard routes
- App layout → Sign in: routes · Root app also exposes auth entrypoints
- App layout → Org select: routes · Root app also exposes org selection
- Dashboard shell → Dashboard home: shows · Dashboard shell renders the home entry page
- Dashboard shell → TTS page: contains · Dashboard shell contains TTS routes
- Dashboard shell → Voices page: contains · Dashboard shell contains voice routes
- TTS page → TTS view: delegates · Route page delegates to feature view
- TTS detail → TTS detail view: delegates · Generation detail route delegates to feature view
- Voices page → Voices view: delegates · Route page delegates to voice management view
- Dashboard home → Dashboard view: delegates · Dashboard page renders feature view
- TTS view → TTS controls: composes · Primary workspace is assembled from TTS controls
- TTS view → TTS state: uses · View depends on shared TTS state and playback
- TTS detail view → TTS state: uses · Detail playback relies on the same voice/playback state
- Voices view → Voice tools: composes · Voice management view is assembled from voice tools
- Voices view → Voice audio: uses · Voice workflows use recording/playback helpers
- TTS controls → UI kit: builds on · Feature UI is built from shared primitives
- Voice tools → UI kit: builds on · Voice UI is built from shared primitives
- Dashboard view → UI kit: builds on · Dashboard UI is built from shared primitives
- TTS controls → API routes: starts generation · Generation form submits to create/audio endpoints
- Voice tools → API routes: manages voices · Voice tooling talks to voice API routes
- API routes → Database: reads/writes · Route handlers persist and query relational state
- API routes → Audio storage: streams audio · Binary audio is fetched from object storage
- API routes → Speech engine: orchestrates · Creation requests are forwarded to the external speech engine
- tRPC layer → Database: queries · Routers expose typed domain access over Prisma
- tRPC layer → tRPC client: served by · Routers are consumed by the React client wiring
- TTS state → tRPC client: fetches data · Client hooks use typed queries and mutations
- Voice audio → API routes: uploads/records · Recorder flows ultimately hand off through backend routes
