# duong2402/swd architecture

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

- Interactive diagram: https://gitdiagram.com/duong2402/swd
- Repository: https://github.com/duong2402/swd

## Overview

##### Main Components
- Frontend (FigureShop_FE): An Angular application that serves both admin and client user interfaces. It contains separate modules for UI-Admin (handling product, category, order management among others) and UI-Client (covering cart, checkout, product display, and user interactions).
- API Layer (EShopWebAPI): An ASP.NET Core Web API project exposing RESTful endpoints. Controllers for authentication, cart, category, figures (products), orders, and users let the frontend interact with the backend.
- Application Layer (Application folder): Contains DTOs, mapping profiles for converting between domain and transfer objects, pagination helpers, and various business services (cart, image, order, product, user). This layer encapsulates the business logic and acts as the mediator between the API controllers and the domain layer.
- Domain Layer (Domain folder): Holds your core business entities (Cart, Product, Order, User, etc.), base entities, value objects (including enums for order status and stock status), and domain interfaces (like the generic repository and UnitOfWork definitions).

##### Out Relationships and Interactions
- API controllers in EShopWebAPI invoke methods in the Application layer. Represent these as calls from controllers (e.g., AuthController, CartController, etc.) to services in the Application folder.
- The Application layer uses DTOs to interact with the Domain layer’s Entities and passes data to/from the Infrastructure layer. Clearly mark these interactions.
- Infrastructure handles data persistence. The Application layer calls repository methods (through UnitOfWork) to query or update the database (as represented by the OnlineFigureShopDB.sql file).
- Additional services (like the ImageService) and configurations (e.g., JwtHelper) can be highlighted, showing any external or cross-cutting concerns like authentication or file handling.

##### Architectural Patterns
- Layered Architecture / Onion Architecture: Emphasize the separation of concerns between the Frontend, API, Application logic, Domain, and Infrastructure.
- Use of DTOs and Mapping Profiles: Show that there are mapping profiles which convert between Domain objects and DTOs, ensuring data encapsulation.
- Repository and Unit of Work Patterns in the Infrastructure layer: These provide abstraction over data persistence.
- Dependency Injection: Although not explicitly seen here, the separation suggests use of IoC containers to inject dependencies (services, repositories, etc.).

##### Relevant Technologies
- Frontend: Angular (with its routing, service layers, and component-based structure).
- Backend: ASP.NET Core with controllers, dependency injection, and configuration via appsettings.json.
- Persistence: Likely Entity Framework Core (given the presence of ApplicationDbContext and repository patterns) with a SQL database.
- Other Utilities: AutoMapper (implied by the MappingProfile), JWT for authentication (by examining the JwtHelper and AuthTokenOptions in Infrastructure).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer (Angular Frontend)"
        FE["Angular Frontend"]:::frontend
        FE_Admin["UI-Admin Module"]:::frontend
        FE_Client["UI-Client Module"]:::frontend
    end

    subgraph "API Layer (EShopWebAPI)"
        API["ASP.NET Core API"]:::api
        Controllers["Controllers"]:::api
    end

    subgraph "Application Layer"
        App["Application Services & DTOs"]:::application
        MappingProfile["MappingProfile (DTO Mapping)"]:::application
        Services["Business Services"]:::application
    end

    subgraph "Domain Layer"
        Domain["Domain Entities & Interfaces"]:::domain
        Entities["Core Entities"]:::domain
        Interfaces["Repositories & UnitOfWork Interfaces"]:::domain
    end

    subgraph "Infrastructure Layer"
        Infra["Infrastructure & Persistence"]:::infrastructure
        DbContext["ApplicationDbContext"]:::infrastructure
        Repos["Repository Implementations"]:::infrastructure
        Config["JWT & Authentication Configs"]:::infrastructure
    end

    Database["SQL Database (OnlineFigureShopDB)"]:::database

    %% Data Flow Connections
    FE -->|"RESTAPI_call"| Controllers
    Controllers -->|"CallsAppLayer"| App
    App -->|"InvokesServices"| Services
    Services -->|"UtilizesMapping"| MappingProfile
    Services -->|"ExecutesBusinessLogic"| Domain
    App -->|"Accesses"| Infra
    Domain -->|"RepositoryCalls"| Repos
    Infra -->|"PersistData"| Database

    %% Additional Internal Relationships
    FE_Admin --- FE
    FE_Client --- FE
    Entities --- Interfaces

    %% Click Events
    click FE "https://github.com/duong2402/swd/tree/main/FigureShop_FE/"
    click FE_Admin "https://github.com/duong2402/swd/tree/main/FigureShop_FE/src/app/UI-Admin"
    click FE_Client "https://github.com/duong2402/swd/tree/main/FigureShop_FE/src/app/UI-Client"
    click API "https://github.com/duong2402/swd/tree/main/EShopWebAPI/"
    click Controllers "https://github.com/duong2402/swd/blob/main/EShopWebAPI/Controllers/AuthController.cs"
    click MappingProfile "https://github.com/duong2402/swd/blob/main/Application/Common/Mappings/MappingProfile.cs"
    click Services "https://github.com/duong2402/swd/blob/main/Application/Services/ProductServices.cs"
    click Domain "https://github.com/duong2402/swd/tree/main/Domain/"
    click Entities "https://github.com/duong2402/swd/tree/main/Domain/Entities"
    click Interfaces "https://github.com/duong2402/swd/tree/main/Domain/Interfaces"
    click DbContext "https://github.com/duong2402/swd/blob/main/Infrastructure/Persistence/ApplicationDbContext.cs"
    click Repos "https://github.com/duong2402/swd/blob/main/Infrastructure/Repositories/GenericRepository.cs"
    click Config "https://github.com/duong2402/swd/blob/main/Infrastructure/Configurations/AuthTokenOptions.cs"
    click Database "https://github.com/duong2402/swd/blob/main/OnlineFigureShopDB.sql"

    %% Styling
    classDef frontend fill:#AED6F1,stroke:#2874A6,stroke-width:2px;
    classDef api fill:#ABEBC6,stroke:#28B463,stroke-width:2px;
    classDef application fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef domain fill:#FADBD8,stroke:#E74C3C,stroke-width:2px;
    classDef infrastructure fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef database fill:#FCF3CF,stroke:#F39C12,stroke-width:2px;
```
