# steveruizok/perfect-freehand architecture

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

- Interactive diagram: https://gitdiagram.com/steveruizok/perfect-freehand
- Repository: https://github.com/steveruizok/perfect-freehand

## Overview

##### Project type and purpose
- This is a monorepo managed by Lerna that contains two packages:
- packages/perfect-freehand: the core library for generating pressure-sensitive stroke outlines (a small open-source tool/library).
- packages/dev: a React-based demo and development harness that consumes the library, shows usage (demo front end).
- The README describes the library’s API (`getStroke`, `getStrokePoints`, `getOutlinePoints`), usage examples, options, tests, and development workflow.

##### File structure
- Top-level: configuration files (.eslintrc.js, tsconfig*, build.mjs, lerna.json, GitHub workflows, Husky hooks).
- packages/perfect-freehand:
- src/: core algorithms (getStroke, outline computation), type definitions, test suite under src/test.
- scripts/: build/dev scripts (Node.js build pipeline).
- tsconfig, package.json – library metadata.
- packages/dev:
- esbuild.config.mjs – bundling config for fast dev server.
- tsconfig, package.json – demo metadata.
- tutorial/: markdown instructions.
- Root: CI pipeline (GitHub Actions), linting, pre-commit, test runner (setupTests.ts), monorepo management (Lerna).

