# pitt500/onlinestoretca architecture

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

- Interactive diagram: https://gitdiagram.com/pitt500/onlinestoretca
- Repository: https://github.com/pitt500/onlinestoretca

## Overview

1. This is an iOS SwiftUI app built with The Composable Architecture (TCA 1.15.2) on iOS 17.6+, organized as a feature-sliced demo of a storefront: products, cart, profile, and tab-based root navigation.

2. The app entry point is `OnlineStoreTCAApp`, which creates the root `Store` and injects the live root reducer. The root view (`RootView`) owns the top-level `TabView` selection and scopes state/actions down into the product and profile tabs.

3. `RootDomain` is the composition boundary for the whole app. It holds shared dependencies and child state for `ProductListDomain` and `ProfileDomain`, then routes actions to those child reducers via `Scope`. This is the main orchestration layer.

4. The products subsystem is centered on `ProductListDomain`, which fetches product data asynchronously from the external fake store API through `APIClient`. It tracks loading status (`DataLoadingStatus`) and turns fetched products into `IdentifiedArrayOf<ProductDomain.State>` so each product cell becomes its own child feature.

5. `ProductDomain` represents a single product row/cell. It composes `AddToCartDomain` as a child reducer and exposes a product-specific view (`ProductCell`) that scopes the nested button state/actions. This keeps product presentation, quantity state, and add-to-cart behavior isolated.

6. `AddToCartDomain` is the smallest interactive unit in the products flow. It handles increment/decrement and add-to-cart interactions, and its UI is built from reusable button views (`AddToCartButton`, `PlusMinusButton`). This feature is reused inside each product cell rather than owning global cart logic.

7. The cart subsystem lives in `CartListDomain`, with supporting models like `CartItem` and `CartItemDomain`. It manages the list of selected items, total/order-related state, and purchase flow. Cart presentation is shown as an optional sheet from the product list/root flow.

8. Navigation is modeled in TCA state rather than as ad hoc SwiftUI bindings. The app uses `@Presents` for optional presented state, `PresentationAction` for alert/sheet actions, and reducer `ifLet` to attach destination reducers. Alerts are used for purchase confirmation/success, and the cart is presented modally as a sheet.

9. `ProfileDomain` is a separate tab feature with its own view and user model (`UserProfile`). It is composed into the root alongside the product list, showing that the app keeps each major screen as an independent reducer/view pair.

10. Data flow is consistently unidirectional: user events originate in SwiftUI views, are sent to stores, reduced into state changes or async effects, and then re-rendered by `WithViewStore`, `ForEachStore`, or `IfLetStore`. External work is isolated behind `APIClient` and async `Effect` tasks.

11. The repository also includes feature-level tests under each domain’s `Test` folder plus a top-level `OnlineStoreTCATests`. Tests use `TestStore` to assert exact state transitions and to mock async dependencies like product fetch/order submission, reinforcing reducer boundaries.

12. Asset-wise, the app is lightweight and self-contained: catalog images and app icons are stored in `Assets.xcassets`, while the `Images` folder is used for README documentation/screenshots rather than runtime logic.

Main entry points: [`OnlineStoreTCA/Root/RootDomain.swift`](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Root/RootDomain.swift) (Root domain), [`OnlineStoreTCA/CartList/CartListDomain.swift`](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/CartList/CartListDomain.swift) (Cart list), [`OnlineStoreTCA/Products/ProductList/ProductListDomain.swift`](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Products/ProductList/ProductListDomain.swift) (Product list), [`OnlineStoreTCA/Products/Product/ProductDomain.swift`](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Products/Product/ProductDomain.swift) (Product row)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_root["Root"]
  node_app["App entry<br/>SwiftUI app"]
  node_root_domain["Root domain<br/>tca root<br/>[RootDomain.swift]"]
  node_root_view["Root view<br/>tab shell<br/>[RootView.swift]"]
end

subgraph group_products["Products"]
  node_product_list["Product list<br/>catalog feature"]
  node_product_list_view["List view<br/>catalog UI"]
  node_product_domain["Product row<br/>cell feature"]
  node_product_cell["Product cell<br/>row view<br/>[ProductCell.swift]"]
  node_add_to_cart["Add to cart<br/>qty control"]
  node_add_to_cart_ui["Cart buttons<br/>control UI"]
end

subgraph group_cart["Cart"]
  node_cart_list["Cart list<br/>cart feature"]
  node_cart_view["Cart view<br/>cart UI<br/>[CartListView.swift]"]
  node_cart_item_domain["Cart item<br/>item feature"]
end

