# duydo131/hust_blog architecture

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

- Interactive diagram: https://gitdiagram.com/duydo131/hust_blog
- Repository: https://github.com/duydo131/hust_blog

## Overview

##### Project’s Main Components
- Spring Boot API Server – The core Java application under src/main/java/com/learnspringboot/demo. It implements:
∘ Controllers (for Auth, Post, Slug, and User endpoints)
∘ DTOs, mapping classes, services (both database and infrastructure abstractions), and the repository layer for persistence.
∘ A comprehensive security module using Spring Security, JWT authentication, and module-specific authentication providers.
- File Server Service – Found under the file_server folder (file_server/file_service.go), this Go microservice likely handles file-related operations such as storage or retrieval requests.
- Database – Although there is a “postgres” folder that might suggest a custom configuration for PostgreSQL, the “How To Run” instructions indicate using MySQL (create database demo_spring_boot). Represent the DB service as an external persistent store accessed by the Spring Boot API.
- Infrastructure Containers – Docker Compose is orchestrating not only the database but also Zookeeper, Kafka, and any necessary API images. These represent external services that the API communicates with (e.g., Kafka for messaging, and Zookeeper for coordination).

##### Out Relationships and Interactions
- API Layer (Spring Boot) – Show how individual controllers (AuthController, PostController, etc.) receive incoming REST requests and pass them onto services.
- Service Layer – Illustrate business logic operations (AuthService, PostService, etc.) that interface with the repository layer.
- File Server – Represent the communication (if any) with the API for file management. Although the specifics of interaction aren’t detailed, note its role as an independent service.

##### Architectural Patterns and Technologies
- Layered Architecture – Clearly delineate the presentation layer (controllers), service or business logic layer, and data access layer. This helps engineers quickly see how requests are processed.
- Security Patterns – Highlight use of JWT for authentication and the specialized module authentication filters which add an extra layer.
- Microservices/Containerization – With Docker managing different service containers (API, file server, database, Kafka, Zookeeper), indicate this separation.
∘ Java with Spring Boot for the API.
∘ Spring Security for authentication and authorization.
∘ Maven (pom.xml, Maven wrapper) for building.
∘ Go for the file server component.
∘ Docker and Docker Compose for container orchestration.
∘ MySQL (as per “How To Run”) for the database (even though there’s a postgres config, follow the README instructions).
∘ Kafka and Zookeeper for messaging/coordination.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Client
    Client["Client/External Requests"]:::infra

    %% Infrastructure Containers Subgraph
    subgraph "Infrastructure Containers"
        API["Spring Boot API Server Container"]:::api
        FS["File Server Container"]:::file
        DB["Database (MySQL)"]:::db
        K["Kafka"]:::mq
        Z["Zookeeper"]:::mq
        DF["Dockerfile"]:::infra
        DC["Docker Compose"]:::infra
    end

    %% Internal Architecture of Spring Boot API
    subgraph "Spring Boot API Internal Architecture"
        Controllers["Controllers (Auth,Post,Slug,User)"]:::api
        DTOs["DTOs"]:::api
        Mappers["Mappers"]:::api
        DBService["DB Service"]:::api
        InfraService["Infra Service"]:::api
        Security["Security (JWT & Filters)"]:::api
        Repository["Repository Layer"]:::api
    end

    %% Relationships between External Client and API Internal Architecture
    Client -->|"sendsRequest"| Controllers

    %% Internal flow in API
    Controllers -->|"mapsData"| DTOs
    Controllers -->|"invokes"| Security
    Controllers -->|"calls"| DBService
    Controllers -->|"calls"| InfraService
    DBService -->|"accesses"| Repository
    Repository -->|"queries"| DB
    Security -->|"authenticates"| DBService

    %% Infrastructure interactions from API container
    API --- Controllers
    API --- DBService
    API --- InfraService
    API --- Security

    %% API container communicating with other containers
    API -->|"fileOps"| FS
    API -->|"publishes"| K
    API -->|"coordinates"| Z

    %% Docker orchestration linking containers
    DC -->|"orchestrates"| API
    DC -->|"orchestrates"| FS
    DC -->|"orchestrates"| DB
    DC -->|"orchestrates"| K
    DC -->|"orchestrates"| Z
    DF -->|"builds"| API

    %% Click Events for Component Mapping
    click API "https://github.com/duydo131/hust_blog/tree/main/src/main/java/com/learnspringboot/demo"
    click Controllers "https://github.com/duydo131/hust_blog/tree/main/src/main/java/com/learnspringboot/demo/controller"
    click DTOs "https://github.com/duydo131/hust_blog/tree/main/src/main/java/com/learnspringboot/demo/dto"
    click Mappers "https://github.com/duydo131/hust_blog/tree/main/src/main/java/com/learnspringboot/demo/dto/mapper"
    click Repository "https://github.com/duydo131/hust_blog/tree/main/src/main/java/com/learnspringboot/demo/respository"
    click Security "https://github.com/duydo131/hust_blog/tree/main/src/main/java/com/learnspringboot/demo/security"
    click DBService "https://github.com/duydo131/hust_blog/tree/main/src/main/java/com/learnspringboot/demo/service/db"
    click InfraService "https://github.com/duydo131/hust_blog/tree/main/src/main/java/com/learnspringboot/demo/service/infra"
    click FS "https://github.com/duydo131/hust_blog/blob/main/file_server/file_service.go"
    click DF "https://github.com/duydo131/hust_blog/tree/main/Dockerfile"
    click DC "https://github.com/duydo131/hust_blog/blob/main/docker-compose.yml"

    %% Styles
    classDef api fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef infra fill:#D4E6F1,stroke:#1B4F72,stroke-width:2px;
    classDef db fill:#ABEBC6,stroke:#196F3D,stroke-width:2px;
    classDef mq fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef file fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
```