##### README for additional insights
- The README focuses on the library’s functions, options, rendering examples, and encourages contributions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Monorepo Root
    subgraph "Monorepo Root (Lerna & CI)"
        direction TB
        lerna["lerna.json"]:::infra
        build_mjs["build.mjs"]:::infra
        workflows[".github/workflows/main.yml"]:::infra
        pkg_root["package.json"]:::infra
        eslint[".eslintrc.js"]:::infra
        husky[".husky/pre-commit"]:::infra
        setup_tests["setupTests.ts"]:::infra
        ts_base["tsconfig.base.json"]:::infra
        ts_root["tsconfig.json"]:::infra
    end

    %% Core Library Package
    subgraph "Core Library (packages/perfect-freehand)" 
        direction TB
        core_index["index.ts"]:::code
        getStroke["getStroke.ts"]:::code
        getPoints["getStrokePoints.ts"]:::code
        getOutline["getStrokeOutlinePoints.ts"]:::code
        getRadius["getStrokeRadius.ts"]:::code
        vec["vec.ts"]:::code
        types["types.ts"]:::code

        subgraph "Tests"
            direction TB
            test_stroke["getStroke.spec.ts"]:::code
            test_points["getStrokePoints.spec.ts"]:::code
            test_outline["getStrokeOutlinePoints.spec.ts"]:::code
            test_radius["getStrokeRadius.spec.ts"]:::code
            test_inputs["inputs.json"]:::code
            test_snaps["__snapshots__"]:::code
        end

        subgraph "Build Scripts"
            direction TB
            script_build["scripts/build.js"]:::infra
            script_dev["scripts/dev.js"]:::infra
            ts_pkg["tsconfig.json"]:::infra
            ts_build["tsconfig.build.json"]:::infra
        end
    end

    %% Demo Application Package
    subgraph "Demo App (packages/dev)" 
        direction TB
        demo_index["index.tsx"]:::code
        demo_html["index.html"]:::code
        esbuild_cfg["esbuild.config.mjs"]:::infra
        demo_pkg["package.json"]:::infra
        demo_ts["tsconfig.json"]:::infra
        demo_tsbuild["tsconfig.build.json"]:::infra

        subgraph "Components"
            direction TB
            comp_checkbox["checkbox.tsx"]:::code
            comp_slider["slider.tsx"]:::code
            comp_controls["controls.tsx"]:::code
            comp_editor["editor.tsx"]:::code
            comp_panel["panel.tsx"]:::code
            comp_colors["colors.tsx"]:::code
            comp_select["select.tsx"]:::code
        end

        subgraph "Hooks & Utils"
            direction TB
            util_shortcuts["useKeyboardShortcuts.ts"]:::code
            util_svg["utils.ts"]:::code
            state_json["state/*.json"]:::code
            state_ts["state/*.ts"]:::code
        end

        subgraph "Styles"
            direction TB
            style_css["styles.css"]:::infra
        end
    end

    %% External Services
    npm["npm Registry"]:::external
    github["GitHub"]:::external
    figma["Figma Plugin"]:::external
    dart["Dart Port"]:::external

    %% Runtime Browser Flow
    comp_editor -->|"pointer events"| getStroke
    getStroke -->|"outline points"| util_svg
    util_svg -->|"SVG path"| comp_editor

    %% Import & Build Flows
    demo_index -->|"imports"| index.tsx
    demo_index -.-> core_index
    pkg_root -->|"lerna bootstrap"| core_index
    pkg_root -->|"lerna bootstrap"| demo_index

    %% CI/CD Flow
    github -->|"push"| workflows
    workflows -->|"run build.mjs"| build_mjs
    workflows -->|"run tests"| test_stroke
    workflows -->|"publish"| npm

    %% External Clients
    figma -->|"uses core library"| core_index
    dart -->|"uses core library"| core_index

    %% Click Events Monorepo
    click lerna "https://github.com/steveruizok/perfect-freehand/blob/main/lerna.json"
    click build_mjs "https://github.com/steveruizok/perfect-freehand/blob/main/build.mjs"
    click workflows "https://github.com/steveruizok/perfect-freehand/blob/main/.github/workflows/main.yml"
    click pkg_root "https://github.com/steveruizok/perfect-freehand/blob/main/package.json"
    click eslint "https://github.com/steveruizok/perfect-freehand/blob/main/.eslintrc.js"
    click husky "https://github.com/steveruizok/perfect-freehand/tree/main/.husky/pre-commit"
    click setup_tests "https://github.com/steveruizok/perfect-freehand/blob/main/setupTests.ts"
    click ts_base "https://github.com/steveruizok/perfect-freehand/blob/main/tsconfig.base.json"
    click ts_root "https://github.com/steveruizok/perfect-freehand/blob/main/tsconfig.json"

    %% Click Events Core Library
    click core_index "https://github.com/steveruizok/perfect-freehand/blob/main/packages/perfect-freehand/src/index.ts"
    click getStroke "https://github.com/steveruizok/perfect-freehand/blob/main/packages/perfect-freehand/src/getStroke.ts"
    click getPoints "https://github.com/steveruizok/perfect-freehand/blob/main/packages/perfect-freehand/src/getStrokePoints.ts"
    click getOutline "https://github.com/steveruizok/perfect-freehand/blob/main/packages/perfect-freehand/src/getStrokeOutlinePoints.ts"
    click getRadius "https://github.com/steveruizok/perfect-freehand/blob/main/packages/perfect-freehand/src/getStrokeRadius.ts"
    click vec "https://github.com/steveruizok/perfect-freehand/blob/main/packages/perfect-freehand/src/vec.ts"
    click types "https://github.com/steveruizok/perfect-freehand/blob/main/packages/perfect-freehand/src/types.ts"
    click test_stroke "https://github.com/steveruizok/perfect-freehand/blob/main/packages/perfect-freehand/src/test/getStroke.spec.ts"
    click test_points "https://github.com/steveruizok/perfect-freehand/blob/main/packages/perfect-freehand/src/test/getStrokePoints.spec.ts"
    click test_outline "https://github.com/steveruizok/perfect-freehand/blob/main/packages/perfect-freehand/src/test/getStrokeOutlinePoints.spec.ts"
    click test_radius "https://github.com/steveruizok/perfect-freehand/blob/main/packages/perfect-freehand/src/test/getStrokeRadius.spec.ts"
    click test_inputs "https://github.com/steveruizok/perfect-freehand/blob/main/packages/perfect-freehand/src/test/inputs.json"
    click test_snaps "https://github.com/steveruizok/perfect-freehand/tree/main/packages/perfect-freehand/src/test/__snapshots__"
    click script_build "https://github.com/steveruizok/perfect-freehand/blob/main/packages/perfect-freehand/scripts/build.js"
    click script_dev "https://github.com/steveruizok/perfect-freehand/blob/main/packages/perfect-freehand/scripts/dev.js"
    click ts_pkg "https://github.com/steveruizok/perfect-freehand/blob/main/packages/perfect-freehand/tsconfig.json"
    click ts_build "https://github.com/steveruizok/perfect-freehand/blob/main/packages/perfect-freehand/tsconfig.build.json"

    %% Click Events Demo App
    click demo_index "https://github.com/steveruizok/perfect-freehand/blob/main/packages/dev/src/index.tsx"
    click demo_html "https://github.com/steveruizok/perfect-freehand/blob/main/packages/dev/src/index.html"
    click esbuild_cfg "https://github.com/steveruizok/perfect-freehand/blob/main/packages/dev/esbuild.config.mjs"
    click demo_pkg "https://github.com/steveruizok/perfect-freehand/blob/main/packages/dev/package.json"
    click demo_ts "https://github.com/steveruizok/perfect-freehand/blob/main/packages/dev/tsconfig.json"
    click demo_tsbuild "https://github.com/steveruizok/perfect-freehand/blob/main/packages/dev/tsconfig.build.json"
    click comp_checkbox "https://github.com/steveruizok/perfect-freehand/blob/main/packages/dev/src/components/checkbox/checkbox.tsx"
    click comp_slider "https://github.com/steveruizok/perfect-freehand/blob/main/packages/dev/src/components/slider/slider.tsx"
    click comp_controls "https://github.com/steveruizok/perfect-freehand/blob/main/packages/dev/src/components/controls/controls.tsx"
    click comp_editor "https://github.com/steveruizok/perfect-freehand/blob/main/packages/dev/src/components/editor/editor.tsx"
    click comp_panel "https://github.com/steveruizok/perfect-freehand/blob/main/packages/dev/src/components/panel/panel.tsx"
    click comp_colors "https://github.com/steveruizok/perfect-freehand/blob/main/packages/dev/src/components/colors/colors.tsx"
    click comp_select "https://github.com/steveruizok/perfect-freehand/blob/main/packages/dev/src/components/select/select.tsx"
    click util_shortcuts "https://github.com/steveruizok/perfect-freehand/blob/main/packages/dev/src/hooks/useKeyboardShortcuts.ts"
    click util_svg "https://github.com/steveruizok/perfect-freehand/blob/main/packages/dev/src/state/utils.ts"
    click state_json "https://github.com/steveruizok/perfect-freehand/tree/main/packages/dev/src/state"
    click state_ts "https://github.com/steveruizok/perfect-freehand/tree/main/packages/dev/src/state"
    click style_css "https://github.com/steveruizok/perfect-freehand/blob/main/packages/dev/src/styles.css"

    %% Styles
    classDef code fill:#e0f7fa,stroke:#006064,color:#000
    classDef infra fill:#e8f5e9,stroke:#2e7d32,color:#000
    classDef external fill:#eeeeee,stroke:#757575,color:#000
```
