# foolish-wang/w-restore architecture

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

- Interactive diagram: https://gitdiagram.com/foolish-wang/w-restore
- Repository: https://github.com/foolish-wang/w-restore

## Overview

##### Project Type and Key Purpose
- The project is a full-stack e-commerce application.
- The core functions include browsing products, shopping cart operations, order processing, user authentication, and payment processing.
- Additional features include admin product management and AI-based recommendations/chat.

##### Main Components
a. Frontend (Client):
- React application (inside the “client” folder).
- Sub-components/modules such as Catalog, Basket, Checkout, Orders, Account, Chat, and Home.
- That it communicates with the backend API via REST calls.
- Use of Vite as the build tool and TypeScript for type safety.

b. Backend (API):
- Use the “API” directory to structure controllers, DTOs, entities, services, middleware, and data layers.
- Split into:
- Controllers (e.g., AIController, AccountController, ProductsController) managing HTTP requests.
- DTOs for data transfer (like BasketDto, OrderDto, LoginDto).
- Data layer with DbContext (StoreContext) and migrations.
- Domain layer with Entities representing business models (OrderAggregate, User, Product, etc.).
- Services for business logic: PaymentService (with Stripe integration), TokenService (JWT authentication), and any AI integration calls.
- Common utilities/extensions (e.g., BasketExtensions, HttpExtensions) and request helpers (for pagination and filtering).

c. Database:
- PostgreSQL as the database, containerized via Docker.
- EF Core migrations and DbInitializer in the API which creates & updates schema.

d. External/Third-Party Services:
- Stripe for payment processing.
- DeepSeek AI for intelligent product recommendations and chat support.
- Docker for container orchestration (highlight the docker-compose configuration that starts the PostgreSQL container).

##### Relationships & Interactions
- API’s internal flow: Controllers receiving requests, invoking Services to process business logic, and accessing the Database.
- From PaymentService to Stripe’s API.
- From AIController or integration services to DeepSeek AI.
- From the API to Dockerized PostgreSQL.
- Make clear the dependency of the API on user secrets/configuration management for authentication keys and external service keys.

##### Architectural Patterns & Design Principles
- MVC-like pattern in the API structure: Controllers handling HTTP requests, DTOs serving as data contracts, and service classes encapsulating business logic.
- The separation of concerns is clear between frontend & backend components.
- The client is organized using feature-based folder structure, emphasizing modularity and separation of UI concerns.

