# k1mb1/edu architecture

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

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

## Overview

##### Main Components

a) Client Layer:
- External clients (Web/Mobile)
- Swagger UI for API documentation

b) Security Layer:
- Keycloak Authentication Server
- JWT Authentication/Authorization flow
- Security Config components

c) API Layer:
- REST Controllers (CourseController)
- Request/Response DTOs
- Error Handling
- OpenAPI Configuration

d) Service Layer:
- Business Logic Services (CourseService, LessonService, UserService)
- DTO-Entity Mappers
- Exception Handling

e) Persistence Layer:
- Repositories
- Entity Models
- PostgreSQL Database

**[External Clients] → [Load Balancer/Gateway*]**
- ↓
**[Keycloak Auth Server] ←→ [Spring Boot Application]**
- ↓
- [PostgreSQL Database]

**API Layer:**
**[Controllers] → [Request/Response DTOs] → [Request/Response Mappers]**
- ↓
**Security Layer:**
**[JWT Converter] → [Security Config] → [Authorization Utils]**
- ↓
**Service Layer:**
**[Service Interfaces] → [Service Implementations] → [DTO/Entity Mappers]**
- ↓
**Repository Layer:**
**[JPA Repositories] → [Entity Models] → [PostgreSQL]**

##### Important Relationships to Highlight

- Authentication flow between client → Keycloak → Application
- JWT token validation path
- Data flow from controllers through services to repositories
- Mapping relationships between DTOs and Entities
- Error handling flow

##### Technical Details

- Spring Boot 3.x as the foundation
- OAuth2/JWT security implementation
- JPA/Hibernate for database access
- MapStruct for object mapping
- Swagger/OpenAPI for documentation

##### Additional Elements

- Version information
- Async operations if any
- Test coverage scope
- Infrastructure components from docker-compose

##### Notes for Implementation

- Maintain consistent styling
- Clear labels
- Brief descriptions for complex flows
- Creating separate detailed views for:
- Authentication flow
- CRUD operations
- Error handling

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef client fill:#2374f7,color:white
    classDef security fill:#ff6b6b,color:white
    classDef api fill:#4CAF50,color:white
    classDef service fill:#FFD700
    classDef repository fill:#FF8C00
    classDef database fill:#A0522D,color:white
    classDef config fill:#808080,color:white

    %% Client Layer
    subgraph Clients
        WC[Web Client]:::client
        MC[Mobile Client]:::client
        SW[Swagger UI]:::client
    end

    %% Security Layer
    subgraph Security
        KC[Keycloak Server]:::security
        JC["JWT Converter"]:::security
        SC["Security Config"]:::security
        AU["Authorization Utils"]:::security
    end

    %% API Layer
    subgraph API
        CC["Course Controller"]:::api
        OC["OpenAPI Config"]:::api
        EH["Rest Error Handler"]:::api
        DTO["Request/Response DTOs"]:::api
        AM["API Mappers"]:::api
    end

    %% Service Layer
    subgraph Services
        SI["Service Interfaces"]:::service
        SI_impl["Service Implementations"]:::service
        SM["Service Mappers"]:::service
        SDTO["Service DTOs"]:::service
        EX["Exception Handling"]:::service
    end

    %% Repository Layer
    subgraph Persistence
        CR["Course Repository"]:::repository
        LR["Lesson Repository"]:::repository
        UR["User Repository"]:::repository
        EM["Entity Models"]:::repository
    end

    DB[(PostgreSQL)]:::database

    %% Relationships
    WC & MC & SW --> KC
    KC --> JC
    JC --> SC
    SC --> AU

    WC & MC & SW --> CC
    CC --> OC
    CC --> EH
    CC <--> DTO
    DTO <--> AM

    CC --> SI
    SI --> SI_impl
    SI_impl <--> SM
    SI_impl <--> SDTO
    SI_impl --> EX

    SI_impl --> CR & LR & UR
    CR & LR & UR --> EM
    EM --> DB

    %% Click Events
    click JC "https://github.com/k1mb1/edu/blob/main/src/main/java/me/k1mb/edu/controller/converter/JwtAuthConverter.java"
    click SC "https://github.com/k1mb1/edu/blob/main/src/main/java/me/k1mb/edu/controller/config/SecurityConfig.java"
    click AU "https://github.com/k1mb1/edu/blob/main/src/main/java/me/k1mb/edu/controller/utils/AuthorizationTypeUtil.java"
    click CC "https://github.com/k1mb1/edu/blob/main/src/main/java/me/k1mb/edu/controller/CourseController.java"
    click OC "https://github.com/k1mb1/edu/blob/main/src/main/java/me/k1mb/edu/controller/config/OpenApiConfig.java"
    click EH "https://github.com/k1mb1/edu/blob/main/src/main/java/me/k1mb/edu/controller/handler/RestErrorHandler.java"
    click DTO "https://github.com/k1mb1/edu/tree/main/src/main/java/me/k1mb/edu/controller/model/"
    click AM "https://github.com/k1mb1/edu/tree/main/src/main/java/me/k1mb/edu/controller/mapper/"
    click SI "https://github.com/k1mb1/edu/tree/main/src/main/java/me/k1mb/edu/service/"
    click SI_impl "https://github.com/k1mb1/edu/tree/main/src/main/java/me/k1mb/edu/service/impl/"
    click SM "https://github.com/k1mb1/edu/tree/main/src/main/java/me/k1mb/edu/service/mapper/"
    click SDTO "https://github.com/k1mb1/edu/tree/main/src/main/java/me/k1mb/edu/service/model/"
    click EX "https://github.com/k1mb1/edu/tree/main/src/main/java/me/k1mb/edu/service/exception/"
    click CR "https://github.com/k1mb1/edu/blob/main/src/main/java/me/k1mb/edu/repository/CourseRepository.java"
    click LR "https://github.com/k1mb1/edu/blob/main/src/main/java/me/k1mb/edu/repository/LessonRepository.java"
    click UR "https://github.com/k1mb1/edu/blob/main/src/main/java/me/k1mb/edu/repository/UserRepository.java"
    click EM "https://github.com/k1mb1/edu/tree/main/src/main/java/me/k1mb/edu/repository/entity/"
```
