# microappstech/lungualink architecture

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

- Interactive diagram: https://gitdiagram.com/microappstech/lungualink
- Repository: https://github.com/microappstech/lungualink

## Overview

##### Project type and purpose
- This is a monolithic, multi-project .NET solution (“LunguaLink.sln”) implementing a learning-session management platform (candidates, teachers, groups, sessions, chat/AI, resources).
- It uses Blazor for UI (both server-hosted and WebAssembly), ASP.NET Core Web API for backend, Entity Framework Core for persistence, SignalR for real-time chat, and JWT for authentication.

##### File structure
- Top-level layers:
- API: Langua.Api (controllers, SignalR hub), Langua.Auth (authentication).
- Business/Core: Langua.Core (interfaces/services), Langua.Repositories (data services/AI/mail).
- Data: Langua.DataContext (EF Core DbContext + Migrations), Langua.DAL (low-level SQL access/Stored procs).
- Domain/Models: Langua.Models (entity classes).
- DTO/Mapping: Langua.ModelView & ViewModels (input models).
- Shared libs: Langua.Shared (common constants, exceptions, API responses), Langua.Api.Shared (JWT middleware/helper).
- UI Components: Langua.UIComponents (reusable Blazor components).
- Web UI:
‑ Langua.WebUI.Client (Blazor WebAssembly client).
‑ Langua.WebUI (Blazor server or hosting project serving the client + authentication pages).
- Configuration: Dockerfile in root and WebUI, SQL scripts, EF migrations under DataContext.

##### README insights
- Focuses on SQL/transaction errors, dynamic LINQ, mail-service setup.
- Highlights use of multiple DbContext instances in a distributed transaction, JWT tokens, SMTP with app-passwords.

##### Main components & relationships
a. Components
1. Client: Blazor WebAssembly (Langua.WebUI.Client)
2. Server UI host: Blazor Server/Static host (Langua.WebUI)
3. REST API: ASP.NET Core Web API (Langua.Api) + Authentication API (Langua.Auth)
4. Real-time Hub: SignalR ChatHub (under Langua.Api/LanguaHub)
5. Business Logic Layer: Services in Langua.Core & Langua.Repositories
6. Data Access Layer: EF Core DbContext (Langua.DataContext) + custom SQL access (Langua.DAL)
7. Domain Entities: Langua.Models
8. Shared Libraries: DTOs, common helpers (Langua.Shared, Langua.Api.Shared, Langua.ModelView)
9. External Services:
- SQL Server (LanguaDb)
- SMTP server for email
- (Optional) Third-party AI service (GeminiApiResponse)
b. Interactions
1. Client ↔ Server UI:
- HTTP (static files, Razor pages)
2. Client ↔ API:
- HTTP calls to REST endpoints (SessionsController, GroupsController, etc.)
- WebSocket/SignalR for real-time chat
- JWT Bearer tokens in Authorization header
3. API ↔ BLL:
- Controllers invoke service interfaces from Langua.Core & Langua.Repositories
4. BLL ↔ DAL:
- Services use EF Core (DbContext) or ISqlDataAccess to query/update SQL Server
5. BLL ↔ External:
- MailService sends via SMTP
- AIService calls external AI API
c. Architectural patterns & principles
- Layered architecture (Presentation → API → BLL → DAL → Database)
- Dependency inversion: abstractions (IBaseRepository, IAIService) in Core and Shared
- Shared models/DTOs to decouple projects
- EF Core Code-First with migrations
- JWT middleware for stateless auth
- SignalR for pub/sub messaging
d. Key technologies/frameworks
- .NET 8, ASP.NET Core, Blazor (WebAssembly & Server)
- Entity Framework Core
- SignalR
- System.Linq.Dynamic.Core (dynamic queries)
- SMTP mail via MailKit/SmtpClient (configured in MailService)
- Docker for containerization

