How hemanthghy/blog-management-system works
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: AuthController.java Auth, post & comment controllers · JwtAuthenticationFilter.java JWT authentication filter · AuthServiceImpl.java Authentication service · BlogPostServiceImpl.java Blog post service
Components 19
REST API
- API clients
- Auth, post & comment controllers · Validated DTO REST endpoints under /api/auth, /api/posts, and /api/comments.
src/main/java/com/ghy/blogmanagementsystem/controller/AuthController.java - Request DTOs
src/main/java/com/ghy/blogmanagementsystem/dto/request/CreatePostRequest.java - Response mappers · Maps entities to response contracts.
src/main/java/com/ghy/blogmanagementsystem/mapper/BlogPostMapper.java - Global exception handler · Converts application and security failures to API errors.
src/main/java/com/ghy/blogmanagementsystem/exception/GlobalExceptionHandler.java - OpenAPI / Swagger
src/main/java/com/ghy/blogmanagementsystem/config/OpenApiConfig.java
Security
- Security configuration · Defines protected routes and JWT failure handling.
src/main/java/com/ghy/blogmanagementsystem/config/SecurityConfig.java - JWT authentication filter · Validates Bearer tokens and establishes the security context.
src/main/java/com/ghy/blogmanagementsystem/security/JwtAuthenticationFilter.java - JWT service · Issues and validates JWTs.
src/main/java/com/ghy/blogmanagementsystem/security/JwtService.java - Custom user details service · Bridges persisted users to Spring Security.
src/main/java/com/ghy/blogmanagementsystem/security/CustomUserDetailsService.java - Security context utility
src/main/java/com/ghy/blogmanagementsystem/util/SecurityUtil.java
Application Services
- Authentication service · Handles registration, credential verification, and login.
src/main/java/com/ghy/blogmanagementsystem/service/AuthServiceImpl.java - Blog post service · Applies post lifecycle and ownership rules.
src/main/java/com/ghy/blogmanagementsystem/service/BlogPostServiceImpl.java - Comment service · Applies comment lifecycle and ownership rules.
src/main/java/com/ghy/blogmanagementsystem/service/CommentServiceImpl.java
Domain & Persistence
- User, post & comment entities · User roles distinguish USER and ADMIN authorization.
src/main/java/com/ghy/blogmanagementsystem/entity/User.java - JPA repositories · Repository interfaces for user, post, and comment aggregates.
- MySQL · Hibernate-backed persistent storage.
Other components
- Spring Boot app · Application entry point and runtime wiring.
src/main/java/com/ghy/blogmanagementsystem/BlogManagementSystemApplication.java - Runtime properties · Configures MySQL and application runtime settings.
src/main/resources/application.yml
Connections 23
- 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