# alimhtsai/e_commerce architecture

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

- Interactive diagram: https://gitdiagram.com/alimhtsai/e_commerce
- Repository: https://github.com/alimhtsai/e_commerce

## Overview

##### Project type and purpose
- This is a full-stack e-commerce shopping site.
- Frontend: Angular SPA with modules for shop, basket, checkout, orders, account.
- Backend: ASP.NET Core REST API implementing repository, unit-of-work, specification patterns; uses EF Core against SQLite (identity.db) and Redis for basket caching; integrates Stripe for payments via webhooks.

##### File structure
- Top level:
- API/ – ASP.NET Core Web API
- Core/ – domain entities, interfaces, specifications
- Infrastructure/ – EF Core DbContexts, repositories, migrations, services
- client/ – Angular application
- docker-compose.yml – spins up Redis container
- Patterns:
- API.Controllers → Controllers
- Core.Interfaces → repository/unit-of-work/ token/ payment service abstractions
- Core.Specifications & Infrastructure.Data.SpecificationEvaluator → specification pattern for querying
- Infrastructure.Data.GenericRepository & UnitOfWork → data access
- Infrastructure.Services → business-facing implementations (OrderService, PaymentService, TokenService, ResponseCacheService)

a. Main components:
– Angular Frontend (client)
– ASP.NET Core API (Controllers → ApplicationServicesExtensions → Services)
– Domain Layer (Core.Entities & Core.Interfaces)
– Persistence Layer (Infrastructure.Data StoreContext & AppIdentityDbContext)
– Redis Cache service (in Docker container)
– Stripe External Payment Service
– SQLite-based identity.db for user accounts
b. Relationships & interactions:
– Browser → Angular HTTPClient → API Controllers (Account, Products, Basket, Orders, Payments)
– Controllers → Core Interfaces (IProductRepository, IBasketRepository, IOrderService, IPaymentService)
– Interfaces → Infrastructure implementations → EF Core contexts → SQL data store
– BasketController uses IResponseCacheService → Redis
– PaymentsController calls PaymentService → Stripe API & listens to webhooks
– TokenService issues JWT via ASP.NET Identity
c. Architectural patterns:
– Layered architecture: Presentation (Angular), API layer, Application/Domain (Core), Persistence (Infrastructure), External services
– Repository + Unit of Work for data decoupling
– Specification pattern for flexible querying
– Dependency Injection throughout ASP.NET Core and Angular
d. Technologies:
– Angular, TypeScript, Bootstrap; ASP.NET Core, C#; EF Core; Redis; Docker Compose; SQLite; Stripe; JWT; ASP.NET Identity

##### Detail level
- Break the API layer into sub-components: Controllers, Services, Repositories, EF Core contexts
- Where JWT tokens are generated and checked (TokenService, Auth guard/ JWT interceptor)
- How the specification evaluator constructs queries, then GenericRepository executes them
- Redis caching path on basket requests (via CachedAttribute)

## Diagram (Mermaid)

