# ngocthong37/hair-salon-management-system architecture

> Architecture diagram of the GitHub repository ngocthong37/hair-salon-management-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ngocthong37/hair-salon-management-system
- Repository: https://github.com/ngocthong37/hair-salon-management-system

## Overview

##### Main Architectural Components
- API/Controller Layer: Representing the front door of the application, this layer exposes various REST endpoints. Components include controllers like AppointmentController, AuthenticationController, ProductController, SalonController, etc.
- Service Layer: This layer contains the business logic. Key components include AppointmentService, AuthenticationService, ProductService, EmailSendService, and others. It acts as a bridge between the controllers and repositories.
- Repository/Data Access Layer: Comprising repository interfaces (e.g., AppointmentRepository, ProductRepository) and their implementations (EmailServiceRepositoryImp, RevenueRepositoryImp), these interact directly with the database.
- Domain/Entity Layer: Includes all the entities (for instance, Appointment, Order, User, Salon) and models that represent the business data.
- Security Layer: Contains classes under the security package such as SecurityConfiguration, JwtAuthenticationFilter, and JwtService to enforce JWT-based authentication.
- External/Utility Components: Email notification functionality is supported by FreeMarker templates (in resources/templates) and might interact with external SMTP/email services.

##### Relationships and Flow
- Requests go to Controllers, which validate the inputs and delegate to the Service layer.
- The Services process business logic and interact with the Repository layer for database operations.
- The Security component (JWT authentication) interjects in the request pipeline to secure endpoints.
- Email notifications are triggered from services (like EmailSendService) and make use of FreeMarker templates.
- The database (MySQL based on README instructions) supports persistent storage for entities.

##### Architectural Patterns and Design Principles
- Layered (n-tier) Architecture: The clear separation into controllers, services, and repositories.
- Security as a Cross-Cutting Concern: Integrated via Spring Security and JWT.
- Separation of Concerns: Each package (controller, service, repository, security) has focused responsibilities.
- Use of MVC for handling web requests and FreeMarker for email templating.

##### Relevant Technologies and Frameworks
- Spring Boot (including built-in REST support).
- Spring Security with JWT for authentication.
- Maven for build and dependency management.
- MySQL (as indicated by the “managementsalon” database creation needed).
- FreeMarker for rendering email templates.
- Docker (a Dockerfile is present, suggesting containerized deployment).

##### Instructing the Principal Software Engineer
- That every component’s role is clearly labeled.
- To capture cross-cutting concerns (like security) and middleware (email, templating) explicitly.