subgraph group_profile["Profile"]
  node_profile_domain["Profile tab<br/>profile feature"]
  node_profile_view["Profile view<br/>profile UI<br/>[ProfileView.swift]"]
end

subgraph group_network["Network"]
  node_api_client["API client<br/>http client<br/>[APIClient.swift]"]
  node_load_status["Load status<br/>state model"]
end

subgraph group_tests["Tests"]
  node_tca_tests["App tests<br/>test suite"]
  node_product_tests["Product tests<br/>test suite"]
  node_cart_tests["Cart tests<br/>test suite"]
end

node_app -->|"creates store"| node_root_domain
node_root_domain -->|"hosts"| node_root_view
node_root_domain -->|"scopes"| node_product_list
node_root_domain -->|"scopes"| node_profile_domain
node_root_view -->|"renders"| node_product_list_view
node_root_view -->|"renders"| node_profile_view
node_product_list -->|"fetches"| node_api_client
node_product_list -->|"tracks"| node_load_status
node_product_list -->|"creates"| node_product_domain
node_product_list_view -->|"lists"| node_product_cell
node_product_domain -->|"presents"| node_product_cell
node_product_domain -->|"composes"| node_add_to_cart
node_product_cell -->|"uses"| node_add_to_cart_ui
node_add_to_cart -->|"drives"| node_add_to_cart_ui
node_root_domain -->|"presents"| node_cart_list
node_product_list -->|"opens"| node_cart_list
node_cart_list -->|"renders"| node_cart_view
node_cart_list -->|"contains"| node_cart_item_domain
node_cart_list -.->|"shares"| node_profile_domain
node_product_tests -->|"covers"| node_product_domain
node_product_tests -->|"covers"| node_add_to_cart
node_cart_tests -->|"covers"| node_cart_list
node_tca_tests -->|"covers"| node_root_domain

