# edu-trailblaze/edu-trailblaze-be architecture

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

- Interactive diagram: https://gitdiagram.com/edu-trailblaze/edu-trailblaze-be
- Repository: https://github.com/edu-trailblaze/edu-trailblaze-be

## Overview

##### Project type and purpose
- This is a cloud-ready, backend-only solution for an online course platform (EduTrailblaze).
- It combines a modular monolith (EduTrailblaze.API + Entities + Repositories + Services) with a microservice (Cart.API) and an Ocelot API Gateway.
- It uses DDD-style layers, an event-driven style (EventBus/Consumers), CQRS in at least one service, and shared BuildingBlocks libraries.

##### File structure
- Top-level “EduTrailblaze” solution:
- EduTrailblaze.API (ASP.NET Core WebAPI controllers, middleware, DI extensions, SignalR hubs, Hangfire)
- EduTrailblaze.Entities (POCOs/entity definitions)
- EduTrailblaze.Repositories (EF DbContext, generic repository, unit-of-work)
- EduTrailblaze.Services (business logic, DTOs, mapping profiles, helpers, external integrations, event consumers, SignalR Hubs)
- EduTrailblaze.Tests (unit tests)
- OcelotApiGw (API Gateway for routing to monolith & services)
- Under “src”:
- BuildingBlocks (common logging, contracts, event‐bus messages, infrastructure, shared seedwork)
- Services/Cart (microservice following layered architecture + CQRS using MediatR‐style Commands/Queries)

##### README points
- ASP.NET Core Web API with Identity for auth & JWT
- SQL Server as primary datastore
- Redis for caching/locks
- Elasticsearch for search
- SignalR for real‐time notifications
- Hangfire for background jobs
- Generative AI & fine-tuned AI integration
- Payment providers: PayPal, MoMo, VNPAY
- Cloudinary & ClamAV & Windows Defender for media/security

a. Clients
- Web/Mobile frontend (React, Angular, etc.)
b. API Gateway
- Ocelot routing layer
c. Monolithic Backend (“EduTrailblaze.API”)
- Controllers → Services → Repositories → SQL Server
- SignalR Hub for real-time updates
- Hangfire server for scheduled/background jobs
- EventBus publisher to RabbitMQ (via BuildingBlocks.EventBus)
d. Microservices
- Cart.API service (Controllers → Application layer (CQRS) → Domain → Infrastructure → SQL Server)
- (Other future microservices follow same template)
e. Shared BuildingBlocks
- Contracts library (interfaces, base entities)
- Infrastructure (repository base, unit‐of‐work, AutoMapper extensions, common logging)
- EventBus.Messages (integration events definitions)
f. External Systems
- Redis (cache, distributed locks)
- Elasticsearch (search indices)
- Identity (ASP.NET Identity store, JWT issuer)
- Payment Gateways (PayPal, MoMo, VNPAY)
- Cloudinary (media upload)
- ClamAV / Windows Defender (virus scanning)
- External AI provider (OpenAI)

##### Relationships and data flows
- Clients → (HTTP + JWT) → API Gateway → proper backend (monolith or microservice)
- Controllers call into business Services (or MediatR handlers)
- Services call Repositories → SQL Server
- Services publish domain events → RabbitMQ → subscribed Consumers in monolith or other services
- Background tasks (Hangfire) invoked by API or scheduled → Services → Repositories
- SignalR pushes notifications from Services → Clients over WebSocket
- Cache reads/writes via Redis from Services
- Search writes/reads via Elasticsearch from Services
- External calls from Services to Payment / AI / Cloudinary / ClamAV

##### Architectural patterns & principles
- Layered (API → Application/Services → Domain/Entities → Infrastructure/Repositories)
- DDD boundaries: Entities, Repositories, Services
- CQRS pattern in Cart microservice (Commands vs Queries)
- API Gateway pattern (Ocelot)
- Event‐driven integration (RabbitMQ/EventBus, Consumers)
- Shared libraries for cross‐cutting concerns (BuildingBlocks)
- Background processing (Hangfire)
- Real‐time messaging (SignalR)

