Project data and storage
Project data is durable editing state that lives in a user-selected workspace folder. The system keeps project JSON and media records in that folder, uses a small IndexedDB database only for browser file handles, stores derived media data as replaceable caches, and upgrades older project or workspace formats when they are read.
Storage boundary
Workspace selection
The workspace is the user-selected folder that provides the durable storage boundary for project work. The application protects project and editor routes until it has a folder handle with read/write permission, then prepares the folder before storage reads begin. See the project lifecycle page for the wider project flow.
The browser keeps enough handle data to find the selected folder again after a reload. A lost permission moves the application back to a reconnect state instead of allowing storage calls to fail without a clear user action.
References: src/…/workspace-gate.tsx• L4-20 src/…/workspace-gate.tsx• L62-80 src/…/root.ts• L17-60
IndexedDB role
IndexedDB is not the main project database. The remaining handle database stores browser-only FileSystemDirectoryHandle and FileSystemFileHandle values because these handles cannot be written into project JSON or ordinary workspace files. The old project database is read only during the explicit legacy migration flow.
Workspace and media handles use stable records so the application can restore access to the same folder or source file. The handle database has a fixed schema; future changes use a separate database rather than changing this one in place.
References: src/…/handles-db.ts• L1-14 src/…/handles-db.ts• L21-45 src/…/reader.ts• L1-17
Project state
Project record
The project record is the durable description of an edit. It combines identity and display data with output settings and an optional timeline. The timeline holds tracks, items, markers, transitions, nested compositions, keyframes, and view or playback state needed to reopen the edit.
Each project has a schema version. A missing version means the oldest supported project format, while the current format is version 15. Project data can therefore travel through a sequence of format changes without requiring every caller to understand every historical shape.
References: src/…/project.ts• L22-49 src/…/project.ts• L51-78 src/…/project.ts• L237-283 src/…/types.ts• L9-19
Project persistence
Project JSON is the source of truth for project state in the workspace. A small workspace index contains only the fields needed to show a project list, so the application can find projects quickly while still reading the full record when a project opens.
Project writes use replacement-safe file writes. The index can be rebuilt from project folders when it is absent, empty, or damaged, so a bad derived index does not hide healthy project records.
References: src/…/projects.ts• L36-45 src/…/projects.ts• L88-112 src/…/projects.ts• L176-205 src/…/workspace-index.ts• L1-7
Project state coordination
The project state store connects project screens to workspace persistence. It keeps the visible project list and the open project responsive during create, update, delete, and restore actions, then reconciles that state with the result from storage. A failed action restores the prior in-memory state when no durable data was changed.
Deletion has separate reversible and permanent stages. A normal delete moves the project to workspace trash while keeping its media links available for restore. Permanent deletion then removes the project data and asks media cleanup to remove only media that no longer has another project. If the user also removes the project’s local folder, permission is checked first; a failure after files were touched is reported as an inconsistency instead of being hidden by a UI rollback.
The store also guards the delete boundary against stale list loads. A reload that finishes while soft-delete is pending cannot reinsert the deleted project into the visible list.
References: src/…/project-store.ts• L104-231 src/…/project-store.ts• L233-388 src/…/project-store.test.ts• L65-91
Media relationships
Media records and project state are separate so one media asset can serve more than one project. A project keeps explicit media links, while the loader also finds media IDs referenced by timeline items and repairs missing links or removes links to media that no longer exists.
This relationship protects cleanup and restore behavior. Trashed projects keep their links so their media remains available until the project is permanently removed. Permanent removal checks those links before cleaning up media, so media shared with another project remains available.
References: src/…/project-media.ts• L1-14 src/…/project-media.ts• L97-112 src/…/project-media.ts• L212-218 src/…/trash.ts• L213-231 src/…/project-store.ts• L362-387
Workspace file system
Workspace layout
The workspace folder makes the durable data visible outside the browser and lets different origins use the same physical folder. Project records live below projects/, media metadata and source files live below media/, and shared or derived data has its own area below content/ or each media folder.
The layout also separates authoritative data from data that can be rebuilt. Project folders and media metadata are primary records. Thumbnails, waveforms, filmstrips, decoded audio, proxies, and analysis results are derived data with defined paths and cache behavior. See project bundle workflows for data exchange rather than in-place workspace storage.
References: src/…/paths.ts• L10-44 src/…/paths.ts• L55-75 src/…/paths.ts• L245-327
Source file access
Media can use a source file in the workspace, a direct file handle, or an older origin-private copy. Workspace copies are durable and usable by another origin that selects the same folder. Direct handles avoid a copy but remain tied to browser permission and the original file.
The system records enough source information to detect a missing, inaccessible, or changed direct file. When older source files use the prior filename pattern, reads still find them so an existing workspace can keep working.
References: src/…/storage.ts• L1-16 src/…/storage.ts• L38-56 src/…/media.ts• L60-81 src/…/media-source.ts• L1-15
Safe file operations
The file layer gives all storage services one contract for JSON, binary data, missing files, corrupt JSON, and lost permission. It uses replacement-safe writes for important JSON so a crash does not leave a half-written project or index.
Read failures have different meanings. A missing file can be a normal cache miss, corrupt JSON is a damaged record, and a permission error tells the workspace gate to ask the user to reconnect the folder.
References: src/…/fs-primitives.ts• L1-15 src/…/fs-primitives.ts• L24-55 src/…/fs-primitives.ts• L141-159
Cache lifecycle
Derived data
Derived media data exists to speed editing and playback without changing the project’s meaning. The system keeps local fast copies where useful and mirrors selected caches into the workspace so another origin can reuse work such as proxies, filmstrips, and conformed preview audio.
Cache reads can fall back from origin-private storage to the workspace copy. A successful workspace read may refill the local copy, while a cache write remains non-critical when no workspace is active.
References: src/…/cache-mirror.ts• L1-18 src/…/cache-mirror.ts• L28-43 src/…/cache-mirror.ts• L78-108
Cache versions
Each cache type has an independent version stored in local browser settings. A format change makes the old version stale, so the cache owner can clear or rebuild that derived data before using it. Project data does not use this cache version mechanism; project format changes use project schema migrations instead.
The current version list covers filmstrips, waveforms, thumbnails, and media caches. The version is marked complete only after the cache owner finishes its invalidation work.
References: src/…/cache-version.ts• L1-13 src/…/cache-version.ts• L21-39 src/…/cache-version.ts• L41-63
Workspace layout migration
The workspace marker records the layout schema of the selected folder. On bootstrap, an older layout is moved to the current layout before normal readers use it. The migration keeps source data intact until each copy succeeds and leaves the old marker in place when errors require a later retry.
The current workspace layout is version 2.0. It groups per-media caches under each media record, places shared proxies under content/proxies/, and places project covers under the project that owns them.
References: src/…/bootstrap.ts• L173-217 src/…/migrate-workspace-v2.ts• L1-23 src/…/migrate-workspace-v2.ts• L97-164 src/…/paths.ts• L46-55
Compatibility
Project schema migration
When a project is loaded, version migrations run in order and then normalization applies current defaults. The result is a current project plus any non-fatal warnings found during repair. Callers can save the result so the next load does not repeat the upgrade work.
The migration rules are append-only. Older projects remain readable because the loader treats a missing version as version 1 and advances it to the current version.
References: src/…/index.ts• L1-17 src/…/index.ts• L32-48 src/…/index.ts• L50-88 src/…/index.ts• L92-121
Upgrade backups
An editor upgrade can first create a separate project backup. The backup keeps the old schema and the original media links, which gives the user a restorable copy if the upgraded project has an unexpected result.
The backup is independent of the current project. Its thumbnail is copied when available, while failure to copy that optional image does not remove the backup itself.
References: src/…/project-upgrade-service.ts• L18-29 src/…/project-upgrade-service.ts• L30-53 src/…/project-upgrade-service.ts• L75-100
Legacy IndexedDB migration
Users with data in the former video-editor-db can move that data into the selected workspace. The migration reads legacy records without changing them, writes projects and media through the current workspace services, records progress and per-item errors, and marks completion only after a clean run.
The old database stays available after migration. Deletion is a separate user-confirmed action, which preserves a recovery path when a migration has partial errors or when another tab still has the old database open.
The main compatibility flow is:
flowchart LR
A[Legacy IndexedDB] --> B[Read legacy records]
B --> C[Write workspace projects and media]
C --> D[Write links and derived data]
D --> E{Errors?}
E -- Yes --> F[Keep error marker and allow retry]
E -- No --> G[Mark migration complete]
G --> H[Optional user-confirmed deletion]
References: src/…/reader.ts• L1-17 src/…/migrate.ts• L120-160 src/…/migrate.ts• L397-474 src/…/migrate.ts• L500-505
Change checklist
When these files or sections are changed, remember to consider these:
- When the project shape changes, add a new ordered migration and keep the current schema version aligned with the loader and project creation defaults.
- When a workspace path or layout changes, update the marker migration and all readers that must still find the prior path.
- When a cache format changes, bump only that cache’s version and confirm that workspace mirrors are invalidated or rebuilt with the same meaning.
- When a handle-backed field changes, keep its JSON record separate from the handle database and preserve permission or relink behavior on reload.
- When media association rules change, check timeline references, explicit link files, trash restore, and permanent cleanup as one contract.
- When project deletion or restore changes, keep the visible project list, trash marker, media links, and permanent cleanup in step. Also ensure stale list loads cannot reinsert a project after soft-delete.
- When local project-folder cleanup changes, preserve the permission check and distinguish a failed cleanup from a failure that touched files before the trash move.
- When legacy migration changes, keep retry behavior safe and do not delete the legacy database as part of a normal migration run.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| No workspace permission on a protected route | Project data cannot load or save | Workspace gate checks or requests permission and shows reconnect state |
| Corrupt or missing index.json | Project list can be incomplete | Project storage rebuilds the index from project folders |
| Corrupt project.json | That project is skipped during a list load | Storage reports the corrupt record instead of treating it as valid state |
| Direct source file is moved, deleted, or changed | Clips can no longer match their stored derived data | Media handle validation returns missing or changed status for relink or rebuild |
| Cache format version is stale | Old derived data can render incorrectly or waste work | Cache owners compare their stored version and invalidate before use |
| Workspace migration has a copy or write error | Old and new layout data may coexist | The marker stays old so bootstrap can retry the migration |
| Project-folder permission is denied when the user requests local cleanup | The project is not deleted | The project store requests permission before changing project state and stops if access is not granted |
| Local cleanup touches files but soft-delete fails | The project and its folder can be inconsistent | The project store reports the partial or complete file deletion instead of restoring a misleading UI state |
| A stale project reload completes during soft-delete | A deleted project could reappear in the visible list | The delete completion filters the project from the latest state before returning |
| Legacy migration has per-record errors | Some data is present while migration is not complete | Error records remain in the workspace and the legacy database stays intact |
Key files
| File | Why to read it |
|---|---|
| src/…/workspace-gate.tsx | Shows when a workspace is required and how folder permission controls access to project routes |
| src/…/handles-db.ts | Defines the narrow IndexedDB role for workspace, media, and project-folder handles |
| src/…/paths.ts | Gives the high-level workspace layout and its schema versions |
| src/…/projects.ts | Shows the project record and index persistence boundary |
| src/…/project-media.ts | Explains project-to-media links and repair of drift |
| src/…/project-store.ts | Coordinates visible project state with workspace CRUD, trash, restore, and permanent cleanup |
| src/…/project-store.test.ts | Shows the contract that stale project loads cannot undo a completed soft-delete |
| src/…/cache-mirror.ts | Shows how derived data crosses from origin-private storage into the workspace |
| src/…/cache-version.ts | Defines independent cache invalidation versions |
| src/…/migrate-workspace-v2.ts | Shows compatibility between old and current workspace layouts |
| src/…/index.ts | Defines the project schema upgrade and normalization boundary |
| src/…/migrate.ts | Shows the one-time path from legacy IndexedDB into workspace storage |