How pitt500/onlinestoretca works
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: RootDomain.swift Root domain · CartListDomain.swift Cart list · ProductListDomain.swift Product list · ProductDomain.swift Product row
Components 19
Root
App entry and top-level composition
- App entry · Creates the root store and launches the app.
OnlineStoreTCA/Root/OnlineStoreTCAApp.swift - Root domain · Top-level composition boundary for tabs and shared state.
OnlineStoreTCA/Root/RootDomain.swift - Root view · Owns tab selection and scopes state into child tabs.
OnlineStoreTCA/Root/RootView.swift
Products
Catalog browsing and add-to-cart flow
- Product list · Fetches products and manages the main storefront list.
OnlineStoreTCA/Products/ProductList/ProductListDomain.swift - List view · Renders loading, errors, and the product list.
OnlineStoreTCA/Products/ProductList/ProductListView.swift - Product row · Per-product state and behavior for a single catalog item.
OnlineStoreTCA/Products/Product/ProductDomain.swift - Product cell · Presentation for one product and its nested controls.
OnlineStoreTCA/Products/Product/ProductCell.swift - Add to cart · Increment/decrement and add-to-cart interaction unit.
OnlineStoreTCA/Products/AddToCart/AddToCartDomain.swift - Cart buttons · Reusable plus/minus and action buttons for quantity selection.
OnlineStoreTCA/Products/AddToCart/AddToCartButton.swift
Cart
Selected items and checkout flow
- Cart list · Owns selected items, totals, and purchase flow.
OnlineStoreTCA/CartList/CartListDomain.swift - Cart view · Modal cart presentation and list rendering.
OnlineStoreTCA/CartList/CartListView.swift - Cart item · Per-item cart state and row behavior.
OnlineStoreTCA/CartList/Cart/CartItemDomain.swift
Profile
User profile tab
- Profile tab · Independent user profile reducer and view pair.
OnlineStoreTCA/Profile/ProfileDomain.swift - Profile view · Renders the profile screen.
OnlineStoreTCA/Profile/ProfileView.swift
Network
External data and loading state
- API client · Fetches product data from the external store API.
OnlineStoreTCA/Network/APIClient.swift - Load status · Represents loading and error state for async fetches.
OnlineStoreTCA/Network/DataLoadingStatus.swift
Tests
Reducer tests
- App tests · Top-level reducer and integration coverage.
OnlineStoreTCATests/OnlineStoreTCATests.swift - Product tests · Reducer tests for catalog and add-to-cart behavior.
OnlineStoreTCA/Products/Product/Test/ProductDomainTest.swift - Cart tests · Reducer tests for cart list behavior.
OnlineStoreTCA/CartList/Test/CartListDomainTest.swift
Connections 23
- 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.