# reharsh67/monk-task architecture

> Architecture diagram of the GitHub repository reharsh67/monk-task, 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/reharsh67/monk-task
- Repository: https://github.com/reharsh67/monk-task

## Overview

##### Project Type and Purpose
- The project is a RESTful API designed for coupon management and discount calculation for an e-commerce platform.
- Its purpose is to support various coupon types (cart-wise, product-wise, and Buy X Get Y) and includes endpoints to create, retrieve, update, delete, and apply coupons.

##### File Structure
- The project uses Maven (evident by the pom.xml and the .mvn folder) and is structured following a standard Spring Boot application layout.
- The source code is primarily under src/main/java, organized in a package tree (code.monk.coupon.api) that contains subpackages for controllers (handling REST endpoints), entities (data models for Coupon, Cart, CartItem), repositories (data access), services (business logic), and a mock data loader for testing purposes.
- There are separate test directories under src/test to ensure unit testing of the important components (like CouponService and API endpoints).

a. Main Components:
- Client/API Consumer: Represents external tools (e.g., Postman, front-end clients) interacting with the API endpoints.
- REST Controller (CouponController): The entry point for handling coupon-related HTTP requests.
- Service Layer (CouponService): Contains the business logic for coupon management and the discount application algorithm.
- Data Access Layer (Repositories - CouponRepository, CartRepository): Manages communication with the underlying database.
- Domain/Entity Models (Coupon, Cart, CartItem): Represent the core data structure and business entities.
- Data Loader/Mock: (DataLoader) Used for seeding or testing initial data.
- Database: The underlying data store (e.g., H2, MySQL, or another DB as mentioned in the README).

b. Relationships and Interactions:
- The Client makes RESTful calls to the CouponController.
- The Controller delegates operations to the CouponService, which carries out business logic.
- The Service interacts with Repository components to perform CRUD operations on the Coupon, Cart, and CartItem entities.
- DataLoader may be invoked at startup to pre-populate or mock data for testing.
- The Repository layer communicates with the Database.

c. Architectural Patterns and Design Principles:
- Layered Architecture (Controller → Service → Repository), a common pattern in Spring Boot applications.
- Clear separation of concerns ensures that API handling, business logic, and data persistence are decoupled.
- Extensibility is achieved by isolating coupon types and discount rules (making it easy to add new coupon types in the future).

d. Relevant Technologies and Frameworks:
- Spring Boot (for the API, dependency injection, and application management)
- Maven (for project build and dependency management)
- Testing Frameworks (e.g., JUnit for unit tests)
- A Database (configured in application.properties, could be H2 for testing or MySQL/MongoDB for production)
- Postman (for API testing, indicated by the Coupon API .postman_collection)

- Use clear labels for each component. For example, label blocks as “Client (Postman/Frontend)”, “CouponController”, “CouponService”, “CouponRepository”, “CartRepository”, “Coupon Entity”, “Cart & CartItem Entities” and “Database”.
- From the Client to the CouponController: representing incoming HTTP requests.
- From CouponController to CouponService: for business logic processing.
- From CouponService to Repository components: indicating data persistence operations.
- From Repository components to the Database.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        Client["Client (Postman/Frontend)"]:::client
    end

    subgraph "API Layer"
        Controller["CouponController"]:::controller
    end

    subgraph "Business Logic Layer"
        Service["CouponService"]:::service
        DataLoader["DataLoader"]:::mock
    end

    subgraph "Data Persistence Layer"
        RepoCoupon["CouponRepository"]:::repository
        RepoCart["CartRepository"]:::repository
        CouponEntity["Coupon Entity"]:::entity
        CartEntity["Cart Entity"]:::entity
        CartItemEntity["CartItem Entity"]:::entity
        Database["Database"]:::database
    end

    Client -->|"HTTP_Request"| Controller
    Controller -->|"delegates_to"| Service
    Service -->|"CRUD_Coupon"| RepoCoupon
    Service -->|"CRUD_CartItem"| RepoCart
    RepoCoupon -->|"maps_to"| CouponEntity
    RepoCart -->|"maps_to"| CartEntity
    RepoCart -->|"maps_to"| CartItemEntity
    RepoCoupon -->|"queries_DB"| Database
    RepoCart -->|"queries_DB"| Database
    DataLoader -->|"seeds"| RepoCoupon
    DataLoader -->|"seeds"| RepoCart

    classDef client fill:#a2d9ff,stroke:#1b4f72,stroke-width:2px;
    classDef controller fill:#f9e79f,stroke:#7d6608,stroke-width:2px;
    classDef service fill:#fad7a0,stroke:#873600,stroke-width:2px;
    classDef repository fill:#a9dfbf,stroke:#145a32,stroke-width:2px;
    classDef entity fill:#f5b7b1,stroke:#922b21,stroke-width:2px;
    classDef database fill:#f1948a,stroke:#641e16,stroke-width:2px,stroke-dasharray: 5, 5;
    classDef mock fill:#d2b4de,stroke:#4a235a,stroke-width:2px;

    click Client "https://github.com/reharsh67/monk-task/blob/main/Coupon API.postman_collection.json"
    click Controller "https://github.com/reharsh67/monk-task/blob/main/src/main/java/code/monk/coupon/api/controller/CouponController.java"
    click Service "https://github.com/reharsh67/monk-task/blob/main/src/main/java/code/monk/coupon/api/service/CouponService.java"
    click RepoCoupon "https://github.com/reharsh67/monk-task/blob/main/src/main/java/code/monk/coupon/api/repo/CouponRepository.java"
    click RepoCart "https://github.com/reharsh67/monk-task/blob/main/src/main/java/code/monk/coupon/api/repo/CartRepository.java"
    click CouponEntity "https://github.com/reharsh67/monk-task/blob/main/src/main/java/code/monk/coupon/api/entity/Coupon.java"
    click CartEntity "https://github.com/reharsh67/monk-task/blob/main/src/main/java/code/monk/coupon/api/entity/Cart.java"
    click CartItemEntity "https://github.com/reharsh67/monk-task/blob/main/src/main/java/code/monk/coupon/api/entity/CartItem.java"
    click DataLoader "https://github.com/reharsh67/monk-task/blob/main/src/main/java/code/monk/coupon/api/mock/DataLoader.java"
    click Database "https://github.com/reharsh67/monk-task/blob/main/src/main/resources/application.properties"
```
