# analytica-manulife/apigateway architecture

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

- Interactive diagram: https://gitdiagram.com/analytica-manulife/apigateway
- Repository: https://github.com/analytica-manulife/apigateway

## Overview

##### Project type and purpose
- This is a .NET 9.0 Web API project named “APIGateway.”
- It acts as a centralized HTTP entry point (an API Gateway) that handles authentication/authorization, session management, and request‐proxying for downstream services (Budget, News, StockMarket).
- It also persists user/KYC data in a relational database via Entity Framework Core (AppDbContext).

##### File structure
- Program.cs & appsettings*.json
– Bootstraps ASP.NET Core middleware, routing, DI containers, EF DbContext, authentication schemes.
- Controller/
– AuthController: user login, registration, token issuance.
– BudgetProxyController, NewsProxyController, StockMarketProxyController: forwards/aggregates requests to external microservices.
- Data/AppDbContext.cs
– EF Core DbContext mapping Models (Account, KycModel, etc.) to database tables.
- Model/
– DTOs and domain entities for authentication and KYC workflows.
- Repositories/AuthRepository.cs
– Data access abstraction over AppDbContext for user credentials.
- Services/
– AuthService: business logic for sign-up, sign-in, token generation.
– SessionService & RequireLoginAttribute: session validation, attribute-based authorization.
- .github/workflows/*.yml
– CI/CD pipelines for building, testing, deploying the API Gateway across multiple environments (Analytica, Manulife, etc.).

##### Key insights from the README
- The README only contains the title (“APIGateway”).
- All architectural intent must be derived from code structure and file names.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    subgraph "Clients"
        direction TB
        Web["Web/Mobile Client"]:::external
        OtherSvc["Other Services"]:::external
    end

    %% API Gateway Application
    subgraph "API Gateway Application"
        direction TB

        subgraph "Controllers" 
            direction TB
            AuthController["AuthController"]:::controller
            BudgetProxyController["BudgetProxyController"]:::controller
            NewsProxyController["NewsProxyController"]:::controller
            StockMarketProxyController["StockMarketProxyController"]:::controller
        end

        subgraph "Services"
            direction TB
            AuthService["AuthService"]:::service
            SessionService["SessionService"]:::service
            RequireLoginAttribute["RequireLoginAttribute"]:::service
        end

        subgraph "Repositories"
            direction TB
            AuthRepository["AuthRepository"]:::repository
        end

        subgraph "Data & Models"
            direction TB
            DB["AppDbContext"]:::database
            Account["Account Model"]:::model
            KycModel["KycModel"]:::model
            KycInsertRequest["KycInsertRequest DTO"]:::model
            UserLoginRequest["UserLoginRequest DTO"]:::model
            UserRegisterRequest["UserRegisterRequest DTO"]:::model
        end

        subgraph "Configuration"
            direction TB
            AppSettings["appsettings.json\nappsettings.Development.json"]:::config
            ProgramFile["Program.cs"]:::config
        end

        subgraph "CI/CD Workflows"
            direction TB
            WorkflowA["main_analytica-gateway.yml"]:::ci
            WorkflowB["main_api-gateway-analytica.yml"]:::ci
            WorkflowC["main_apigateway-manulife.yml"]:::ci
        end
    end

    %% External downstream services
    subgraph "Downstream Services"
        direction TB
        BudgetService["Budget Service"]:::external
        NewsService["News Service"]:::external
        StockMarketService["StockMarket Service"]:::external
    end

    %% Flows
    Web -->|"HTTP/HTTPS"| AuthController
    Web -->|"HTTP/HTTPS"| BudgetProxyController
    Web -->|"HTTP/HTTPS"| NewsProxyController
    Web -->|"HTTP/HTTPS"| StockMarketProxyController
    OtherSvc -->|"HTTP/HTTPS"| AuthController

    AuthController -->|"uses"| AuthService
    AuthController -->|"validated by"| RequireLoginAttribute
    BudgetProxyController -->|"validated by"| RequireLoginAttribute
    NewsProxyController -->|"validated by"| RequireLoginAttribute
    StockMarketProxyController -->|"validated by"| RequireLoginAttribute

    AuthService -->|"calls"| AuthRepository
    AuthService -->|"issues JWT"| SessionService
    AuthRepository -->|"EF Core SQL"| DB

    BudgetProxyController -->|"forwards request"| BudgetService
    NewsProxyController -->|"forwards request"| NewsService
    StockMarketProxyController -->|"forwards request"| StockMarketService

    %% Configuration and bootstrap
    AppSettings --> ProgramFile
    ProgramFile --> AuthController
    ProgramFile --> BudgetProxyController
    ProgramFile --> NewsProxyController
    ProgramFile --> StockMarketProxyController
    ProgramFile --> AuthService
    ProgramFile --> SessionService
    ProgramFile --> AuthRepository
    ProgramFile --> DB

    %% CI/CD to Deployment (note only mapping)
    WorkflowA -->|"deploys to Analytica"| ProgramFile
    WorkflowB -->|"deploys to Analytica"| ProgramFile
    WorkflowC -->|"deploys to Manulife"| ProgramFile

    %% Click Events
    click AuthController "https://github.com/analytica-manulife/apigateway/blob/main/Controller/AuthController.cs"
    click BudgetProxyController "https://github.com/analytica-manulife/apigateway/blob/main/Controller/BudgetProxyController.cs"
    click NewsProxyController "https://github.com/analytica-manulife/apigateway/blob/main/Controller/NewsProxyController.cs"
    click StockMarketProxyController "https://github.com/analytica-manulife/apigateway/blob/main/Controller/StockMarketProxyController.cs"
    click DB "https://github.com/analytica-manulife/apigateway/blob/main/Data/AppDbContext.cs"
    click Account "https://github.com/analytica-manulife/apigateway/blob/main/Model/Account.cs"
    click KycModel "https://github.com/analytica-manulife/apigateway/blob/main/Model/KycModel.cs"
    click KycInsertRequest "https://github.com/analytica-manulife/apigateway/blob/main/Model/KycInsertRequest.cs"
    click UserLoginRequest "https://github.com/analytica-manulife/apigateway/blob/main/Model/UserLoginRequest.cs"
    click UserRegisterRequest "https://github.com/analytica-manulife/apigateway/blob/main/Model/UserRegisterRequest.cs"
    click AuthRepository "https://github.com/analytica-manulife/apigateway/blob/main/Repositories/AuthRepository.cs"
    click AuthService "https://github.com/analytica-manulife/apigateway/blob/main/Services/AuthService.cs"
    click SessionService "https://github.com/analytica-manulife/apigateway/blob/main/Services/SessionSerivce.cs"
    click RequireLoginAttribute "https://github.com/analytica-manulife/apigateway/blob/main/Services/RequireLoginAttribute.cs"
    click ProgramFile "https://github.com/analytica-manulife/apigateway/blob/main/Program.cs"
    click AppSettings "https://github.com/analytica-manulife/apigateway/blob/main/appsettings.json"
    %% additional config
    click AppSettings "https://github.com/analytica-manulife/apigateway/blob/main/appsettings.Development.json"
    click WorkflowA "https://github.com/analytica-manulife/apigateway/blob/main/.github/workflows/main_analytica-gateway.yml"
    click WorkflowB "https://github.com/analytica-manulife/apigateway/blob/main/.github/workflows/main_api-gateway-analytica.yml"
    click WorkflowC "https://github.com/analytica-manulife/apigateway/blob/main/.github/workflows/main_apigateway-manulife.yml"

    %% Styles
    classDef controller fill:#D6EAF8,stroke:#3498DB,color:#1B4F72;
    classDef service fill:#E8DAEF,stroke:#8E44AD,color:#4A235A;
    classDef repository fill:#FDEDEC,stroke:#C0392B,color:#641E16;
    classDef database fill:#FCF3CF,stroke:#F1C40F,color:#7D6608;
    classDef model fill:#EBF5FB,stroke:#5DADE2,color:#21618C;
    classDef config fill:#E9F7EF,stroke:#27AE60,color:#145A32;
    classDef ci fill:#FDFEFE,stroke:#AAB7B8,color:#566573;
    classDef external fill:#F5EEF8,stroke:#BB8FCE,color:#4A235A;
```
