# janwilmake/ssreact architecture

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

- Interactive diagram: https://gitdiagram.com/janwilmake/ssreact
- Repository: https://github.com/janwilmake/ssreact

## Overview

This project is a lightweight library that lets developers use React-style (or more precisely, Preact-style) components directly in HTML without a full React build setup. The package, “Stupid Simple React” (ssreact), leverages a tiny JSX compiler (micro-jsx) and Preact to offer a production-ready, minimal bundle. Its purpose is to rapidly enable rich, interactive elements on static websites with minimal overhead—perfect for leveraging cloud deployments (like Cloudflare Workers) and coupling with LLMs for dynamic content generation.

##### Main Components Identification
a. Core Library Bundle: This includes the minified bundle (min.js/min.html) that users import on their pages.
b. JSX Compiler Layer: The micro-jsx components (found in microjsx.js and microjsx2.js) handle JSX transformation.
c. Preact Integration: The underlying dependency (from the project README) that powers the lightweight virtual DOM and component rendering.
d. Component Definition & Scaffolding: User-written scripts (via script tags with type="text/babel") that define React components and rely on a naming convention (div id’s like ssreact.{ComponentName}).
e. Demonstration & Experimentation Modules: The “examples” and “experiments” folders serve to illustrate usage and test specific features.
f. Bundling & Build Scripts: Found in the “src” folder (generate-all.js, bundle.js, bundle.html) which automate the creation of the distributable bundle.
g. Deployment Configuration: The wrangler.toml file, which indicates integration with Cloudflare Workers or similar deployment environments.

##### Relationships and Interactions
- The entry point is the imported ssreact bundle (min.js) which aggregates the JSX compiler (micro-jsx) and Preact.
- User HTML pages (like those in index.html or one of the example HTMLs) include a script that defines React components. These components are transformed by the micro-jsx compiler and then rendered by Preact onto matching DOM elements.
- The directory structure supports clarity: the “src” folder holds the core source, whereas “examples” and “experiments” provide live demos and tests to validate behavior.
- The bundling process (using generate-all.js and bundle.js) compiles and packages these components into a production-ready script.

##### Relevant Technologies and Frameworks
- Preact: The lightweight alternative to React that powers the component rendering.
- micro-jsx: The minimal JSX compiler that powers the transformation of JSX to standard JS calls.
- Cloudflare Workers (as indicated in deployment tips in the README): Points to serverless deployment usage.
- Standard build tools and JavaScript/HTML bundling techniques.

## Diagram (Mermaid)

```mermaid
flowchart TD
    U["User HTML File (with component definitions)"]:::frontend

    subgraph "Core Library Bundle"
        L1["min.js"]:::bundle
        L2["min.html"]:::bundle
    end

    subgraph "Bundling & Build Scripts"
        B1["generate-all.js"]:::build
        B2["bundle.js"]:::build
        B3["bundle.html"]:::build
    end

    subgraph "JSX Compiler Layer"
        J1["microjsx.js"]:::transformation
        J2["microjsx2.js"]:::transformation
    end

    P["ssreact.js"]:::rendering

    RM["DOM Mounting (Rendered Output)"]:::rendering

    subgraph "Demos/Experiments"
        D1["demo.html"]:::demos
        D2["todo.html"]:::demos
        D3["Experiments"]:::demos
    end

    Dcfg["wrangler.toml"]:::deployment

    %% Flow Connections
    U -->|"includes"| L1
    B1 -->|"builds"| L1
    B2 -->|"bundles"| L1
    B3 -->|"assets for"| L1

    L1 -->|"aggregates"| J1
    L1 -->|"aggregates"| J2
    L1 -->|"aggregates"| P

    J1 -->|"transformsJSX"| P
    J2 -->|"transformsJSX"| P

    P -->|"mounts"| RM

    Dcfg -->|"configures"| B1

    U ---|"exampleUsage"| D1
    U ---|"exampleUsage"| D2
    U ---|"exampleUsage"| D3

    %% Styles
    classDef frontend fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef bundle fill:#FFE0B2,stroke:#FB8C00,stroke-width:2px;
    classDef transformation fill:#BBDEFB,stroke:#1976D2,stroke-width:2px;
    classDef rendering fill:#C5E1A5,stroke:#7CB342,stroke-width:2px;
    classDef build fill:#FFCDD2,stroke:#E53935,stroke-width:2px;
    classDef demos fill:#D1C4E9,stroke:#673AB7,stroke-width:2px;
    classDef deployment fill:#CFD8DC,stroke:#607D8B,stroke-width:2px;

    %% Click Events (paths are for click events only)
    click L1 "https://github.com/janwilmake/ssreact/blob/main//min.js"
    click L2 "https://github.com/janwilmake/ssreact/blob/main//min.html"
    click J1 "https://github.com/janwilmake/ssreact/blob/main//src/microjsx.js"
    click J2 "https://github.com/janwilmake/ssreact/blob/main//src/microjsx2.js"
    click P "https://github.com/janwilmake/ssreact/blob/main//src/ssreact.js"
    click B1 "https://github.com/janwilmake/ssreact/blob/main//src/generate-all.js"
    click B2 "https://github.com/janwilmake/ssreact/blob/main//src/bundle.js"
    click B3 "https://github.com/janwilmake/ssreact/blob/main//src/bundle.html"
    click D1 "https://github.com/janwilmake/ssreact/blob/main//examples/demo.html"
    click D2 "https://github.com/janwilmake/ssreact/blob/main//examples/todo.html"
    click D3 "https://github.com/janwilmake/ssreact/tree/main//experiments"
    click Dcfg "https://github.com/janwilmake/ssreact/blob/main//wrangler.toml"
```
