# hemanthghy/blog-management-system architecture

> Architecture diagram of the GitHub repository hemanthghy/blog-management-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hemanthghy/blog-management-system
- Repository: https://github.com/hemanthghy/blog-management-system

## Overview

#### Purpose and Runtime
A Spring Boot REST API for blog management: registration/login, JWT-authenticated access, role-based authorization, post CRUD, and comment operations. It runs on Java 21 with Spring Boot/Security, Spring Data JPA/Hibernate, Maven, and MySQL. Application bootstrap: `src/main/java/com/ghy/blogmanagementsystem/BlogManagementSystemApplication.java`; runtime properties: `src/main/resources/application.yml`.

#### HTTP API Boundary
Controllers expose the public REST surface: authentication at `/api/auth`, posts at `/api/posts`, comments at `/api/comments`, plus user-oriented operations. They accept validated request DTOs and return response DTOs rather than entities.
Paths: `src/main/java/com/ghy/blogmanagementsystem/controller/AuthController.java`, `src/main/java/com/ghy/blogmanagementsystem/controller/BlogPostController.java`, `src/main/java/com/ghy/blogmanagementsystem/controller/CommentController.java`.

#### Authentication and Authorization Pipeline
Login/register flows delegate to authentication services; credentials are BCrypt-protected and successful login produces a JWT. For protected requests, the security filter extracts and validates `Bearer` tokens, loads the user principal, and establishes Spring Security context. Security configuration defines access rules and the JWT failure response.
Paths: `src/main/java/com/ghy/blogmanagementsystem/config/SecurityConfig.java`, `src/main/java/com/ghy/blogmanagementsystem/security/JwtAuthenticationFilter.java`, `src/main/java/com/ghy/blogmanagementsystem/security/JwtService.java`.

#### Domain and Persistence Model
JPA entities model `User`, `BlogPost`, and `Comment`, with shared persistence fields in a base entity. `Role` distinguishes USER and ADMIN authorization. Repository interfaces form the database boundary to MySQL/Hibernate for each aggregate.
Paths: `src/main/java/com/ghy/blogmanagementsystem/entity/User.java`, `src/main/java/com/ghy/blogmanagementsystem/entity/BlogPost.java`, `src/main/java/com/ghy/blogmanagementsystem/entity/Comment.java`.

#### Service Layer and Ownership Rules
Service implementations hold application workflows: account creation/authentication, post lifecycle, comment lifecycle, existence checks, and ownership/role decisions before mutation or deletion. Controllers depend on service interfaces, isolating HTTP concerns from business and persistence logic.
Paths: `src/main/java/com/ghy/blogmanagementsystem/service/AuthServiceImpl.java`, `src/main/java/com/ghy/blogmanagementsystem/service/BlogPostServiceImpl.java`, `src/main/java/com/ghy/blogmanagementsystem/service/CommentServiceImpl.java`.

#### Data Translation and Error Boundary
Request DTOs constrain inbound registration, login, post, and comment payloads; MapStruct-style mappers translate entities to response contracts. A global exception handler converts domain/security failures into consistent API error responses instead of leaking implementation exceptions.
Paths: `src/main/java/com/ghy/blogmanagementsystem/dto/request/CreatePostRequest.java`, `src/main/java/com/ghy/blogmanagementsystem/mapper/BlogPostMapper.java`, `src/main/java/com/ghy/blogmanagementsystem/exception/GlobalExceptionHandler.java`.

#### Supporting Integration
OpenAPI configuration publishes Swagger UI at the documented local endpoint. `CustomUserDetailsService` bridges persisted users to Spring Security, while `SecurityUtil` supplies the authenticated-user context to ownership-sensitive service operations.
Paths: `src/main/java/com/ghy/blogmanagementsystem/config/OpenApiConfig.java`, `src/main/java/com/ghy/blogmanagementsystem/security/CustomUserDetailsService.java`, `src/main/java/com/ghy/blogmanagementsystem/util/SecurityUtil.java`.

