# kpzxpf/auction architecture

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

- Interactive diagram: https://gitdiagram.com/kpzxpf/auction
- Repository: https://github.com/kpzxpf/auction

## Overview

##### Project type and purpose
- This is a full-stack Spring-Boot auction application that:
– Serves a static JS/HTML/CSS frontend from src/main/resources/static
– Exposes REST endpoints and WebSocket channels for user operations (create lots, place bids, user auth, profile, feed, etc.)
– Uses a relational database (with Liquibase changelogs for schema)
– Integrates with external systems: Kafka for event messaging, Amazon S3 for image storage
– Implements caching layers for lots and bids, plus image resizing

##### File structure
- src/main/java/com/volzhin/auction/config
– Configures WebSocket, Kafka producer/consumer, Argon2 password hashing, Amazon S3
- src/main/java/com/volzhin/auction/controller
– REST controllers: AuthController, LotController, BidController, etc.
- src/main/java/com/volzhin/auction/service
– Service layer: business logic, caches, image services (resize & S3), transaction management
- src/main/java/com/volzhin/auction/producer & consumer
– Kafka producers publish events (NewBid, UpdateLot, DeleteLot)
– Kafka consumers subscribe to the same topics to handle asynchronous updates (e.g., update in-memory caches or push WebSocket notifications)
- src/main/java/com/volzhin/auction/repository
– JPA repositories for DB persistence plus cache repositories
- src/main/resources
– application.yaml – DB, Kafka, S3 credentials
– Liquibase changelogs to initialize schema and seed data
– static – UI assets
- docker-compose.yaml
– Defines external services: likely Postgres, Kafka, Zookeeper, possibly Redis

##### Core components
a. Frontend clients (browser)
b. Spring Boot monolith
– REST API layer
– WebSocket endpoint
– Service layer
– Cache layer (bid/lot caches)
– Kafka producers & consumers
– JPA persistence
– Image resizing & S3 client
c. External systems
– Relational database (Postgres/MySQL)
– Kafka cluster
– Amazon S3 bucket
– (Optional) Redis or in-memory cache store if used
d. Continuous deployment artifacts
– Docker Compose orchestrates DB, Kafka, ZK

##### Relationships & data flows
- UI → HTTP REST → Controllers → Services → Repositories → Database
- Services → KafkaProducer → Kafka topics
- Kafka topics → KafkaConsumer → Services → Cache update → WebSocketPush → UI
- Controllers → ImageService → ResizeService → S3ServiceImpl → S3
- Services → PasswordHashingService (Argon2) → Secure storage in DB
- Liquibase migrations run on application startup against the DB