##### Important reminders
- Be detailed: capture all layers (API, Biz Logic, Domain, Infrastructure).
- Don’t over-simplify: include shared BuildingBlocks and event flows.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    subgraph "Clients"
        Client["Web/Mobile Frontend"]:::external
    end

    %% API Gateway
    Client -->|"HTTP + JWT"| APIGW
    subgraph "API Gateway"
        APIGW["API Gateway (Ocelot)"]:::api
    end
    click APIGW "https://github.com/edu-trailblaze/edu-trailblaze-be/tree/main/EduTrailblaze/OcelotApiGw"

    %% Monolith
    APIGW -->|"Route"| MonAPI
    subgraph "Monolith"
        MonAPI["EduTrailblaze.API"]:::api
        Entities["Domain Entities"]:::domain
        Repos["Data Access"]:::repo
        Services["Business Logic Services"]:::service
        Consumers["Event Consumers"]:::service
        Hub["SignalR Hub"]:::service
        Hangfire["Hangfire Server"]:::service
    end
    click MonAPI "https://github.com/edu-trailblaze/edu-trailblaze-be/blob/main/EduTrailblaze/EduTrailblaze.API"
    click Entities "https://github.com/edu-trailblaze/edu-trailblaze-be/blob/main/EduTrailblaze/EduTrailblaze.Entities"
    click Repos "https://github.com/edu-trailblaze/edu-trailblaze-be/blob/main/EduTrailblaze/EduTrailblaze.Repositories"
    click Services "https://github.com/edu-trailblaze/edu-trailblaze-be/blob/main/EduTrailblaze/EduTrailblaze.Services"
    click Consumers "https://github.com/edu-trailblaze/edu-trailblaze-be/tree/main/EduTrailblaze/EduTrailblaze.Services/Consumer"
    click Hub "https://github.com/edu-trailblaze/edu-trailblaze-be/blob/main/EduTrailblaze/EduTrailblaze.Services/Hubs/NotificationHub.cs"

    MonAPI -->|"calls"| Services
    Services -->|"EF Core"| Repos
    Services -->|"Publish Events"| RabbitMQ
    Services -->|"StackExchange.Redis"| Redis
    Services -->|"Elasticsearch"| ES
    Services -->|"External Calls"| Payment
    Services -->|"External Calls"| AI
    Services -->|"External Calls"| Cloudinary
    Services -->|"SignalR"| Hub
    MonAPI -->|"Enqueue"| Hangfire
    Consumers --> RabbitMQ
    Hangfire --> Services

    %% Cart Microservice
    APIGW --> CartAPI
    subgraph "Cart Microservice"
        CartAPI["Cart.API"]:::api
        CartApp["Cart.Application"]:::service
        CartDom["Cart.Domain"]:::domain
        CartInfra["Cart.Infrastructure"]:::repo
    end
    click CartAPI "https://github.com/edu-trailblaze/edu-trailblaze-be/blob/main/src/Services/Cart/Cart.API"
    click CartApp "https://github.com/edu-trailblaze/edu-trailblaze-be/blob/main/src/Services/Cart/Cart.Application"
    click CartDom "https://github.com/edu-trailblaze/edu-trailblaze-be/blob/main/src/Services/Cart/Cart.Domain"
    click CartInfra "https://github.com/edu-trailblaze/edu-trailblaze-be/blob/main/src/Services/Cart/Cart.Infrastructure"

    CartAPI -->|"MediatR Commands/Queries"| CartApp
    CartApp --> CartDom
    CartApp --> CartInfra
    CartInfra --> SQL2

    %% Shared BuildingBlocks
    subgraph "Shared BuildingBlocks"
        Logging["Common.Logging"]:::buildingblocks
        Contracts["Contracts"]:::buildingblocks
        EBMsgs["EventBus.Messages"]:::buildingblocks
        BBInfra["Infrastructure"]:::buildingblocks
        Seed["SeedWork"]:::buildingblocks
    end
    click Logging "https://github.com/edu-trailblaze/edu-trailblaze-be/blob/main/src/BuildingBlocks/Common.Logging"
    click Contracts "https://github.com/edu-trailblaze/edu-trailblaze-be/tree/main/src/BuildingBlocks/Contracts"
    click EBMsgs "https://github.com/edu-trailblaze/edu-trailblaze-be/blob/main/src/BuildingBlocks/EventBus/EventBus.Messages"
    click BBInfra "https://github.com/edu-trailblaze/edu-trailblaze-be/tree/main/src/BuildingBlocks/Infrastructure"
    click Seed "https://github.com/edu-trailblaze/edu-trailblaze-be/tree/main/src/BuildingBlocks/Shared/SeedWork"

    Services --> Logging
    Services --> Contracts
    Services --> EBMsgs
    Services --> BBInfra
    Services --> Seed
    CartApp --> Logging
    CartApp --> Contracts
    CartApp --> EBMsgs

    %% Infrastructure
    subgraph "Infrastructure"
        SQL1["SQL Server"]:::db
        SQL2["SQL Server"]:::db
        Redis["Redis"]:::db
        ES["Elasticsearch"]:::db
        RabbitMQ["RabbitMQ"]:::broker
    end

    Services --> SQL1
    CartInfra --> SQL2
    Services --> Redis
    Services --> ES
    Services --> RabbitMQ
    CartApp --> RabbitMQ

    %% External Systems
    subgraph "External Systems"
        Payment["Payment Gateways"]:::external
        AI["External AI"]:::external
        Cloudinary["Cloudinary/ClamAV"]:::external
    end

    Services --> Payment
    Services --> AI
    Services --> Cloudinary

    %% Styles
    classDef api fill:#cce5ff,stroke:#0062cc,color:#004085;
    classDef service fill:#d4edda,stroke:#155724,color:#155724;
    classDef domain fill:#f8d7da,stroke:#721c24,color:#721c24;
    classDef repo fill:#fff3cd,stroke:#856404,color:#856404;
    classDef db fill:#d1ecf1,stroke:#0c5460,color:#0c5460;
    classDef broker fill:#e2e3e5,stroke:#6c757d,color:#383d41;
    classDef external fill:#f5c6cb,stroke:#721c24,color:#721c24;
    classDef buildingblocks fill:#e2f0d9,stroke:#0f5132,color:#0f5132;
```
