# programador-tv/monorepo architecture

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

- Interactive diagram: https://gitdiagram.com/programador-tv/monorepo
- Repository: https://github.com/programador-tv/monorepo

## Overview

##### Project type and purpose
- This is a full-stack, .NET-centric monorepo powering the “programador.tv” ecosystem. It includes:
- An ASP.NET Razor-Pages UI (“APP.Platform”)
- Multiple backend services (WebApi, WebSocket, Background workers, RTMP.Live, Background.Live, Background.Browser)
- A Core bounded-context broken into Presentation (API & WebSocket endpoints, queues, workers), Application (business logic), Domain (entities, contracts, interfaces), and Infrastructure (EF Core, Redis, repositories, web-service clients, video handling, email handling).
- Messaging via MassTransit/RabbitMQ and Redis for real-time chat.
- Streaming ingestion/processing (RTMP → HLS via Infrastructure.VideoHandling).
- Identity & authentication with ASP.NET Identity.

##### File structure
- Top-level “src” contains:
- APP.Platform: front-end UI (Razor pages + client JS + Identity).
- WebApi: REST API front door.
- WebSocket: real-time channels for chat/live.
- Background, Background.Live, Background.Browser: long-running services (email sender, mentor notifications, browser automation).
- RTMP.Live: Go-based RTMP ingest server.
- Core: the heart of the domain (Presentation, Application, Domain, Infrastructure).
- “docker-compose.yml” orchestrates all services plus dependencies (SQL, Redis, RabbitMQ).
- “monorepo.sln” references all .NET projects.

##### Readme insights

a. Frontend/UI
- APP.Platform (Razor Pages, JS components) serving user interactions.
- Authentication (Identity Area).
b. API layer
- WebApi + Core.Presentation REST EndPoints.
- WebSocket service + ChatHub, LiveSockets for real-time messages.
c. Business core
- Core.Application: business logic for chat, follow, live, scheduling, notifications.
- MassTransit message publisher/consumers.
d. Data layer
- Core.Infrastructure EF Core (ApplicationDbContext) → SQL Server.
- Redis (Chat channel pub/sub).
- Repositories (SQL + Redis) behind Domain interfaces.
e. Messaging & workers
- RabbitMQ (queues for ChatsQueue, CommentsQueue, EmailsQueue, LiveStreamingQueue, etc.).
- Core.Presentation Workers (JoinTimeWorker, LiveCloseWorker, TimeSelectionWorker) listen and process.
f. Streaming
- RTMP.Live ingests video → pushes to Infrastructure.VideoHandling (HLSProcessManager) → clients via APP.Platform Studio page or CDN.
g. External services
- OpenAI (OpenAiService & OpenaiWebService client).
- 3rd-party WebServices (BocaSuja, ChatWebService, etc.).
- Email service (SMTP clients via Infrastructure.EmailHandling).

##### Relationships & data flow
- User → UI (APP.Platform) → REST API or WebSocket
- REST API → Core.Presentation EndPoints → Core.Application Logic → Core.Infrastructure Repositories → Database
- UI real-time chat/live → WebSocket → Core.Presentation Hubs → Redis pub/sub or RabbitMQ → Subscribers
- Streams: RTMP.Live → RabbitMQ LiveStreamingQueue → VideoHandling → HLS segments → UI player
- Core.Application publishes domain events to RabbitMQ → Core.Presentation Workers consume → update DB or notify UI

