How rainyaya/bikuri-nihongolens works
Purpose and Entry Points
Kotoba Studio is a local-first, single-user Japanese video study application. It imports or downloads video, transcribes it with word-level Japanese timing, and presents a synchronized study workspace. Runtime entry points are FastAPI in backend/app/main.py and the React/Vite client in frontend/src/main.tsx, with routing in frontend/src/router.tsx.
Local Application Boundary
The browser communicates with a localhost FastAPI API; Vite provides the development /api proxy. No remote application backend stores user data. The system depends on local disk, SQLite, GPU-capable WhisperX, ffmpeg/ffprobe, and optionally yt-dlp. Core architecture decisions are recorded in docs/adr/0001-local-web-app-architecture.md and docs/adr/0003-persistence-sqlite-plus-library.md.
API, Domain, and Persistence Layer
FastAPI routers separate projects, folders, study state, settings, and asynchronous tasks:
• backend/app/routers/projects.py
• backend/app/routers/study.py
• backend/app/routers/tasks.py
SQLite holds durable metadata such as projects, notes, saved vocabulary, viewing progress, and folders through backend/app/db.py and backend/app/models.py. The filesystem library manages per-project media and generated artifacts via backend/app/library.py and backend/app/media.py; the database references this local library rather than replacing it.
Import and Background Work Orchestration
Project creation accepts either a local media import or a remote URL. URL acquisition uses yt-dlp integration in backend/app/ytdlp.py; media then enters the task manager in backend/app/tasks/manager.py. The task system supports download concurrency, serialized transcription, cancellation, persisted task state, and SSE progress delivery. Work implementations are split between backend/app/tasks/download.py and backend/app/tasks/transcribe.py.
Transcription and Artifact Pipeline
The transcription worker invokes the vendored pipeline: ASR/alignment produces canonical segment-and-word JSON, while SRT is a derived export. Pipeline responsibilities are concentrated in:
• backend/pipeline/asr.py
• backend/pipeline/tokenize.py
• backend/pipeline/subtitle.py
Video processing such as duration inspection, thumbnail extraction, and waveform peak generation is in backend/pipeline/video.py. WhisperX uses local HuggingFace model caches and CUDA fp16 where available; ffmpeg/ffprobe are required external executables.
Study API and Playback Model
Study endpoints expose transcript/token data, saved words, notes, and progress from backend/app/routers/study.py. Playback time is the single client-side synchronization source: active word highlighting, transcript/focus selection, auto-scroll, subtitle display, and timeline playhead derive from the same player clock rather than independently maintained state. This boundary is formalized in docs/adr/0004-playback-as-single-source-of-truth.md.
Frontend Experience Structure
The application shell and page routing are rooted in frontend/src/layouts/AppLayout.tsx and frontend/src/pages/StudyPage.tsx. Project library, task monitoring, and settings are dedicated pages:
• frontend/src/pages/ProjectsPage.tsx
• frontend/src/pages/TasksPage.tsx
• frontend/src/pages/SettingsPage.tsx
The study workspace composes the video stage, timed subtitle/transcript views, vocabulary/notes panels, and timeline from frontend/src/components/study/VideoStage.tsx, frontend/src/components/study/TranscriptPane.tsx, and frontend/src/components/study/Timeline.tsx. frontend/src/components/study/usePlayerClock.ts is the key synchronization mechanism. Client API calls are centralized in frontend/src/lib/api.ts.
Main entry points: library.py Project media library · StudyPage.tsx Study workspace · projects.py Projects, study & task APIs · manager.py Task manager
Components 20
React client
- Vite client entry
frontend/src/main.tsx - Client routing
frontend/src/router.tsx - Application shell
frontend/src/layouts/AppLayout.tsx - Library, tasks & settings
frontend/src/pages/ProjectsPage.tsx - Study workspace
frontend/src/pages/StudyPage.tsx - Playback clock · Single source for study-view synchronization.
frontend/src/components/study/usePlayerClock.ts - Video, transcript & timeline
frontend/src/components/study/VideoStage.tsx - API client
frontend/src/lib/api.ts
Local API
- FastAPI application
backend/app/main.py - Projects, study & task APIs
backend/app/routers/projects.py
Background pipeline
- Task manager · Coordinates concurrency, cancellation, persisted state, and SSE progress.
backend/app/tasks/manager.py - Download worker
backend/app/tasks/download.py - Transcription worker
backend/app/tasks/transcribe.py - yt-dlp acquisition · Optional remote URL download.
backend/app/ytdlp.py - ASR & alignment · Produces canonical timed segment-and-word JSON.
backend/pipeline/asr.py - Tokenization & SRT export · SRT is derived from canonical transcript data.
backend/pipeline/subtitle.py - Media analysis · Inspects duration and generates thumbnails and waveform peaks.
backend/pipeline/video.py - Local ML & media tools · WhisperX model cache, CUDA, ffmpeg, and ffprobe.
Local persistence
- SQLite metadata · Stores projects, folders, notes, vocabulary, progress, and task state.
backend/app/db.py - Project media library · Per-project source media and generated artifacts.
backend/app/library.py
Connections 27
- Vite client entry → Client routing
- Client routing → Application shell
- Application shell → Library, tasks & settings
- Application shell → Study workspace
- Study workspace → Video, transcript & timeline
- Study workspace → Playback clock: drives UI state
- Playback clock → Video, transcript & timeline: synchronizes
- Library, tasks & settings → API client
- Study workspace → API client
- API client → FastAPI application: localhost /api · Vite proxies API calls during development.
- FastAPI application → Projects, study & task APIs
- Projects, study & task APIs → SQLite metadata: metadata & study state
- Projects, study & task APIs → Project media library: media & artifacts
- Projects, study & task APIs → Task manager: enqueue and stream progress
- Task manager → Download worker: concurrent downloads
- Task manager → Transcription worker: serialized transcription
- Task manager → SQLite metadata: persist task state
- Download worker → yt-dlp acquisition: remote URL
- Download worker → Project media library: store media
- Transcription worker → ASR & alignment
- Transcription worker → Media analysis
- ASR & alignment → Tokenization & SRT export: canonical transcript
- ASR & alignment → Project media library: timed transcript JSON
- Tokenization & SRT export → Project media library: derived SRT
- Media analysis → Project media library: thumbnails & waveform
- ASR & alignment → Local ML & media tools: WhisperX/CUDA
- Media analysis → Local ML & media tools: ffmpeg/ffprobe