##### Architectural patterns & design principles
- Monolithic, layered architecture (Controller → Service → Repository)
- Event-driven modules via Kafka for decoupling business operations (new bids, lot updates, deletions)
- Cache-aside strategy for lots and bids to reduce DB load
- S3 adapter pattern for image storage
- WebSocket for real-time updates to the UI
- Configuration centralization (application.yaml) & dependency injection via Spring

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Top Layer: UI
    BrowserUI["Browser UI<br/>(JS/HTML/CSS)"]:::ui -->|HTTP REST| RESTControllers
    BrowserUI -->|WebSocket| WebSocketEndpoint

    click BrowserUI "https://github.com/kpzxpf/auction/tree/main/src/main/resources/static"

    %% Monolith
    subgraph "Spring Boot Monolith"
        direction TB

        AuctionApp["AuctionApplication"]:::core
        click AuctionApp "https://github.com/kpzxpf/auction/blob/main/src/main/java/com/volzhin/auction/AuctionApplication.java"

        %% Configuration
        subgraph "Configuration" 
            direction TB
            AppConfig["application.yaml<br/>(DB,Kafka,S3)"]:::config
            click AppConfig "https://github.com/kpzxpf/auction/blob/main/src/main/resources/application.yaml"
            LiquibaseChangelog["Liquibase Migrations"]:::config
            click LiquibaseChangelog "https://github.com/kpzxpf/auction/tree/main/src/main/resources/db/changelog"
            Argon2Cfg["Argon2Config"]:::config
            click Argon2Cfg "https://github.com/kpzxpf/auction/blob/main/src/main/java/com/volzhin/auction/config/Argon2Config.java"
            AmazonS3Cfg["AmazonS3Config"]:::config
            click AmazonS3Cfg "https://github.com/kpzxpf/auction/blob/main/src/main/java/com/volzhin/auction/config/AmazonS3Config.java"
            KafkaCfg["KafkaConfig<br/>(producer/consumer)"]:::config
            click KafkaCfg "https://github.com/kpzxpf/auction/tree/main/src/main/java/com/volzhin/auction/config/kafka"
            WebSocketCfg["WebSocketConfig"]:::config
            click WebSocketCfg "https://github.com/kpzxpf/auction/blob/main/src/main/java/com/volzhin/auction/config/WebSocketConfig.java"
        end

        %% API Layer
        subgraph "API Layer" 
            direction TB
            RESTControllers["REST API Layer"]:::api
            click RESTControllers "https://github.com/kpzxpf/auction/tree/main/src/main/java/com/volzhin/auction/controller"
            WebSocketEndpoint["WebSocket Endpoint"]:::api
        end

        %% Service Layer
        subgraph "Service Layer"
            direction TB
            BusinessService["Business Logic Services"]:::service
            click BusinessService "https://github.com/kpzxpf/auction/tree/main/src/main/java/com/volzhin/auction/service"
            PasswordHashingService["PasswordHashingService"]:::service
            click PasswordHashingService "https://github.com/kpzxpf/auction/blob/main/src/main/java/com/volzhin/auction/service/PasswordHashingService.java"
            subgraph "Cache Services"
                direction TB
                CacheServices["Lot & Bid Cache Services"]:::cache
                click CacheServices "https://github.com/kpzxpf/auction/tree/main/src/main/java/com/volzhin/auction/service/cache"
            end
            subgraph "Image Services"
                direction TB
                ResizeService["ResizeService"]:::service
                click ResizeService "https://github.com/kpzxpf/auction/blob/main/src/main/java/com/volzhin/auction/service/image/resize/ResizeService.java"
                S3Service["S3Service"]:::service
                click S3Service "https://github.com/kpzxpf/auction/blob/main/src/main/java/com/volzhin/auction/service/image/s3/S3Service.java"
                S3Impl["S3ServiceImpl"]:::service
                click S3Impl "https://github.com/kpzxpf/auction/blob/main/src/main/java/com/volzhin/auction/service/image/s3/S3ServiceImpl.java"
            end
            KafkaProducer["Kafka Producers"]:::service
            click KafkaProducer "https://github.com/kpzxpf/auction/tree/main/src/main/java/com/volzhin/auction/producer"
            KafkaConsumer["Kafka Consumers"]:::service
            click KafkaConsumer "https://github.com/kpzxpf/auction/tree/main/src/main/java/com/volzhin/auction/consumer"
        end

        %% Persistence
        subgraph "Persistence Layer"
            direction TB
            JPAAuctionRepo["JPA Repositories"]:::db
            click JPAAuctionRepo "https://github.com/kpzxpf/auction/tree/main/src/main/java/com/volzhin/auction/repository"
            CacheRepo["Cache Repositories"]:::db
            click CacheRepo "https://github.com/kpzxpf/auction/tree/main/src/main/java/com/volzhin/auction/repository/cache"
        end

        AuctionApp --> AppConfig
        AuctionApp --> LiquibaseChangelog
        AuctionApp --> Argon2Cfg
        AuctionApp --> AmazonS3Cfg
        AuctionApp --> KafkaCfg
        AuctionApp --> WebSocketCfg
        AuctionApp --> RESTControllers

        RESTControllers --> BusinessService
        WebSocketEndpoint --> BusinessService

        BusinessService --> JPAAuctionRepo
        BusinessService --> CacheRepo
        BusinessService --> PasswordHashingService
        BusinessService --> ResizeService
        ResizeService --> S3Service
        S3Service --> S3Impl
        BusinessService --> KafkaProducer
        KafkaConsumer --> BusinessService

    end

    %% External Systems
    subgraph "External Services"
        direction TB
        RDBMS["Relational Database<br/>(Postgres)"]:::external
        KafkaCluster["Kafka Cluster<br/>(with Zookeeper)"]:::external
        S3Bucket["Amazon S3 Bucket"]:::external
        DockerCompose["docker-compose.yaml"]:::external
        click DockerCompose "https://github.com/kpzxpf/auction/blob/main/docker-compose.yaml"
    end

    %% Data Flows
    JPAAuctionRepo -->|JDBC| RDBMS
    LiquibaseChangelog -->|migrations| RDBMS
    KafkaProducer -->|async| KafkaCluster
    KafkaCluster -->|async| KafkaConsumer
    S3Impl -->|stores images| S3Bucket

    %% Legend
    classDef ui fill:#CEF,stroke:#036,stroke-width:1px;
    classDef api fill:#CFC,stroke:#073,stroke-width:1px;
    classDef service fill:#EFE,stroke:#383,stroke-width:1px;
    classDef db fill:#FCF,stroke:#630,stroke-width:1px;
    classDef cache fill:#FFC,stroke:#663,stroke-width:1px;
    classDef config fill:#CCC,stroke:#666,stroke-width:1px;
    classDef core fill:#EEE,stroke:#999,stroke-width:1px;
    classDef external fill:#EEC,stroke:#660,stroke-width:1px;
```
