# shopify/discount-app-components architecture

> Architecture diagram of the GitHub repository shopify/discount-app-components, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shopify/discount-app-components
- Repository: https://github.com/shopify/discount-app-components

## Overview

##### Main Components
- Library Entry Point & Packaging:
- Main entry at src/index.ts. This represents the public API that consumers of the library will use.
- Build configuration files such as babel.config.js, the Rollup configuration in config/rollup, and the changesets files (e.g., .changeset folder). These show how the library is built and versioned.
- UI Component Modules:
- Extensive src/components directory where each discount-related component (e.g., ActiveDatesCard, CombinationCard, CurrencyField, etc.) is implemented. Each component has its own directory that includes source, styles, README, and tests.
- Emphasis on the AppProvider component in src/components/AppProvider. This wraps the discount app components and manages locale and timezone settings, making it a central component in the system.
- Storybook & Documentation:
- The src/stories directory contains multiple Storybook stories which serve as living documentation and playgrounds for the components.
- Additionally, include the documentation folder (documentation/SAMPLE_README.md) which may provide further context.
- Utilities & Configurations:
- Testing & Quality Assurance:
- Presence of tests within the src/components/*/tests folders and the separate tests directory that contains setup files and custom matchers.
- The CI configuration in .github/workflows and various config files (e.g., .eslintrc, .prettierrc) showcase the quality assurance practices.

##### Dependencies and External Relationships
- External Integrations:
- Connection between this library and external dependencies such as @shopify/polaris and @shopify/app-bridge (as specified in the README’s installation instructions).
- Build and Release Process:
- Automated release and publishing process (using changesets, GitHub workflows, and yalc for local testing).
- A segment for versioning and changelog generation (CHANGELOG.md and changeset files) should be shown.

##### Representation of Architectural Patterns
- Component-based Architecture:
- That the project is structured around discrete, stateless components that are composed to build the discount experience.
- Separation of Concerns:
- Clearly separate the UI components from utility functions, configuration, and testing.
- Extensibility & Integration Points:
- AppProvider as a critical integration point where both Polaris and discount components are composed together.
- Locales folder as it demonstrates internationalization support within components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Public API & Integration Layer
    subgraph "Public API & Integration"
        PublicAPI["Public API"]:::publicStyle
        ExternalPolaris["Polaris"]:::externalStyle
        ExternalAppBridge["App Bridge"]:::externalStyle
    end

    %% Component Layer
    subgraph "Component Layer"
        AppProvider["AppProvider"]:::ui
        ActiveDatesCard["ActiveDatesCard"]:::ui
        CombinationCard["CombinationCard"]:::ui
        CurrencyField["CurrencyField"]:::ui
    end

    %% Build & Deployment Layer
    subgraph "Build & Deployment"
        BabelConfig["Babel Config"]:::configStyle
        RollupConfig["Rollup Config"]:::configStyle
        Changeset["Changeset"]:::configStyle
        Changelog["Changelog"]:::configStyle
        Configurations["Configurations"]:::configStyle
        CICD["CI/CD"]:::configStyle
    end

    %% Testing & Documentation Layer
    subgraph "Testing & Documentation"
        Storybook["Storybook"]:::docStyle
        Documentation["Documentation"]:::docStyle
        Tests["Tests"]:::testStyle
    end

    %% Utilities Layer
    subgraph "Utilities"
        Utilities["Utilities"]:::utilStyle
    end

    %% Relationships between layers
    PublicAPI -->|"imports"| AppProvider
    PublicAPI -->|"integrates"| ExternalPolaris
    PublicAPI -->|"integrates"| ExternalAppBridge

    AppProvider -->|"provides locale"| ActiveDatesCard
    AppProvider -->|"provides locale"| CombinationCard
    AppProvider -->|"provides locale"| CurrencyField

    Utilities -->|"helpers"| AppProvider
    Utilities -->|"helpers"| ActiveDatesCard
    Utilities -->|"helpers"| CombinationCard
    Utilities -->|"helpers"| CurrencyField

    BabelConfig --> CICD
    RollupConfig --> CICD
    Changeset --> CICD
    Changelog --> CICD
    Configurations --> CICD
    CICD --> PublicAPI
    CICD --> Tests
    CICD --> Documentation

    %% Style Definitions
    classDef publicStyle fill:#e0ffff,stroke:#333,stroke-width:2px;
    classDef ui fill:#f9f,stroke:#333,stroke-width:2px;
    classDef configStyle fill:#ccf,stroke:#333,stroke-width:2px;
    classDef testStyle fill:#cfc,stroke:#333,stroke-width:2px;
    classDef docStyle fill:#ffc,stroke:#333,stroke-width:2px;
    classDef utilStyle fill:#fcf,stroke:#333,stroke-width:2px;
    classDef externalStyle fill:#ffd700,stroke:#333,stroke-width:2px;

    %% Click Events
    click PublicAPI "https://github.com/shopify/discount-app-components/blob/main/src/index.ts"
    click BabelConfig "https://github.com/shopify/discount-app-components/blob/main/babel.config.js"
    click RollupConfig "https://github.com/shopify/discount-app-components/tree/main/config/rollup"
    click Changeset "https://github.com/shopify/discount-app-components/blob/main/.changeset"
    click Changelog "https://github.com/shopify/discount-app-components/blob/main/CHANGELOG.md"
    click AppProvider "https://github.com/shopify/discount-app-components/tree/main/src/components/AppProvider"
    click ActiveDatesCard "https://github.com/shopify/discount-app-components/tree/main/src/components/ActiveDatesCard"
    click CombinationCard "https://github.com/shopify/discount-app-components/tree/main/src/components/CombinationCard"
    click CurrencyField "https://github.com/shopify/discount-app-components/tree/main/src/components/CurrencyField"
    click Storybook "https://github.com/shopify/discount-app-components/tree/main/src/stories"
    click Documentation "https://github.com/shopify/discount-app-components/blob/main/documentation/SAMPLE_README.md"
    click Utilities "https://github.com/shopify/discount-app-components/tree/main/src/utilities"
    click Configurations "https://github.com/shopify/discount-app-components/tree/main/config"
    click CICD "https://github.com/shopify/discount-app-components/tree/main/.github/workflows"
    click Tests "https://github.com/shopify/discount-app-components/tree/main/tests"
```
