How mahakagarwal7/bharatvidya works
Purpose and entry points
BharatVidya converts a concept prompt into a narrated, animated MP4 in selected languages. It has three entry surfaces: React SPA (frontend/src/main.jsx, frontend/src/App.jsx), FastAPI service (web_app/api.py, launched by run.py), and direct CLI pipeline (src/main.py).
Client application
The Vite/React frontend collects concept, language, and animation preferences; submits generation requests; polls job state; and presents generated videos/gallery. Its integration boundary is the backend /api contract, configured separately for frontend deployment.
Paths: frontend/src/App.jsx, frontend/src/main.jsx, frontend/vercel.json.
API, job lifecycle, and delivery
FastAPI owns public HTTP endpoints for generation, status, video listing/retrieval, supported topics, and health. Requests are validated by Pydantic models, converted into asynchronous job work, and expose progress/error/final URL through job status. The job subsystem is described as Redis-backed; video persistence/delivery is abstracted through S3 service code.
Paths: web_app/api.py, web_app/models.py, web_app/jobs.py, web_app/video_service.py, web_app/s3_service.py.
Content-planning boundary
The core engine first translates an input concept into a structured educational plan: title, summary, sections, facts, and narration-oriented content. planner.py delegates model calls to a local Ollama client; plans are materialized under outputs/plans/. This structured plan is the key handoff between generative AI and deterministic media stages.
Paths: src/planner.py, src/local_llm_client.py, outputs/plans/plan_00157e08.json.
Media-generation pipeline
Animator orchestrates plan consumption, narration, visuals, and final composition. The narrator uses Edge-TTS and audio processing to create per-intro/step assets; the renderer uses MoviePy/OpenCV and FFmpeg to combine timed audio, generated cards, images, transitions, and optional animation clips into MP4. Runtime artifacts are filesystem-backed before cloud upload.
Paths: src/animator.py, src/narrator.py, src/renderer.py, src/card_generator.py, outputs/audio/00afbd0b_combined.mp3.
Topic-specific visualization
A router selects specialized visual engines for recognized concepts, while generic rendering remains available for other topics. Existing domain engines cover algorithms and STEM concepts such as binary search, bubble sort, projectile motion, quadratic equations, and sine waves. LaTeX rendering supports formula/image assets within visual scenes.
Paths: src/topic_router.py, src/domain_engines/binary_search.py, src/domain_engines/quadratic.py, src/latex_renderer.py.
Runtime and infrastructure boundaries
Python 3.9+ runs FastAPI and the media pipeline; Node 18+ builds/serves the frontend. External dependencies are Ollama (local LLM), Edge-TTS, FFmpeg/MoviePy/OpenCV, Redis job management, and AWS S3 storage. Production topology places the frontend on Vercel and backend on AWS EC2, with Docker/Compose and CloudFormation deployment options.
Paths: requirements.txt, deploy/Dockerfile, deploy/docker-compose.yml, deploy/aws/cloudformation.yaml.
Main entry points: renderer.py MP4 renderer · api.py FastAPI service · animator.py Animator · jobs.py Async jobs
Components 24
React client
- SPA entry
frontend/src/main.jsx - Generation UI · Collects requests, polls jobs, and displays videos.
frontend/src/App.jsx - Vercel deployment · Configures deployed frontend integration.
frontend/vercel.json
API and jobs
- FastAPI service · Public generation, status, video, topic, and health endpoints.
web_app/api.py - Request models
web_app/models.py - Async jobs · Tracks progress, errors, and final video URLs.
web_app/jobs.py - Video delivery
web_app/video_service.py - S3 persistence
web_app/s3_service.py
Media pipeline
- CLI pipeline
src/main.py - Educational planner · Produces structured title, sections, facts, and narration content.
src/planner.py - Local LLM client
src/local_llm_client.py - Structured plan · Key handoff from generative planning to media production.
outputs/plans/plan_00157e08.json - Animator · Coordinates narration, visuals, and final composition.
src/animator.py - Narration builder · Creates timed narration assets.
src/narrator.py - Topic visual router · Chooses domain-specific or generic visual generation.
src/topic_router.py - Domain visual engines · Includes algorithm and STEM visualizations.
src/domain_engines/binary_search.py - LaTeX renderer
src/latex_renderer.py - MP4 renderer · Combines audio, cards, visuals, transitions, and clips.
src/renderer.py - Audio assets
outputs/audio/00afbd0b_combined.mp3
External services
- Ollama
- Edge-TTS
- FFmpeg / MoviePy / OpenCV
- Redis
- AWS S3
Connections 27
- SPA entry → Generation UI: mounts
- Vercel deployment → Generation UI: deploys
- Generation UI → FastAPI service: /api requests and polling
- FastAPI service → Request models: validates
- FastAPI service → Async jobs: queues generation
- FastAPI service → Video delivery: serves videos
- Async jobs → Redis: stores state
- Async jobs → Educational planner: runs pipeline
- CLI pipeline → Educational planner: starts
- Educational planner → Local LLM client: requests content
- Local LLM client → Ollama: model calls
- Educational planner → Structured plan: writes
- Structured plan → Animator: drives
- Animator → Narration builder: generates narration
- Narration builder → Edge-TTS: synthesizes speech
- Narration builder → Audio assets: writes
- Animator → Topic visual router: selects visuals
- Topic visual router → Domain visual engines: recognized topics
- Domain visual engines → LaTeX renderer: formula assets
- Animator → MP4 renderer: composes video
- Audio assets → MP4 renderer: timed audio
- Topic visual router → MP4 renderer: visual scenes
- MP4 renderer → FFmpeg / MoviePy / OpenCV: encodes MP4
- MP4 renderer → Video delivery: completed video
- Video delivery → S3 persistence: persists through
- S3 persistence → AWS S3: uploads
- Video delivery → Async jobs: final URL