# capstonefpt/giveaway-api architecture

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

- Interactive diagram: https://gitdiagram.com/capstonefpt/giveaway-api
- Repository: https://github.com/capstonefpt/giveaway-api

## Overview

##### Main Components

a. API Layer
- REST API endpoints (WebApi2.0 folder)
- Authentication/Authorization system
- SignalR Hub for real-time auctions

b. Core Business Domain
- Account Management
- Product Management (Fashion Items)
- Order Processing
- Auction System
- Consignment System
- Payment Processing
- Transaction Management

c. Infrastructure
- Database (Entity Framework Core)
- External Services Integration
- VNPay Payment Gateway
- GiaoHangNhanh (GHN) Delivery Service
- Background Jobs (Auction ending, Refund processing)

##### Key Relationships to Highlight

a. User Management Flow:
- Authentication → Account Management → Roles (Member, Staff, Admin)
- Account Balance → Transactions → Withdrawals/Deposits

b. Product Flow:
- Master Fashion Items → Individual Items
- Categories → Products
- Shops → Products

c. Sales Flow:
- Regular Sales
- Auction System
- Consignment System

##### Architectural Patterns to Emphasize

a. Clean Architecture
- Domain Layer (Business Objects)
- Application Layer (Services)
- Infrastructure Layer
- Presentation Layer (WebApi)

b. Feature-based Organization
- Each business capability is organized in its own feature folder
- Clear separation of concerns

Use these visual elements:
- Red lines for critical paths
- Gray lines for secondary relationships

Layout:
**[Client Applications]**
- ↓
**[API Gateway Layer]**
- ↙     ↓     ↘
**[Auth] [Core]  [Payment]**
- ↘     ↓     ↙
**[Database Layer]**

##### Technical Details

a. Database:
- Entity Framework Core
- SQL Server
- Migration support

b. Authentication:
- JWT Token-based auth
- Role-based access control

c. Integration Points:
- Payment gateways
- Delivery service
- Real-time notifications

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Client Layer"
        Client[Client Applications]
    end

    subgraph "API Layer"
        API[REST API Gateway]:::api
        click API "https://github.com/CapstoneFPT/GiveAway-API/tree/main/WebApi2.0/Features/"
        Auth[Authentication Service]:::auth
        click Auth "https://github.com/CapstoneFPT/GiveAway-API/tree/main/WebApi2.0/Features/Auth"
        SignalR[SignalR Hub]:::realtime
        click SignalR "https://github.com/CapstoneFPT/GiveAway-API/blob/main/Services/Auctions/AuctionHub.cs"
    end

    subgraph "Core Business Domain"
        AccountMgmt[Account Management]:::core
        click AccountMgmt "https://github.com/CapstoneFPT/GiveAway-API/tree/main/WebApi2.0/Features/Accounts"
        ProductMgmt[Product Management]:::core
        click ProductMgmt "https://github.com/CapstoneFPT/GiveAway-API/tree/main/WebApi2.0/Features/Products"
        OrderMgmt[Order Management]:::core
        click OrderMgmt "https://github.com/CapstoneFPT/GiveAway-API/tree/main/WebApi2.0/Features/Orders"
        AuctionSys[Auction System]:::core
        click AuctionSys "https://github.com/CapstoneFPT/GiveAway-API/blob/main/BusinessObjects/Entities/Auction.cs"
        ConsignmentSys[Consignment System]:::core
        PaymentProc[Payment Processing]:::core
        TransactionMgmt[Transaction Management]:::core
    end

    subgraph "Infrastructure Layer"
        DB[(Database)]:::db
        click DB "https://github.com/CapstoneFPT/GiveAway-API/blob/main/WebApi2.0/Infrastructure/Persistence/GiveAwayDbContext.cs"
        Migrations[Database Migrations]:::db
        click Migrations "https://github.com/CapstoneFPT/GiveAway-API/tree/main/WebApi2.0/Infrastructure/Persistence/Migrations"
        BackgroundJobs[Background Jobs]:::infra
        click BackgroundJobs "https://github.com/CapstoneFPT/GiveAway-API/blob/main/Services/Auctions/AuctionEndingJob.cs"
    end

    subgraph "External Services"
        VNPay[VNPay Payment Gateway]:::external
        click VNPay "https://github.com/CapstoneFPT/GiveAway-API/tree/main/WebApi2.0/Infrastructure/ExternalServices/VNPay"
        GHN[GiaoHangNhanh Delivery]:::external
    end

    subgraph "Domain Entities"
        AccountEntity[Account Entity]:::entity
        click AccountEntity "https://github.com/CapstoneFPT/GiveAway-API/blob/main/BusinessObjects/Entities/Account.cs"
        OrderEntity[Order Entity]:::entity
        click OrderEntity "https://github.com/CapstoneFPT/GiveAway-API/blob/main/BusinessObjects/Entities/Order.cs"
        ProductEntity[Product Entity]:::entity
        click ProductEntity "https://github.com/CapstoneFPT/GiveAway-API/blob/main/BusinessObjects/Entities/MasterFashionItem.cs"
    end

    %% Relationships
    Client --> API
    API --> Auth
    API --> SignalR
    
    Auth --> AccountMgmt
    API --> ProductMgmt
    API --> OrderMgmt
    API --> AuctionSys
    API --> ConsignmentSys
    API --> PaymentProc
    API --> TransactionMgmt

    AccountMgmt --> AccountEntity
    OrderMgmt --> OrderEntity
    ProductMgmt --> ProductEntity
    
    PaymentProc --> VNPay
    OrderMgmt --> GHN
    
    AccountEntity --> DB
    OrderEntity --> DB
    ProductEntity --> DB
    
    DB --> Migrations
    AuctionSys --> BackgroundJobs
    SignalR --> AuctionSys

    %% Styles
    classDef api fill:#87CEEB
    classDef auth fill:#FFB6C1
    classDef core fill:#98FB98
    classDef db fill:#DEB887
    classDef external fill:#FFA07A
    classDef infra fill:#D8BFD8
    classDef entity fill:#F0E68C
    classDef realtime fill:#87CEFA

    %% Legend
    subgraph Legend
        L1[API Components]:::api
        L2[Auth Services]:::auth
        L3[Core Services]:::core
        L4[Database Components]:::db
        L5[External Services]:::external
        L6[Infrastructure]:::infra
        L7[Domain Entities]:::entity
        L8[Real-time Components]:::realtime
    end
```
