# achaljain/smart-context architecture

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

- Interactive diagram: https://gitdiagram.com/achaljain/smart-context
- Repository: https://github.com/achaljain/smart-context

## Overview

##### Project Type and Purpose
- This is an open-source React state-management library (“smart-context”) with zero-boilerplate, config-driven stores.
- It’s shipped as an npm package and accompanied by a documentation & demo website (built with Docusaurus + React) that showcases usage, performance benchmarks, and guides.

##### Top-Level Structure
- Root: library source (`src/`), build config (Rollup, TypeScript), CI/CD (Travis, semantic-release), and project metadata (package.json, README, LICENSE).
- `src/`: core modules (`consumer.tsx`, `provider.tsx`, `manager.ts`, `register.ts`), TypeScript definitions, and unit tests (`__tests__/`).
- `website/`: Docusaurus site with docs (`website/docs/`), custom React components & CSS (`website/src/components`, `website/src/css`), demos (`website/src/demo`), performance samples (`website/src/perf`), and site config.

##### Key Components to Portray
a. Library Core
- Provider HOC (`WithContextProvider`)
- Hook API (`useSmartContext`)
- Store Manager (action dispatch, async handling)
- Registration module (registering multiple contexts)
- Utility functions
b. Build & Release Pipeline
- Rollup bundler (rollup.config.js)
- CI (Travis CI + semantic-release)
- npm registry (publishing)
c. Documentation & Demo Website
- Docusaurus app
- Markdown docs → React pages
- Demo apps (class vs functional components)
- Performance benchmarks (vanilla vs smart vs redux-context)
- Static assets & Netlify hosting
d. External Dependencies
- React
- Babel (in website)
- TypeScript
- Docusaurus

##### Relationships and Data Flows
- Developer → GitHub → Travis CI → semantic-release → npm registry.
- Local development:
- `src/` library built by Rollup → published.
- `website/` pulls library from local or npm → Docusaurus build → Netlify.
- Runtime:
- App code wraps root with `WithContextProvider` → Provider injects contexts.
- Components call `useSmartContext` → Hooks into Manager → dispatch actions → update state → re-render.
- Plugins (if any) extend Manager behavior.

##### Architectural Patterns & Principles
- Modular, plugin-driven store managers.
- Separation of concerns: Provider vs Consumer vs Manager.
- Zero-boilerplate, config-centric approach.
- Single responsibility: Core library vs documentation site.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External
    GitHub["GitHub"]:::external
    NPMRegistry["npm Registry"]:::external
    Netlify["Netlify Hosting"]:::external

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        direction TB
        RollupNode["Rollup Bundler"]:::ci
        TravisCI["Travis CI"]:::ci
        SR["semantic-release"]:::ci
        NPMMeta["package.json (npm metadata)"]:::ci
    end

    %% Library Core
    subgraph "Library Core"
        direction TB
        Provider["WithContextProvider"]:::library
        Hook["useSmartContext Hook"]:::library
        Manager["Action Dispatch & Async Handling"]:::library
        Register["Registration Module"]:::library
        Utils["Utility Functions"]:::library
    end

    %% Runtime Flow
    subgraph "Runtime Flow"
        direction TB
        AppComp["App Component"]:::library
        State["Context State"]:::library
        Render["Re-render View"]:::library
    end

    %% Documentation & Demo Site
    subgraph "Documentation & Demo Site"
        direction TB
        Docusaurus["Docusaurus App"]:::docs
        Docs["Markdown Docs → React Pages"]:::docs
        Demo["Demo Apps (class & functional)"]:::docs
        Perf["Performance Benchmarks"]:::docs
        StaticAssets["Static Assets"]:::docs
    end

    %% Relationships
    GitHub -->|triggers build| TravisCI
    TravisCI -->|runs release| SR
    SR -->|publishes to| NPMRegistry

    RollupNode -->|builds library| NPMRegistry
    NPMRegistry -->|dependency| Docusaurus

    %% Runtime arrows
    AppComp -->|wraps with| Provider
    Provider -->|provides context| AppComp
    AppComp -->|calls hook| Hook
    Hook -->|invokes| Manager
    Manager -->|updates| State
    State -->|triggers| Render

    %% Website build & deploy
    Docusaurus -->|builds site| StaticAssets
    StaticAssets -->|deploys to| Netlify
    Docusaurus -->|includes| Docs
    Docusaurus -->|includes| Demo
    Docusaurus -->|includes| Perf

    %% Click Events
    click Provider "https://github.com/achaljain/smart-context/blob/master/src/provider.tsx"
    click Hook "https://github.com/achaljain/smart-context/blob/master/src/consumer.tsx"
    click Manager "https://github.com/achaljain/smart-context/blob/master/src/manager.ts"
    click Register "https://github.com/achaljain/smart-context/blob/master/src/register.ts"
    click Utils "https://github.com/achaljain/smart-context/blob/master/src/utils.ts"
    click RollupNode "https://github.com/achaljain/smart-context/blob/master/rollup.config.js"
    click TravisCI "https://github.com/achaljain/smart-context/blob/master/.travis.yml"
    click SR "https://github.com/achaljain/smart-context/blob/master/.releaserc.json"
    click NPMMeta "https://github.com/achaljain/smart-context/blob/master/package.json"
    click Docusaurus "https://github.com/achaljain/smart-context/blob/master/website/docusaurus.config.js"
    click Docs "https://github.com/achaljain/smart-context/tree/master/website/docs/"
    click Demo "https://github.com/achaljain/smart-context/tree/master/website/src/demo/components"
    click Perf "https://github.com/achaljain/smart-context/tree/master/website/src/perf/"
    click StaticAssets "https://github.com/achaljain/smart-context/tree/master/website/static/"

    %% Styles
    classDef library fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef ci fill:#DFFFE0,stroke:#333,stroke-width:1px
    classDef docs fill:#FFE8C0,stroke:#333,stroke-width:1px
    classDef external fill:#DDDDDD,stroke:#333,stroke-width:1px
```
