# paul-19658/ai_video architecture

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

- Interactive diagram: https://gitdiagram.com/paul-19658/ai_video
- Repository: https://github.com/paul-19658/ai_video

## Overview

#### Purpose and Runtime Entry Points
DreamWeaver is a local-first AI video-creation platform: a user topic progresses through outline, story, keyframe, and video generation, with editable project state and version history. The frontend is a React 18/TypeScript Vite SPA, entered through `dreamweaver-frontend/src/main.tsx` and composed by `dreamweaver-frontend/src/App.tsx`. The backend is a FastAPI service launched as `app.main:app` from `dreamweaver-backend/app/main.py`.

#### Frontend Application Shell and State
The SPA presents a staged generation workflow and account/project UI. Generation-wide state is centralized in `dreamweaver-frontend/src/contexts/GenerationContext.tsx`; authentication/session state is handled by `dreamweaver-frontend/src/contexts/AuthContext.tsx`. The step UI maps directly to pipeline phases:
- Topic input: `dreamweaver-frontend/src/components/steps/InputStep.tsx`
- Outline and story editing: `dreamweaver-frontend/src/components/steps/OutlineStep.tsx`, `dreamweaver-frontend/src/components/steps/StoryStep.tsx`
- Keyframe and final-video presentation: `dreamweaver-frontend/src/components/steps/KeyframesStep.tsx`, `dreamweaver-frontend/src/components/steps/VideoStep.tsx`

#### API Boundary and Authentication
The frontend API client in `dreamweaver-frontend/src/services/api.ts` communicates through the Vite `/dreamweaver-api/*` proxy to FastAPI on port 8000. Backend route groups separate identity, persisted project operations, and AI work: `dreamweaver-backend/app/routers/auth.py`, `dreamweaver-backend/app/routers/projects.py`, and `dreamweaver-backend/app/routers/generation.py`. Protected operations use Bearer tokens; auth covers registration, login, current-user retrieval, avatar, and password-related flows.

#### Generation Orchestration
Generation endpoints implement the ordered control flow: topic → AI outline → story → keyframes → video. `dreamweaver-backend/app/routers/generation.py` exposes each stage to the client and delegates model interactions to `dreamweaver-backend/app/services/llm_service.py`. DeepSeek supplies text-generation models for outline, story, and keyframe descriptions; MiniMax supplies image and video generation. API keys, selected models, secret material, and service settings are configured in `dreamweaver-backend/app/config.py`.

#### Persistence, Projects, and Versions
SQLite via SQLAlchemy is the system of record for users, projects, generated artifacts, and versioned edited content. Database setup and startup-oriented schema evolution live in `dreamweaver-backend/app/database/db.py`; relational entities live in `dreamweaver-backend/app/database/models.py`; request/response contracts live in `dreamweaver-backend/app/models/schemas.py`. Project APIs allow listing and loading saved work, while frontend project/version UX is concentrated in `dreamweaver-frontend/src/pages/ProjectsPage.tsx` and `dreamweaver-frontend/src/components/modals/VersionHistoryModal.tsx`.

#### Media and External-Service Boundary
Generated images/videos and user avatars are managed by `dreamweaver-backend/app/services/file_service.py` and exposed as static media from the backend’s `media/` area. The backend is containerizable through `dreamweaver-backend/Dockerfile`, while its primary development deployment is Uvicorn with SQLite. External dependencies are DeepSeek (text) and MiniMax (image/video); their asynchronous or remote-generation behavior is isolated behind backend generation endpoints rather than accessed directly by the browser.