This detailed representation should provide the principal software engineer with a comprehensive blueprint of the project’s system architecture, ensuring that all essential components and their interactions are visible and well-organized.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "External Components"
        Client["External Clients (API Consumers)"]:::external
        DB["MySQL Database"]:::database
        EmailTemplates["FreeMarker Email Templates"]:::external
    end

    subgraph "Security Layer"
        SecurityConfig["SecurityConfiguration\n(enforces JWT)"]:::security
        JwtFilter["JwtAuthenticationFilter"]:::security
        JwtService["JwtService"]:::security
        AppConfig["ApplicationConfig"]:::security
    end

    subgraph "API/Controller Layer"
        AppCtrl["AppointmentController"]:::controller
        AuthCtrl["AuthenticationController"]:::controller
        ProdCtrl["ProductController"]:::controller
        SalonCtrl["SalonController"]:::controller
        OtherCtrl["OtherControllers"]:::controller
    end

    subgraph "Service Layer"
        AppService["AppointmentService"]:::service
        AuthService["AuthenticationService"]:::service
        ProdService["ProductService"]:::service
        EmailService["EmailSendService"]:::service
        OtherService["OtherServices"]:::service
    end

    subgraph "Repository/Data Access Layer"
        AppRepository["AppointmentRepository"]:::repository
        IEmailRepo["IEmailServiceRepository"]:::repository
        EmailRepoImp["EmailServiceRepositoryImp"]:::repository
        IRevenueRepo["IRevenueRepository"]:::repository
        RevenueRepoImp["RevenueRepositoryImp"]:::repository
        OtherRepo["OtherRepositories"]:::repository
    end

    subgraph "Domain/Entity Layer"
        AppointmentEntity["Appointment"]:::entity
        UserEntity["User"]:::entity
        OrderEntity["Order"]:::entity
        SalonEntity["Salon"]:::entity
        OtherEntity["OtherEntities"]:::entity
    end

    %% Data Flow
    Client -->|"HTTP_Request"| JwtFilter
    JwtFilter -->|"Validates_Request"| AppCtrl
    SecurityConfig -->|"Secures"| AppCtrl
    JwtService -->|"Supports JWT"| AppCtrl
    AppConfig -->|"Configures Security"| SecurityConfig

    AppCtrl -->|"Delegates"| AppService
    AuthCtrl -->|"Delegates"| AuthService
    ProdCtrl -->|"Delegates"| ProdService
    SalonCtrl -->|"Delegates"| OtherService
    OtherCtrl -->|"Delegates"| OtherService

    AppService -->|"Performs DB Ops"| AppRepository
    AuthService -->|"Validates User"| UserEntity
    ProdService -->|"Performs DB Ops"| OtherRepo
    EmailService -->|"Sends_Email"| EmailTemplates
    OtherService -->|"Handles Ops"| OtherRepo

    IEmailRepo -.->|"Implemented_by"| EmailRepoImp
    IRevenueRepo -.->|"Implemented_by"| RevenueRepoImp

    AppRepository -->|"CRUD"| DB
    EmailRepoImp -->|"CRUD"| DB
    RevenueRepoImp -->|"CRUD"| DB
    OtherRepo -->|"CRUD"| DB

    AppRepository ---|"Maps to"| AppointmentEntity
    OtherRepo ---|"Maps to"| OtherEntity

    %% Click Events
    click AppCtrl "https://github.com/ngocthong37/hair-salon-management-system/blob/main/src/main/java/com/hairsalon/controller/AppointmentController.java"
    click AuthCtrl "https://github.com/ngocthong37/hair-salon-management-system/blob/main/src/main/java/com/hairsalon/controller/AuthenticationController.java"
    click ProdCtrl "https://github.com/ngocthong37/hair-salon-management-system/blob/main/src/main/java/com/hairsalon/controller/ProductController.java"
    click SalonCtrl "https://github.com/ngocthong37/hair-salon-management-system/blob/main/src/main/java/com/hairsalon/controller/SalonController.java"
    click OtherCtrl "https://github.com/ngocthong37/hair-salon-management-system/tree/main/src/main/java/com/hairsalon/controller/"

    click AppService "https://github.com/ngocthong37/hair-salon-management-system/blob/main/src/main/java/com/hairsalon/service/AppointmentService.java"
    click AuthService "https://github.com/ngocthong37/hair-salon-management-system/blob/main/src/main/java/com/hairsalon/service/AuthenticationService.java"
    click ProdService "https://github.com/ngocthong37/hair-salon-management-system/blob/main/src/main/java/com/hairsalon/service/ProductService.java"
    click EmailService "https://github.com/ngocthong37/hair-salon-management-system/blob/main/src/main/java/com/hairsalon/service/EmailSendService.java"
    click OtherService "https://github.com/ngocthong37/hair-salon-management-system/tree/main/src/main/java/com/hairsalon/service/"

    click AppRepository "https://github.com/ngocthong37/hair-salon-management-system/blob/main/src/main/java/com/hairsalon/respository/AppointmentRepository.java"
    click IEmailRepo "https://github.com/ngocthong37/hair-salon-management-system/blob/main/src/main/java/com/hairsalon/respository/IEmailServiceRepository.java"
    click EmailRepoImp "https://github.com/ngocthong37/hair-salon-management-system/blob/main/src/main/java/com/hairsalon/respository/imp/EmailServiceRepositoryImp.java"
    click IRevenueRepo "https://github.com/ngocthong37/hair-salon-management-system/blob/main/src/main/java/com/hairsalon/respository/IRevenueRepository.java"
    click RevenueRepoImp "https://github.com/ngocthong37/hair-salon-management-system/blob/main/src/main/java/com/hairsalon/respository/imp/RevenueRepositoryImp.java"
    click OtherRepo "https://github.com/ngocthong37/hair-salon-management-system/tree/main/src/main/java/com/hairsalon/respository/"

    click AppointmentEntity "https://github.com/ngocthong37/hair-salon-management-system/blob/main/src/main/java/com/hairsalon/entity/Appointment.java"
    click UserEntity "https://github.com/ngocthong37/hair-salon-management-system/blob/main/src/main/java/com/hairsalon/entity/User.java"
    click OrderEntity "https://github.com/ngocthong37/hair-salon-management-system/blob/main/src/main/java/com/hairsalon/entity/Order.java"
    click SalonEntity "https://github.com/ngocthong37/hair-salon-management-system/blob/main/src/main/java/com/hairsalon/entity/Salon.java"
    click OtherEntity "https://github.com/ngocthong37/hair-salon-management-system/tree/main/src/main/java/com/hairsalon/entity/"

    click SecurityConfig "https://github.com/ngocthong37/hair-salon-management-system/blob/main/src/main/java/com/hairsalon/security/SecurityConfiguration.java"
    click JwtFilter "https://github.com/ngocthong37/hair-salon-management-system/blob/main/src/main/java/com/hairsalon/security/JwtAuthenticationFilter.java"
    click JwtService "https://github.com/ngocthong37/hair-salon-management-system/blob/main/src/main/java/com/hairsalon/security/JwtService.java"
    click AppConfig "https://github.com/ngocthong37/hair-salon-management-system/blob/main/src/main/java/com/hairsalon/security/ApplicationConfig.java"
    click EmailTemplates "https://github.com/ngocthong37/hair-salon-management-system/tree/main/src/main/resources/templates/"

    %% Styles
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef controller fill:#FAD6A5,stroke:#333,stroke-width:2px;
    classDef service fill:#CDEAC0,stroke:#333,stroke-width:2px;
    classDef repository fill:#F7D7A8,stroke:#333,stroke-width:2px;
    classDef entity fill:#D0E1F9,stroke:#333,stroke-width:2px;
    classDef security fill:#F1C0E8,stroke:#333,stroke-width:2px;
    classDef database fill:#FFE0E6,stroke:#333,stroke-width:2px;
```
