# trycatchlearn/skinet-2024 architecture

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

- Interactive diagram: https://gitdiagram.com/trycatchlearn/skinet-2024
- Repository: https://github.com/trycatchlearn/skinet-2024

## Overview

##### Project Type and Purpose
- This is a full-stack e-commerce application (“Skinet”) built with a .NET 8 backend (API, Core, Infrastructure projects) and an Angular 18 frontend (client directory).
- Purpose: Provide a shopping platform with product catalog, cart, checkout (including Stripe payments), order management, caching (Redis), real-time notifications (SignalR), and admin interfaces.

##### Main Components
A. Frontend (Angular SPA)
- Hosted in client/wwwroot (API) or served via Angular dev server in development.
- Modules:
– Core (guards, interceptors, shared singleton services like auth, cart, shop, Stripe, SignalR)
– Features (account, shop, cart, checkout, orders, admin, test-error)
– Shared components/directives/pipes (dialogs, empty states, order summary, error screens)
– Layout (header)
- Communicates with backend via HTTP REST calls and SignalR.

B. Backend (.NET 8 API)
- Layers:
1. API (Controllers, DTOs, Middleware, SignalR Hub)
2. Core (Domain entities, repository & service interfaces, specifications)
3. Infrastructure (EF Core DbContext, migrations, repository implementations, services, caching, Stripe integration, data seeding)
- Exposes REST endpoints (Products, Cart, Orders, Payments webhook, Admin, Coupons, WeatherForecast)
- Real-time: SignalR NotificationHub for push events (e.g., payment succeeded notifications).

C. Data Stores & External Services
- SQL Server (EF Core via StoreContext)
- Redis (ResponseCacheService for caching GET responses)
- Stripe (payment processing, webhooks)
- Docker Compose spins up SQL Server and Redis on ports 1433/6379.

##### Relationships & Data Flows
- Browser (Angular) → HTTP(S) → .NET API Controllers
- Controllers → Core services (e.g., ICartService, IPaymentService) → Infrastructure implementations (e.g., CartService → GenericRepository → StoreContext → SQL DB)
- Controllers use Redis cache attributes (CacheAttribute, InvalidateCache) to store/retrieve cached data.
- API uses Stripe CLI webhook forwarding to `/api/payments/webhook`; PaymentController triggers events.
- API pushes real-time notifications to connected clients via SignalR hub.

##### Architectural Patterns & Principles
- Clean Architecture / Onion Architecture: separation of API, Core, Infrastructure.
- Repository + Unit of Work (IUnitOfWork, GenericRepository).
- Specification pattern to encapsulate query logic.
- DTO mapping extensions for decoupling domain entities from API contracts.
- Middleware for global exception handling.
- HTTP caching via attributes & Redis.
- Dependency Injection throughout.

