# phaptrinh/myedu2 architecture

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

- Interactive diagram: https://gitdiagram.com/phaptrinh/myedu2
- Repository: https://github.com/phaptrinh/myedu2

## Overview

##### Project Type Analysis
This is a backend-only Spring Boot application for course management with role-based access control. It's built using Spring Security, Spring Data JPA, and MySQL database, following a typical layered architecture pattern.

##### Main Components

A. Core Layers (Vertical Layers):
- Controllers Layer (REST API endpoints)
- Service Layer (Business Logic)
- Repository Layer (Data Access)
- Entity Layer (Domain Models)

B. Cross-Cutting Concerns (Horizontal Layers):
- Security Layer (JWT Authentication & Authorization)
- Exception Handling Layer
- DTOs/Request-Response Models

##### Relationships and Flows

- REST API calls (from client to controllers)
- Security filter chain flow
- Service-to-repository interactions
- Database operations

- Blue: API/Controller layer
- Green: Service layer
- Yellow: Security components
- Purple: Repository layer
- Gray: Database layer
- Red: Exception handling components

##### Additional Elements

- Request/Response DTOs
- Security configurations
- Exception handling flow
- JWT token flow

##### Specific Implementation Details

Specific flows for:
- Authentication process
- Role-based access control
- Class enrollment process
- Admin management operations

##### Notes Section

Notes about:
- Security implementation
- Database relationships
- API endpoint groupings
- Cross-cutting concerns

Remember to emphasize the security layer as it's a crucial part of the system, showing how JWT authentication and authorization flow through the application.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef client fill:#E1F5FE,stroke:#01579B
    classDef api fill:#BBDEFB,stroke:#1565C0
    classDef security fill:#FFF9C4,stroke:#F57F17
    classDef service fill:#C8E6C9,stroke:#2E7D32
    classDef repo fill:#E1BEE7,stroke:#4A148C
    classDef db fill:#CFD8DC,stroke:#37474F
    classDef dto fill:#FFCCBC,stroke:#BF360C
    classDef entity fill:#B2EBF2,stroke:#006064

    %% Client Layer
    subgraph Clients
        Student[Student Client]:::client
        Teacher[Teacher Client]:::client
        Admin[Admin Client]:::client
    end

    %% API Controllers Layer
    subgraph Controllers
        AuthC[Auth Controller]:::api
        AdminC[Admin Controller]:::api
        StudentC[Student Controller]:::api
        TeacherC[Teacher Controller]:::api
        UserC[User Controller]:::api
    end

    %% Security Layer
    subgraph Security
        JWT[JWT Config]:::security
        SecConfig[Web Security Config]:::security
        UserDetails[User Details Impl]:::security
        AuthFilter[Auth Token Filter]:::security
    end

    %% Service Layer
    subgraph Services
        UserS[User Service]:::service
        ClassS[Class Service]:::service
        EnrollS[Enrollment Service]:::service
        SubjectS[Subject Service]:::service
        RoomS[Room Service]:::service
        TimeS[Time Service]:::service
    end

    %% Repository Layer
    subgraph Repositories
        UserR[User Repository]:::repo
        ClassR[Class Repository]:::repo
        EnrollR[Enrollment Repository]:::repo
        SubjectR[Subject Repository]:::repo
        RoomR[Room Repository]:::repo
        TimeR[Time Repository]:::repo
    end

    %% Entity Layer
    subgraph Entities
        UserE[User Entity]:::entity
        ClassE[Class Entity]:::entity
        EnrollE[Enrollment Entity]:::entity
        SubjectE[Subject Entity]:::entity
        RoomE[Room Entity]:::entity
        TimeE[Time Entity]:::entity
        RoleE[Role Entity]:::entity
    end

    %% Database
    DB[(MySQL Database)]:::db

    %% Cross-Cutting Concerns
    ExHandler[Exception Handler]:::dto
    DTOs[DTOs]:::dto

    %% Relationships
    Student & Teacher & Admin --> AuthC & StudentC & TeacherC & AdminC & UserC
    AuthC & AdminC & StudentC & TeacherC & UserC --> JWT
    JWT --> SecConfig
    SecConfig --> AuthFilter
    AuthFilter --> UserDetails
    AuthC & AdminC & StudentC & TeacherC & UserC --> UserS & ClassS & EnrollS & SubjectS & RoomS & TimeS
    UserS & ClassS & EnrollS & SubjectS & RoomS & TimeS --> UserR & ClassR & EnrollR & SubjectR & RoomR & TimeR
    UserR & ClassR & EnrollR & SubjectR & RoomR & TimeR --> DB
    UserE & ClassE & EnrollE & SubjectE & RoomE & TimeE & RoleE --> DB

    %% Click Events
    click AuthC "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/controller/AuthController.java"
    click AdminC "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/controller/AdminController.java"
    click StudentC "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/controller/StudentController.java"
    click TeacherC "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/controller/TeacherController.java"
    click UserC "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/controller/UserController.java"
    click JWT "https://github.com/phaptrinh/myedu2/tree/main/src/main/java/com/example/myedu/security/jwt"
    click SecConfig "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/security/WebSecurityConfig.java"
    click UserDetails "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/security/service/UserDetailsImpl.java"
    click AuthFilter "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/security/jwt/AuthTokenFilter.java"
    click UserS "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/service/UserServiceImpl.java"
    click ClassS "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/service/ClassServiceImpl.java"
    click EnrollS "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/service/EnrollmentServiceImpl.java"
    click SubjectS "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/service/SubjectServiceImpl.java"
    click RoomS "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/service/RoomServiceImpl.java"
    click TimeS "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/service/TimeServiceImpl.java"
    click UserR "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/repository/UserRepository.java"
    click ClassR "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/repository/ClassRepository.java"
    click EnrollR "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/repository/EnrollmentRepository.java"
    click SubjectR "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/repository/SubjectRepository.java"
    click RoomR "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/repository/RoomRepository.java"
    click TimeR "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/repository/TimeRepository.java"
    click UserE "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/entity/User.java"
    click ClassE "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/entity/Class.java"
    click EnrollE "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/entity/Enrollment.java"
    click SubjectE "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/entity/Subject.java"
    click RoomE "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/entity/Room.java"
    click TimeE "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/entity/Time.java"
    click RoleE "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/entity/Role.java"
    click ExHandler "https://github.com/phaptrinh/myedu2/blob/main/src/main/java/com/example/myedu/exception/CustomExceptionHandler.java"
    click DTOs "https://github.com/phaptrinh/myedu2/tree/main/src/main/java/com/example/myedu/model"
```
