# shraddhagadale/employee-management-rest-api architecture

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

- Interactive diagram: https://gitdiagram.com/shraddhagadale/employee-management-rest-api
- Repository: https://github.com/shraddhagadale/employee-management-rest-api

## Overview

##### Main components
- API (Controller) Layer: Represented by the EmployeeController class that exposes endpoints (e.g., create, read, update, delete).
- Service Layer: Represented by the EmployeeService class which contains the business logic for operations on employee records.
- Data Access Layer (Repository): Represented by the EmployeeRepository interface that abstracts database operations.
- Model/Data Layer: Represented by the Employee class which maps to the business entity stored in the MySQL database.
- Exception Handling: Include exception classes like GlobalExceptionHandler and ResourceNotFoundException to illustrate error management.
- External Database: MySQL, as described in the README and configured in the application.properties.
- Build and Dependency Management: Maven is used to manage the project’s dependencies and build lifecycle.

##### Relationships and interactions
- Request Flow: A request made to an API endpoint (e.g., POST /api/employee/create-employee) is handled by the EmployeeController.
- The Controller calls methods in the EmployeeService to perform business logic.
- The Service layer interacts with the EmployeeRepository to retrieve or manipulate data in the MySQL database.
- Exception handling components intercept any errors and provide appropriate responses.

##### Architectural patterns and design principles
- Follow a layered (N-tier) architecture: Presentation (Controller), Business Logic (Service), and Data Access (Repository).
- Use inversion of control (IoC) / dependency injection provided by Spring Boot.
- RESTful design principles are at play with a focus on CRUD operations and stateless HTTP requests.
- Error handling is centralized through GlobalExceptionHandler.

##### Additional details
- Connection configuration details from application.properties might be noted near the MySQL component.
- Reference to error handling: Show how GlobalExceptionHandler catches exceptions from any part of the flow.
- That the system is built with dependencies managed by Maven, which handles the build, lifecycle, and dependency injection at runtime.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global entities
    A["Client (HTTP Client)"]:::client

    %% Presentation Layer
    subgraph "Presentation Layer"
        B["EmployeeController\n(API Layer)"]:::controller
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        C["EmployeeService\n(Business Layer)"]:::service
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        D["EmployeeRepository\n(Data Access Layer)"]:::repository
    end

    %% Domain Model
    subgraph "Domain Model"
        E["Employee\n(Domain Model)"]:::model
    end

    %% Exception Handling
    subgraph "Exception Handling"
        F["GlobalExceptionHandler\n(Exception Handling)"]:::exception
        G["ResourceNotFoundException\n(Exception Handling)"]:::exception
    end

    %% External Systems
    H["MySQL Database\n(Configured via application.properties)"]:::database
    I["Maven\n(Build & Dependency Management)"]:::build

    %% Legend / Notes
    L["Note: Layered Architecture, RESTful API and Dependency Injection via Spring Boot"]:::legend

    %% Connections
    A -->|"sends request"| B
    B -->|"delegates to"| C
    C -->|"invokes operations on"| D
    D -->|"manages data for"| E
    D -->|"performs CRUD on"| H

    %% Exception Handling Flow (dashed lines indicate error handling)
    B -.->|"errors forwarded"| F
    C -.->|"errors forwarded"| F
    F -->|"handles"| G

    %% Build and Dependency Injection
    I ---|"manages dependencies for"| B
    I ---|"manages dependencies for"| C
    I ---|"manages dependencies for"| D
    I ---|"manages dependencies for"| E

    %% Click Events
    click B "https://github.com/shraddhagadale/employee-management-rest-api/blob/main/src/main/java/com/example/employee/controller/EmployeeController.java"
    click C "https://github.com/shraddhagadale/employee-management-rest-api/blob/main/src/main/java/com/example/employee/service/EmployeeService.java"
    click D "https://github.com/shraddhagadale/employee-management-rest-api/blob/main/src/main/java/com/example/employee/repository/EmployeeRepository.java"
    click E "https://github.com/shraddhagadale/employee-management-rest-api/blob/main/src/main/java/com/example/employee/model/Employee.java"
    click F "https://github.com/shraddhagadale/employee-management-rest-api/blob/main/src/main/java/com/example/employee/exception/GlobalExceptionHandler.java"
    click G "https://github.com/shraddhagadale/employee-management-rest-api/blob/main/src/main/java/com/example/employee/exception/ResourceNotFoundException.java"
    click H "https://github.com/shraddhagadale/employee-management-rest-api/blob/main/src/main/resources/application.properties"
    click I "https://github.com/shraddhagadale/employee-management-rest-api/blob/main/pom.xml"

    %% Styles
    classDef client fill:#E6E6FA,stroke:#9370DB,stroke-width:2px,color:#000;
    classDef controller fill:#ADD8E6,stroke:#0000FF,stroke-width:2px,color:#000;
    classDef service fill:#90EE90,stroke:#008000,stroke-width:2px,color:#000;
    classDef repository fill:#FFA07A,stroke:#FF4500,stroke-width:2px,color:#000;
    classDef model fill:#DDA0DD,stroke:#800080,stroke-width:2px,color:#000;
    classDef exception fill:#FFB6C1,stroke:#FF69B4,stroke-width:2px,color:#000;
    classDef database fill:#F0E68C,stroke:#DAA520,stroke-width:2px,color:#000;
    classDef build fill:#FFFFE0,stroke:#DAA520,stroke-width:2px,color:#000;
    classDef legend fill:#D3D3D3,stroke:#696969,stroke-width:2px,color:#000;
```
