# james-phan/eshop architecture

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

- Interactive diagram: https://gitdiagram.com/james-phan/eshop
- Repository: https://github.com/james-phan/eshop

## Overview

##### Main Components
- Frontend/Client Applications:
- Web-based frontends (src/WebApp, src/HybridApp, src/WebhookClient, src/WebAppComponents)
- Mobile client and cross-platform apps (src/ClientApp, src/Mobile.Bff.Shopping)
- Backend/API Services:
- Catalog.API – manages product catalog data and image assets.
- Basket.API – handles shopping basket operations.
- Identity.API – provides authentication, authorization, and user profile management.
- Ordering.API – manages order creation, updates, and order lifecycle commands.
- PaymentProcessor – processes payments and related integration events.
- OrderProcessor – deals with background tasks and order processing workflows.
- Webhooks.API – handles webhook subscriptions and notifications.
- Integration and Messaging:
- EventBus libraries (src/EventBus, src/EventBusRabbitMQ) – responsible for broadcasting integration events between microservices.
- IntegrationEventLogEF – keeps track of integration events and provides resiliency.
- Shared and Infrastructure Components:
- Shared libraries (src/Shared, src/eShop.ServiceDefaults) containing helper methods and cross-cutting concerns.
- Various configuration files, code for dependency injection, extension methods, and migration scripts that support the architecture.
- CI/CD and Build:
- CI/workflow configuration (under .github/workflows, build scripts) that automates deployments, quality checks, and containerization (Docker).

##### Out Relationships and Data Flow
- Client Applications interact with backend APIs (Catalog, Basket, Identity, Ordering, etc.) over REST or gRPC.
- Shared infrastructure services and libraries (such as IntegrationEventLogEF) should be noted as a common resource to ensure reliable event processing and outbox pattern.
- External dependencies: Include components like Azure OpenAI integration (Azure Developer CLI steps in Azure) and Docker, which are used for deployment and runtime configuration.
- Optional: Show testing components (unit and functional tests) that validate the various microservices.

##### Architectural Patterns and Design Principles
- Microservices architecture: Each backend service is built as an independent project (e.g., Catalog.API, Basket.API, Identity.API, Ordering.API, etc.). Emphasize the separation and distinct database/migrations used by various services.
- Event-driven communication: Integration events and the centralized event bus (RabbitMQ) enable asynchronous inter-service communication.
- CI/CD and container-based deployment: Use Docker (as indicated in scripts and CI workflows) and configuration management to deploy the entire system.
- Clean separation between presentation (client UIs) and backend services with a possible API Gateway or BFF (see Mobile.Bff.Shopping).

##### Specific Elements
- API calls from client apps to backend services.
- Event flow between services via the EventBus.
- Data flow (for instance, the catalog service sending product data, basket service managing user baskets, etc.).
- Annotations: Annotate with key concepts like “gRPC communication,” “REST API,” “Integration Events,” and “CI/CD Pipelines.”

