# pinzi/getui-pushapi-netcoresdk-v2 architecture

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

- Interactive diagram: https://gitdiagram.com/pinzi/getui-pushapi-netcoresdk-v2
- Repository: https://github.com/pinzi/getui-pushapi-netcoresdk-v2

## Overview

##### Main Components
- Client Applications & Sample Code: Represented by the “Sample” projects (e.g., Core.Sample.Net6, Core.Sample.Net7) that demonstrate how to consume the SDK.
- API Layer: The GeTuiPushApiV2.NetCoreSDK.Core.Api project contains the REST API call wrappers (e.g., Auth, Push, Report, User). These components essentially form the gateway to the external GeTui REST service.
- Core Business Logic: The GeTuiPushApiV2.NetCoreSDK.Core project handles common DTOs, utility functions (SHA256Helper, HTTP helper) and encapsulates push service logic.
- Service Layer: Within the Core project you have the “Service” subdirectories (Auth, Push, Report, User) that implement the business logic for authenticating, pushing messages, and handling user-related operations.
- Storage & Caching: Separate modules (MemoryCache, Redis and Storage) abstract caching and persistent storage of tokens, user identifiers, etc.
- Dependency Injection (IOC): The GeTuiPushApiV2.NetCoreSDK.Core.IOC project and associated ServiceCollectionExtensions manage IOC registration and plug in custom implementations (like alternate Redis clients).
- Utility Library: Contains helper methods for common operations (e.g., HTTP requests and cryptographic operations).

##### Relationships and Data Flow
- The client (which might call through one of the three calling mechanisms) first uses the API layer to perform authentication by invoking the “Auth” API. This response is then cached using either Redis or MemoryCache (via the Storage component).
- Once a token is obtained and cached, the client calls one of the Push or User-related API methods (such as single push, list push or alias binding).
- The Service layer leverages these APIs, coordinating the proper sequence of calls (e.g., token retrieval, then message pushing) and routing requests, based on conditions (is it a “direct API” call or an IOC-managed push call).
- Dependency injection is used to wire together implementations of IStorage, IRedis, and concrete services (for example, GeTuiPushService).

##### Design Patterns & Architectural Strategies
- Abstraction and Encapsulation: The SDK wraps the raw HTTP calls in higher-level API methods; internal classes hide details such as caching and token refresh.
- Separation of Concerns: Distinct projects for API communication, business logic (core), service orchestration, storage/caching, and IOC registration.
- Pluggable Storage Mechanism: Multiple implementations of IStorage (via Redis or in-memory cache) are available and can be configured through StorageType.
- IOC/DI Pattern: The SDK supports both direct service instantiation and IOC registration for integration with developer applications.

##### Relevant Technologies and Frameworks
- .NET Core 6/7: Underlying runtime specification.
- StackExchange.Redis: Default Redis client for caching.
- HTTP Clients: For communication with GeTui REST API endpoints.
- Common NuGet Tools: Including utility packages for cryptography (SHA256) and JSON handling (Newtonsoft.Json).

##### Elements
- Nodes for each major component:
- "Client / Sample Applications"
- "Authentication API" (Auth layer under Core.Api)
- "Push APIs" (different methods under API / Service)
- "User Management APIs"
- "Core Business Logic & DTOs"
- "Storage/Caching Layer" (MemoryCache, Redis)
- "IOC / Dependency Injection Container"
- "External GeTui REST Service" (to show external dependency)
- Client calls the "Authentication API" to get a token.
- Token stored in the "Storage/Caching Layer".
- Push Service retrieves token and then calls "Push APIs".
- Similar patterns for User APIs where alias binding or tag management occurs.

##### Detail and Clarity
- Keep labels descriptive (e.g., “GeTuiPushV2Api – API Wrapper”, “GeTuiPushService – Message Orchestration”, “IStorage (Redis/MemoryCache) – Caching Storage”).
- Every dependency and interaction is clearly drawn.
- On the fact that there are multiple entry points (direct HTTP calls versus IOC-managed services), and include notes or sub-components that show these alternate flows.

## Diagram (Mermaid)

