# fecony/checkout-ts architecture

> Architecture diagram of the GitHub repository fecony/checkout-ts, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fecony/checkout-ts
- Repository: https://github.com/fecony/checkout-ts

## Overview

##### Main Components

a) Core Domain Layer:
- Products (src/models/product.ts)
- Cart (src/models/cart.ts)
- Promotional Rules Hierarchy:
- Base Promotional Rule Interface
- Concrete Rule Implementations:
- Bulk Price Reduction Rule
- Buy One Get One Rule
- Percentage Discount Rule

b) Service Layer:
- Checkout Service
- Promotion Engine Service

##### Component Relationships

**Checkout Service**
- ↓ (uses)
**Promotion Engine**
- ↓ (manages)
**Promotional Rules (Interface)**
- ↑ (implements)
**Concrete Rule Implementations**

**Cart ← → Product (association)**

##### Specific Implementation Details

a) PromotionalRule Interface with methods:
**isApplicable(cart: Cart): boolean**
**apply(cart: Cart): number**

b) Three concrete rule implementations:
- BulkPriceReductionRule
- BuyOneGetOneRule
- PercentageDiscountRule

##### Additional Elements

Supporting elements:

- Relationship types (inheritance, composition, usage)

b) Data flow indicators:
- How products flow through the system
- Discount calculation flow

**[Client/Entry Point]**
- ↓
**[Checkout Service]**
- ↓
**[Promotion Engine]**
- ↓
**[Promotional Rules]**
- ↓
**[Core Domain Models]**

##### Important Notes

- Extensibility of the promotional rules system
- Clear boundaries between services and domain models
- Validation points for products and cart operations
- Error handling flow (reference to errors.ts)

##### Technical Details

- That it's a TypeScript implementation
- Test coverage relationship (parallel structure to src/)
- Build/configuration dependencies

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Entry["Entry Point"]:::entry
    end

    subgraph Services
        CS["Checkout Service"]:::service
        PE["Promotion Engine"]:::service
    end

    subgraph "Domain Models"
        Cart["Cart"]:::model
        Product["Product"]:::model
    end

    subgraph "Promotional Rules"
        PR["Promotional Rule Interface"]:::interface
        BPRR["Bulk Price Reduction Rule"]:::rule
        BOGOR["Buy One Get One Rule"]:::rule
        PDR["Percentage Discount Rule"]:::rule
    end

    subgraph "Error Handling"
        EH["Error Handler"]:::error
    end

    Entry --> CS
    CS --> PE
    CS --> Cart
    PE --> PR
    PR --> |implements| BPRR
    PR --> |implements| BOGOR
    PR --> |implements| PDR
    Cart --> Product
    CS --> EH
    PE --> EH

    %% Click Events
    click Entry "https://github.com/fecony/checkout-ts/blob/main/src/index.ts"
    click CS "https://github.com/fecony/checkout-ts/blob/main/src/services/checkout.ts"
    click PE "https://github.com/fecony/checkout-ts/blob/main/src/services/promotion-engine.ts"
    click Cart "https://github.com/fecony/checkout-ts/blob/main/src/models/cart.ts"
    click Product "https://github.com/fecony/checkout-ts/blob/main/src/models/product.ts"
    click PR "https://github.com/fecony/checkout-ts/blob/main/src/models/promotions/promotional-rule.ts"
    click BPRR "https://github.com/fecony/checkout-ts/blob/main/src/models/promotions/bulk-price-reduction-rule.ts"
    click BOGOR "https://github.com/fecony/checkout-ts/blob/main/src/models/promotions/buy-one-get-one-rule.ts"
    click PDR "https://github.com/fecony/checkout-ts/blob/main/src/models/promotions/percentage-discount-rule.ts"
    click EH "https://github.com/fecony/checkout-ts/blob/main/src/errors.ts"

    %% Styles
    classDef entry fill:#f9f,stroke:#333,stroke-width:2px
    classDef service fill:#90EE90,stroke:#333,stroke-width:2px
    classDef model fill:#ADD8E6,stroke:#333,stroke-width:2px
    classDef interface fill:#FFE4B5,stroke:#333,stroke-width:2px
    classDef rule fill:#FFA07A,stroke:#333,stroke-width:2px
    classDef error fill:#FF6B6B,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1["Entry Point"]:::entry
        L2["Service"]:::service
        L3["Model"]:::model
        L4["Interface"]:::interface
        L5["Rule Implementation"]:::rule
        L6["Error Handling"]:::error
    end
```
