# plmlkff/vk-for-business-back architecture

> Architecture diagram of the GitHub repository plmlkff/vk-for-business-back, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/plmlkff/vk-for-business-back
- Repository: https://github.com/plmlkff/vk-for-business-back

## Overview

##### Project type and purpose
- This is a monolithic Spring Boot backend service (no frontend code), modeled after the “VK for Business” logic as a training application.
- It exposes REST APIs for user management, goals, groups, subscriptions, promotions, transactions, file uploads, and integrates with object storage and a payment gateway.

##### File structure
- Top‐level build and deployment: Dockerfile, docker-compose.yaml, Gradle scripts.
- src/main/java/ru/itmo/blpslab1/ – Java/Kotlin code organized in:
– config: JWT, security, OpenAPI, Minio beans
– core: event definitions & handlers, Minio file manager
– domain: JPA entities, enums, Spring Data repositories & specifications
– rest: Controllers + DTO request/response trees + global error advice
– security: JwtFilter, JwtUserDetails
– service: service interfaces, impls, interceptors, Minio and payment-gateway services
– utils: JWT utilities, hashing, extension functions, etc.
- src/main/resources: application.yaml, Liquibase changelog scripts for DB schema evolution.
- Tests: a basic SpringBootTest.

##### README
- Confirms it’s a pedagogical clone of a business-oriented social-media API.

a. Main components
– External Clients: Web or mobile apps (or API consumers)
– API Layer: Spring MVC Controllers behind JwtFilter/SecurityConfig
– Service Layer: business logic services (AuthUserService, GoalService, etc.) + interceptors
– Domain Layer: JPA repositories managing entities in RDBMS
– Event Subsystem: TransactionEvent producer/handler for async processing
– Object Storage: Minio (UserImageService → MinioFilesManager)
– External Payment Gateway: PaymentGatewayService
– Configuration: beans defined in Config packages (JwtProperties, MinioConfig, OpenAPIConfig)
– Persistence: relational database (Liquibase → schema)

b. Relationships & data flows
1. Client → HTTP(S) → JwtFilter → Controllers
2. Controller → DTO mapping → Service layer
3. Service → Repository → Database
4. Service → Domain events → Event handler
5. Service → Minio SDK → Minio server
6. Service → REST/SDK → Payment gateway
7. Config classes inject external endpoints, credentials

c. Architectural patterns & principles
– Layered (Controller → Service → Repository)
– DTOs for request/response separation
– Spring Security + JWT filter chain
– Event-driven subcomponent for transaction processing
– Externalized configuration + DI
– Liquibase for schema migrations

