# emilkowalski/sonner architecture

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

- Interactive diagram: https://gitdiagram.com/emilkowalski/sonner
- Repository: https://github.com/emilkowalski/sonner

## Overview

##### Main Components
- Core Library:
- Core functionality located in the src folder (files like assets.tsx, hooks.tsx, index.tsx, state.ts, etc.). This is where the toast functionality is implemented.
- Components such as the Toaster component and other helper functions/types for managing the notifications.
- Testing Suite:
- Test folder as a separate component which manages both configuration (eslintrc, tsconfig, etc.) and actual test files (e.g. basic.spec.ts, testing app pages).
- That the tests simulate user interactions with the toast notifications (including Playwright tests from .github/workflows/playwright.yml).
- Example/Demo Application:
- The website folder contains a demo or documentation site (built with Next.js) showcasing the library usage.
- Components like individual pages, demo components (CodeBlock, Hero, Installation, etc.) demonstrating the functionalities.
- CI/CD and Build Infrastructure:
- .github directory that manages workflows, along with configuration files such as tsup.config.ts, turbo.json, and package.json. These illustrate the build, test, and deployment integration.
- Dependency and Tooling Configuration:
- Presence of configurations from package managers (pnpm-lock.yaml, pnpm-workspace.yaml) showing that the project is set up as a monorepo or multi-package project supporting multiple entry points.

##### Relationships and Data Flow
- That application developers import the “Sonner Library” into their projects (using npm install, as mentioned).
- From the “Sonner Library” to consumer React applications to show component integration.
- From “Demo Website” to the “Sonner Library” indicating demonstration and documentation usage.
- From “Test Suite” to “Sonner Library” to illustrate continuous verification.
- You show CI/CD pipelines triggering test executions and builds that deploy the demo/documentation site.

