# emilefokkema/infinite-canvas architecture

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

- Interactive diagram: https://gitdiagram.com/emilefokkema/infinite-canvas
- Repository: https://github.com/emilefokkema/infinite-canvas

## Overview

##### Main Components
a. Core Library:
- Central “InfiniteCanvas” code found in the “src” folder. This includes modules such as:
– API layer (in src/api) which defines the public interface (e.g. getContext, event handling)
– Implementation details (in src/impl) for drawing instructions, event handling, geometry calculations, transformation, rectangle and state management, etc.
– Submodules for event utilities, internal events, and additional helper functions.
- How these submodules interact internally; for instance, the API calls map to implementation routines that use geometry, state management, and event dispatchers.

b. Demo / Development Application:
- The “dev-app” directory contains a sample backend and a frontend that demonstrates the InfiniteCanvas capabilities.
- The backend (using Node.js) might serve test cases or dev endpoints, and the frontend (which includes Vue components, Vite config, etc.) shows the live usage of the library.

c. Testing Infrastructure:
- Unit tests (in “test-unit” and “e2e” directories) that validate both the core rendering, event mapping, and state transitions.
- End-to-end tests that run using Puppeteer (noted in the README) to manipulate pages with InfiniteCanvas, ensuring that visual output—via image snapshots—matches expected behavior.
- Separation between unit testing components and the e2e/snapshot testing (with Jest and Puppeteer).

d. Documentation & Examples:
- The “docs” folder (using VitePress) provides API docs, guides, and example usage.
- The “examples” directory contains sample configurations and project examples that illustrate basic to advanced usage scenarios.

e. Supporting & Utility Tools:
- There are utility modules for dark theme handling, Vite configuration, and window message passing in the “utils” folder.
- These support development and build processes of both the library and its demos.

##### Relationships and Interactions
- The Core Library exposes its API to developers so that the canvas element can be manipulated. This API layer is built upon many internal modules (for drawing, transformation, event state, geometry, etc.).
- The Demo Application (dev-app frontend) consumes the InfiniteCanvas library by retrieving the context from the canvas element and displaying it.
- The Backend component (in dev-app/backend) may serve dynamic content or configuration, which then feeds into the frontend.
- Testing layers (unit and e2e) simulate usage by calling the library’s API and verifying rendering results.
- Documentation is generated from source (or manually maintained based on the API definitions in src) and refers back to the actual examples and code use cases.

##### Architectural Patterns and Design Principles
- The project uses a modular approach that separates core functionality (the “engine” in src) from the demo application and tests.
- There is an emphasis on abstraction; for example, event handling is encapsulated in separate modules that handle different event types (mouse, touch, pointer) and transformation.
- The project also uses TypeScript’s strict typing (as seen by multiple tsconfig.json files) to maintain robustness across modules.
- The separation of concerns is evident through distinct directories that handle API definitions, implementations, tests, and external integration (documentation and demo).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Library Subgraph
    subgraph "InfiniteCanvas Core Library"
        Core_Source["InfiniteCanvas Core - Source"]:::core
        API_Layer["InfiniteCanvas Core - API"]:::core
        Impl_Modules["InfiniteCanvas Core - Implementation"]:::core
    end

    %% Demo Application Subgraph
    subgraph "Demo Application"
        Demo_Frontend["Demo Frontend (Vue/Vite)"]:::demo
        Demo_Backend["Demo Backend (Node.js)"]:::demo
        Demo_Runner["Demo Examples Runner"]:::demo
    end

    %% Testing Infrastructure Subgraph
    subgraph "Testing Infrastructure"
        Unit_Tests["Unit Tests"]:::testing
        E2E_Tests["End-to-End Tests"]:::testing
        E2E_Utils["E2E Test Utils"]:::testing
    end

    %% Documentation & Examples Subgraph
    subgraph "Documentation & Examples"
        Docs["Documentation (VitePress)"]:::docs
        Examples["Examples"]:::docs
    end

    %% Supporting & Utility Tools Subgraph
    subgraph "Supporting & Utility Tools"
        Utils["Utility Modules"]:::utils
    end

    %% Relationships within Core Library
    Core_Source -->|"initializes"| API_Layer
    Core_Source -->|"initializes"| Impl_Modules

    %% Relationships between Core Library and Demo Application
    API_Layer -->|"invokedBy"| Demo_Frontend
    Impl_Modules -->|"renders via"| Demo_Frontend
    Demo_Frontend -->|"requestsData"| Demo_Backend

    %% Relationships with Testing Infrastructure
    Unit_Tests -->|"validates"| API_Layer
    Unit_Tests -->|"verifies"| Impl_Modules
    E2E_Tests -->|"simulatesCanvas"| Demo_Frontend
    E2E_Utils -->|"supports"| E2E_Tests

    %% Relationships with Documentation & Examples
    Docs -->|"describes"| API_Layer
    Examples -->|"demonstrates"| API_Layer

    %% Relationships with Supporting & Utility Tools
    Utils -->|"supports"| Core_Source
    Utils -->|"assists"| Demo_Frontend

    %% Connections from Testing to Demo Application
    Unit_Tests -->|"testsUsage"| Demo_Frontend
    E2E_Tests -->|"verifiesIntegration"| Demo_Backend

    %% Click Events for Core Library
    click Core_Source "https://github.com/emilefokkema/infinite-canvas/tree/master/src"
    click API_Layer "https://github.com/emilefokkema/infinite-canvas/tree/master/src/api"
    click Impl_Modules "https://github.com/emilefokkema/infinite-canvas/tree/master/src/impl"

    %% Click Events for Demo / Development Application
    click Demo_Frontend "https://github.com/emilefokkema/infinite-canvas/tree/master/dev-app/frontend"
    click Demo_Backend "https://github.com/emilefokkema/infinite-canvas/tree/master/dev-app/backend"
    click Demo_Runner "https://github.com/emilefokkema/infinite-canvas/tree/master/dev-app/examples-runner"

    %% Click Events for Testing Infrastructure
    click Unit_Tests "https://github.com/emilefokkema/infinite-canvas/tree/master/test-unit"
    click E2E_Tests "https://github.com/emilefokkema/infinite-canvas/tree/master/e2e"
    click E2E_Utils "https://github.com/emilefokkema/infinite-canvas/tree/master/e2e-test-utils"

    %% Click Events for Documentation & Examples
    click Docs "https://github.com/emilefokkema/infinite-canvas/tree/master/docs"
    click Examples "https://github.com/emilefokkema/infinite-canvas/tree/master/examples"

    %% Click Event for Supporting & Utility Tools
    click Utils "https://github.com/emilefokkema/infinite-canvas/tree/master/utils"

    %% Style Definitions
    classDef core fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef demo fill:#A9DFBF,stroke:#1E8449,stroke-width:2px;
    classDef testing fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef docs fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef utils fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
```