Main entry points: [`dreamweaver-backend/app/main.py`](https://github.com/paul-19658/ai_video/blob/master/dreamweaver-backend/app/main.py) (FastAPI application), [`dreamweaver-frontend/src/App.tsx`](https://github.com/paul-19658/ai_video/blob/master/dreamweaver-frontend/src/App.tsx) (Application shell), [`dreamweaver-backend/app/routers/generation.py`](https://github.com/paul-19658/ai_video/blob/master/dreamweaver-backend/app/routers/generation.py) (Generation routes), [`dreamweaver-frontend/src/services/api.ts`](https://github.com/paul-19658/ai_video/blob/master/dreamweaver-frontend/src/services/api.ts) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React SPA"]
  node_spa_entry["SPA entry<br/>Vite entry<br/>[main.tsx]"]
  node_app_shell["Application shell<br/>React composition<br/>[App.tsx]"]
  node_generation_state["Generation state<br/>React context"]
  node_auth_state["Auth session<br/>React context<br/>[AuthContext.tsx]"]
  node_generation_steps["Generation steps<br/>React step UI<br/>[InputStep.tsx]"]
  node_projects_ui["Projects and versions<br/>React project UI<br/>[ProjectsPage.tsx]"]
  node_api_client["API client<br/>frontend service<br/>[api.ts]"]
end

subgraph group_backend["FastAPI backend"]
  node_fastapi_app["FastAPI application<br/>service entry<br/>[main.py]"]
  node_auth_routes["Identity routes<br/>FastAPI router<br/>[auth.py]"]
  node_project_routes["Project routes<br/>FastAPI router<br/>[projects.py]"]
  node_generation_routes["Generation routes<br/>FastAPI router<br/>[generation.py]"]
  node_llm_service["AI orchestration<br/>backend service<br/>[llm_service.py]"]
  node_media_service["Media service<br/>backend service<br/>[file_service.py]"]
  node_database_layer[("SQLAlchemy database<br/>persistence layer<br/>[db.py]")]
  node_entities["Relational entities<br/>SQLAlchemy models<br/>[models.py]"]
  node_api_contracts["API contracts<br/>schemas<br/>[schemas.py]"]
  node_static_media[("Static media<br/>backend media area")]
end

subgraph group_external["External services"]
  node_deepseek{{"DeepSeek<br/>text AI provider"}}
  node_minimax{{"MiniMax<br/>media AI provider"}}
end

node_spa_entry -->|"mounts"| node_app_shell
node_app_shell -->|"provides"| node_generation_state
node_app_shell -->|"provides"| node_auth_state
node_generation_state -->|"drives"| node_generation_steps
node_app_shell -->|"renders"| node_projects_ui
node_generation_steps -->|"requests stages"| node_api_client
node_projects_ui -->|"loads and saves"| node_api_client
node_auth_state -->|"supplies Bearer token"| node_api_client
node_api_client -->|"proxied HTTP"| node_fastapi_app
node_fastapi_app -->|"routes"| node_auth_routes
node_fastapi_app -->|"routes"| node_project_routes
node_fastapi_app -->|"routes"| node_generation_routes
node_auth_routes -->|"accounts"| node_database_layer
node_project_routes -->|"projects and versions"| node_database_layer
node_generation_routes -->|"delegates AI work"| node_llm_service
node_generation_routes -->|"persists artifacts"| node_database_layer
node_generation_routes -->|"stores outputs"| node_media_service
node_llm_service -->|"text generation"| node_deepseek
node_llm_service -->|"image and video generation"| node_minimax
node_media_service -->|"writes and serves"| node_static_media
node_database_layer -->|"maps"| node_entities
node_fastapi_app -.->|"validates payloads"| node_api_contracts

click node_spa_entry "https://github.com/paul-19658/ai_video/blob/master/dreamweaver-frontend/src/main.tsx"
click node_app_shell "https://github.com/paul-19658/ai_video/blob/master/dreamweaver-frontend/src/App.tsx"
click node_generation_state "https://github.com/paul-19658/ai_video/blob/master/dreamweaver-frontend/src/contexts/GenerationContext.tsx"
click node_auth_state "https://github.com/paul-19658/ai_video/blob/master/dreamweaver-frontend/src/contexts/AuthContext.tsx"
click node_generation_steps "https://github.com/paul-19658/ai_video/blob/master/dreamweaver-frontend/src/components/steps/InputStep.tsx"
click node_projects_ui "https://github.com/paul-19658/ai_video/blob/master/dreamweaver-frontend/src/pages/ProjectsPage.tsx"
click node_api_client "https://github.com/paul-19658/ai_video/blob/master/dreamweaver-frontend/src/services/api.ts"
click node_fastapi_app "https://github.com/paul-19658/ai_video/blob/master/dreamweaver-backend/app/main.py"
click node_auth_routes "https://github.com/paul-19658/ai_video/blob/master/dreamweaver-backend/app/routers/auth.py"
click node_project_routes "https://github.com/paul-19658/ai_video/blob/master/dreamweaver-backend/app/routers/projects.py"
click node_generation_routes "https://github.com/paul-19658/ai_video/blob/master/dreamweaver-backend/app/routers/generation.py"
click node_llm_service "https://github.com/paul-19658/ai_video/blob/master/dreamweaver-backend/app/services/llm_service.py"
click node_media_service "https://github.com/paul-19658/ai_video/blob/master/dreamweaver-backend/app/services/file_service.py"
click node_database_layer "https://github.com/paul-19658/ai_video/blob/master/dreamweaver-backend/app/database/db.py"
click node_entities "https://github.com/paul-19658/ai_video/blob/master/dreamweaver-backend/app/database/models.py"
click node_api_contracts "https://github.com/paul-19658/ai_video/blob/master/dreamweaver-backend/app/models/schemas.py"

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_spa_entry,node_app_shell,node_generation_state,node_auth_state,node_generation_steps,node_projects_ui,node_api_client toneBlue
class node_fastapi_app,node_auth_routes,node_project_routes,node_generation_routes,node_llm_service,node_media_service,node_database_layer,node_entities,node_api_contracts,node_static_media toneAmber
class node_deepseek,node_minimax toneMint
```

## Components

### React SPA

- [SPA entry](https://github.com/paul-19658/ai_video/blob/master/dreamweaver-frontend/src/main.tsx): Vite entry · `dreamweaver-frontend/src/main.tsx`
- [Application shell](https://github.com/paul-19658/ai_video/blob/master/dreamweaver-frontend/src/App.tsx): React composition · `dreamweaver-frontend/src/App.tsx`
- [Generation state](https://github.com/paul-19658/ai_video/blob/master/dreamweaver-frontend/src/contexts/GenerationContext.tsx): React context · Coordinates the staged creation workflow. · `dreamweaver-frontend/src/contexts/GenerationContext.tsx`
- [Auth session](https://github.com/paul-19658/ai_video/blob/master/dreamweaver-frontend/src/contexts/AuthContext.tsx): React context · `dreamweaver-frontend/src/contexts/AuthContext.tsx`
- [Generation steps](https://github.com/paul-19658/ai_video/blob/master/dreamweaver-frontend/src/components/steps/InputStep.tsx): React step UI · Topic, outline, story, keyframes, and video views. · `dreamweaver-frontend/src/components/steps/InputStep.tsx`
- [Projects and versions](https://github.com/paul-19658/ai_video/blob/master/dreamweaver-frontend/src/pages/ProjectsPage.tsx): React project UI · Saved-project and version-history experience. · `dreamweaver-frontend/src/pages/ProjectsPage.tsx`
- [API client](https://github.com/paul-19658/ai_video/blob/master/dreamweaver-frontend/src/services/api.ts): frontend service · Uses the Vite /dreamweaver-api proxy. · `dreamweaver-frontend/src/services/api.ts`

### FastAPI backend

- [FastAPI application](https://github.com/paul-19658/ai_video/blob/master/dreamweaver-backend/app/main.py): service entry · `dreamweaver-backend/app/main.py`
- [Identity routes](https://github.com/paul-19658/ai_video/blob/master/dreamweaver-backend/app/routers/auth.py): FastAPI router · Bearer-token authentication and account flows. · `dreamweaver-backend/app/routers/auth.py`
- [Project routes](https://github.com/paul-19658/ai_video/blob/master/dreamweaver-backend/app/routers/projects.py): FastAPI router · Loads and persists project work. · `dreamweaver-backend/app/routers/projects.py`
- [Generation routes](https://github.com/paul-19658/ai_video/blob/master/dreamweaver-backend/app/routers/generation.py): FastAPI router · Exposes ordered topic-to-video stages. · `dreamweaver-backend/app/routers/generation.py`
- [AI orchestration](https://github.com/paul-19658/ai_video/blob/master/dreamweaver-backend/app/services/llm_service.py): backend service · Dispatches text, image, and video model work. · `dreamweaver-backend/app/services/llm_service.py`
- [Media service](https://github.com/paul-19658/ai_video/blob/master/dreamweaver-backend/app/services/file_service.py): backend service · Manages generated media and avatars. · `dreamweaver-backend/app/services/file_service.py`
- [SQLAlchemy database](https://github.com/paul-19658/ai_video/blob/master/dreamweaver-backend/app/database/db.py): persistence layer · SQLite system of record with startup schema evolution. · `dreamweaver-backend/app/database/db.py`
- [Relational entities](https://github.com/paul-19658/ai_video/blob/master/dreamweaver-backend/app/database/models.py): SQLAlchemy models · Users, projects, artifacts, and versions. · `dreamweaver-backend/app/database/models.py`
- [API contracts](https://github.com/paul-19658/ai_video/blob/master/dreamweaver-backend/app/models/schemas.py): schemas · `dreamweaver-backend/app/models/schemas.py`
- **Static media**: backend media area · Generated files and avatars are served by the application.

### External services

- **DeepSeek**: text AI provider · Generates outlines, stories, and keyframe descriptions.
- **MiniMax**: media AI provider · Generates images and videos.

## Connections

- SPA entry → Application shell: mounts
- Application shell → Generation state: provides
- Application shell → Auth session: provides
- Generation state → Generation steps: drives
- Application shell → Projects and versions: renders
- Generation steps → API client: requests stages
- Projects and versions → API client: loads and saves
- Auth session → API client: supplies Bearer token
- API client → FastAPI application: proxied HTTP
- FastAPI application → Identity routes: routes
- FastAPI application → Project routes: routes
- FastAPI application → Generation routes: routes
- Identity routes → SQLAlchemy database: accounts
- Project routes → SQLAlchemy database: projects and versions
- Generation routes → AI orchestration: delegates AI work
- Generation routes → SQLAlchemy database: persists artifacts
- Generation routes → Media service: stores outputs
- AI orchestration → DeepSeek: text generation
- AI orchestration → MiniMax: image and video generation
- Media service → Static media: writes and serves
- SQLAlchemy database → Relational entities: maps
- FastAPI application → API contracts: validates payloads