click node_app "https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Root/OnlineStoreTCAApp.swift"
click node_root_domain "https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Root/RootDomain.swift"
click node_root_view "https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Root/RootView.swift"
click node_product_list "https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Products/ProductList/ProductListDomain.swift"
click node_product_list_view "https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Products/ProductList/ProductListView.swift"
click node_product_domain "https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Products/Product/ProductDomain.swift"
click node_product_cell "https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Products/Product/ProductCell.swift"
click node_add_to_cart "https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Products/AddToCart/AddToCartDomain.swift"
click node_add_to_cart_ui "https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Products/AddToCart/AddToCartButton.swift"
click node_cart_list "https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/CartList/CartListDomain.swift"
click node_cart_view "https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/CartList/CartListView.swift"
click node_cart_item_domain "https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/CartList/Cart/CartItemDomain.swift"
click node_profile_domain "https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Profile/ProfileDomain.swift"
click node_profile_view "https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Profile/ProfileView.swift"
click node_api_client "https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Network/APIClient.swift"
click node_load_status "https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Network/DataLoadingStatus.swift"
click node_tca_tests "https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCATests/OnlineStoreTCATests.swift"
click node_product_tests "https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Products/Product/Test/ProductDomainTest.swift"
click node_cart_tests "https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/CartList/Test/CartListDomainTest.swift"

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_app,node_root_domain,node_root_view toneBlue
class node_product_list,node_product_list_view,node_product_domain,node_product_cell,node_add_to_cart,node_add_to_cart_ui toneAmber
class node_cart_list,node_cart_view,node_cart_item_domain toneMint
class node_profile_domain,node_profile_view toneRose
class node_api_client,node_load_status toneIndigo
class node_tca_tests,node_product_tests,node_cart_tests toneTeal
```

## Components

### Root

App entry and top-level composition

- [App entry](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Root/OnlineStoreTCAApp.swift): SwiftUI app · Creates the root store and launches the app. · `OnlineStoreTCA/Root/OnlineStoreTCAApp.swift`
- [Root domain](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Root/RootDomain.swift): tca root · Top-level composition boundary for tabs and shared state. · `OnlineStoreTCA/Root/RootDomain.swift`
- [Root view](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Root/RootView.swift): tab shell · Owns tab selection and scopes state into child tabs. · `OnlineStoreTCA/Root/RootView.swift`

### Products

Catalog browsing and add-to-cart flow

- [Product list](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Products/ProductList/ProductListDomain.swift): catalog feature · Fetches products and manages the main storefront list. · `OnlineStoreTCA/Products/ProductList/ProductListDomain.swift`
- [List view](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Products/ProductList/ProductListView.swift): catalog UI · Renders loading, errors, and the product list. · `OnlineStoreTCA/Products/ProductList/ProductListView.swift`
- [Product row](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Products/Product/ProductDomain.swift): cell feature · Per-product state and behavior for a single catalog item. · `OnlineStoreTCA/Products/Product/ProductDomain.swift`
- [Product cell](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Products/Product/ProductCell.swift): row view · Presentation for one product and its nested controls. · `OnlineStoreTCA/Products/Product/ProductCell.swift`
- [Add to cart](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Products/AddToCart/AddToCartDomain.swift): qty control · Increment/decrement and add-to-cart interaction unit. · `OnlineStoreTCA/Products/AddToCart/AddToCartDomain.swift`
- [Cart buttons](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Products/AddToCart/AddToCartButton.swift): control UI · Reusable plus/minus and action buttons for quantity selection. · `OnlineStoreTCA/Products/AddToCart/AddToCartButton.swift`

### Cart

Selected items and checkout flow

- [Cart list](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/CartList/CartListDomain.swift): cart feature · Owns selected items, totals, and purchase flow. · `OnlineStoreTCA/CartList/CartListDomain.swift`
- [Cart view](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/CartList/CartListView.swift): cart UI · Modal cart presentation and list rendering. · `OnlineStoreTCA/CartList/CartListView.swift`
- [Cart item](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/CartList/Cart/CartItemDomain.swift): item feature · Per-item cart state and row behavior. · `OnlineStoreTCA/CartList/Cart/CartItemDomain.swift`

### Profile

User profile tab

- [Profile tab](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Profile/ProfileDomain.swift): profile feature · Independent user profile reducer and view pair. · `OnlineStoreTCA/Profile/ProfileDomain.swift`
- [Profile view](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Profile/ProfileView.swift): profile UI · Renders the profile screen. · `OnlineStoreTCA/Profile/ProfileView.swift`

### Network

External data and loading state

- [API client](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Network/APIClient.swift): http client · Fetches product data from the external store API. · `OnlineStoreTCA/Network/APIClient.swift`
- [Load status](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Network/DataLoadingStatus.swift): state model · Represents loading and error state for async fetches. · `OnlineStoreTCA/Network/DataLoadingStatus.swift`

### Tests

Reducer tests

- [App tests](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCATests/OnlineStoreTCATests.swift): test suite · Top-level reducer and integration coverage. · `OnlineStoreTCATests/OnlineStoreTCATests.swift`
- [Product tests](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/Products/Product/Test/ProductDomainTest.swift): test suite · Reducer tests for catalog and add-to-cart behavior. · `OnlineStoreTCA/Products/Product/Test/ProductDomainTest.swift`
- [Cart tests](https://github.com/pitt500/onlinestoretca/blob/main/OnlineStoreTCA/CartList/Test/CartListDomainTest.swift): test suite · Reducer tests for cart list behavior. · `OnlineStoreTCA/CartList/Test/CartListDomainTest.swift`

## Connections

- App entry → Root domain: creates store · App bootstraps the root reducer and state.
- Root domain → Root view: hosts · Root state drives the tab shell view.
- Root domain → Product list: scopes · Routes product tab state and actions into the catalog feature.
- Root domain → Profile tab: scopes · Routes profile tab state and actions into the profile feature.
- Root view → List view: renders · Tab content is rendered through the product list view.
- Root view → Profile view: renders · Tab content is rendered through the profile view.
- Product list → API client: fetches · Loads products asynchronously from the external API client.
- Product list → Load status: tracks · Maintains loading and error state for catalog fetches.
- Product list → Product row: creates · Maps fetched products into child row features.
- List view → Product cell: lists · Displays a collection of product cells.
- Product row → Product cell: presents · Each product feature owns its cell view.
- Product row → Add to cart: composes · Each row embeds the add-to-cart subfeature.
- Product cell → Cart buttons: uses · Cell UI includes the reusable button controls.
- Add to cart → Cart buttons: drives · Quantity and add actions are handled by the control unit.
- Root domain → Cart list: presents · Cart is attached as presented destination state.
- Product list → Cart list: opens · Catalog flow can trigger the cart sheet.
- Cart list → Cart view: renders · Cart reducer is presented through the cart view.
- Cart list → Cart item: contains · Cart list manages item-level child state.
- Cart list → Profile tab: shares · Profile remains a sibling feature at the root boundary.
- Product tests → Product row: covers · Validates product reducer behavior.
- Product tests → Add to cart: covers · Validates add-to-cart interactions.
- Cart tests → Cart list: covers · Validates cart reducer behavior.
- App tests → Root domain: covers · Top-level tests assert app orchestration.
