# dgeniust/hcmute-care architecture

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

- Interactive diagram: https://gitdiagram.com/dgeniust/hcmute-care
- Repository: https://github.com/dgeniust/hcmute-care

## Overview

##### Main Components
- Frontend: Built with React 18; includes various components for administration, booking, and personal user pages. It handles user interactions and communicates with the backend via Axios for RESTful API calls.
- Backend: Built with Spring Boot. Its structure follows typical layered architecture with controllers (handling REST endpoints such as AuthenticationController and HomeController), services (business logic implemented in classes like AuthenticationServiceImpl, JwtServiceImpl, OtpServiceImpl), repositories (data access layer), configuration classes (AppConfig, OpenApiConfig, RedisConfig, etc.), and central exception handling.
- Database: A relational database (MySQL is mentioned as default, although Postgres is also an option).
- Docker & Containerization: Each layer (backend and frontend) is containerized with its own Dockerfile and docker-compose configuration, providing isolated build and deployment environments.

##### Relationships and Data Flow
- From the Backend, illustrate connections to the Database for CRUD operations managed via Spring Data JPA.
- Interactions with external services if applicable (for example, Redis for caching/security in the backend).
- Docker ecosystem for each major component – indicate that both frontend and backend are encapsulated in Docker containers orchestrated via respective docker-compose files.
- Optionally, mark the build tools / environments: Maven for the backend and Node.js/npm for the frontend.

##### Architectural Patterns and Components
- For the Backend: Emphasize the layered (MVC-like) design:
a. Controller Layer (REST endpoints)
b. Service Layer (business logic, token handling, OTP operations)
c. Data Access Layer (repositories interfacing with the database)
d. Configuration and Exception Handling components.
- For the Frontend: Note the component-based design using React components that handle different pages (Admin, Booking, Personal, etc.) and specific utilities like routing (React Router) and HTTP communication (Axios).
- Docker containerization as a pattern to ensure that both parts can be built, tested, and deployed independently.

##### Technologies and Tools
- Docker and Docker Compose as critical for containerization and deployment.

##### Putting It All Together
- Next to the Backend, add the Database component and, if in use, the Redis cache component.
- On the Frontend side, illustrate a breakdown of major pages or components such as Admin, Booking, and Personal modules.

- Frontend (React components, API calls, routing)
- Backend (Spring Boot layers, business logic, database access)
- Database/Cache (MySQL/Postgres, Redis)
- Containerization (Docker components orchestrated via docker-compose)

This approach ensures a comprehensive, visually clear representation of the project’s components and their interactions.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        F["Frontend (React UI)"]:::frontend
        FC["React Components"]:::frontend
        FP["React Pages"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        B["Spring Boot Application"]:::backend
        C["Controllers"]:::backend
        S["Services"]:::backend
        SI["Service Implementations"]:::backend
        R["Repositories"]:::backend
        CFG["Configurations"]:::backend
        EX["Exception Handling"]:::backend
        DTO["DTOs"]:::backend
        DBINIT["DB Initialization"]:::backend
        BDF["Backend Dockerfile"]:::container
        BDCC["Backend docker-compose"]:::container
    end

    %% External and Container Components
    subgraph "Infrastructure"
        DB["Database (MySQL/Postgres)"]:::external
        RED["Redis Cache"]:::external
        FD["Frontend Docker (Implicit)"]:::container
    end

    %% Connections between Frontend and Backend
    F -->|"APICalls"| B
    F --> FC
    F --> FP
    F -.->|"Container"| FD

    %% Backend internal layers and external integrations
    B -->|"RESTEndpoints"| C
    C -->|"Invoke"| S
    S -->|"Implementation"| SI
    SI -->|"DataAccess"| R
    R -->|"CRUD"| DB
    C -->|"DataTransfer"| DTO
    C -->|"ErrorHandling"| EX
    S -->|"CacheOps"| RED

    %% Auxiliary Backend components
    CFG --- B
    DBINIT --- DB
    B -.->|"ContainerizedBy"| BDF
    BDF -.-> BDCC

    %% Click Events
    click F "https://github.com/dgeniust/hcmute-care/tree/main/frontend/"
    click FC "https://github.com/dgeniust/hcmute-care/tree/main/frontend/src/components"
    click FP "https://github.com/dgeniust/hcmute-care/tree/main/frontend/src/pages"
    click B "https://github.com/dgeniust/hcmute-care/blob/main/backend/src/main/java/vn/edu/hcmute/utecare/UteCareApplication.java"
    click C "https://github.com/dgeniust/hcmute-care/tree/main/backend/src/main/java/vn/edu/hcmute/utecare/controller"
    click S "https://github.com/dgeniust/hcmute-care/tree/main/backend/src/main/java/vn/edu/hcmute/utecare/service"
    click SI "https://github.com/dgeniust/hcmute-care/tree/main/backend/src/main/java/vn/edu/hcmute/utecare/service/impl"
    click R "https://github.com/dgeniust/hcmute-care/tree/main/backend/src/main/java/vn/edu/hcmute/utecare/repository"
    click CFG "https://github.com/dgeniust/hcmute-care/tree/main/backend/src/main/java/vn/edu/hcmute/utecare/configuration"
    click EX "https://github.com/dgeniust/hcmute-care/tree/main/backend/src/main/java/vn/edu/hcmute/utecare/exception"
    click DTO "https://github.com/dgeniust/hcmute-care/tree/main/backend/src/main/java/vn/edu/hcmute/utecare/dto"
    click DBINIT "https://github.com/dgeniust/hcmute-care/blob/main/backend/initdb.sql"
    click BDF "https://github.com/dgeniust/hcmute-care/tree/main/backend/Dockerfile"
    click BDCC "https://github.com/dgeniust/hcmute-care/blob/main/backend/docker-compose.yml"

    %% Styles
    classDef frontend fill:#D1E8FF,stroke:#1F78C1,stroke-width:2px;
    classDef backend fill:#F8D7DA,stroke:#C0392B,stroke-width:2px;
    classDef container fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#D4AC0D,stroke-width:2px;
```