##### Details
- Micro-layers (Model, DTO, Service, Repository).
- JWT authentication flow: Client stores token → Attach to API calls → JwtMiddleware in Langua.Api.Shared validates.
- EF migrations driving schema in Langua.DataContext → SQL Server.
- SignalR hub endpoint (/languaHub) and clients subscribing to chat groups.
- Detail error-handling or transaction-scope notes near the data-access flows to reflect guidance from the README.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    subgraph "UI Layer"
        LWC["Blazor WASM Client"]:::ui
        LWS["Blazor Server UI Host"]:::ui
        UICOMP["UI Component Library"]:::ui
    end

    %% API Layer
    subgraph "API Layer"
        API["REST API Controllers"]:::api
        AuthCtrl["AuthController"]:::api
        SecSvc["SecurityService"]:::api
        HUB["ChatHub (SignalR)"]:::api
    end

    %% Business Layer
    subgraph "Business Layer"
        BIZIF["Business Interfaces"]:::biz
        BIZSRV["Business Base Services"]:::biz
        REPIF["Repository Interfaces"]:::biz
        REPIMP["Repository Implementations"]:::biz
    end

    %% Data Layer
    subgraph "Data Layer"
        DBCTX["ApplicationDbContext (EF Core)"]:::data
        MIG["EF Migrations"]:::data
        SQLACC["SQL DataAccess"]:::data
        SP["Stored Procedures"]:::data
    end

    %% Shared Libraries
    subgraph "Shared Libraries"
        MODELS["Domain Entities"]:::shared
        DTO["DTOs / Input Models"]:::shared
        VM["ViewModels"]:::shared
        APSH["API Shared Middleware"]:::shared
        SL["Shared Constants & Responses"]:::shared
    end

    %% External Services
    subgraph "External Services"
        DB["SQL Server"]:::external
        SMTP["SMTP Email Service"]:::external
        AIEXT["Third-party AI Service"]:::external
    end

    %% Interactions
    LWC -->|"HTTP/HTTPS"| LWS
    LWC -->|"HTTP/HTTPS (JWT)"| API
    LWS -->|"HTTP/HTTPS (JWT)"| API
    LWC -->|"WebSocket (SignalR)"| HUB

    API -->|"calls"| BIZIF
    AuthCtrl -->|"calls"| BIZIF
    SecSvc -->|"calls"| BIZIF
    HUB -->|"invokes"| BIZIF

    BIZIF -->|"used by"| BIZSRV
    BIZSRV -->|"uses"| REPIF
    REPIF -->|"implemented by"| REPIMP

    REPIMP -->|"EF Core"| DBCTX
    REPIMP -->|"SQL Access"| SQLACC
    REPIMP -->|"Stored Procs"| SP

    DBCTX -->|"migrations apply"| MIG
    DBCTX -->|"reads/writes"| DB
    MIG -->|"updates schema"| DB
    SQLACC -->|"executes"| DB
    SP -->|"executes"| DB

    REPIMP -->|"sends email via SMTP"| SMTP
    REPIMP -->|"calls AI API"| AIEXT

    API -->|"uses DTOs"| DTO
    API -->|"uses ViewModels"| VM
    BIZSRV -->|"uses Entities"| MODELS
    REPIMP -->|"uses Entities"| MODELS
    API -->|"JWT validation"| APSH
    API -->|"common responses"| SL

    %% Click Events
    click LWC "https://github.com/microappstech/lungualink/blob/main/Langua.WebUI.Client"
    click LWS "https://github.com/microappstech/lungualink/blob/main/Langua.WebUI"
    click UICOMP "https://github.com/microappstech/lungualink/blob/main/Langua.UIComponents"
    click API "https://github.com/microappstech/lungualink/tree/main/Langua.Api/ApiControllers"
    click AuthCtrl "https://github.com/microappstech/lungualink/blob/main/Langua.Auth/Controllers/AuthController.cs"
    click SecSvc "https://github.com/microappstech/lungualink/blob/main/Langua.Auth/SecurityService.cs"
    click HUB "https://github.com/microappstech/lungualink/blob/main/Langua.Api/LanguaHub/ChatHub.cs"
    click BIZIF "https://github.com/microappstech/lungualink/blob/main/Langua.Core/Interfaces/IBaseRepository.cs"
    click BIZSRV "https://github.com/microappstech/lungualink/blob/main/Langua.Core/Services/BaseRepository.cs"
    click REPIF "https://github.com/microappstech/lungualink/tree/main/Langua.Repositories/Interfaces"
    click REPIMP "https://github.com/microappstech/lungualink/tree/main/Langua.Repositories/Services"
    click DBCTX "https://github.com/microappstech/lungualink/blob/main/Langua.DataContext/Data/ApplicationDbContext.cs"
    click MIG "https://github.com/microappstech/lungualink/tree/main/Langua.DataContext/Data/Migrations"
    click SQLACC "https://github.com/microappstech/lungualink/blob/main/Langua.DAL/SqlDataAccess.cs"
    click SP "https://github.com/microappstech/lungualink/blob/main/Langua.DAL/Sp/SqlProcedure.cs"
    click MODELS "https://github.com/microappstech/lungualink/blob/main/Langua.Models"
    click DTO "https://github.com/microappstech/lungualink/tree/main/Langua.ModelView/InputModels"
    click VM "https://github.com/microappstech/lungualink/blob/main/ViewModels/InputModels/LoginModel.cs"
    click APSH "https://github.com/microappstech/lungualink/blob/main/Langua.Api.Shared/ApiHelper/JwtMiddleware.cs"
    click SL "https://github.com/microappstech/lungualink/blob/main/Langua.Shared/Constants/Enums.cs"

    %% Styles
    classDef ui fill:#CFE2F3,stroke:#6FA8DC,color:#000;
    classDef api fill:#D5E8D4,stroke:#82B366,color:#000;
    classDef biz fill:#FFE599,stroke:#E69138,color:#000;
    classDef data fill:#F2F2F2,stroke:#999999,color:#000;
    classDef shared fill:#E1D5E7,stroke:#9673A6,color:#000;
    classDef external fill:#FCE5CD,stroke:#F6B26B,color:#000;
```
