# akhil373/freecut architecture

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

- Interactive diagram: https://gitdiagram.com/akhil373/freecut
- Repository: https://github.com/akhil373/freecut

## Overview

#### Purpose and Entry Points
FreeCut is a local-first, browser-based multitrack video editor. The React application boots through `src/main.tsx`, initializes app concerns in `src/bootstrap.ts`, and renders the routed shell from `src/app.tsx`. TanStack Router routes users through workspace selection, projects, editor, docs, and changelog; the primary editing route is `src/routes/editor/$projectId.tsx` with lazy editor loading in `src/routes/editor/$projectId.lazy.tsx`.

A separate Node/headless automation surface exists under `headless/`, centered on `headless/server.mjs` and `headless/agent.mjs`; browser-facing headless support is in `src/headless/main.ts`.

#### Workspace, Projects, and Persistence
The chosen local workspace folder is the system of record. Storage is implemented as plain workspace files behind File System Access API/OPFS adapters, not a remote backend. `src/infrastructure/storage/workspace-fs/bootstrap.ts` establishes workspace storage; `src/infrastructure/storage/workspace-fs/projects.ts` manages project files; `src/infrastructure/storage/workspace-fs/media.ts` manages local media records.

Project UI/state sits in `src/features/projects/stores/project-store.ts`; schema/version migration is isolated in `src/shared/projects/migrations/migrations.ts`. Project bundles cross an explicit import/export boundary via `src/features/project-bundle/schemas/project-schema.ts` and bundle services.

#### Editorial Data Model and Timeline
The timeline is the authoritative editable composition model: sequences, tracks, items, transitions, markers, keyframes, and media dependencies. Core stores include `src/features/timeline/stores/timeline-store.ts`, `src/features/timeline/stores/items-store.ts`, and `src/features/timeline/stores/sequences-store.ts`. Mutation logic is separated into action modules such as `src/features/timeline/stores/actions/item-actions.ts` and `src/features/timeline/stores/actions/edit/trim-actions.ts`, supporting undoable editing workflows.

`src/features/timeline/components/timeline.tsx` presents this model. Media drops and editing gestures flow from UI/hooks into timeline actions, updating persistent project state; preview and export consume snapshots rather than owning editorial state.

#### Playback, Composition Runtime, and Preview
The runtime translates a timeline/composition frame into positioned media, text, shapes, masks, effects, transitions, and audio. `src/runtime/player/Player.tsx` and `src/runtime/player/clock/Clock.ts` provide frame-accurate playback coordination. `src/runtime/composition-runtime/components/composition-content.tsx` assembles item rendering, while `src/runtime/composition-runtime/utils/scene-assembly.ts` builds frame scene state.

The preview feature hosts this runtime and editing overlays: `src/features/preview/components/preview-stage.tsx`, `src/features/preview/hooks/use-preview-renderer-controller.ts`, and `src/features/preview/stores/playback-store.ts`. Interactive gizmos commit transforms back through timeline state, maintaining a boundary between transient preview interaction and persisted edits.

#### Media Ingestion and Background Processing
The media library imports and links local files, then coordinates metadata extraction, thumbnails, waveforms, proxies, subtitle scanning, transcription, interpolation, and upscale jobs. Its central service is `src/features/media-library/services/media-library-service.ts`; background task orchestration is `src/features/media-library/services/background-media-work.ts`; worker-backed processing includes `src/features/media-library/workers/media-processor.worker.ts`.

Media resolution/storage bridges browser file handles and OPFS caches through `src/infrastructure/browser/opfs-file-access.ts` and workspace media storage. This layer feeds timeline placement, preview decoders, and export sources.

#### GPU, Local AI, and Animation
Platform-intensive capabilities are infrastructure rather than feature-owned logic. WebGPU compositing is centered on `src/infrastructure/gpu-compositor/compositor-pipeline.ts`; GPU effects and transitions are registered through `src/infrastructure/gpu-effects/registry.ts` and `src/infrastructure/gpu-transitions/registry.ts`.

Keyframes evaluate through feature utilities such as `src/features/keyframes/utils/interpolation.ts` and are edited in `src/features/keyframes/components/dopesheet-editor/index.tsx`. Local analysis/ML runs in workers: scene detection at `src/infrastructure/analysis/scene-detection.ts`, embeddings at `src/infrastructure/analysis/embeddings/embeddings-worker.ts`, and transcription workers under `src/features/media-library/transcription/workers/`.

#### Export and Render Queue
Export converts a timeline snapshot into a render job, selects viable browser render paths, composites frames, encodes/remuxes media, and writes output locally. Job construction begins in `src/features/export/utils/build-render-job.ts`; the client render engine is `src/features/export/utils/client-render-engine.ts`; heavy work moves to `src/features/export/workers/export-render.worker.ts`.

