# j0suke/morphing-2d-demo architecture

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

- Interactive diagram: https://gitdiagram.com/j0suke/morphing-2d-demo
- Repository: https://github.com/j0suke/morphing-2d-demo

## Overview

##### Project type and purpose
- This is a single-page, front-end demo application showcasing a Canvas2D “morphing” animation effect.
- It uses Vite as a dev/build tool, TypeScript for scripting, a simple HTML entry point, CSS for styling, and static image assets in a `public` folder.
- There is no backend or database; it runs entirely in the browser.

##### File structure
- Top-level files:
- package.json & package-lock.json → dependencies and NPM scripts
- vite.config.ts & tsconfig.json → build/dev configuration
- index.html → HTML shell and entry point
- global.d.ts → global TypeScript declarations
- README.md & LICENSE → documentation and license
- `src/`
- main.ts → initializes the Canvas2D context, imports assets, contains the animation loop
- style.css → layout and styling of the canvas container
- `public/`

##### README for additional insights
- Describes installation (run on a local HTTP server for CORS support)
- Points to an article and live demo but does not outline deeper architectural layers
- Confirms it is a front-end only demo, MIT-licensed

##### Components
a. Development & Build Environment
- Node.js & NPM (scripts: `npm run dev`, `npm run build`)
- Vite Dev Server (ESM hot-reload)
- Vite Production Bundler
b. Source Code
- index.html (HTML entry)
- style.css (styling)
- main.ts (Canvas logic, module imports)
- global.d.ts (type definitions)
- tsconfig.json (TS settings)
- vite.config.ts (build paths, aliases)
c. Static Assets
- public/morphing images
d. Runtime Environment
- Browser
- Canvas2D API
e. Data Flow & Interactions
- Browser requests `index.html` → receives bundled JS & CSS → main.ts runs
- main.ts loads image assets from `/morphing/*` → decodes into browser memory
- User events (e.g., start/stop) fed into main.ts to control animation

##### Architectural patterns & principles
- Modular design: ES modules imported by main.ts
- Separation of concerns: HTML/CSS/UI shell vs. TS animation logic vs. static assets
- Build vs. runtime distinction: Vite handles dev hot-reload and production bundling

##### Detail
- Every directory or file that contributes to the animation pipeline
- How configuration files (tsconfig.json, vite.config.ts) feed into the bundler
- Full life-cycle: local dev server → production build → browser runtime

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Build-time Environment"
        Pkg["package.json & package-lock.json"]:::build
        NodeNPM["Node.js & NPM"]:::build
        ViteDev["Vite Dev Server & Production Bundler"]:::build
        TSConfig["tsconfig.json"]:::code
        GlobalD["global.d.ts"]:::code
        ViteCfg["vite.config.ts"]:::code

        Pkg -->|"defines deps"| NodeNPM
        NodeNPM -->|"npm run dev/build"| ViteDev
        TSConfig --> ViteDev
        GlobalD --> ViteDev
        ViteCfg --> ViteDev
    end

    subgraph "Source Code Modules"
        HTML["index.html"]:::code
        CSS["src/style.css"]:::code
        MainTS["src/main.ts"]:::code
    end

    subgraph "Static Assets"
        M12["public/morphing/1-2"]:::asset
        M23["public/morphing/2-3"]:::asset
        M34["public/morphing/3-4"]:::asset
        M45["public/morphing/4-5"]:::asset
        M51["public/morphing/5-1"]:::asset
    end

    ViteDev -->|"bundles"| Bundle["JS & CSS Bundle"]:::code

    HTML --> Bundle
    CSS --> Bundle
    MainTS --> Bundle
    M12 --> Bundle
    M23 --> Bundle
    M34 --> Bundle
    M45 --> Bundle
    M51 --> Bundle

    subgraph "Documentation"
        README["README.md"]:::code
        LICENSE["LICENSE"]:::code
    end

    subgraph "Runtime Environment"
        Browser["Browser"]:::runtime
        CanvasAPI["Canvas2D API"]:::runtime
    end

    Bundle -->|"HTTP GET"| Browser
    Browser -->|"executes bundle"| Bundle
    Browser -->|"calls draw()"| CanvasAPI
    CanvasAPI -->|"renders frames"| Browser

    click Pkg "https://github.com/j0suke/morphing-2d-demo/blob/main/package.json"
    click NodeNPM "https://github.com/j0suke/morphing-2d-demo/blob/main/package-lock.json"
    click TSConfig "https://github.com/j0suke/morphing-2d-demo/blob/main/tsconfig.json"
    click GlobalD "https://github.com/j0suke/morphing-2d-demo/blob/main/global.d.ts"
    click ViteCfg "https://github.com/j0suke/morphing-2d-demo/blob/main/vite.config.ts"
    click HTML "https://github.com/j0suke/morphing-2d-demo/blob/main/index.html"
    click CSS "https://github.com/j0suke/morphing-2d-demo/blob/main/src/style.css"
    click MainTS "https://github.com/j0suke/morphing-2d-demo/blob/main/src/main.ts"
    click M12 "https://github.com/j0suke/morphing-2d-demo/tree/main/public/morphing/1-2"
    click M23 "https://github.com/j0suke/morphing-2d-demo/tree/main/public/morphing/2-3"
    click M34 "https://github.com/j0suke/morphing-2d-demo/tree/main/public/morphing/3-4"
    click M45 "https://github.com/j0suke/morphing-2d-demo/tree/main/public/morphing/4-5"
    click M51 "https://github.com/j0suke/morphing-2d-demo/tree/main/public/morphing/5-1"
    click README "https://github.com/j0suke/morphing-2d-demo/blob/main/README.md"
    click LICENSE "https://github.com/j0suke/morphing-2d-demo/tree/main/LICENSE"

    classDef build fill:#FFA500,stroke:#333,stroke-width:1px
    classDef code fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef asset fill:#90EE90,stroke:#333,stroke-width:1px
    classDef runtime fill:#DDA0DD,stroke:#333,stroke-width:1px
```
