# loosap/voucher architecture

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

- Interactive diagram: https://gitdiagram.com/loosap/voucher
- Repository: https://github.com/loosap/voucher

## Overview

##### Project type and purpose
- This is a monolithic, full-stack backend service built with Spring Boot. It exposes REST endpoints for voucher management (create/list) and voucher redemption. Authentication is handled in-process via Spring Security (Basic Auth).

##### File structure
- Top-level: pom.xml, Maven wrapper, README.
- src/main/java/com/loosap/voucher:
- config/SecurityConfig.java – sets up Basic Auth and HTTP security.
- controller/…Controller.java – two controllers (VoucherManagementController, VoucherRedemptionController) that expose the API endpoints.
- service/VoucherService + VoucherServiceImpl – business logic layer.
- repository/VoucherRepository – Spring Data JPA repository for DB access.
- entity/Voucher – JPA entity.
- validation/… – custom Bean Validation annotation and validator.
- src/main/resources: application.properties, data.sql (DB seed), static/ (images for README).
- src/test: mirrors main code structure, unit & integration tests.

##### README for additional insights
- Describes three endpoints (/api/vouchers GET, /api/vouchers POST, /api/redeem/{code} GET).
- Demonstrates use of Basic Auth in Postman.
- Payload JSON example shows expiryDate and redemptionLimit fields.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Configuration"
        App["VoucherApplication"]:::config
        SecCfg["SecurityConfig"]:::config
    end

    subgraph "Client"
        Client["Client (Postman/HTTP Client)"]:::client
    end

    subgraph "Security Layer"
        Security["Security Filter (Basic Auth)"]:::security
    end

    subgraph "Presentation Layer"
        MController["VoucherManagementController"]:::controller
        RController["VoucherRedemptionController"]:::controller
    end

    subgraph "Service Layer"
        VServIfc["VoucherService (Interface)"]:::service
        VServImpl["VoucherServiceImpl"]:::service
    end

    subgraph "Validation Module"
        ValidAnno["ValidValueRange Annotation"]:::validation
        ValidVal["ValueRangeValidator"]:::validation
    end

    subgraph "Persistence Layer"
        Repo["VoucherRepository"]:::repository
        Entity["Voucher Entity"]:::entity
    end

    subgraph "Database"
        DB[(Database)]:::database
    end

    subgraph "Resources"
        AppProps1["application.properties"]:::resource
        AppProps2["application-test.properties"]:::resource
        DataSql["data.sql"]:::resource
    end

    %% Connections
    Client -->|"HTTP/JSON + Basic Auth"| Security
    Security -->|passes to| MController
    Security -->|passes to| RController

    MController -->|"calls"| VServIfc
    RController -->|"calls"| VServIfc

    VServIfc -->|"implemented by"| VServImpl
    VServImpl -->|"validates using"| ValidAnno
    VServImpl -->|"validates using"| ValidVal
    VServImpl -->|"uses"| Repo

    Repo -->|"CRUD via JPA"| Entity
    Entity -->|"stored in"| DB

    App --> SecCfg
    App --> AppProps1
    App --> AppProps2
    App --> DataSql

    %% Click Events
    click App "https://github.com/loosap/voucher/blob/main/src/main/java/com/loosap/voucher/VoucherApplication.java"
    click SecCfg "https://github.com/loosap/voucher/blob/main/src/main/java/com/loosap/voucher/config/SecurityConfig.java"
    click MController "https://github.com/loosap/voucher/blob/main/src/main/java/com/loosap/voucher/controller/VoucherManagementController.java"
    click RController "https://github.com/loosap/voucher/blob/main/src/main/java/com/loosap/voucher/controller/VoucherRedemptionController.java"
    click VServIfc "https://github.com/loosap/voucher/blob/main/src/main/java/com/loosap/voucher/service/VoucherService.java"
    click VServImpl "https://github.com/loosap/voucher/blob/main/src/main/java/com/loosap/voucher/service/VoucherServiceImpl.java"
    click Repo "https://github.com/loosap/voucher/blob/main/src/main/java/com/loosap/voucher/repository/VoucherRepository.java"
    click Entity "https://github.com/loosap/voucher/blob/main/src/main/java/com/loosap/voucher/entity/Voucher.java"
    click ValidAnno "https://github.com/loosap/voucher/blob/main/src/main/java/com/loosap/voucher/validation/ValidValueRange.java"
    click ValidVal "https://github.com/loosap/voucher/blob/main/src/main/java/com/loosap/voucher/validation/ValueRangeValidator.java"
    click AppProps1 "https://github.com/loosap/voucher/blob/main/src/main/resources/application.properties"
    click AppProps2 "https://github.com/loosap/voucher/blob/main/src/main/resources/application-test.properties"
    click DataSql "https://github.com/loosap/voucher/blob/main/src/main/resources/data.sql"

    %% Styles
    classDef client fill:#D5F5E3,stroke:#27AE60;
    classDef security fill:#FDEBD0,stroke:#D35400;
    classDef controller fill:#D6EAF8,stroke:#3498DB;
    classDef service fill:#FADBD8,stroke:#E74C3C;
    classDef validation fill:#E8DAEF,stroke:#9B59B6;
    classDef repository fill:#FEF9E7,stroke:#F1C40F;
    classDef entity fill:#F2F3F4,stroke:#566573;
    classDef database fill:#E8F8F5,stroke:#1ABC9C;
    classDef config fill:#FCF3CF,stroke:#B7950B;
    classDef resource fill:#F4ECF7,stroke:#8E44AD;
```