```mermaid
graph TD
    Browser["Browser"]:::external

    subgraph Frontend
        direction TB
        ShopModule["Shop Module"]:::frontend
        BasketModule["Basket Module"]:::frontend
        CheckoutModule["Checkout Module"]:::frontend
        OrdersModule["Orders Module"]:::frontend
        AccountModule["Account Module"]:::frontend
        JWTInterceptor["JWT Interceptor"]:::frontend
        AuthGuard["Auth Guard"]:::frontend
    end

    subgraph API_Layer["API Layer"]
        direction TB
        Controllers["API Controllers"]:::api
        ExceptionMiddleware["Exception Middleware"]:::api
        ApplicationServicesExt["ApplicationServicesExtensions"]:::api
        CachedAttribute["CachedAttribute"]:::api
    end

    subgraph Domain_Layer["Domain Layer"]
        direction TB
        Entities["Domain Entities"]:::domain
        Interfaces["Domain Interfaces"]:::domain
        Specifications["Specifications"]:::domain
    end

    subgraph Persistence_Layer["Persistence Layer"]
        direction TB
        StoreContext["StoreContext"]:::persistence
        AppIdentityDbContext["AppIdentityDbContext"]:::persistence
        GenericRepo["GenericRepository"]:::persistence
        SpecEvaluator["SpecificationEvaluator"]:::persistence
        ProductRepo["ProductRepository"]:::persistence
        BasketRepo["BasketRepository"]:::persistence
        UnitOfWork["UnitOfWork"]:::persistence
        MigrationsStore["Migrations (Store)"]:::persistence
        MigrationsIdentity["Migrations (Identity)"]:::persistence
        SQLiteDB["identity.db"]:::persistence
        RedisCache["Redis Cache"]:::persistence
    end

    External["Stripe"]:::external

    Browser -->|"routes via"| ShopModule
    ShopModule -->|"HTTP" | Controllers
    BasketModule -->|"HTTP" | Controllers
    CheckoutModule -->|"HTTP" | Controllers
    OrdersModule -->|"HTTP" | Controllers
    AccountModule -->|"HTTP" | Controllers
    JWTInterceptor -->|applies JWT| Controllers
    AuthGuard -->|guards routes| ShopModule

    Controllers -->|uses| Interfaces
    Controllers -->|calls| OrderService{"OrderService"}:::api
    Controllers -->|calls| PaymentService{"PaymentService"}:::api
    Controllers -->|uses| TokenService{"TokenService"}:::api
    Controllers -->|uses| ResponseCacheService{"ResponseCacheService"}:::api
    Controllers -->|applies| CachedAttribute
    Controllers -->|handled by| ExceptionMiddleware
    Controllers -->|registered in| ApplicationServicesExt

    Interfaces -->|implemented by| ProductRepo
    Interfaces -->|implemented by| BasketRepo
    Interfaces -->|implemented by| UnitOfWork
    Interfaces -->|implemented by| OrderService{"OrderService"}:::api
    Interfaces -->|implemented by| PaymentService{"PaymentService"}:::api
    Interfaces -->|implemented by| TokenService{"TokenService"}:::api
    Interfaces -->|implemented by| ResponseCacheService{"ResponseCacheService"}:::api

    ProductRepo -->|uses| StoreContext
    BasketRepo -->|uses| StoreContext
    GenericRepo -->|executes| SpecEvaluator
    StoreContext -->|migrations| MigrationsStore
    AppIdentityDbContext -->|migrations| MigrationsIdentity
    AppIdentityDbContext -->|database file| SQLiteDB
    ResponseCacheService -->|connects to| RedisCache

    PaymentService -->|dashed| External
    class PaymentService,OrderService,TokenService,ResponseCacheService api

    classDef frontend fill:#9f6,stroke:#333
    classDef api fill:#6bf,stroke:#333
    classDef domain fill:#bbb,stroke:#333
    classDef persistence fill:#c69,stroke:#333
    classDef external fill:#f90,stroke:#333,stroke-dasharray:5 5

    click ShopModule "https://github.com/alimhtsai/e_commerce/tree/main/client/src/app/shop"
    click BasketModule "https://github.com/alimhtsai/e_commerce/tree/main/client/src/app/basket"
    click CheckoutModule "https://github.com/alimhtsai/e_commerce/tree/main/client/src/app/checkout"
    click OrdersModule "https://github.com/alimhtsai/e_commerce/tree/main/client/src/app/orders"
    click AccountModule "https://github.com/alimhtsai/e_commerce/tree/main/client/src/app/account"
    click JWTInterceptor "https://github.com/alimhtsai/e_commerce/blob/main/client/src/app/core/interceptors/jwt.interceptor.ts"
    click AuthGuard "https://github.com/alimhtsai/e_commerce/blob/main/client/src/app/core/guards/auth.guard.ts"
    click Controllers "https://github.com/alimhtsai/e_commerce/tree/main/API/Controllers"
    click CachedAttribute "https://github.com/alimhtsai/e_commerce/blob/main/API/Helpers/CachedAttribute.cs"
    click ExceptionMiddleware "https://github.com/alimhtsai/e_commerce/blob/main/API/MiddleWare/ExceptionMiddleware.cs"
    click ApplicationServicesExt "https://github.com/alimhtsai/e_commerce/blob/main/API/Extensions/ApplicationServicesExtensions.cs"
    click Entities "https://github.com/alimhtsai/e_commerce/tree/main/Core/Entities"
    click Interfaces "https://github.com/alimhtsai/e_commerce/tree/main/Core/Interfaces"
    click Specifications "https://github.com/alimhtsai/e_commerce/tree/main/Core/Specifications"
    click StoreContext "https://github.com/alimhtsai/e_commerce/blob/main/Infrastructure/Data/StoreContext.cs"
    click AppIdentityDbContext "https://github.com/alimhtsai/e_commerce/blob/main/Infrastructure/Identity/AppIdentityDbContext.cs"
    click GenericRepo "https://github.com/alimhtsai/e_commerce/blob/main/Infrastructure/Data/GenericRepository.cs"
    click SpecEvaluator "https://github.com/alimhtsai/e_commerce/blob/main/Infrastructure/Data/SpecificationEvaluator.cs"
    click ProductRepo "https://github.com/alimhtsai/e_commerce/blob/main/Infrastructure/Data/ProductRepository.cs"
    click BasketRepo "https://github.com/alimhtsai/e_commerce/blob/main/Infrastructure/Data/BasketRepository.cs"
    click UnitOfWork "https://github.com/alimhtsai/e_commerce/blob/main/Infrastructure/Data/UnitOfWork.cs"
    click OrderService "https://github.com/alimhtsai/e_commerce/blob/main/Infrastructure/Services/OrderService.cs"
    click PaymentService "https://github.com/alimhtsai/e_commerce/blob/main/Infrastructure/Services/PaymentService.cs"
    click TokenService "https://github.com/alimhtsai/e_commerce/blob/main/Infrastructure/Services/TokenService.cs"
    click ResponseCacheService "https://github.com/alimhtsai/e_commerce/blob/main/Infrastructure/Services/ResponseCacheService.cs"
    click MigrationsStore "https://github.com/alimhtsai/e_commerce/tree/main/Infrastructure/Data/Migrations"
    click MigrationsIdentity "https://github.com/alimhtsai/e_commerce/tree/main/Infrastructure/Identity/Migrations"
    click SQLiteDB "https://github.com/alimhtsai/e_commerce/blob/main/API/identity.db"
    click RedisCache "https://github.com/alimhtsai/e_commerce/blob/main/docker-compose.yml"
```