d. Key technologies/frameworks
– Spring Boot, Spring MVC, Spring Security, Spring Data JPA
– JWT (io.jsonwebtoken or custom JwtUtil)
– Liquibase for DB changelogs
– Minio Java/Kotlin SDK
– Gradle Kotlin DSL, Docker/Docker-Compose

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Clients
    Clients["Clients (Web/Mobile)"]:::external

    %% Backend Service Box
    subgraph "Backend Service"
        direction TB

        %% API Layer
        subgraph "API Layer"
            direction TB
            JwtFilter["JwtFilter"]:::security
            SecurityConfig["SecurityConfig"]:::security
            Controllers["Controllers"]:::api
            GlobalAdvice["GlobalControllerAdvice"]:::api
        end

        %% Service Layer
        subgraph "Service Layer"
            direction TB
            ServiceInterfaces["Service Interfaces"]:::service
            ServiceImpls["Service Implementations"]:::service
            ServiceInterceptor["ServiceInterceptor"]:::service
        end

        %% Domain & Persistence
        subgraph "Domain & Persistence"
            direction TB
            Entities["Entities"]:::domain
            Enums["Enums"]:::domain
            Repositories["Repositories"]:::domain
            Specs["Repository Specifications"]:::domain
        end

        %% Event Processor
        subgraph "Event Processor"
            direction TB
            TransactionEvent["TransactionEvent"]:::event
            TransactionHandler["TransactionEventHandler"]:::event
        end

        %% Object Storage
        subgraph "Object Storage"
            direction TB
            UserImageService["UserImageService"]:::storage
            UserImageServiceImpl["UserImageServiceImpl"]:::storage
            MinioFilesManager["MinioFilesManager"]:::storage
        end

        %% Payment Service
        subgraph "Payment Service"
            direction TB
            PaymentService["PaymentGatewayService"]:::external
            PaymentServiceImpl["PaymentGatewayServiceImpl"]:::external
        end

        %% Config & Utils
        subgraph "Config & Utils"
            direction TB
            JwtProperties["JwtProperties"]:::config
            OpenAPIConfig["OpenAPIConfig"]:::config
            MinioConfig["MinioConfig"]:::config
            JwtUtil["JwtUtil"]:::util
            HashUtil["SHA512HashUtil"]:::util
        end
    end

    %% External Systems
    DB["Relational DB"]:::db
    Liquibase["Liquibase Changelog"]:::db
    MinioServer["Minio Server"]:::external
    PaymentGateway["External Payment Gateway"]:::external

    %% Connections
    Clients -->|"HTTP/JSON, JWT"| JwtFilter
    JwtFilter --> Controllers
    Controllers -->|"handles requests"| ServiceInterfaces
    ServiceInterfaces --> ServiceImpls
    ServiceImpls --> ServiceInterceptor
    ServiceImpls --> Repositories
    Repositories --> Entities
    Repositories --> Specs
    Repositories --> DB
    Liquibase --> DB
    ServiceImpls --> TransactionEvent
    TransactionEvent --> TransactionHandler
    TransactionHandler --> ServiceImpls
    ServiceImpls --> UserImageService
    UserImageService --> UserImageServiceImpl
    UserImageServiceImpl --> MinioFilesManager
    MinioFilesManager --> MinioServer
    ServiceImpls --> PaymentService
    PaymentService --> PaymentServiceImpl
    PaymentServiceImpl --> PaymentGateway

    %% Config injections
    JwtProperties --> JwtFilter
    SecurityConfig --> JwtFilter
    SecurityConfig --> Controllers
    OpenAPIConfig --> Controllers
    MinioConfig --> MinioFilesManager

    %% Click Events
    click Controllers "https://github.com/plmlkff/vk-for-business-back/tree/develop/src/main/java/ru/itmo/blpslab1/rest"
    click GlobalAdvice "https://github.com/plmlkff/vk-for-business-back/blob/develop/src/main/java/ru/itmo/blpslab1/rest/GlobalControllerAdvice.kt"
    click JwtFilter "https://github.com/plmlkff/vk-for-business-back/blob/develop/src/main/java/ru/itmo/blpslab1/security/filter/JwtFilter.java"
    click SecurityConfig "https://github.com/plmlkff/vk-for-business-back/blob/develop/src/main/java/ru/itmo/blpslab1/config/SecurityConfig.java"
    click JwtProperties "https://github.com/plmlkff/vk-for-business-back/blob/develop/src/main/java/ru/itmo/blpslab1/config/JwtProperties.java"
    click OpenAPIConfig "https://github.com/plmlkff/vk-for-business-back/blob/develop/src/main/java/ru/itmo/blpslab1/config/OpenAPIConfig.kt"
    click MinioConfig "https://github.com/plmlkff/vk-for-business-back/blob/develop/src/main/java/ru/itmo/blpslab1/config/MinioConfig.kt"
    click ServiceInterfaces "https://github.com/plmlkff/vk-for-business-back/tree/develop/src/main/java/ru/itmo/blpslab1/service"
    click ServiceImpls "https://github.com/plmlkff/vk-for-business-back/tree/develop/src/main/java/ru/itmo/blpslab1/service/impl"
    click ServiceInterceptor "https://github.com/plmlkff/vk-for-business-back/blob/develop/src/main/java/ru/itmo/blpslab1/service/interceptor/ServiceInterceptor.kt"
    click UserImageService "https://github.com/plmlkff/vk-for-business-back/blob/develop/src/main/java/ru/itmo/blpslab1/service/minio/UserImageService.kt"
    click UserImageServiceImpl "https://github.com/plmlkff/vk-for-business-back/blob/develop/src/main/java/ru/itmo/blpslab1/service/minio/UserImageServiceImpl.kt"
    click MinioFilesManager "https://github.com/plmlkff/vk-for-business-back/blob/develop/src/main/java/ru/itmo/blpslab1/core/minio/MinioFilesManager.kt"
    click PaymentService "https://github.com/plmlkff/vk-for-business-back/blob/develop/src/main/java/ru/itmo/blpslab1/service/paymentgateway/PaymentGatewayService.kt"
    click PaymentServiceImpl "https://github.com/plmlkff/vk-for-business-back/blob/develop/src/main/java/ru/itmo/blpslab1/service/paymentgateway/PaymentGatewayServiceImpl.kt"
    click Entities "https://github.com/plmlkff/vk-for-business-back/tree/develop/src/main/java/ru/itmo/blpslab1/domain/entity"
    click Enums "https://github.com/plmlkff/vk-for-business-back/tree/develop/src/main/java/ru/itmo/blpslab1/domain/enums"
    click Repositories "https://github.com/plmlkff/vk-for-business-back/tree/develop/src/main/java/ru/itmo/blpslab1/domain/repository"
    click Specs "https://github.com/plmlkff/vk-for-business-back/tree/develop/src/main/java/ru/itmo/blpslab1/domain/repository/specification"
    click TransactionEvent "https://github.com/plmlkff/vk-for-business-back/blob/develop/src/main/java/ru/itmo/blpslab1/core/event/entity/TransactionEvent.kt"
    click TransactionHandler "https://github.com/plmlkff/vk-for-business-back/blob/develop/src/main/java/ru/itmo/blpslab1/core/event/handler/TransactionEventHandler.kt"
    click JwtUtil "https://github.com/plmlkff/vk-for-business-back/blob/develop/src/main/java/ru/itmo/blpslab1/utils/security/JwtUtil.java"
    click HashUtil "https://github.com/plmlkff/vk-for-business-back/blob/develop/src/main/java/ru/itmo/blpslab1/utils/security/SHA512HashUtil.java"

    %% Styles
    classDef api fill:#D0E6FF,stroke:#4A90E2
    classDef service fill:#DFFFD0,stroke:#7FBF3F
    classDef domain fill:#FFE6CC,stroke:#F5A623
    classDef event fill:#FFF4CC,stroke:#E0A800
    classDef storage fill:#CCFAFA,stroke:#3FBFBE
    classDef security fill:#FFD0D8,stroke:#E24A62
    classDef config fill:#FFF0B3,stroke:#D4A017
    classDef util fill:#E5CCFF,stroke:#8E44AD
    classDef db fill:#EEEEEE,stroke:#888888
    classDef external fill:#F2F2F2,stroke:#666666
```