Main entry points: [`src/main/java/com/ghy/blogmanagementsystem/controller/AuthController.java`](https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/controller/AuthController.java) (Auth, post & comment controllers), [`src/main/java/com/ghy/blogmanagementsystem/security/JwtAuthenticationFilter.java`](https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/security/JwtAuthenticationFilter.java) (JWT authentication filter), [`src/main/java/com/ghy/blogmanagementsystem/service/AuthServiceImpl.java`](https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/service/AuthServiceImpl.java) (Authentication service), [`src/main/java/com/ghy/blogmanagementsystem/service/BlogPostServiceImpl.java`](https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/service/BlogPostServiceImpl.java) (Blog post service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["REST API"]
  node_api_clients(("API clients<br/>external client"))
  node_controllers["Auth, post &amp; comment controllers<br/>REST controllers"]
  node_request_dtos["Request DTOs<br/>input contracts"]
  node_mappers["Response mappers<br/>DTO mapping"]
  node_exception_handler["Global exception handler<br/>error boundary"]
  node_openapi["OpenAPI / Swagger<br/>API documentation<br/>[OpenApiConfig.java]"]
end

subgraph group_security["Security"]
  node_security_config["Security configuration<br/>access policy"]
  node_jwt_filter["JWT authentication filter<br/>security filter"]
  node_jwt_service["JWT service<br/>token service<br/>[JwtService.java]"]
  node_user_details["Custom user details service<br/>principal loader"]
  node_security_util["Security context utility<br/>authenticated-user access<br/>[SecurityUtil.java]"]
end

subgraph group_application["Application Services"]
  node_auth_service["Authentication service<br/>application service"]
  node_post_service["Blog post service<br/>application service"]
  node_comment_service["Comment service<br/>application service"]
end

subgraph group_persistence["Domain &amp; Persistence"]
  node_domain_entities["User, post &amp; comment entities<br/>JPA domain model<br/>[User.java]"]
  node_repositories["JPA repositories<br/>persistence ports"]
  node_mysql[("MySQL<br/>database")]
end

node_bootstrap{{"Spring Boot app<br/>bootstrap"}}
node_runtime_config["Runtime properties<br/>configuration<br/>[application.yml]"]

node_bootstrap -->|"loads"| node_runtime_config
node_bootstrap -->|"wires"| node_security_config
node_api_clients -->|"HTTP requests"| node_controllers
node_api_clients -->|"Bearer token"| node_jwt_filter
node_controllers -->|"validates"| node_request_dtos
node_controllers -->|"delegates auth"| node_auth_service
node_controllers -->|"delegates posts"| node_post_service
node_controllers -->|"delegates comments"| node_comment_service
node_controllers -->|"returns DTOs"| node_mappers
node_controllers -.->|"failures handled by"| node_exception_handler
node_openapi -.->|"documents"| node_controllers
node_security_config -->|"installs"| node_jwt_filter
node_jwt_filter -->|"validates token"| node_jwt_service
node_jwt_filter -->|"loads principal"| node_user_details
node_auth_service -->|"issues JWT"| node_jwt_service
node_user_details -->|"loads users"| node_repositories
node_post_service -->|"checks caller"| node_security_util
node_comment_service -->|"checks caller"| node_security_util
node_auth_service -->|"persists users"| node_repositories
node_post_service -->|"persists posts"| node_repositories
node_comment_service -->|"persists comments"| node_repositories
node_repositories -->|"manages"| node_domain_entities
node_repositories -->|"Hibernate/JPA"| node_mysql

click node_bootstrap "https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/BlogManagementSystemApplication.java"
click node_runtime_config "https://github.com/hemanthghy/blog-management-system/blob/main/src/main/resources/application.yml"
click node_controllers "https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/controller/AuthController.java"
click node_request_dtos "https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/dto/request/CreatePostRequest.java"
click node_mappers "https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/mapper/BlogPostMapper.java"
click node_exception_handler "https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/exception/GlobalExceptionHandler.java"
click node_openapi "https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/config/OpenApiConfig.java"
click node_security_config "https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/config/SecurityConfig.java"
click node_jwt_filter "https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/security/JwtAuthenticationFilter.java"
click node_jwt_service "https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/security/JwtService.java"
click node_user_details "https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/security/CustomUserDetailsService.java"
click node_security_util "https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/util/SecurityUtil.java"
click node_auth_service "https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/service/AuthServiceImpl.java"
click node_post_service "https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/service/BlogPostServiceImpl.java"
click node_comment_service "https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/service/CommentServiceImpl.java"
click node_domain_entities "https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/entity/User.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api_clients,node_controllers,node_request_dtos,node_mappers,node_exception_handler,node_openapi toneBlue
class node_security_config,node_jwt_filter,node_jwt_service,node_user_details,node_security_util toneAmber
class node_auth_service,node_post_service,node_comment_service toneMint
class node_domain_entities,node_repositories,node_mysql toneRose
class node_bootstrap,node_runtime_config toneNeutral
```

## Components

### REST API

- **API clients**: external client
- [Auth, post & comment controllers](https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/controller/AuthController.java): REST controllers · Validated DTO REST endpoints under /api/auth, /api/posts, and /api/comments. · `src/main/java/com/ghy/blogmanagementsystem/controller/AuthController.java`
- [Request DTOs](https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/dto/request/CreatePostRequest.java): input contracts · `src/main/java/com/ghy/blogmanagementsystem/dto/request/CreatePostRequest.java`
- [Response mappers](https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/mapper/BlogPostMapper.java): DTO mapping · Maps entities to response contracts. · `src/main/java/com/ghy/blogmanagementsystem/mapper/BlogPostMapper.java`
- [Global exception handler](https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/exception/GlobalExceptionHandler.java): error boundary · Converts application and security failures to API errors. · `src/main/java/com/ghy/blogmanagementsystem/exception/GlobalExceptionHandler.java`
- [OpenAPI / Swagger](https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/config/OpenApiConfig.java): API documentation · `src/main/java/com/ghy/blogmanagementsystem/config/OpenApiConfig.java`

### Security

- [Security configuration](https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/config/SecurityConfig.java): access policy · Defines protected routes and JWT failure handling. · `src/main/java/com/ghy/blogmanagementsystem/config/SecurityConfig.java`
- [JWT authentication filter](https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/security/JwtAuthenticationFilter.java): security filter · Validates Bearer tokens and establishes the security context. · `src/main/java/com/ghy/blogmanagementsystem/security/JwtAuthenticationFilter.java`
- [JWT service](https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/security/JwtService.java): token service · Issues and validates JWTs. · `src/main/java/com/ghy/blogmanagementsystem/security/JwtService.java`
- [Custom user details service](https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/security/CustomUserDetailsService.java): principal loader · Bridges persisted users to Spring Security. · `src/main/java/com/ghy/blogmanagementsystem/security/CustomUserDetailsService.java`
- [Security context utility](https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/util/SecurityUtil.java): authenticated-user access · `src/main/java/com/ghy/blogmanagementsystem/util/SecurityUtil.java`

### Application Services

- [Authentication service](https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/service/AuthServiceImpl.java): application service · Handles registration, credential verification, and login. · `src/main/java/com/ghy/blogmanagementsystem/service/AuthServiceImpl.java`
- [Blog post service](https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/service/BlogPostServiceImpl.java): application service · Applies post lifecycle and ownership rules. · `src/main/java/com/ghy/blogmanagementsystem/service/BlogPostServiceImpl.java`
- [Comment service](https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/service/CommentServiceImpl.java): application service · Applies comment lifecycle and ownership rules. · `src/main/java/com/ghy/blogmanagementsystem/service/CommentServiceImpl.java`

### Domain & Persistence

- [User, post & comment entities](https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/entity/User.java): JPA domain model · User roles distinguish USER and ADMIN authorization. · `src/main/java/com/ghy/blogmanagementsystem/entity/User.java`
- **JPA repositories**: persistence ports · Repository interfaces for user, post, and comment aggregates.
- **MySQL**: database · Hibernate-backed persistent storage.

### Other components

- [Spring Boot app](https://github.com/hemanthghy/blog-management-system/blob/main/src/main/java/com/ghy/blogmanagementsystem/BlogManagementSystemApplication.java): bootstrap · Application entry point and runtime wiring. · `src/main/java/com/ghy/blogmanagementsystem/BlogManagementSystemApplication.java`
- [Runtime properties](https://github.com/hemanthghy/blog-management-system/blob/main/src/main/resources/application.yml): configuration · Configures MySQL and application runtime settings. · `src/main/resources/application.yml`

## Connections

- Spring Boot app → Runtime properties: loads
- Spring Boot app → Security configuration: wires
- API clients → Auth, post & comment controllers: HTTP requests
- API clients → JWT authentication filter: Bearer token
- Auth, post & comment controllers → Request DTOs: validates
- Auth, post & comment controllers → Authentication service: delegates auth
- Auth, post & comment controllers → Blog post service: delegates posts
- Auth, post & comment controllers → Comment service: delegates comments
- Auth, post & comment controllers → Response mappers: returns DTOs
- Auth, post & comment controllers → Global exception handler: failures handled by
- OpenAPI / Swagger → Auth, post & comment controllers: documents
- Security configuration → JWT authentication filter: installs
- JWT authentication filter → JWT service: validates token
- JWT authentication filter → Custom user details service: loads principal
- Authentication service → JWT service: issues JWT
- Custom user details service → JPA repositories: loads users
- Blog post service → Security context utility: checks caller
- Comment service → Security context utility: checks caller
- Authentication service → JPA repositories: persists users
- Blog post service → JPA repositories: persists posts
- Comment service → JPA repositories: persists comments
- JPA repositories → User, post & comment entities: manages
- JPA repositories → MySQL: Hibernate/JPA