- Layout:
1. Client Layer: Browser/Angular SPA
2. API Layer:
- Controllers
- Middleware
- SignalR Hub
3. Application Layer: Core interfaces & domain models
4. Infrastructure Layer: EF Core, repositories, services
5. Data Stores & External: SQL Server, Redis, Stripe.
- From Angular services → REST endpoints (e.g., /products, /cart)
- From Controllers → Core services → Infrastructure → Data stores
- From API → Redis (cache)
- From Stripe webhook → PaymentController
- From API → SignalR Hub → Angular SignalR client
- API Layer (green),
- Core (yellow),
- Infrastructure (orange),
- External (gray).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (Angular SPA)" 
        direction TB
        Angular["Angular SPA"]:::frontend
        CoreModule["Core Module"]:::frontend
        Guards["Guards"]:::frontend
        Interceptors["Interceptors"]:::frontend
        ServicesFS["Singleton Services"]:::frontend
        Features["Feature Modules"]:::frontend
        Layout["Layout (Header)"]:::frontend
        SharedComp["Shared Components"]:::frontend
        SharedDir["Shared Directives"]:::frontend
        SharedPipes["Shared Pipes"]:::frontend
        SharedModels["Shared Models"]:::frontend
    end

    %% API Layer
    subgraph "API Layer (.NET 8 API)" 
        direction TB
        Controllers["API Controllers"]:::api
        DTOs["API DTOs"]:::api
        Middleware["Exception Middleware"]:::api
        CacheAttr["CacheAttribute"]:::api
        InvalidateCache["InvalidateCache"]:::api
        NotificationHub["SignalR Hub"]:::api
    end

    %% Core Layer
    subgraph "Core Layer" 
        direction TB
        Entities["Domain Entities"]:::core
        Interfaces["Repository & Service Interfaces"]:::core
        Specs["Specifications"]:::core
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer" 
        direction TB
        StoreContext["EF Core StoreContext"]:::infra
        StoreSeed["StoreContextSeed"]:::infra
        GenericRepo["GenericRepository & UnitOfWork"]:::infra
        ProdRepo["ProductRepository"]:::infra
        Migrations["Migrations"]:::infra
        InfraServices["Infrastructure Services"]:::infra
    end

    %% External Services & Data Stores
    subgraph "External Services & Data" 
        direction TB
        SQL[(SQL Server)]:::external
        Redis[(Redis Cache)]:::external
        Stripe[("Stripe")]:::external
    end

    %% Docker Compose Boundary
    subgraph "Docker Compose" 
        direction TB
        SQL
        Redis
    end

    %% Data Flows
    Angular -->|"HTTP GET /api/products"| Controllers
    Angular -->|"SignalR connect"| NotificationHub
    Controllers -->|"use DTOs"| DTOs
    Controllers -->|"Exception Handling"| Middleware
    Controllers -->|"Cache GET response"| CacheAttr
    Controllers -->|"Invalidate Cache"| InvalidateCache
    Controllers -->|"ICartService, IPaymentService"| Interfaces
    Interfaces -->|"GenericRepository"| GenericRepo
    GenericRepo -->|"StoreContext"| StoreContext
    StoreContext -->|"migrations & seeding"| StoreSeed
    GenericRepo --> ProdRepo
    Controllers -->|"push events"| NotificationHub
    CacheAttr -->|"GET cache"| Redis
    InvalidateCache -->|"clear cache"| Redis
    Controllers -->|"process payment webhook"| Interfaces
    Stripe -->|"webhook POST /api/payments/webhook"| Controllers
    NotificationHub -->|"SignalR event"| Angular
    InfraServices -->|"use Stripe SDK"| Stripe
    StoreContext -->|"persist data"| SQL

    %% Click Events
    click Angular "https://github.com/trycatchlearn/skinet-2024/tree/main/client/src/app"
    click CoreModule "https://github.com/trycatchlearn/skinet-2024/tree/main/client/src/app/core"
    click Guards "https://github.com/trycatchlearn/skinet-2024/tree/main/client/src/app/core/guards"
    click Interceptors "https://github.com/trycatchlearn/skinet-2024/tree/main/client/src/app/core/interceptors"
    click ServicesFS "https://github.com/trycatchlearn/skinet-2024/tree/main/client/src/app/core/services"
    click Features "https://github.com/trycatchlearn/skinet-2024/tree/main/client/src/app/features"
    click Layout "https://github.com/trycatchlearn/skinet-2024/tree/main/client/src/app/layout/header"
    click SharedComp "https://github.com/trycatchlearn/skinet-2024/tree/main/client/src/app/shared/components"
    click SharedDir "https://github.com/trycatchlearn/skinet-2024/tree/main/client/src/app/shared/directives"
    click SharedPipes "https://github.com/trycatchlearn/skinet-2024/tree/main/client/src/app/shared/pipes"
    click SharedModels "https://github.com/trycatchlearn/skinet-2024/tree/main/client/src/app/shared/models"
    click Controllers "https://github.com/trycatchlearn/skinet-2024/tree/main/API/Controllers"
    click DTOs "https://github.com/trycatchlearn/skinet-2024/tree/main/API/DTOs"
    click Middleware "https://github.com/trycatchlearn/skinet-2024/blob/main/API/Middleware/ExceptionMiddleware.cs"
    click NotificationHub "https://github.com/trycatchlearn/skinet-2024/blob/main/API/SignalR/NotificationHub.cs"
    click CacheAttr "https://github.com/trycatchlearn/skinet-2024/blob/main/API/RequestHelpers/CacheAttribute.cs"
    click InvalidateCache "https://github.com/trycatchlearn/skinet-2024/blob/main/API/RequestHelpers/InvalidateCache.cs"
    click Entities "https://github.com/trycatchlearn/skinet-2024/tree/main/Core/Entities"
    click Interfaces "https://github.com/trycatchlearn/skinet-2024/tree/main/Core/Interfaces"
    click Specs "https://github.com/trycatchlearn/skinet-2024/tree/main/Core/Specifications"
    click StoreContext "https://github.com/trycatchlearn/skinet-2024/blob/main/Infrastructure/Data/StoreContext.cs"
    click StoreSeed "https://github.com/trycatchlearn/skinet-2024/blob/main/Infrastructure/Data/StoreContextSeed.cs"
    click GenericRepo "https://github.com/trycatchlearn/skinet-2024/blob/main/Infrastructure/Data/GenericRepository.cs"
    click ProdRepo "https://github.com/trycatchlearn/skinet-2024/blob/main/Infrastructure/Data/ProductRepository.cs"
    click Migrations "https://github.com/trycatchlearn/skinet-2024/tree/main/Infrastructure/Migrations"
    click InfraServices "https://github.com/trycatchlearn/skinet-2024/tree/main/Infrastructure/Services"
    click Controllers "https://github.com/trycatchlearn/skinet-2024/blob/main/API/Controllers/PaymentsController.cs"
    click SQL "https://github.com/trycatchlearn/skinet-2024/blob/main/docker-compose.yml"
    click Redis "https://github.com/trycatchlearn/skinet-2024/blob/main/docker-compose.yml"
    click Angular "https://github.com/trycatchlearn/skinet-2024/tree/main/API/wwwroot"

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#000,stroke-width:1px
    classDef api fill:#C8E6C9,stroke:#000,stroke-width:1px
    classDef core fill:#FFF9C4,stroke:#000,stroke-width:1px
    classDef infra fill:#FFE0B2,stroke:#000,stroke-width:1px
    classDef external fill:#CFD8DC,stroke:#000,stroke-width:1px
```