`src/features/export/components/render-queue-runner.tsx` executes persisted queue entries. Export depends on WebCodecs, GPU/Canvas paths, browser codec availability, and local workspace output; it has no server-side rendering service.

#### Architectural Boundaries and Runtime Requirements
Feature modules communicate across feature boundaries through local `deps/*` contract adapters—for example `src/features/export/deps/timeline-contract.ts` and `src/features/preview/deps/player-contract.ts`—rather than broad direct imports. Shared types in `src/types/` and framework-neutral primitives in `src/shared/` support those contracts.

The production runtime is a modern Chromium browser requiring WebGPU, WebCodecs, Web Workers, AudioWorklets, OPFS, and File System Access API. External network services are optional/content-oriented (for example `src/features/lottie-browser/services/lottiefiles-api.ts`); editing, storage, AI inference, preview, and export are designed to remain on-device.

Main entry points: [`src/features/projects/stores/project-store.ts`](https://github.com/akhil373/freecut/blob/main/src/features/projects/stores/project-store.ts) (Project state), [`src/features/timeline/stores/timeline-store.ts`](https://github.com/akhil373/freecut/blob/main/src/features/timeline/stores/timeline-store.ts) (Timeline composition), [`src/features/timeline/stores/actions/item-actions.ts`](https://github.com/akhil373/freecut/blob/main/src/features/timeline/stores/actions/item-actions.ts) (Timeline actions), [`src/features/media-library/services/media-library-service.ts`](https://github.com/akhil373/freecut/blob/main/src/features/media-library/services/media-library-service.ts) (Media library)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application"]
  node_entry["Browser entry<br/>React bootstrap<br/>[main.tsx]"]
  node_bootstrap["App initialization<br/>app bootstrap<br/>[bootstrap.ts]"]
  node_shell["Routed app shell<br/>TanStack Router<br/>[app.tsx]"]
  node_editor_route["Editor route<br/>lazy route"]
  node_headless{{"Headless automation<br/>Node automation<br/>[server.mjs]"}}
end

subgraph group_editorial["Editorial state"]
  node_project_state["Project state<br/>feature store<br/>[project-store.ts]"]
  node_project_bundle["Project bundle boundary<br/>import/export schema<br/>[project-schema.ts]"]
  node_timeline[("Timeline composition<br/>authoritative store<br/>[timeline-store.ts]")]
  node_timeline_actions["Timeline actions<br/>undoable mutations<br/>[item-actions.ts]"]
  node_timeline_ui["Timeline editor<br/>React component<br/>[timeline.tsx]"]
end

subgraph group_media["Media pipeline"]
  node_media_library["Media library<br/>ingestion service"]
  node_media_work["Background media work<br/>job orchestrator"]
  node_media_worker["Media processor<br/>Web Worker"]
end

subgraph group_runtime["Preview and rendering"]
  node_preview["Preview stage<br/>editor preview<br/>[preview-stage.tsx]"]
  node_player["Frame player<br/>playback runtime<br/>[Player.tsx]"]
  node_composition["Composition runtime<br/>scene renderer"]
  node_export_queue["Render queue<br/>persisted job runner"]
  node_render_job["Render job builder<br/>timeline snapshot export"]
  node_export_worker["Export renderer<br/>Web Worker"]
end

subgraph group_local["Local platform"]
  node_workspace[("Workspace storage<br/>filesystem adapter<br/>[bootstrap.ts]")]
  node_projects_fs[("Project files<br/>workspace persistence<br/>[projects.ts]")]
  node_opfs["OPFS media access<br/>browser file bridge"]
  node_gpu["GPU compositor<br/>WebGPU pipeline"]
end

node_entry -->|"initializes"| node_bootstrap
node_bootstrap -->|"starts"| node_shell
node_shell -->|"routes to"| node_editor_route
node_editor_route -->|"opens project"| node_project_state
node_workspace -->|"establishes"| node_projects_fs
node_projects_fs -->|"persists"| node_project_state
node_project_state -->|"imports / exports"| node_project_bundle
node_project_state -->|"owns composition"| node_timeline
node_timeline_ui -->|"editing gestures"| node_timeline_actions
node_timeline_actions -->|"mutates"| node_timeline
node_media_library -->|"schedules processing"| node_media_work
node_media_work -->|"dispatches"| node_media_worker
node_media_library -->|"resolves local media"| node_opfs
node_opfs -->|"bridges files and cache"| node_workspace
node_media_library -->|"places media"| node_timeline_actions
node_timeline -.->|"composition snapshot"| node_preview
node_preview -->|"coordinates playback"| node_player
node_player -->|"renders frames"| node_composition
node_composition -->|"composites with"| node_gpu
node_timeline_actions -.->|"committed edits"| node_preview
node_timeline -.->|"snapshot"| node_render_job
node_render_job -->|"enqueues"| node_export_queue
node_export_queue -->|"executes"| node_export_worker
node_export_worker -->|"composites frames"| node_gpu
node_export_worker -->|"writes output"| node_workspace
node_headless -.->|"browser-facing control"| node_shell

click node_entry "https://github.com/akhil373/freecut/blob/main/src/main.tsx"
click node_bootstrap "https://github.com/akhil373/freecut/blob/main/src/bootstrap.ts"
click node_shell "https://github.com/akhil373/freecut/blob/main/src/app.tsx"
click node_editor_route "https://github.com/akhil373/freecut/blob/main/src/routes/editor/%24projectId.lazy.tsx"
click node_headless "https://github.com/akhil373/freecut/blob/main/headless/server.mjs"
click node_workspace "https://github.com/akhil373/freecut/blob/main/src/infrastructure/storage/workspace-fs/bootstrap.ts"
click node_projects_fs "https://github.com/akhil373/freecut/blob/main/src/infrastructure/storage/workspace-fs/projects.ts"
click node_project_state "https://github.com/akhil373/freecut/blob/main/src/features/projects/stores/project-store.ts"
click node_project_bundle "https://github.com/akhil373/freecut/blob/main/src/features/project-bundle/schemas/project-schema.ts"
click node_timeline "https://github.com/akhil373/freecut/blob/main/src/features/timeline/stores/timeline-store.ts"
click node_timeline_actions "https://github.com/akhil373/freecut/blob/main/src/features/timeline/stores/actions/item-actions.ts"
click node_timeline_ui "https://github.com/akhil373/freecut/blob/main/src/features/timeline/components/timeline.tsx"
click node_media_library "https://github.com/akhil373/freecut/blob/main/src/features/media-library/services/media-library-service.ts"
click node_media_work "https://github.com/akhil373/freecut/blob/main/src/features/media-library/services/background-media-work.ts"
click node_media_worker "https://github.com/akhil373/freecut/blob/main/src/features/media-library/workers/media-processor.worker.ts"
click node_opfs "https://github.com/akhil373/freecut/blob/main/src/infrastructure/browser/opfs-file-access.ts"
click node_preview "https://github.com/akhil373/freecut/blob/main/src/features/preview/components/preview-stage.tsx"
click node_player "https://github.com/akhil373/freecut/blob/main/src/runtime/player/Player.tsx"
click node_composition "https://github.com/akhil373/freecut/blob/main/src/runtime/composition-runtime/components/composition-content.tsx"
click node_gpu "https://github.com/akhil373/freecut/blob/main/src/infrastructure/gpu-compositor/compositor-pipeline.ts"
click node_export_queue "https://github.com/akhil373/freecut/blob/main/src/features/export/components/render-queue-runner.tsx"
click node_render_job "https://github.com/akhil373/freecut/blob/main/src/features/export/utils/build-render-job.ts"
click node_export_worker "https://github.com/akhil373/freecut/blob/main/src/features/export/workers/export-render.worker.ts"

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_entry,node_bootstrap,node_shell,node_editor_route,node_headless toneBlue
class node_project_state,node_project_bundle,node_timeline,node_timeline_actions,node_timeline_ui toneAmber
class node_media_library,node_media_work,node_media_worker toneMint
class node_preview,node_player,node_composition,node_export_queue,node_render_job,node_export_worker toneRose
class node_workspace,node_projects_fs,node_opfs,node_gpu toneIndigo
```

## Components

### Application

- [Browser entry](https://github.com/akhil373/freecut/blob/main/src/main.tsx): React bootstrap · `src/main.tsx`
- [App initialization](https://github.com/akhil373/freecut/blob/main/src/bootstrap.ts): app bootstrap · `src/bootstrap.ts`
- [Routed app shell](https://github.com/akhil373/freecut/blob/main/src/app.tsx): TanStack Router · `src/app.tsx`
- [Editor route](https://github.com/akhil373/freecut/blob/main/src/routes/editor/%24projectId.lazy.tsx): lazy route · `src/routes/editor/$projectId.lazy.tsx`
- [Headless automation](https://github.com/akhil373/freecut/blob/main/headless/server.mjs): Node automation · Separate Node/headless control surface. · `headless/server.mjs`

### Editorial state

- [Project state](https://github.com/akhil373/freecut/blob/main/src/features/projects/stores/project-store.ts): feature store · `src/features/projects/stores/project-store.ts`
- [Project bundle boundary](https://github.com/akhil373/freecut/blob/main/src/features/project-bundle/schemas/project-schema.ts): import/export schema · `src/features/project-bundle/schemas/project-schema.ts`
- [Timeline composition](https://github.com/akhil373/freecut/blob/main/src/features/timeline/stores/timeline-store.ts): authoritative store · Sequences, tracks, items, transitions, markers, and keyframes. · `src/features/timeline/stores/timeline-store.ts`
- [Timeline actions](https://github.com/akhil373/freecut/blob/main/src/features/timeline/stores/actions/item-actions.ts): undoable mutations · `src/features/timeline/stores/actions/item-actions.ts`
- [Timeline editor](https://github.com/akhil373/freecut/blob/main/src/features/timeline/components/timeline.tsx): React component · `src/features/timeline/components/timeline.tsx`

### Media pipeline

- [Media library](https://github.com/akhil373/freecut/blob/main/src/features/media-library/services/media-library-service.ts): ingestion service · `src/features/media-library/services/media-library-service.ts`
- [Background media work](https://github.com/akhil373/freecut/blob/main/src/features/media-library/services/background-media-work.ts): job orchestrator · Coordinates metadata, proxies, thumbnails, waveforms, and AI jobs. · `src/features/media-library/services/background-media-work.ts`
- [Media processor](https://github.com/akhil373/freecut/blob/main/src/features/media-library/workers/media-processor.worker.ts): Web Worker · `src/features/media-library/workers/media-processor.worker.ts`

### Preview and rendering

- [Preview stage](https://github.com/akhil373/freecut/blob/main/src/features/preview/components/preview-stage.tsx): editor preview · Hosts runtime and transient editing overlays. · `src/features/preview/components/preview-stage.tsx`
- [Frame player](https://github.com/akhil373/freecut/blob/main/src/runtime/player/Player.tsx): playback runtime · `src/runtime/player/Player.tsx`
- [Composition runtime](https://github.com/akhil373/freecut/blob/main/src/runtime/composition-runtime/components/composition-content.tsx): scene renderer · `src/runtime/composition-runtime/components/composition-content.tsx`
- [Render queue](https://github.com/akhil373/freecut/blob/main/src/features/export/components/render-queue-runner.tsx): persisted job runner · `src/features/export/components/render-queue-runner.tsx`
- [Render job builder](https://github.com/akhil373/freecut/blob/main/src/features/export/utils/build-render-job.ts): timeline snapshot export · `src/features/export/utils/build-render-job.ts`
- [Export renderer](https://github.com/akhil373/freecut/blob/main/src/features/export/workers/export-render.worker.ts): Web Worker · Composites, encodes, and writes output locally. · `src/features/export/workers/export-render.worker.ts`

### Local platform

- [Workspace storage](https://github.com/akhil373/freecut/blob/main/src/infrastructure/storage/workspace-fs/bootstrap.ts): filesystem adapter · Local workspace is the system of record. · `src/infrastructure/storage/workspace-fs/bootstrap.ts`
- [Project files](https://github.com/akhil373/freecut/blob/main/src/infrastructure/storage/workspace-fs/projects.ts): workspace persistence · `src/infrastructure/storage/workspace-fs/projects.ts`
- [OPFS media access](https://github.com/akhil373/freecut/blob/main/src/infrastructure/browser/opfs-file-access.ts): browser file bridge · `src/infrastructure/browser/opfs-file-access.ts`
- [GPU compositor](https://github.com/akhil373/freecut/blob/main/src/infrastructure/gpu-compositor/compositor-pipeline.ts): WebGPU pipeline · `src/infrastructure/gpu-compositor/compositor-pipeline.ts`

## Connections

- Browser entry → App initialization: initializes
- App initialization → Routed app shell: starts
- Routed app shell → Editor route: routes to
- Editor route → Project state: opens project
- Workspace storage → Project files: establishes
- Project files → Project state: persists
- Project state → Project bundle boundary: imports / exports
- Project state → Timeline composition: owns composition
- Timeline editor → Timeline actions: editing gestures
- Timeline actions → Timeline composition: mutates
- Media library → Background media work: schedules processing
- Background media work → Media processor: dispatches
- Media library → OPFS media access: resolves local media
- OPFS media access → Workspace storage: bridges files and cache
- Media library → Timeline actions: places media
- Timeline composition → Preview stage: composition snapshot
- Preview stage → Frame player: coordinates playback
- Frame player → Composition runtime: renders frames
- Composition runtime → GPU compositor: composites with
- Timeline actions → Preview stage: committed edits
- Timeline composition → Render job builder: snapshot
- Render job builder → Render queue: enqueues
- Render queue → Export renderer: executes
- Export renderer → GPU compositor: composites frames
- Export renderer → Workspace storage: writes output
- Headless automation → Routed app shell: browser-facing control