1. Client/Presentation Layer (showing WebApp, ClientApp, HybridApp, Mobile.Bff, WebhookClient).
2. Backend Services Layer (grouping Catalog.API, Basket.API, Identity.API, Ordering.API, PaymentProcessor, OrderProcessor, etc.).
3. Integration Layer (central EventBus, IntegrationEventLogEF, RabbitMQ).
4. Infrastructure/Shared Components (Shared libraries and service defaults).
- Next, drill down to illustrate how these layers interact; for example:
- Clients call the API endpoints.
- API services emit integration events that are consumed by other services/regulatory background processes.
- Identity API provides authentication tokens to secure API calls.
- Finally, detail any external services (Docker, Azure deployments, CI/CD pipelines) that interact with the system.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client/Presentation Layer
    subgraph "Client/Presentation Layer"
        A1["WebApp"]:::client
        A2["HybridApp"]:::client
        A3["WebhookClient"]:::client
        A4["WebAppComponents"]:::client
        A5["ClientApp"]:::client
        A6["Mobile.Bff.Shopping"]:::client
    end

    %% Backend/API Services
    subgraph "Backend/API Services"
        B1["Catalog.API"]:::service
        B2["Basket.API"]:::service
        B3["Identity.API"]:::service
        B4["Ordering.API"]:::service
        B5["PaymentProcessor"]:::service
        B6["OrderProcessor"]:::service
        B7["Webhooks.API"]:::service
    end

    %% Integration/Events Layer
    subgraph "Integration/Events"
        C1["EventBus"]:::integration
        C2["RabbitMQEventBus"]:::integration
        C3["IntegrationEventLogEF"]:::integration
    end

    %% Shared/Infrastructure Components
    subgraph "Shared/Infrastructure"
        D1["Shared Libraries"]:::shared
        D2["Service Defaults"]:::shared
    end

    %% CI/CD and External Services
    subgraph "CI/CD Pipeline"
        E1["CI/CD Pipeline"]:::cicd
        E2["Docker"]:::external
        E3["Azure Integration"]:::external
    end

    %% Client to Backend API calls (REST/gRPC)
    A1 -->|"REST/gRPC"| B1
    A1 -->|"REST/gRPC"| B2
    A1 -->|"auth"| B3
    A5 -->|"REST/gRPC"| B4
    A6 -->|"REST/gRPC"| B3

    %% Identity API issues tokens to secure communication with other services
    B3 -->|"issuesToken"| B1
    B3 -->|"issuesToken"| B2
    B3 -->|"issuesToken"| B4

    %% Backend Services publish integration events
    B1 -->|"pubEvent"| C2
    B2 -->|"pubEvent"| C2
    B4 -->|"pubEvent"| C2
    B5 -->|"pubEvent"| C2
    B6 -->|"processEvent"| C2
    B7 -->|"subscribeEvent"| C2

    %% Integration Event logging and bus implementation
    C2 -->|"logEvent"| C3
    C1 -->|"impl"| C2

    %% Backend Services use Shared Libraries and Service Defaults
    B1 -->|"uses"| D1
    B2 -->|"uses"| D1
    B3 -->|"uses"| D1
    B4 -->|"uses"| D1

    B1 -->|"extends"| D2
    B2 -->|"extends"| D2
    B3 -->|"extends"| D2
    B4 -->|"extends"| D2

    %% CI/CD Pipeline deploys components and builds shared libraries
    E1 -->|"deploys"| A1
    E1 -->|"deploys"| A2
    E1 -->|"deploys"| A3
    E1 -->|"deploys"| A4
    E1 -->|"deploys"| A5
    E1 -->|"deploys"| A6
    E1 -->|"deploys"| B1
    E1 -->|"deploys"| B2
    E1 -->|"deploys"| B3
    E1 -->|"deploys"| B4
    E1 -->|"deploys"| B5
    E1 -->|"deploys"| B6
    E1 -->|"deploys"| B7
    E1 -->|"builds"| D1

    %% CI/CD integrates with external services
    E1 -->|"containerizes"| E2
    E2 -->|"runs"| B1
    E2 -->|"runs"| B2
    E2 -->|"runs"| B3
    E2 -->|"runs"| B4
    E3 -->|"configures"| E1

    %% Class definitions for colors and styles
    classDef client fill:#d0e1f9,stroke:#1c608d,stroke-width:2px;
    classDef service fill:#f9d0d0,stroke:#d81c1c,stroke-width:2px;
    classDef integration fill:#d0f9d8,stroke:#1cd81c,stroke-width:2px;
    classDef shared fill:#f9f3d0,stroke:#d8a31c,stroke-width:2px;
    classDef cicd fill:#e0d0f9,stroke:#8d1cba,stroke-width:2px;
    classDef external fill:#f0e0f0,stroke:#a31cad,stroke-width:2px;

    %% Click Events for Component Mapping
    click A1 "https://github.com/james-phan/eshop/tree/main/src/WebApp"
    click A2 "https://github.com/james-phan/eshop/tree/main/src/HybridApp"
    click A3 "https://github.com/james-phan/eshop/tree/main/src/WebhookClient"
    click A4 "https://github.com/james-phan/eshop/tree/main/src/WebAppComponents"
    click A5 "https://github.com/james-phan/eshop/tree/main/src/ClientApp"
    click A6 "https://github.com/james-phan/eshop/blob/main/src/Mobile.Bff.Shopping"
    click B1 "https://github.com/james-phan/eshop/blob/main/src/Catalog.API"
    click B2 "https://github.com/james-phan/eshop/blob/main/src/Basket.API"
    click B3 "https://github.com/james-phan/eshop/blob/main/src/Identity.API"
    click B4 "https://github.com/james-phan/eshop/blob/main/src/Ordering.API"
    click B5 "https://github.com/james-phan/eshop/tree/main/src/PaymentProcessor"
    click B6 "https://github.com/james-phan/eshop/tree/main/src/OrderProcessor"
    click B7 "https://github.com/james-phan/eshop/blob/main/src/Webhooks.API"
    click C1 "https://github.com/james-phan/eshop/tree/main/src/EventBus"
    click C2 "https://github.com/james-phan/eshop/tree/main/src/EventBusRabbitMQ"
    click C3 "https://github.com/james-phan/eshop/tree/main/src/IntegrationEventLogEF"
    click D1 "https://github.com/james-phan/eshop/tree/main/src/Shared"
    click D2 "https://github.com/james-phan/eshop/blob/main/src/eShop.ServiceDefaults"
    click E1 "https://github.com/james-phan/eshop/tree/main/.github/workflows"
```
