# theanh994/kiemthu architecture

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

- Interactive diagram: https://gitdiagram.com/theanh994/kiemthu
- Repository: https://github.com/theanh994/kiemthu

## Overview

##### Project type and purpose
- EduMana is a Spring Boot–based, full-stack education management system.
- It provides both server-rendered HTML views (Thymeleaf + static CSS) and a RESTful API.
- Uses H2 in-memory database with Flyway migrations, Spring Data JPA for persistence, and Maven for build.

##### File structure
- Top-level artifacts:
- pom.xml – Maven project definition
- src/main/java/com/edumana – Java source split into controller, service, repository, model, dto
- src/main/resources:
– application.properties – runtime configuration
– db/migration – Flyway SQL migrations
– static/css – styles
– templates – Thymeleaf views organized by feature (course, teacher, statistics, etc.)
- Patterns:
- Layered MVC: Controllers → Services → Repositories → Database
- One monolithic deployable JAR with embedded Tomcat

##### Main components
a. Client Layer
– Browser/UI (HTML pages + CSS)
– REST client (e.g., AJAX, Postman)
b. Web Server
– Spring Boot embedded Tomcat
– Spring MVC dispatcher
c. Presentation Layer
– Thymeleaf templates + static assets
– API controllers (CourseClassApiController, etc.)
d. Service Layer
– Business logic services (CourseService, TeachingPaymentService, etc.)
e. Data Access Layer
– Spring Data JPA repositories
f. Persistence
– H2 in-memory database
– Flyway migration scripts
g. (Optional) H2 Console as external admin UI

##### Relationships & data flows
- Browser → HTTP GET/POST → MVC Controller → Service → Repository → H2 DB → back up chain → Browser
- REST client → HTTP JSON → ApiController → Service → Repository → DB → JSON response
- At application start: Flyway migrations → DB schema
- DB console access routes to H2 engine

##### Architectural patterns and design principles
- Layered architecture (separation of concerns)
- MVC for server-rendered pages
- RESTful resource controllers
- Dependency inversion: Controllers depend on Service interfaces, Services depend on Repository interfaces
- Flyway for versioned DB schema migration
- DTO pattern for reports and statistics

