# denk0403/videocrop architecture

> Architecture diagram of the GitHub repository denk0403/videocrop, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/denk0403/videocrop
- Repository: https://github.com/denk0403/videocrop

## Overview

##### Project type and purpose
- This is a single-page, browser-based, offline PWA (Progressive Web App) for video cropping.
- It uses ffmpeg.wasm to perform all video manipulation on the client, never uploading data to a server.
- Assets are hosted statically (e.g., Vercel CDN).

##### File structure
- Top-level: configuration files (.gitignore, .prettierrc, vercel.json), a scripts folder, README.
- public/: contains index.html, index.js, styles.css, area-selector.mjs, service-worker files (sw.js, sw-registrar.js).
- No backend or server code—pure frontend/PWA.

##### README for additional insights
- Confirms offline, client-only processing using ffmpeg.wasm.
- Mentions demo and usage but no server dependencies.

##### Main components
a. Static Hosting / CDN
- Serves index.html, scripts, styles, service-worker files.
b. Browser (Client)
- Network layer (fetches static assets)
- Service Worker
- Application Shell (UI)
- Video Input Module
- ffmpeg.wasm Engine (WebAssembly)
- Output/Download Module
c. Local Storage / Cache (optional)
- Service Worker Cache Storage for offline assets
d. External Services (minimal)
- cdn.vercel.app (for static asset hosting)

##### Relationships and data flow
- On first load: Browser → CDN: GET index.html, JS, CSS, sw.js
- Service Worker registration: index.js → sw-registrar.js → install sw.js
- sw.js intercepts fetch requests to cache assets and serve them offline
- User selects a video file (File API) → Video Input Module passes file to ffmpeg.wasm
- ffmpeg.wasm processes the in-memory video buffer and returns the cropped video blob
- Output Module presents download link or triggers a save dialog

##### Important architectural patterns and principles
- Offline-first / PWA: service worker caching, manifest-less but works offline
- Single-page Application (SPA) with module organization:
- area-selector.mjs for UI cropping rectangle
- index.js for orchestration, event handling, ffmpeg.wasm initialization
- WebAssembly integration: heavy processing offloaded to ffmpeg.wasm
- Static hosting: minimal server concerns, easier scaling and deployment

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Static Hosting / CDN"
        CDN["Vercel CDN (public/)"]:::network
    end

    subgraph "Browser (Client)"
        direction TB
        HTML["index.html"]:::ui
        CSS["styles.css"]:::ui
        JS["index.js"]:::ui
        Area["area-selector.mjs"]:::ui
        SWR["sw-registrar.js"]:::ui
        SW["sw.js"]:::cache
        CacheStorage["Cache Storage API"]:::cache
        VideoInput["Video Input Module\n(File API)"]:::ui
        FFMpeg["ffmpeg.wasm Engine"]:::processing
        Output["Output/Download Module"]:::ui
    end

    subgraph "Configuration"
        Vercel["vercel.json"]:::config
        Prettierrc[".prettierrc"]:::config
        PrettIgnore[".prettierignore"]:::config
        GitIgnore[".gitignore"]:::config
    end

    DOC["README.md"]:::doc

    CDN -->|"serve assets"| HTML
    CDN -->|"serve assets"| CSS
    CDN -->|"serve assets"| JS
    CDN -->|"serve assets"| Area
    CDN -->|"serve assets"| SWR

    HTML -->|"load app"| JS
    JS -->|"init SW registrar"| SWR
    SWR -->|"register SW"| SW
    SW -->|"cache assets"| CacheStorage
    CSS -->|"fetch (cached)"| SW
    HTML -->|"fetch (cached)"| SW
    JS -->|"fetch (cached)"| SW
    Area -->|"fetch (cached)"| SW

    HTML -->|"render UI"| VideoInput
    VideoInput -->|"file buffer"| FFMpeg
    FFMpeg -->|"cropped blob"| Output

    style CDN fill:#a2fca2,stroke:#333,stroke-width:1px
    style SW fill:#a2d4ff,stroke:#333,stroke-width:1px
    style CacheStorage fill:#a2d4ff,stroke:#333,stroke-width:1px
    style FFMpeg fill:#ffd380,stroke:#333,stroke-width:1px
    style HTML fill:#d3d3d3,stroke:#333,stroke-width:1px
    style CSS fill:#d3d3d3,stroke:#333,stroke-width:1px
    style JS fill:#d3d3d3,stroke:#333,stroke-width:1px
    style Area fill:#d3d3d3,stroke:#333,stroke-width:1px
    style SWR fill:#d3d3d3,stroke:#333,stroke-width:1px
    style VideoInput fill:#d3d3d3,stroke:#333,stroke-width:1px
    style Output fill:#d3d3d3,stroke:#333,stroke-width:1px

    style Vercel fill:#f0d4ff,stroke:#333,stroke-width:1px
    style Prettierrc fill:#f0d4ff,stroke:#333,stroke-width:1px
    style PrettIgnore fill:#f0d4ff,stroke:#333,stroke-width:1px
    style GitIgnore fill:#f0d4ff,stroke:#333,stroke-width:1px
    style DOC fill:#fff2a8,stroke:#333,stroke-width:1px

    click CDN "https://github.com/denk0403/videocrop/tree/master/public/"
    click SWR "https://github.com/denk0403/videocrop/blob/master/public/sw-registrar.js"
    click SW "https://github.com/denk0403/videocrop/blob/master/public/sw.js"
    click HTML "https://github.com/denk0403/videocrop/blob/master/public/index.html"
    click CSS "https://github.com/denk0403/videocrop/blob/master/public/styles.css"
    click JS "https://github.com/denk0403/videocrop/blob/master/public/index.js"
    click Area "https://github.com/denk0403/videocrop/blob/master/public/area-selector.mjs"
    click Vercel "https://github.com/denk0403/videocrop/blob/master/vercel.json"
    click Prettierrc "https://github.com/denk0403/videocrop/blob/master/.prettierrc"
    click PrettIgnore "https://github.com/denk0403/videocrop/blob/master/.prettierignore"
    click GitIgnore "https://github.com/denk0403/videocrop/blob/master/.gitignore"
    click DOC "https://github.com/denk0403/videocrop/blob/master/README.md"
```
