# dhyaa-km/typescript-ecommerce-cart architecture

> Architecture diagram of the GitHub repository dhyaa-km/typescript-ecommerce-cart, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dhyaa-km/typescript-ecommerce-cart
- Repository: https://github.com/dhyaa-km/typescript-ecommerce-cart

## Overview

A vanilla TypeScript storefront lets shoppers browse products fetched from Fake Store API, search them, add them to a persistent cart, and manage quantities and order totals on the cart page. The map separates product retrieval, shop rendering, cart operations/state, and cart-page presentation. The sampled source confirms the main shop workflow and cart behavior; cart persistence and the cart page are implemented directly in their respective modules. Relationships involving HTML entry wiring are omitted because those files were not sampled.

Main entry points: [`ecommerce-carttt/src/main.ts`](https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/main.ts) (Shop Entry), [`ecommerce-carttt/src/services/cartService.ts`](https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/services/cartService.ts) (Cart Service), [`ecommerce-carttt/src/ui/renderProducts.ts`](https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/ui/renderProducts.ts) (Product Grid), [`ecommerce-carttt/src/services/productService.ts`](https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/services/productService.ts) (Product Service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_catalog["Product Catalog"]
  node_product_service["Product Service<br/>[productService.ts]"]
  node_search["Product Search<br/>[search.ts]"]
end

subgraph group_cart["Cart Management"]
  node_cart_service["Cart Service<br/>[cartService.ts]"]
  node_cart_state[("Persistent Cart State<br/>[cartState.ts]")]
end

subgraph group_presentation["Shop &amp; Cart UI"]
  node_shop_entry["Shop Entry<br/>[main.ts]"]
  node_product_grid["Product Grid<br/>[renderProducts.ts]"]
  node_cart_view["Shop Cart View<br/>[renderCart.ts]"]
  node_cart_page["Cart Page<br/>[Cartpage.ts]"]
end

subgraph group_shared["Shared Types &amp; Formatting"]
  node_product_types["Product Types<br/>[types.ts]"]
  node_price_format["Price Formatting<br/>[format.ts]"]
end

node_shopper(("Shopper"))
node_fake_store{{"Fake Store API"}}
node_local_storage[("Browser LocalStorage")]

node_shopper -->|"opens shop"| node_shop_entry
node_shop_entry -->|"fetches products"| node_product_service
node_product_service -->|"requests catalog"| node_fake_store
node_product_service -->|"returns products"| node_product_types
node_shop_entry -->|"renders products"| node_product_grid
node_shop_entry -->|"initializes search"| node_search
node_search -->|"renders filtered"| node_product_grid
node_product_grid -->|"adds product"| node_cart_service
node_cart_service -->|"updates state"| node_cart_state
node_cart_service -->|"renders cart"| node_cart_view
node_cart_state -->|"loads and saves"| node_local_storage
node_cart_view -->|"removes or updates"| node_cart_service
node_cart_page -->|"reads and updates"| node_cart_state
node_cart_page -->|"formats totals"| node_price_format
node_product_grid -->|"formats prices"| node_price_format

click node_shop_entry "https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/main.ts"
click node_product_service "https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/services/productService.ts"
click node_product_types "https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/types.ts"
click node_product_grid "https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/ui/renderProducts.ts"
click node_search "https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/ui/search.ts"
click node_cart_service "https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/services/cartService.ts"
click node_cart_state "https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/state/cartState.ts"
click node_cart_view "https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/ui/renderCart.ts"
click node_cart_page "https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/Cartpage.ts"
click node_price_format "https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/utils/format.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_product_service,node_search toneBlue
class node_cart_service,node_cart_state,node_local_storage toneAmber
class node_shop_entry,node_product_grid,node_cart_view,node_cart_page,node_fake_store toneMint
class node_product_types,node_price_format toneRose
class node_shopper toneIndigo
```

## Components

### Product Catalog

- [Product Service](https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/services/productService.ts): `ecommerce-carttt/src/services/productService.ts`
- [Product Search](https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/ui/search.ts): `ecommerce-carttt/src/ui/search.ts`

### Cart Management

- [Cart Service](https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/services/cartService.ts): `ecommerce-carttt/src/services/cartService.ts`
- [Persistent Cart State](https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/state/cartState.ts): `ecommerce-carttt/src/state/cartState.ts`

### Shop & Cart UI

- [Shop Entry](https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/main.ts): `ecommerce-carttt/src/main.ts`
- [Product Grid](https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/ui/renderProducts.ts): `ecommerce-carttt/src/ui/renderProducts.ts`
- [Shop Cart View](https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/ui/renderCart.ts): `ecommerce-carttt/src/ui/renderCart.ts`
- [Cart Page](https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/Cartpage.ts): `ecommerce-carttt/src/Cartpage.ts`

### Shared Types & Formatting

- [Product Types](https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/types.ts): `ecommerce-carttt/src/types.ts`
- [Price Formatting](https://github.com/dhyaa-km/typescript-ecommerce-cart/blob/main/ecommerce-carttt/src/utils/format.ts): `ecommerce-carttt/src/utils/format.ts`

### Other components

- **Shopper**
- **Fake Store API**
- **Browser LocalStorage**

## Connections

- Shopper → Shop Entry: opens shop (evidence: `readme.md`)
- Shop Entry → Product Service: fetches products (evidence: `ecommerce-carttt/src/main.ts`)
- Product Service → Fake Store API: requests catalog (evidence: `ecommerce-carttt/src/services/productService.ts`)
- Product Service → Product Types: returns products (evidence: `ecommerce-carttt/src/services/productService.ts`)
- Shop Entry → Product Grid: renders products (evidence: `ecommerce-carttt/src/main.ts`)
- Shop Entry → Product Search: initializes search (evidence: `ecommerce-carttt/src/main.ts`)
- Product Search → Product Grid: renders filtered (evidence: `ecommerce-carttt/src/ui/search.ts`)
- Product Grid → Cart Service: adds product (evidence: `ecommerce-carttt/src/ui/renderProducts.ts`)
- Cart Service → Persistent Cart State: updates state (evidence: `ecommerce-carttt/src/services/cartService.ts`)
- Cart Service → Shop Cart View: renders cart (evidence: `ecommerce-carttt/src/services/cartService.ts`)
- Persistent Cart State → Browser LocalStorage: loads and saves (evidence: `ecommerce-carttt/src/state/cartState.ts`)
- Shop Cart View → Cart Service: removes or updates (evidence: `ecommerce-carttt/src/ui/renderCart.ts`)
- Cart Page → Persistent Cart State: reads and updates (evidence: `ecommerce-carttt/src/Cartpage.ts`)
- Cart Page → Price Formatting: formats totals (evidence: `ecommerce-carttt/src/Cartpage.ts`)
- Product Grid → Price Formatting: formats prices (evidence: `ecommerce-carttt/src/ui/renderProducts.ts`)