##### Essential details to capture
- All controller classes and their channels (UI vs. API)
- Key service classes and the domain they serve (e.g., TeachingPaymentService)
- Repository interfaces and Flyway migrations feeding into the database
- Static asset server and H2 console as side-car

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        Browser["Browser/UI"]:::client
        RESTClient["REST Client"]:::client
        Templates["Thymeleaf Templates"]:::client
        CSS["static/css/styles.css"]:::client
    end

    %% Web Server
    subgraph "Web Server"
        App["EduManaApplication"]:::infra
        Dispatcher["Spring MVC Dispatcher"]:::infra
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        subgraph "UI Controllers"
            C1["CourseController"]:::presentation
            C2["CourseClassController"]:::presentation
            C3["TeacherController"]:::presentation
            C4["DepartmentController"]:::presentation
            C5["DegreeController"]:::presentation
            C6["SemesterController"]:::presentation
            C7["ClassCoefficientController"]:::presentation
            C8["TeachingAssignmentController"]:::presentation
            C9["TeachingPaymentController"]:::presentation
            C10["TeachingRateController"]:::presentation
            C11["StatisticsController"]:::presentation
        end
        subgraph "API Controllers"
            API["CourseClassApiController"]:::presentation
        end
    end

    %% Service Layer
    subgraph "Service Layer"
        S1["CourseService"]:::business
        S2["CourseClassService"]:::business
        S3["TeacherService"]:::business
        S4["DepartmentService"]:::business
        S5["DegreeService"]:::business
        S6["SemesterService"]:::business
        S7["ClassCoefficientService"]:::business
        S8["TeachingPaymentService"]:::business
        S9["TeachingRateService"]:::business
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        R1["CourseRepository"]:::dataaccess
        R2["CourseClassRepository"]:::dataaccess
        R3["TeacherRepository"]:::dataaccess
        R4["DepartmentRepository"]:::dataaccess
        R5["DegreeRepository"]:::dataaccess
        R6["SemesterRepository"]:::dataaccess
        R7["ClassCoefficientRepository"]:::dataaccess
        R8["TeachingRateRepository"]:::dataaccess
    end

    %% Persistence
    subgraph "Database"
        H2["H2 In-Memory DB"]:::infra
        Migrations["Flyway Migrations"]:::infra
        H2Console["H2 Console"]:::infra
    end

    %% DTOs
    subgraph "DTOs"
        D1["CourseStatistics"]:::dataaccess
        D2["TeacherStatistics"]:::dataaccess
        D3["TeachingPaymentDTO"]:::dataaccess
        D4["TeachingPaymentYearlyReport"]:::dataaccess
    end

    %% Config
    Properties["application.properties"]:::infra

    %% Connections
    Browser -->|"HTTP/HTML"| Dispatcher
    RESTClient -->|"HTTP/JSON"| Dispatcher

    Dispatcher -->|"routes to"| C1
    Dispatcher -->|"routes to"| C2
    Dispatcher -->|"routes to"| C3
    Dispatcher -->|"routes to"| C4
    Dispatcher -->|"routes to"| C5
    Dispatcher -->|"routes to"| C6
    Dispatcher -->|"routes to"| C7
    Dispatcher -->|"routes to"| C8
    Dispatcher -->|"routes to"| C9
    Dispatcher -->|"routes to"| C10
    Dispatcher -->|"routes to"| C11
    Dispatcher -->|"routes to"| API

    C1 -->|"calls"| S1
    C2 -->|"calls"| S2
    C3 -->|"calls"| S3
    C4 -->|"calls"| S4
    C5 -->|"calls"| S5
    C6 -->|"calls"| S6
    C7 -->|"calls"| S7
    C9 -->|"calls"| S8
    C10 -->|"calls"| S9
    C11 -->|"calls"| S2

    API -->|"calls"| S2

    S1 -->|"uses"| R1
    S2 -->|"uses"| R2
    S3 -->|"uses"| R3
    S4 -->|"uses"| R4
    S5 -->|"uses"| R5
    S6 -->|"uses"| R6
    S7 -->|"uses"| R7
    S9 -->|"uses"| R8
    S8 -->|"uses"| R7

    R1 -->|"JPA query"| H2
    R2 -->|"JPA query"| H2
    R3 -->|"JPA query"| H2
    R4 -->|"JPA query"| H2
    R5 -->|"JPA query"| H2
    R6 -->|"JPA query"| H2
    R7 -->|"JPA query"| H2
    R8 -->|"JPA query"| H2

    Migrations -->|"at startup"| H2
    Properties -->|"configures"| App
    App -->|"embeds"| Dispatcher
    H2Console -->|"accesses"| H2

    Templates --> C1
    CSS --> Templates

    %% Click Events
    click Templates "https://github.com/theanh994/kiemthu/tree/master/src/main/resources/templates"
    click CSS "https://github.com/theanh994/kiemthu/blob/master/src/main/resources/static/css/styles.css"
    click App "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/EduManaApplication.java"
    click C1 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/controller/CourseController.java"
    click C2 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/controller/CourseClassController.java"
    click C3 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/controller/TeacherController.java"
    click C4 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/controller/DepartmentController.java"
    click C5 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/controller/DegreeController.java"
    click C6 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/controller/SemesterController.java"
    click C7 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/controller/ClassCoefficientController.java"
    click C8 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/controller/TeachingAssignmentController.java"
    click C9 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/controller/TeachingPaymentController.java"
    click C10 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/controller/TeachingRateController.java"
    click C11 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/controller/StatisticsController.java"
    click API "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/controller/CourseClassApiController.java"
    click S1 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/service/CourseService.java"
    click S2 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/service/CourseClassService.java"
    click S3 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/service/TeacherService.java"
    click S4 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/service/DepartmentService.java"
    click S5 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/service/DegreeService.java"
    click S6 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/service/SemesterService.java"
    click S7 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/service/ClassCoefficientService.java"
    click S8 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/service/TeachingPaymentService.java"
    click S9 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/service/TeachingRateService.java"
    click R1 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/repository/CourseRepository.java"
    click R2 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/repository/CourseClassRepository.java"
    click R3 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/repository/TeacherRepository.java"
    click R4 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/repository/DepartmentRepository.java"
    click R5 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/repository/DegreeRepository.java"
    click R6 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/repository/SemesterRepository.java"
    click R7 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/repository/ClassCoefficientRepository.java"
    click R8 "https://github.com/theanh994/kiemthu/blob/master/src/main/java/com/edumana/repository/TeachingRateRepository.java"
    click Migrations "https://github.com/theanh994/kiemthu/tree/master/src/main/resources/db/migration"
    click Properties "https://github.com/theanh994/kiemthu/blob/master/src/main/resources/application.properties"

    %% Styles
    classDef client fill:#DDEEFF,stroke:#888888,color:#000000
    classDef presentation fill:#BBCCFF,stroke:#888888,color:#000000
    classDef business fill:#CCFFCC,stroke:#888888,color:#000000
    classDef dataaccess fill:#FFDD99,stroke:#888888,color:#000000
    classDef infra fill:#EEEEEE,stroke:#888888,color:#000000
```
