How varunvekaria/languageai works
1. High-level shape
- This repo is a split full-stack app: a Next.js frontend in src/ and a FastAPI backend in backend/app/.
- The backend is the main orchestration layer for user onboarding, voice cloning, lesson retrieval, and audio generation.
- Supabase provides auth, persistence, and storage; ElevenLabs provides voice cloning and text-to-speech.
2. Frontend boundary
- The Next.js app uses the App Router with pages for landing, auth, dashboard, and lesson playback:
- src/app/page.tsx
- src/app/auth/*
- src/app/dashboard/page.tsx
- src/app/lesson/[lessonId]/page.tsx
- src/components/LessonWorkspace.tsx is the main interactive lesson UI surface.
- src/app/layout.tsx and src/app/globals.css provide the shared shell and styling.
3. Frontend integrations
- src/lib/supabase/client.ts is the frontend Supabase client, used for sign-in/session handling and token acquisition.
- src/lib/api.ts is the frontend wrapper for calling the FastAPI backend.
- src/types/api.ts suggests the frontend consumes typed backend responses rather than ad hoc JSON shapes.
4. Authentication flow
- Authentication is delegated to Supabase Auth on the frontend.
- The backend does not own login; instead, protected endpoints require Authorization: Bearer <supabase_access_token>.
- backend/app/deps/auth.py is the auth boundary that validates the Supabase token and resolves the current user.
5. Backend API structure
- backend/app/main.py is the FastAPI entrypoint.
- The backend is organized by router:
- routers/health.py for liveness checks
- routers/users.py for onboarding/profile operations
- routers/voices.py for cloning and listing voices
- routers/lessons.py for lesson library and audio rendering
- The API is versioned under /api/v1, matching the README contract.
6. Lesson content subsystem
- backend/app/data/lessons.py holds the prewritten lesson library.
- This means lesson content is currently application-owned/static, not user-generated or fetched from an external CMS.
- GET /api/v1/lessons/library exposes that content, and GET /api/v1/lessons/{lesson_id} returns a specific lesson.
7. User profile onboarding
- POST /api/v1/users/onboard is the profile bootstrap step after auth.
- The backend verifies the Supabase token, then upserts a profile row into Supabase, typically in user_profiles.
- This creates the link between the authenticated auth user and app-specific preferences like target_language.
8. Voice cloning subsystem
- POST /api/v1/voices/clone accepts multipart uploads of voice samples plus a voice_name.
- backend/app/services/elevenlabs.py handles the ElevenLabs VoiceLab clone API call.
- The resulting voice metadata is persisted in Supabase, usually in user_voices.
- The backend also cleans up the temporary cloned voice after generating the needed lesson audio, so cloning is treated as an intermediate step.
9. Lesson audio generation pipeline
- POST /api/v1/lessons/render-audio is the main media pipeline.
- backend/app/services/lesson_audio.py orchestrates per-line TTS generation rather than producing one long file.
- Audio is stored in a private Supabase Storage bucket (lesson-audio), and metadata is written to user_lesson_audio.
- The API returns signed playback URLs, so the client can stream audio without making the bucket public.
10. Persistence and service boundaries
- backend/app/services/supabase.py centralizes Supabase client access and likely switches between anon/service-role credentials.
- The backend uses the service role key for server-side writes to profiles, voice metadata, and lesson-audio metadata/storage.
- The frontend uses only the public Supabase anon key and never writes directly to the sensitive tables.
11. External service dependencies
- Supabase is the system of record for identity, user data, and generated audio metadata.
- ElevenLabs is the external media-generation provider for both cloned voices and TTS.
- These two services define the main runtime boundary: the app coordinates them, but does not implement its own auth or speech synthesis.
12. Operational/runtime view
- Frontend runs on localhost:3000, backend on localhost:8000, with Swagger at /docs and health at /api/v1/health.
- Configuration is environment-driven in both layers:
- frontend: Supabase URL/anon key, API base URL
- backend: Supabase credentials, ElevenLabs key, storage/bucket/table names, TTS speed
- This makes the system easy to diagram as a browser app talking to a stateless API, which in turn talks to Supabase and ElevenLabs.
Main entry points: main.py API entry · supabase.py Supabase adapter · voices.py Voices router · lessons.py Lessons router
Components 21
Frontend
Next.js app, client-side auth, and lesson UI
- Next.js app · App Router shell and pages for the browser experience
src/app - Landing · Public entry page
src/app/page.tsx - Auth pages · Login, callback, and reset-password routes
src/app/auth - Dashboard · Post-login workspace entry
src/app/dashboard/page.tsx - Lesson page · Lesson playback route
src/app/lesson/[lessonId]/page.tsx - Lesson workspace · Main interactive lesson interface
src/components/LessonWorkspace.tsx - API client · Frontend wrapper for backend requests
src/lib/api.ts - Supabase client · Browser-side Supabase session and token access
src/lib/supabase/client.ts - API types · Shared response types for backend calls
src/types/api.ts
Backend
FastAPI API, orchestration, and persistence
- API entry · FastAPI application and route mounting
backend/app/main.py - Auth guard · Validates Supabase bearer tokens and resolves user context
backend/app/deps/auth.py - Users router · Onboarding and profile operations
backend/app/routers/users.py - Voices router · Voice cloning and voice listing endpoints
backend/app/routers/voices.py - Lessons router · Lesson library and audio rendering endpoints
backend/app/routers/lessons.py - Health router · Liveness endpoint
backend/app/routers/health.py - Lesson catalog · Static lesson library bundled with the app
backend/app/data/lessons.py - Audio pipeline · Orchestrates per-line TTS generation and playback asset creation
backend/app/services/lesson_audio.py - ElevenLabs adapter · Voice clone and text-to-speech integration
backend/app/services/elevenlabs.py - Supabase adapter · Server-side Supabase client and data access boundary
backend/app/services/supabase.py
External services
Third-party systems used for identity, storage, and speech
- Supabase · Auth, database, and storage system of record
- ElevenLabs · Voice cloning and TTS provider
Connections 22
- Landing → Supabase client: sign in · Starts auth/session flow
- Auth pages → Supabase client: auth callback · Completes login and token handling
- Dashboard → Lesson workspace: uses · Loads the main lesson UI
- Lesson page → Lesson workspace: renders · Embeds lesson playback workspace
- Lesson workspace → API client: fetches data · Loads lesson and audio state from backend
- API client → API entry: requests · Calls the FastAPI backend
- Supabase client → Supabase: auth/session · Uses public Supabase auth and token acquisition
- API entry → Auth guard: protects · Applies bearer-token auth to protected routes
- Auth guard → Supabase: verifies token · Validates Supabase access tokens
- API entry → Users router: mounts · Exposes onboarding/profile routes
- API entry → Voices router: mounts · Exposes voice routes
- API entry → Lessons router: mounts · Exposes lesson routes
- API entry → Health router: mounts · Exposes liveness checks
- Users router → Supabase adapter: writes profiles · Persists user onboarding state
- Voices router → ElevenLabs adapter: clones voice · Creates cloned voices through ElevenLabs
- Voices router → Supabase adapter: stores voice meta · Persists voice records in Supabase
- Lessons router → Lesson catalog: reads lessons · Serves the static lesson library
- Lessons router → Audio pipeline: renders audio · Generates lesson playback assets
- Audio pipeline → ElevenLabs adapter: tts calls · Generates per-line speech audio
- Audio pipeline → Supabase adapter: stores metadata · Writes generated audio records and signed-access state
- Supabase adapter → Supabase: data+storage · Uses service-role access for persistence and storage
- ElevenLabs adapter → ElevenLabs: api calls · Invokes cloning and TTS APIs