##### Detailed Elements to Capture
- Configuration aspects like “appsettings.Development.template.json” and use of “dotnet user-secrets” for sensitive information.
- Point out the use of Docker (Dockerfile in API, docker-compose.yml in the project root) to manage containerization.
- How requests flow through middleware (like ExceptionMiddleware) handling error management.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["React App (Client)"]:::frontend
        FE_Cat["Catalog"]:::frontend
        FE_Basket["Basket"]:::frontend
        FE_Checkout["Checkout"]:::frontend
        FE_Orders["Orders"]:::frontend
        FE_Account["Account"]:::frontend
        FE_Chat["Chat"]:::frontend
        FE_Home["Home"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE_API["ASP.NET Core API"]:::backend
        subgraph "API Controllers"
            AI["AIController"]:::controller
            AC["AccountController"]:::controller
            PC["ProductsController"]:::controller
            BC["BasketController"]:::controller
            OC["OrdersController"]:::controller
            PC2["PaymentsController"]:::controller
        end
        DTO["DTOs"]:::dto
        subgraph "Data Access"
            DataLayer["Data Layer"]:::data
            Migrations["EF Core Migrations"]:::data
            Entities["Domain Entities"]:::entities
        end
        subgraph "Business Logic Services"
            PS["PaymentService"]:::services
            TS["TokenService"]:::services
        end
        Utils["Utilities & Extensions"]:::utils
        Middleware["ExceptionMiddleware"]:::middleware
        Dockerfile["Dockerfile"]:::backend
    end

    %% Database Layer
    subgraph "Database Layer"
        DB["Dockerized PostgreSQL"]:::database
    end

    %% External Services
    subgraph "External Services"
        Stripe["Stripe Payment API"]:::external
        DeepSeek["DeepSeek AI"]:::external
        DockerCompose["docker-compose.yml"]:::external
    end

    %% Connections
    FE -->|"RESTCalls"| BE_API

    %% Frontend modules invoking API (optional detailed view)
    FE_Cat -->|"REST"| BE_API
    FE_Basket -->|"REST"| BE_API
    FE_Checkout -->|"REST"| BE_API
    FE_Orders -->|"REST"| BE_API
    FE_Account -->|"REST"| BE_API
    FE_Chat -->|"REST"| BE_API
    FE_Home -->|"REST"| BE_API

    %% API Routing to Controllers
    BE_API -->|"routes"| AI
    BE_API -->|"routes"| AC
    BE_API -->|"routes"| PC
    BE_API -->|"routes"| BC
    BE_API -->|"routes"| OC
    BE_API -->|"routes"| PC2

    %% Controllers invoking Business Logic Services
    AC -->|"calls"| TS
    PC2 -->|"calls"| PS

    %% AIController integration with external AI service
    AI -->|"calls"| DeepSeek

    %% Services interacting with Data Layer
    TS -->|"logic"| DataLayer
    PS -->|"logic"| DataLayer

    %% Data access to Database and Migrations
    DataLayer -->|"accesses"| DB
    DataLayer -->|"manages"| Migrations

    %% Middleware for error handling within API
    BE_API -->|"handlesErrors"| Middleware

    %% API Dockerfile and containerization
    BE_API -->|"containerizedBy"| Dockerfile

    %% PaymentService external integration with Stripe
    PS -->|"integrates"| Stripe

    %% Orchestration: docker-compose manages PostgreSQL container
    DockerCompose -->|"orchestrates"| DB

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef controller fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef dto fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef data fill:#9370DB,stroke:#333,stroke-width:2px;
    classDef entities fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef services fill:#FFFF99,stroke:#333,stroke-width:2px;
    classDef utils fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef middleware fill:#F08080,stroke:#333,stroke-width:2px;
    classDef database fill:#87CEFA,stroke:#333,stroke-width:2px;
    classDef external fill:#F5DEB3,stroke:#333,stroke-width:2px;

    %% Click Events for Frontend Components
    click FE "https://github.com/foolish-wang/w-restore/tree/main/client"
    click FE_Cat "https://github.com/foolish-wang/w-restore/tree/main/client/src/features/catalog"
    click FE_Basket "https://github.com/foolish-wang/w-restore/tree/main/client/src/features/basket"
    click FE_Checkout "https://github.com/foolish-wang/w-restore/tree/main/client/src/features/checkout"
    click FE_Orders "https://github.com/foolish-wang/w-restore/tree/main/client/src/features/orders"
    click FE_Account "https://github.com/foolish-wang/w-restore/tree/main/client/src/features/account"
    click FE_Chat "https://github.com/foolish-wang/w-restore/tree/main/client/src/features/chat"
    click FE_Home "https://github.com/foolish-wang/w-restore/tree/main/client/src/features/home"

    %% Click Events for Backend Components
    click BE_API "https://github.com/foolish-wang/w-restore/tree/main/API"
    click AI "https://github.com/foolish-wang/w-restore/blob/main/API/Controllers/AIController.cs"
    click AC "https://github.com/foolish-wang/w-restore/blob/main/API/Controllers/AccountController.cs"
    click PC "https://github.com/foolish-wang/w-restore/blob/main/API/Controllers/ProductsController.cs"
    click BC "https://github.com/foolish-wang/w-restore/blob/main/API/Controllers/BasketController.cs"
    click OC "https://github.com/foolish-wang/w-restore/blob/main/API/Controllers/OrdersController.cs"
    click PC2 "https://github.com/foolish-wang/w-restore/blob/main/API/Controllers/PaymentsController.cs"
    click DTO "https://github.com/foolish-wang/w-restore/tree/main/API/DTOs"
    click DataLayer "https://github.com/foolish-wang/w-restore/tree/main/API/Data"
    click Migrations "https://github.com/foolish-wang/w-restore/tree/main/API/Data/Migrations"
    click Entities "https://github.com/foolish-wang/w-restore/tree/main/API/Entities"
    click PS "https://github.com/foolish-wang/w-restore/blob/main/API/Services/PaymentService.cs"
    click TS "https://github.com/foolish-wang/w-restore/blob/main/API/Services/TokenService.cs"
    click Utils "https://github.com/foolish-wang/w-restore/tree/main/API/Extensions"
    click Middleware "https://github.com/foolish-wang/w-restore/blob/main/API/Middleware/ExceptionMiddleware.cs"
    click Dockerfile "https://github.com/foolish-wang/w-restore/tree/main/API/Dockerfile"

    %% Click Event for docker-compose file
    click DockerCompose "https://github.com/foolish-wang/w-restore/blob/main/docker-compose.yml"
```
