# binhfnguyeen/englearn-backend architecture

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

- Interactive diagram: https://gitdiagram.com/binhfnguyeen/englearn-backend
- Repository: https://github.com/binhfnguyeen/englearn-backend

## Overview

##### Project type and purpose
- This is a full-stack e-learning web application:
- Frontend: Next.js (React-based UI)
- Backend: Spring Boot monolith exposing REST controllers, WebSocket endpoints, and GraphQL resolvers
- Database: MySQL for persistent data storage
- AI Chat Memory: Uses Spring AI chat memory repositories (JDBC)
- Auxiliary services: Email (OTP), authentication (JWT/OAuth)

##### File structure
- Top-level artifacts
- Dockerfile + Maven wrapper + pom.xml → build & containerization
- src/main/java/com/heulwen/configs → Spring configuration (security, WebSocket, AI chat)
- src/main/java/com/heulwen/controllers → REST API entry points
- src/main/java/com/heulwen/resolvers → GraphQL query/mutation resolvers
- src/main/java/com/heulwen/services → business logic layer
- src/main/java/com/heulwen/repositories → Spring Data JPA interfaces for MySQL
- src/main/java/com/heulwen/mapper → DTO ↔ entity conversion
- src/main/java/com/heulwen/pojo → JPA entity definitions
- src/main/java/com/heulwen/dto → request/response payload definitions
- src/main/java/com/heulwen/exceptions → global error handling
- src/main/resources → application.properties (DB, AI memory schemas)

##### README for additional insights
- Confirms stack and intended use (English learning site).

##### Detail without over-fragmentation
- Every layer: Presentation, API, Business, Persistence, External Integrations.
- Clarity of how components interact, where data lives, and how requests traverse the system.

## Diagram (Mermaid)

```mermaid
graph TB
    User["User's Browser"]:::frontend
    subgraph "Frontend Layer"
        NextJS["Next.js Frontend"]:::frontend
    end
    User --> NextJS
    NextJS -->|"HTTP(S) REST/GraphQL"| REST
    NextJS -.->|"WebSocket Chat"| WS

    subgraph "Spring Boot Application"
        ElearnApp["ElearnwebApplication"]:::backend
        subgraph "Configuration Layer"
            Configs["configs package"]:::config
        end
        subgraph "API Layer"
            REST["REST API Controllers"]:::backend
            WS["WebSocketChatController"]:::backend
            GQL["GraphQL Resolvers"]:::backend
        end
        subgraph "Business Layer"
            Services["Services"]:::service
        end
        subgraph "Data Layer"
            Repos["Repositories"]:::repository
            Mappers["Entity-DTO Mappers"]:::dtoMapping
            Entities["JPA Entities"]:::repository
            DTOs["DTO Definitions"]:::dtoMapping
            AppProps["application.properties"]:::code
            Schema["schema-mysql.sql"]:::code
        end
        subgraph "Exception Handling"
            Exceptions["GlobalExceptionHandler"]:::error
        end

        ElearnApp --> Configs
        ElearnApp --> REST
        ElearnApp --> WS
        ElearnApp --> GQL

        REST --> Services
        WS --> Services
        GQL --> Services

        Services --> Repos
        Services --> Mappers
        Repos --> Entities
        DTOs --> Services
        Exceptions --> Services

        AppProps --> MySQL
        Schema --> MySQL
    end

    subgraph "External Systems"
        MySQL["MySQL Database"]:::db
        SMTP["External SMTP (Email/OTP)"]:::external
        AI["AI Chat Memory (JDBC)"]:::external
    end

    Repos --> MySQL
    Services --> SMTP
    Services --> AI

    subgraph "Build & Containerization"
        Pom["pom.xml"]:::code
        MVN["mvnw"]:::code
        Dockerfile["Dockerfile"]:::code
    end

    click ElearnApp "https://github.com/binhfnguyeen/englearn-backend/blob/main/src/main/java/com/heulwen/elearnweb/ElearnwebApplication.java"
    click Configs "https://github.com/binhfnguyeen/englearn-backend/tree/main/src/main/java/com/heulwen/configs"
    click REST "https://github.com/binhfnguyeen/englearn-backend/tree/main/src/main/java/com/heulwen/controllers"
    click WS "https://github.com/binhfnguyeen/englearn-backend/blob/main/src/main/java/com/heulwen/controllers/WebSocketChatController.java"
    click GQL "https://github.com/binhfnguyeen/englearn-backend/tree/main/src/main/java/com/heulwen/resolvers"
    click Services "https://github.com/binhfnguyeen/englearn-backend/tree/main/src/main/java/com/heulwen/services"
    click Repos "https://github.com/binhfnguyeen/englearn-backend/tree/main/src/main/java/com/heulwen/repositories"
    click Entities "https://github.com/binhfnguyeen/englearn-backend/tree/main/src/main/java/com/heulwen/pojo"
    click DTOs "https://github.com/binhfnguyeen/englearn-backend/tree/main/src/main/java/com/heulwen/dto"
    click Mappers "https://github.com/binhfnguyeen/englearn-backend/tree/main/src/main/java/com/heulwen/mapper"
    click Exceptions "https://github.com/binhfnguyeen/englearn-backend/tree/main/src/main/java/com/heulwen/exceptions"
    click Pom "https://github.com/binhfnguyeen/englearn-backend/blob/main/pom.xml"
    click MVN "https://github.com/binhfnguyeen/englearn-backend/tree/main/mvnw"
    click Dockerfile "https://github.com/binhfnguyeen/englearn-backend/tree/main/src/main/Dockerfile"
    click AppProps "https://github.com/binhfnguyeen/englearn-backend/blob/main/src/main/resources/application.properties"
    click Schema "https://github.com/binhfnguyeen/englearn-backend/blob/main/src/main/resources/org/springframework/ai/chat/memory/repository/jdbc/schema-mysql.sql"

    classDef frontend fill:#D0E6FF,stroke:#333,stroke-width:1px;
    classDef backend fill:#E0FFE0,stroke:#333,stroke-width:1px;
    classDef service fill:#AAFFAA,stroke:#333,stroke-width:1px;
    classDef repository fill:#CCFFCC,stroke:#333,stroke-width:1px;
    classDef db fill:#FFD580,stroke:#333,stroke-width:1px;
    classDef external fill:#E0CCFF,stroke:#333,stroke-width:1px;
    classDef config fill:#CFE0FF,stroke:#333,stroke-width:1px;
    classDef dtoMapping fill:#FFE0B2,stroke:#333,stroke-width:1px;
    classDef error fill:#FFCCCC,stroke:#333,stroke-width:1px;
    classDef code fill:#F0F0F0,stroke:#333,stroke-width:1px;
```