##### Architectural patterns & design principles
- Onion/Clean architecture: Presentation → Application → Domain → Infrastructure
- CQRS style separation (commands via queues, queries via REST)
- Pub/Sub (MassTransit + RabbitMQ) for decoupled asynchronous processing
- Redis for low-latency chat caching/pub-sub
- Micro-services containerized via Docker Compose
- Single repository (monorepo) with solution reference graph

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        APPPlatform["APP.Platform<br/>(Razor Pages, JS)"]:::frontend
        IdentityArea["Identity Area<br/>(ASP.NET Identity)"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        WebApi["WebApi<br/>(REST API)"]:::api
        WebSocketSvc["WebSocket<br/>(SignalR Chat/Live)"]:::api
    end

    %% Core Presentation
    subgraph "Core.Presentation" 
        direction TB
        CorePresentation["Core.Presentation<br/>(Endpoints, Hubs, Queues, Workers)"]:::corePres
    end

    %% Business Core
    subgraph "Business Core"
        direction TB
        CoreApplication["Core.Application<br/>(Business Logic, Publisher)"]:::coreApp
        CoreDomain["Core.Domain<br/>(Entities, Contracts, Interfaces)"]:::coreDomain
    end

    %% Infrastructure & Data
    subgraph "Infrastructure & Data"
        direction TB
        CoreInfrastructure["Core.Infrastructure<br/>(EF Core, Redis Repos, Video & Email Handling, WebServices)"]:::infra
        SQLDB["SQL Server"]:::db
        Redis["Redis"]:::db
        RabbitMQ["RabbitMQ"]:::messaging
    end

    %% Streaming Processing
    subgraph "Streaming"
        direction TB
        RTMPIngest["RTMP.Live<br/>(Go RTMP Ingest)"]:::streaming
        HLSManager["HLSProcessManager"]:::streaming
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        OpenAIUI["OpenAiService<br/>(UI)"]:::external
        OpenAiCore["OpenaiWebService<br/>(Core)"]:::external
        SMTP["SMTP Email Service"]:::external
        ThirdPartyAPI["3rd-party Web Services"]:::external
    end

    %% User interaction
    User["User"] -->|"HTTP"| APPPlatform
    APPPlatform -->|"REST"| WebApi
    APPPlatform -->|"WS"| WebSocketSvc
    APPPlatform -->|"HTTP"| OpenAIUI
    APPPlatform -->|"DB"| IdentityArea

    %% API to Core
    WebApi -->|"REST"| CorePresentation
    WebSocketSvc -->|"WS"| CorePresentation

    %% Core flows
    CorePresentation -->|"invoke"| CoreApplication
    CoreApplication -->|"uses"| CoreDomain
    CoreDomain -->|"impl by"| CoreInfrastructure

    %% Data persistence
    CoreInfrastructure -->|"EF Core"| SQLDB
    CoreInfrastructure -->|"Redis Repo"| Redis

    %% Messaging flows
    CoreApplication -->|"AMQP publish"| RabbitMQ
    RabbitMQ -->|"AMQP consume"| CorePresentation
    CorePresentation -->|"Redis pub/sub"| Redis

    %% Streaming flows
    RTMPIngest -->|"LiveStreamingQueue"| RabbitMQ
    RabbitMQ -->|"subscribe"| HLSManager
    HLSManager -->|"HLS segments"| APPPlatform

    %% External integrations
    CoreInfrastructure -->|"HTTP"| OpenAiCore
    CoreInfrastructure -->|"SMTP"| SMTP
    CoreInfrastructure -->|"HTTP"| ThirdPartyAPI

    %% Click Events
    click APPPlatform "https://github.com/programador-tv/monorepo/blob/main/src/APP.Platform"
    click IdentityArea "https://github.com/programador-tv/monorepo/tree/main/src/APP.Platform/Areas/Identity"
    click WebApi "https://github.com/programador-tv/monorepo/tree/main/src/WebApi"
    click WebSocketSvc "https://github.com/programador-tv/monorepo/tree/main/src/WebSocket"
    click RTMPIngest "https://github.com/programador-tv/monorepo/blob/main/src/RTMP.Live"
    click CorePresentation "https://github.com/programador-tv/monorepo/tree/main/src/Core/Presentation"
    click CoreApplication "https://github.com/programador-tv/monorepo/tree/main/src/Core/Application"
    click CoreDomain "https://github.com/programador-tv/monorepo/tree/main/src/Core/Domain"
    click CoreInfrastructure "https://github.com/programador-tv/monorepo/tree/main/src/Core/Infrastructure"
    click OpenAIUI "https://github.com/programador-tv/monorepo/blob/main/src/APP.Platform/Services/OpenAiService.cs"
    click OpenAiCore "https://github.com/programador-tv/monorepo/blob/main/src/Core/Infrastructure/WebServices/OpenaiWebService.cs"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef api fill:#90EE90,stroke:#333,stroke-width:1px;
    classDef corePres fill:#FFFACD,stroke:#333,stroke-width:1px;
    classDef coreApp fill:#FFFACD,stroke:#333,stroke-width:1px;
    classDef coreDomain fill:#FFFACD,stroke:#333,stroke-width:1px;
    classDef infra fill:#D3D3D3,stroke:#333,stroke-width:1px;
    classDef db fill:#D3D3D3,stroke:#333,stroke-width:1px;
    classDef messaging fill:#FFA500,stroke:#333,stroke-width:1px;
    classDef external fill:#F0E68C,stroke:#333,stroke-width:1px;
    classDef streaming fill:#E6E6FA,stroke:#333,stroke-width:1px;
```
