# ptkr0/keipai architecture

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

- Interactive diagram: https://gitdiagram.com/ptkr0/keipai
- Repository: https://github.com/ptkr0/keipai

## Overview

- OAuth 2.0 for authentication (Google for YouTube, Twitch for streaming)
- MS SQL for the database along with Entity Framework Core migrations
- Azure Blob Storage for file (images) storage
- Real-time Twitch notifications via webhooks (with optional ngrok for local tunnel testing)
- External services like YouTube Data API v3 and Twitch API

- Frontend (Client Side):
– UI/UX: Indicate integration with Tailwind CSS and daisyUI.

- Backend (Server Side):
– Business Logic: Include “Services” and “Background Services” (e.g., TwitchAccountsBGService, YoutubeBGService, etc.) that process data and integrate with external APIs.
– Data Access Layer: Represent the Repositories and Entity Framework Core (ApplicationDBContext) which interact with the SQL Server.

- Database:
– SQL Server: Indicate MS SQL as the primary database, and optionally a note about SSMS for management.

- External Services & Integrations:
– OAuth 2.0 Services: Google Cloud (for YouTube) and Twitch Developers (for Twitch credentials).
– Azure Blob Storage: For storing images and file uploads.
– ngrok (optional): For tunnelling external notifications (especially Twitch webhooks) when running locally.

##### Out the Relationships & Data Flows
– The Angular application sends HTTP requests (e.g., REST API calls) to the .NET API endpoints.

- Within the Server, show:
– Controllers accepting HTTP calls and delegating tasks to the respective Services.
– Services managing business logic and calling into Repositories for CRUD operations.
– Background Services running asynchronously and integrating with external APIs (Twitch, YouTube) to fetch real-time data.
– Separation where additional supporting components (e.g., secure file uploads/Blob operations, token handling) are clearly indicated.

- For external integrations:
– Clearly label these as “External APIs/Services” with information flow (credential exchanges, content retrieval/update, file storage).

##### Architectural Patterns & Technologies
- Separation of concerns:
– The presentation layer (Angular client) is cleanly decoupled from the server’s API layer.
- Use of MVC-like patterns on the server side.
- Security aspects (JWT stored in cookies and OAuth flows).
- Real-time communication via Twitch webhooks.

##### Additional Notes
- Use descriptive text nodes to mention the specific technologies used (e.g., ".NET 8", "Angular 18", "Entity Framework Core", "MS SQL", "Tailwind CSS").

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend"
        angularApp["Angular Frontend (Angular 18)"]:::frontend
        components["Components"]:::frontend
        pages["Pages"]:::frontend
        uiux["UI/UX (Tailwind CSS & daisyUI)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (.NET 8)"
        controllers["API Controllers"]:::backend
        services["Business Logic Services"]:::backend
        bgServices["Background Services"]:::backend
        dataLayer["Data Access Layer & EF Core"]:::backend
    end

    %% External Integrations
    subgraph "External Integrations"
        oauth["OAuth 2.0 (Google, Twitch)"]:::external
        youtube["YouTube API v3"]:::external
        twitch["Twitch API"]:::external
        blob["Azure Blob Storage"]:::external
        ngrok["ngrok (optional)"]:::external
    end

    %% Database
    database["MS SQL Database"]:::database

    %% Data Flow Connections
    angularApp -->|"HTTP_requests"| controllers
    controllers -->|"delegates"| services
    services -->|"CRUD_operations"| dataLayer
    dataLayer -->|"database_ops"| database

    %% Frontend to External (for authentication)
    angularApp -->|"OAuth_login"| oauth
    controllers -->|"OAuth_redirects"| oauth

    %% Backend External Integrations from Business Services
    services -->|"integrates"| oauth
    services -->|"integrates"| youtube
    services -->|"integrates"| twitch
    services -->|"integrates"| blob

    %% Background Services External Interactions
    bgServices -->|"fetches_realtime"| youtube
    bgServices -->|"fetches_realtime"| twitch
    bgServices -->|"notification_tunnel"| ngrok

    %% Styling Directions within Frontend Layer (components are part of Angular Frontend)
    components --- angularApp
    pages --- angularApp
    uiux --- angularApp

    %% Click Events
    click angularApp "https://github.com/ptkr0/keipai/tree/main/client/src/app"
    click components "https://github.com/ptkr0/keipai/tree/main/client/src/app/components"
    click pages "https://github.com/ptkr0/keipai/tree/main/client/src/app/pages"
    click uiux "https://github.com/ptkr0/keipai/blob/main/client/tailwind.config.js"
    click controllers "https://github.com/ptkr0/keipai/tree/main/server/Controllers"
    click services "https://github.com/ptkr0/keipai/tree/main/server/Services"
    click bgServices "https://github.com/ptkr0/keipai/tree/main/server/Background Services"
    click dataLayer "https://github.com/ptkr0/keipai/blob/main/server/Data/ApplicationDBContext.cs"
    click oauth "https://github.com/ptkr0/keipai/tree/main/server/Dtos/Account"
    click database "https://github.com/ptkr0/keipai/tree/main/server/Migrations"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef external fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef database fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
