# vtex-apps/add-to-cart-button architecture

> Architecture diagram of the GitHub repository vtex-apps/add-to-cart-button, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vtex-apps/add-to-cart-button
- Repository: https://github.com/vtex-apps/add-to-cart-button

## Overview

##### Project type and purpose
- This is a front-end VTEX IO “block” (an add-to-cart-button) packaged as a React/TypeScript app.
- Its sole purpose is to render a configurable “Add to Cart” button on product shelves and detail pages, invoke VTEX Minicart v2 APIs, fire pixel events, and optionally redirect users (one-click buy).

##### File structure
- Top-level config files (.eslintrc, manifest.json, tsconfig.json in react/, store/) indicate a VTEX IO app setup.
- The react/ folder contains:
- Components (AddToCartButton.tsx, Wrapper.tsx)
- Hooks (useMarketingSessionParams.ts)
- Modules (pure functions for mapping catalog items, comparing objects, etc.)
- Tests (__tests__), mocks (__mocks__), and fixtures (__fixtures__) for unit testing and mocking VTEX services.
- The store/ folder holds JSON schemas (contentSchemas.json, interfaces.json) describing the block’s runtime props and data dependencies exposed to the VTEX Store Framework.
- manifest.json declares the block and its dependency on “minicart.v2” (checkout resources) and other VTEX render-runtime services.

##### Review of README for additional insights
- Describes block usage, configuration props, CSS handles, and compatibility with Minicart v2.
- Points to VTEX Store Framework for block composition and theming.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Store Framework Layer
    subgraph "VTEX Store Framework"
        StoreFW["Store Framework"]:::service
        ProductCTX["ProductContext (render-runtime)"]:::service
    end

    %% Block Definition and Config
    subgraph "Add-to-Cart Button Block"
        Manifest["manifest.json"]:::service
        SchemaContent["contentSchemas.json"]:::service
        SchemaInterface["interfaces.json"]:::service
        TSConfig["tsconfig.json"]:::service
        ESLint[".eslintrc"]:::service
        Package["react/package.json"]:::service

        Wrapper["Wrapper"]:::ui
        Button["AddToCartButton"]:::ui
        Hook["useMarketingSessionParams"]:::ui

        subgraph "Business Logic Modules"
            Assembly["assemblyOptions"]:::logic
            CatalogMap["catalogItemToCart"]:::logic
            Compare["compareObjects"]:::logic
        end

        Tests["__tests__"]:::external
        Mocks["__mocks__"]:::external
        Fixtures["__fixtures__"]:::external
        Typings["typings/*.d.ts"]:::external
    end

    %% External Services and APIs
    subgraph "VTEX Services & External APIs"
        CheckoutAPI["minicart.v2 API"]:::service
        PixelMgr["pixel-manager"]:::external
        OrderMgr["order-manager"]:::external
        PWA["PWAContext"]:::external
    end

    %% Data and Dependency Flows
    StoreFW -->|"loads template"| Wrapper
    Wrapper -->|"renders"| Button
    ProductCTX -->|"provides product data"| Button
    Button -->|"uses hook"| Hook
    Button -->|"builds payload"| Assembly
    Assembly --> CatalogMap
    Assembly --> Compare
    CatalogMap --> CheckoutAPI
    Compare --> CheckoutAPI
    Button -->|"calls API"| CheckoutAPI
    CheckoutAPI -->|"updates cart state"| StoreFW
    Button -->|"fires event"| PixelMgr
    Button -->|"optionally calls"| OrderMgr
    Button -->|"reads context"| PWA

    %% Click Events
    click Button "https://github.com/vtex-apps/add-to-cart-button/blob/master/react/AddToCartButton.tsx"
    click Wrapper "https://github.com/vtex-apps/add-to-cart-button/blob/master/react/Wrapper.tsx"
    click Hook "https://github.com/vtex-apps/add-to-cart-button/blob/master/react/hooks/useMarketingSessionParams.ts"
    click Assembly "https://github.com/vtex-apps/add-to-cart-button/blob/master/react/modules/assemblyOptions.ts"
    click CatalogMap "https://github.com/vtex-apps/add-to-cart-button/blob/master/react/modules/catalogItemToCart.ts"
    click Compare "https://github.com/vtex-apps/add-to-cart-button/blob/master/react/modules/compareObjects.ts"
    click Manifest "https://github.com/vtex-apps/add-to-cart-button/blob/master/manifest.json"
    click SchemaContent "https://github.com/vtex-apps/add-to-cart-button/blob/master/store/contentSchemas.json"
    click SchemaInterface "https://github.com/vtex-apps/add-to-cart-button/blob/master/store/interfaces.json"
    click TSConfig "https://github.com/vtex-apps/add-to-cart-button/blob/master/tsconfig.json"
    click ESLint "https://github.com/vtex-apps/add-to-cart-button/blob/master/.eslintrc"
    click Package "https://github.com/vtex-apps/add-to-cart-button/blob/master/react/package.json"
    click Tests "https://github.com/vtex-apps/add-to-cart-button/tree/master/react/__tests__"
    click Mocks "https://github.com/vtex-apps/add-to-cart-button/tree/master/react/__mocks__"
    click Fixtures "https://github.com/vtex-apps/add-to-cart-button/tree/master/react/__fixtures__"
    click Typings "https://github.com/vtex-apps/add-to-cart-button/blob/master/react/typings/*.d.ts"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef logic fill:#D0FFD8,stroke:#333,stroke-width:1px
    classDef service fill:#FFE4B5,stroke:#333,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#333,stroke-width:1px
```
