# rainforesters/imsure-demo architecture

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

- Interactive diagram: https://gitdiagram.com/rainforesters/imsure-demo
- Repository: https://github.com/rainforesters/imsure-demo

## Overview

##### Project type and purpose
- This is a front-end Single-Page Application (SPA) demo built with Vue 3, TypeScript, and Vite.
- Its goal is to showcase the “imsure” library (in the src/wesure folder) for building reactive pages, stores, routers, and data structures in a “省时省力省钱省心省脑子” (“save time, effort, money, worry, and brainpower”) style.

##### File structure
- Top level: configuration files (.editorconfig, tsconfig*, vite.config.ts), package.json, README.md, index.html.
- src/
- App.vue & main.ts: root Vue application bootstrap
- router/index.ts: Vue Router setup
- api/product.ts: HTTP client wrapper for product-related endpoints
- views/*.vue: raw Vue view components (ExchangePage.vue, ProductsPage.vue)
- assets/*.css: global styling
- wesure/ (the demo library)
– basic/: core primitives (App, River, Router, Store, utils)
– page/: page-level logic classes (ExchangePage.ts, ProductsPage.ts)
– struct/: domain data models (Product, Sku, CartProduct)
– types/: custom scalar types (bool, money, string)

##### Extract architectural intent from README
- The README states this is a “demo example” of using imsure for program development.
- No backend code here; the API layer calls out to demo endpoints (could be mocked or real).

##### Main components & interactions
a. Client Browser (runs SPA)
b. Vue Application
- Root: App.vue
- Router (vue-router) → maps URLs to Views
- Views (ExchangePage.vue, ProductsPage.vue)
- API layer (src/api/product.ts)
c. ImSure Library (src/wesure)
- basic/App.ts: app initialization wrapper
- basic/Router.ts: enhanced router integration
- basic/Store.ts: global state management
- basic/River.ts: reactive data stream utility
- basic/utils.ts: low-level helpers
- page/: page controller classes (ExchangePage, ProductsPage) which coordinate between Views, Store, and API
- struct/: typed domain models (Product, Sku, CartProduct)
- types/: domain-specific scalar types
d. External Services
- Product API endpoints

##### Relationships & data flow
- Browser → loads index.html → Vite bundles → mounts main.ts → App.vue
- App.vue uses ImSure basic/App to initialize Router and Store
- User navigates (Router.ts) → selects a route → corresponding PageController (ExchangePage or ProductsPage) instantiates
- PageController calls API (product.ts) → receives JSON → constructs domain models (struct/Product, struct/Sku, struct/CartProduct) → pushes to Store (Store.ts) or River streams
- View components subscribe to Store or River streams → re-render UI
- utils.ts supports parsing/formatting (e.g., money, bool, string types)

##### Architectural patterns & design principles
- SPA with clear separation: UI (Vue Views), Business logic (Page controllers), State (Store), Data models (struct), Reactive streams (River)
- Dependency inversion: Views depend on Page controllers, not directly on API or models
- Single source of truth: centralized Store for shared state
- Type safety: domain models & custom types ensure data correctness

##### Technologies & frameworks
- Vue 3 (SFCs, composition API)
- TypeScript
- Vite for dev & bundling
- Vue Router
- pnpm for package management
- ImSure (in-repo demo library under src/wesure)

##### Detailed capture of essential elements
- How struct classes map JSON → typed instances
- Utils functions used for data transformations
- Bootstrapping sequence: main.ts → App.vue → ImSure basic/App → Router registration → initial PageController

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Swimlane: Browser/Client
    subgraph "Browser/Client"
        direction TB
        Browser["Client Browser"]:::external
        indexHTML["index.html"]:::ui
    end

    %% Swimlane: Vue Core
    subgraph "Vue Core"
        direction TB
        main["src/main.ts"]:::ui
        AppVue["src/App.vue"]:::ui
        router["Router (vue-router)"]:::logic
        ExchangeView["ExchangePage.vue"]:::ui
        ProductsView["ProductsPage.vue"]:::ui
        productAPI["src/api/product.ts"]:::logic
    end

    %% Swimlane: ImSure Library
    subgraph "ImSure Library"
        direction TB

        subgraph "basic"
            direction TB
            AppInit["App (basic/App.ts)"]:::logic
            RouterEnhance["Router (basic/Router.ts)"]:::logic
            Store["Store (basic/Store.ts)"]:::logic
            River["River (basic/River.ts)"]:::logic
            utils["utils (basic/utils.ts)"]:::logic
        end

        subgraph "page"
            direction TB
            ExchangeController["ExchangePageController"]:::logic
            ProductsController["ProductsPageController"]:::logic
        end

        subgraph "struct"
            direction TB
            ProductModel["Product (struct/Product.ts)"]:::data
            SkuModel["Sku (struct/Sku.ts)"]:::data
            CartProductModel["CartProduct (struct/CartProduct.ts)"]:::data
        end

        subgraph "types"
            direction TB
            boolType["bool (types/bool.ts)"]:::data
            moneyType["money (types/money.ts)"]:::data
            stringType["string (types/string.ts)"]:::data
        end
    end

    %% Swimlane: External Services
    subgraph "External Services"
        direction TB
        ExternalAPI["Product API Endpoints"]:::external
    end

    %% Connections: Bootstrapping
    Browser --> indexHTML
    indexHTML --> main
    main --> AppVue
    AppVue --> AppInit
    AppInit --> RouterEnhance
    AppInit --> Store
    AppInit --> River

    %% Router setup and navigation
    RouterEnhance --> router
    router --> ExchangeController
    router --> ProductsController

    %% PageController interactions
    ExchangeController --> productAPI
    ProductsController --> productAPI
    productAPI --> ExternalAPI
    productAPI --> ProductModel
    productAPI --> SkuModel
    productAPI --> CartProductModel

    ExchangeController --> Store
    ProductsController --> Store
    ExchangeController --> River
    ProductsController --> River

    %% View subscriptions and control flow
    ExchangeView --> ExchangeController
    ProductsView --> ProductsController
    Store --> ExchangeView
    Store --> ProductsView
    River --> ExchangeView
    River --> ProductsView

    %% Utils and types usage
    ExchangeController --> utils
    ProductsController --> utils
    utils --> boolType
    utils --> moneyType
    utils --> stringType

    %% Click Events
    click indexHTML "https://github.com/rainforesters/imsure-demo/blob/main/index.html"
    click main "https://github.com/rainforesters/imsure-demo/blob/main/src/main.ts"
    click AppVue "https://github.com/rainforesters/imsure-demo/blob/main/src/App.vue"
    click router "https://github.com/rainforesters/imsure-demo/blob/main/src/router/index.ts"
    click ExchangeView "https://github.com/rainforesters/imsure-demo/blob/main/src/views/ExchangePage.vue"
    click ProductsView "https://github.com/rainforesters/imsure-demo/blob/main/src/views/ProductsPage.vue"
    click productAPI "https://github.com/rainforesters/imsure-demo/blob/main/src/api/product.ts"
    click AppInit "https://github.com/rainforesters/imsure-demo/blob/main/src/wesure/basic/App.ts"
    click RouterEnhance "https://github.com/rainforesters/imsure-demo/blob/main/src/wesure/basic/Router.ts"
    click Store "https://github.com/rainforesters/imsure-demo/blob/main/src/wesure/basic/Store.ts"
    click River "https://github.com/rainforesters/imsure-demo/blob/main/src/wesure/basic/River.ts"
    click utils "https://github.com/rainforesters/imsure-demo/blob/main/src/wesure/basic/utils.ts"
    click ExchangeController "https://github.com/rainforesters/imsure-demo/blob/main/src/wesure/page/ExchangePage.ts"
    click ProductsController "https://github.com/rainforesters/imsure-demo/blob/main/src/wesure/page/ProductsPage.ts"
    click ProductModel "https://github.com/rainforesters/imsure-demo/blob/main/src/wesure/struct/Product.ts"
    click SkuModel "https://github.com/rainforesters/imsure-demo/blob/main/src/wesure/struct/Sku.ts"
    click CartProductModel "https://github.com/rainforesters/imsure-demo/blob/main/src/wesure/struct/CartProduct.ts"
    click boolType "https://github.com/rainforesters/imsure-demo/blob/main/src/wesure/types/bool.ts"
    click moneyType "https://github.com/rainforesters/imsure-demo/blob/main/src/wesure/types/money.ts"
    click stringType "https://github.com/rainforesters/imsure-demo/blob/main/src/wesure/types/string.ts"

    %% Styles
    classDef ui fill:#add8e6,stroke:#333,stroke-width:1px
    classDef logic fill:#98fb98,stroke:#333,stroke-width:1px
    classDef data fill:#ffff99,stroke:#333,stroke-width:1px
    classDef external fill:#ffcc99,stroke:#333,stroke-width:1px
```