##### Architectural Patterns and Technologies
- Separation of concerns (the core library versus the demonstration, and testing are isolated).
- That the component-based structure leverages React’s component model.
- Use of Next.js within the website folder, and tooling such as Playwright for end-to-end tests.
- Mention dependency management from pnpm and build orchestration with turbo (turbo.json) and tsup.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Sonner Library (Core)
    subgraph "Sonner Library (Core)"
        direction TB
        CL["Core (src)"]:::core
        IT["index.tsx"]:::core
        HT["hooks.tsx"]:::core
        AT["assets.tsx"]:::core
        ST["state.ts"]:::core
        TT["types.ts"]:::core
        SC["styles.css"]:::core
        TT1["Toaster Component (UI)"]:::core
        TT2["Toast Trigger Function (toast)"]:::core
        TT3["Supporting Logic (Hooks,State,Types)"]:::core
        CL --> IT
        CL --> HT
        CL --> AT
        CL --> ST
        CL --> TT
        CL --> SC
        CL --> TT1
        CL --> TT2
        CL --> TT3
    end

    %% Test Suite
    subgraph "Test Suite"
        direction TB
        TDIR["Tests (test)"]:::test
        SPEC["basic.spec.ts"]:::test
        TSC["tsconfig.json"]:::test
        TREADME["README.md"]:::test
        ESL[".eslintrc.json"]:::test
        TNC["next.config.js"]:::test
        TDIR --> SPEC
        TDIR --> TSC
        TDIR --> TREADME
        TDIR --> ESL
        TDIR --> TNC
    end

    %% Demo/Documentation Application
    subgraph "Demo Website"
        direction TB
        WD["Website (website)"]:::demo
        WNC["next.config.js"]:::demo
        PAGES["Pages (src/pages)"]:::demo
        MDX1["getting-started.mdx"]:::demo
        MDX2["toast.mdx"]:::demo
        MDX3["toaster.mdx"]:::demo
        COMPS["Components (src/components)"]:::demo
        CODE["CodeBlock"]:::demo
        HERO["Hero"]:::demo
        INSTALL["Installation"]:::demo
        WD --> WNC
        WD --> PAGES
        PAGES --> MDX1
        PAGES --> MDX2
        PAGES --> MDX3
        WD --> COMPS
        COMPS --> CODE
        COMPS --> HERO
        COMPS --> INSTALL
    end

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        direction TB
        CICD["CI/CD (.github/workflows)"]:::cicd
        PW["playwright.yml"]:::cicd
        CICD --> PW
    end

    %% Build & Dependency Management
    subgraph "Build & Dependency Management"
        direction TB
        BUILD["Build Configs"]:::build
        TSUP["tsup.config.ts"]:::build
        TURBO["turbo.json"]:::build
        PKG["package.json"]:::build
        PNPM1["pnpm-lock.yaml"]:::build
        PNPM2["pnpm-workspace.yaml"]:::build
        BUILD --> TSUP
        BUILD --> TURBO
        BUILD --> PKG
        BUILD --> PNPM1
        BUILD --> PNPM2
    end

    %% Relationships
    %% Demo Website uses Sonner Library
    WD ---|"demo_usage"| CL
    %% Test Suite verifies Sonner Library
    TDIR ---|"tests_verify"| CL
    %% CI/CD Pipeline triggers tests and deploys demo
    CICD -->|"triggers_tests"| TDIR
    CICD -->|"deploys_demo"| WD
    CICD -->|"config_build"| BUILD
    %% Build & Dependency Management builds components
    BUILD -->|"builds_core"| CL
    BUILD -->|"builds_tests"| TDIR
    BUILD -->|"builds_demo"| WD

    %% Click Events for Sonner Library (Core)
    click CL "https://github.com/emilkowalski/sonner/tree/main/src"
    click IT "https://github.com/emilkowalski/sonner/blob/main/src/index.tsx"
    click HT "https://github.com/emilkowalski/sonner/blob/main/src/hooks.tsx"
    click AT "https://github.com/emilkowalski/sonner/blob/main/src/assets.tsx"
    click ST "https://github.com/emilkowalski/sonner/blob/main/src/state.ts"
    click TT "https://github.com/emilkowalski/sonner/blob/main/src/types.ts"
    click SC "https://github.com/emilkowalski/sonner/blob/main/src/styles.css"

    %% Click Events for Test Suite
    click TDIR "https://github.com/emilkowalski/sonner/tree/main/test"
    click SPEC "https://github.com/emilkowalski/sonner/blob/main/test/tests/basic.spec.ts"
    click TSC "https://github.com/emilkowalski/sonner/blob/main/test/tsconfig.json"
    click TREADME "https://github.com/emilkowalski/sonner/blob/main/test/README.md"
    click ESL "https://github.com/emilkowalski/sonner/blob/main/test/.eslintrc.json"
    click TNC "https://github.com/emilkowalski/sonner/blob/main/test/next.config.js"

    %% Click Events for Demo Website
    click WD "https://github.com/emilkowalski/sonner/tree/main/website"
    click WNC "https://github.com/emilkowalski/sonner/blob/main/website/next.config.js"
    click PAGES "https://github.com/emilkowalski/sonner/tree/main/website/src/pages"
    click MDX1 "https://github.com/emilkowalski/sonner/blob/main/website/src/pages/getting-started.mdx"
    click MDX2 "https://github.com/emilkowalski/sonner/blob/main/website/src/pages/toast.mdx"
    click MDX3 "https://github.com/emilkowalski/sonner/blob/main/website/src/pages/toaster.mdx"
    click COMPS "https://github.com/emilkowalski/sonner/tree/main/website/src/components"
    click CODE "https://github.com/emilkowalski/sonner/tree/main/website/src/components/CodeBlock"
    click HERO "https://github.com/emilkowalski/sonner/tree/main/website/src/components/Hero"
    click INSTALL "https://github.com/emilkowalski/sonner/tree/main/website/src/components/Installation"

    %% Click Events for CI/CD Pipeline
    click CICD "https://github.com/emilkowalski/sonner/tree/main/.github/workflows"
    click PW "https://github.com/emilkowalski/sonner/blob/main/.github/workflows/playwright.yml"

    %% Click Events for Build & Dependency Management
    click TSUP "https://github.com/emilkowalski/sonner/blob/main/tsup.config.ts"
    click TURBO "https://github.com/emilkowalski/sonner/blob/main/turbo.json"
    click PKG "https://github.com/emilkowalski/sonner/blob/main/package.json"
    click PNPM1 "https://github.com/emilkowalski/sonner/blob/main/pnpm-lock.yaml"
    click PNPM2 "https://github.com/emilkowalski/sonner/blob/main/pnpm-workspace.yaml"

    %% Class Definitions for Colors
    classDef core fill:#a3d5ff,stroke:#333,stroke-width:2px;
    classDef test fill:#ffe699,stroke:#333,stroke-width:2px;
    classDef demo fill:#ffcccb,stroke:#333,stroke-width:2px;
    classDef cicd fill:#d3ffce,stroke:#333,stroke-width:2px;
    classDef build fill:#e0bbff,stroke:#333,stroke-width:2px;
```