```mermaid
graph TD
    A["Client / Sample Applications"]:::client

    subgraph "API Layer"
        B["Authentication API"]:::api
        C["Push APIs"]:::api
        D["Report APIs"]:::api
        E["User Management APIs"]:::api
    end

    subgraph "Core Business Logic & DTOs"
        F["Core Business Logic & DTOs"]:::core
    end

    subgraph "Service Layer"
        G["Authentication Service"]:::service
        H["Push Services"]:::service
        I["Report Services"]:::service
        J["User Management Services"]:::service
    end

    subgraph "Storage & Caching Layer"
        K["In-Memory Cache"]:::storage
        L["Redis Cache"]:::storage
        M["Storage Abstraction"]:::storage
    end

    subgraph "IOC / Dependency Injection"
        N["IOC Container"]:::ioc
    end

    subgraph "Utility Library"
        O["Utility Library"]:::utility
    end

    External["External GeTui REST Service"]:::external

    %% Client calls API Layer
    A -->|"calls"| B
    A -->|"calls"| C
    A -->|"calls"| D
    A -->|"calls"| E

    %% API Layer interacts with external service
    B -->|"auth-call"| External
    C -->|"push-call"| External
    D -->|"report-call"| External
    E -->|"user-call"| External

    %% Token caching from Auth API
    B -->|"storesToken"| M

    %% Service Layer using API Layer
    G -->|"uses"| B
    H -->|"uses"| C
    I -->|"uses"| D
    J -->|"uses"| E

    %% Service Layer retrieves token from Storage
    G -->|"getsToken"| M
    H -->|"getsToken"| M
    I -->|"getsToken"| M
    J -->|"getsToken"| M

    %% Core Business Logic supports Service Layer operations
    F -->|"supports"| G
    F -->|"supports"| H
    F -->|"supports"| I
    F -->|"supports"| J

    %% IOC wiring for services and storage
    N -->|"injects"| G
    N -->|"injects"| H
    N -->|"injects"| I
    N -->|"injects"| J
    N -->|"injects"| M

    %% Storage integration
    K -->|"integratesWith"| M
    L -->|"integratesWith"| M

    %% Utility support for business logic
    O -->|"utils"| F

    %% Click Events
    click A "https://github.com/pinzi/getui-pushapi-netcoresdk-v2/blob/master/GeTuiPushApiV2.NetCoreSDK.Core.Sample.Net6"
    click A "https://github.com/pinzi/getui-pushapi-netcoresdk-v2/blob/master/GeTuiPushApiV2.NetCoreSDK.Core.Sample.Net7"
    click B "https://github.com/pinzi/getui-pushapi-netcoresdk-v2/blob/master/GeTuiPushApiV2.NetCoreSDK.Core.Api/Api/Auth/GeTuiPushV2_AuthApi.cs"
    click C "https://github.com/pinzi/getui-pushapi-netcoresdk-v2/tree/master/GeTuiPushApiV2.NetCoreSDK.Core.Api/Api/Push"
    click D "https://github.com/pinzi/getui-pushapi-netcoresdk-v2/tree/master/GeTuiPushApiV2.NetCoreSDK.Core.Api/Api/Report"
    click E "https://github.com/pinzi/getui-pushapi-netcoresdk-v2/tree/master/GeTuiPushApiV2.NetCoreSDK.Core.Api/Api/User"
    click F "https://github.com/pinzi/getui-pushapi-netcoresdk-v2/blob/master/GeTuiPushApiV2.NetCoreSDK.Core"
    click G "https://github.com/pinzi/getui-pushapi-netcoresdk-v2/blob/master/GeTuiPushApiV2.NetCoreSDK.Core/Service/Auth/GeTuiPush_AuthService.cs"
    click H "https://github.com/pinzi/getui-pushapi-netcoresdk-v2/tree/master/GeTuiPushApiV2.NetCoreSDK.Core/Service/Push"
    click I "https://github.com/pinzi/getui-pushapi-netcoresdk-v2/tree/master/GeTuiPushApiV2.NetCoreSDK.Core/Service/Report"
    click J "https://github.com/pinzi/getui-pushapi-netcoresdk-v2/tree/master/GeTuiPushApiV2.NetCoreSDK.Core/Service/User"
    click K "https://github.com/pinzi/getui-pushapi-netcoresdk-v2/blob/master/GeTuiPushApiV2.NetCoreSDK.Core.MemoryCache"
    click L "https://github.com/pinzi/getui-pushapi-netcoresdk-v2/blob/master/GeTuiPushApiV2.NetCoreSDK.Core.Redis"
    click M "https://github.com/pinzi/getui-pushapi-netcoresdk-v2/blob/master/GeTuiPushApiV2.NetCoreSDK.Core.Storage"
    click N "https://github.com/pinzi/getui-pushapi-netcoresdk-v2/blob/master/GeTuiPushApiV2.NetCoreSDK.Core.IOC"
    click O "https://github.com/pinzi/getui-pushapi-netcoresdk-v2/blob/master/GeTuiPushApiV2.NetCoreSDK.Core.Utility"

    %% Styles
    classDef client fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef api fill:#87cefa,stroke:#333,stroke-width:2px;
    classDef core fill:#8fbc8f,stroke:#333,stroke-width:2px;
    classDef service fill:#f0e68c,stroke:#333,stroke-width:2px;
    classDef storage fill:#ffdead,stroke:#333,stroke-width:2px;
    classDef ioc fill:#dda0dd,stroke:#333,stroke-width:2px;
    classDef utility fill:#ffa500,stroke:#333,stroke-width:2px;
    classDef external fill:#ff6347,stroke:#333,stroke-width:2px;
```
