How subhojitguin/blog_management_system works
1. What this repo is
- A single Spring Boot backend monolith for a blog management system.
- It exposes REST APIs for authentication, users, categories, posts, admin actions, and social interactions like likes, comments, follows, and bookmarks.
2. Primary request flow
- Incoming HTTP requests hit Spring MVC controllers in Controllers.
- Controllers delegate to services in Service.
- Services enforce business rules, call repositories, publish domain events, and return DTOs.
- Repositories in Repositories persist JPA entities in Entities to a relational database.
3. Domain boundaries
- The code is organized around business areas rather than technical layers:
- AuthController / Security for login, signup, token refresh
- UserController / UserServiceImpl for profile, password, email, follow graph
- CategoryController / CategoryServiceImpl
- PostController / PostServiceImpl for CRUD, search, comments, likes, bookmarks, and feed views
- AdminController for category administration
- These boundaries are important for diagramming because most features are coordinated through the service layer, not directly between controllers.
4. Persistence model
- The persistence layer is JPA-based and backed by Flyway migrations in src/main/resources/db/migration.
- Core tables/entities are users, categories, posts, follows, likes, comments, and bookmarks.
- Specification support is used for post filtering/search, so query logic is partly dynamic rather than simple CRUD.
5. Security architecture
- Authentication is JWT-based.
- JWTAuthFilter intercepts requests before controller execution, JWTService handles token creation/validation, and WebSecurityConfig defines protected vs public routes.
- AuthService handles signup/login/refresh flows.
- SecurityUtils and SecurityConfigUtils likely centralize current-user and authorization helpers.
- This is a key boundary: authenticated user context is established before business services run.
6. API response and exception handling
- Advice/GlobalExceptionHandler maps domain exceptions like ResourceNotFoundException, ResourceConflictException, and InvalidActionException into API errors.
- GlobalResponseHandler, ApiResponse, and ApiError standardize response shape.
- This means the controller layer is thin and the API contract is normalized centrally.
7. Async and event-driven side effects
- The app uses Spring application events for actions such as new posts, comments, likes, and new followers.
- Listeners/EmailEventListeners consumes those events and delegates to email services.
- Template models and Freemarker templates in templates/ are used to render notification emails.
- This separates core transactional actions from non-critical side effects like email delivery.
8. Schedulers and background processing
- Schedulers/PostPublishScheduler handles scheduled post publication, so posts can be staged and released later.
- Schedulers/ViewSyncScheduler suggests periodic synchronization of view counts, likely between in-memory/Redis counters and the database.
- Schedulers/UserBatchScheduler indicates batch-oriented user maintenance or reporting.
- These are background subsystems independent of the synchronous API request path.
9. Caching / fast counters
- Service/RedisViewCountServiceImpl and Constants/RedisConstants show Redis-backed view counting or read optimization.
- Annotations/ReadFast suggests a read-optimized path, probably for high-frequency post views.
- In the architecture diagram, Redis should be shown as a side store used for performance-sensitive counters rather than the system of record.
10. Cross-cutting concerns
- Logging/RequestLoggingFilter captures request-level logs, while LoggingAspect adds execution logging around annotated methods such as @LogExecution.
- Deserializers/*SanitizationDeserializer sanitize HTML/text input at the JSON boundary.
- Config/MapperConfig, AsyncConfig, MessageSourceConfig, and SwaggerConfig provide infrastructure wiring for mapping, async execution, localization/messages, and API documentation.
11. Data shaping and transport
- Controllers and services exchange DTOs from Dto/, not entities directly.
- This protects the persistence model from leaking into the API contract.
- The Utils package holds reusable helpers for validation, reading-time calculation, and message handling.
- Constants/ApiRoutes centralizes endpoint paths, which helps keep route definitions consistent across controllers.
12. Infrastructure and deployment
- The repository is container-ready with Dockerfile and docker-compose.yml.
- elk-config contains Filebeat and Logstash configuration, implying logs are intended to flow into an ELK stack for centralized observability.
- logback-spring.xml provides application logging configuration.
- The presence of Swagger/OpenAPI docs in the README indicates the API is meant to be consumed externally and documented as a first-class interface.
13. Testing structure
- Tests mirror the production layers: controllers, services, repositories, listeners, schedulers, security, and utilities.
- This suggests the architecture is designed around independently testable components, with business logic concentrated in services and integration points isolated at the boundaries.
14. How to draw the architecture
- A good diagram would show:
- External clients calling REST controllers
- A security filter/JWT layer in front of controllers
- Controllers delegating to service implementations
- Services coordinating repositories, Redis, events, and schedulers
- Repositories persisting to a relational database managed by Flyway migrations
- Event listeners sending email notifications via template rendering
- Logging, exception handling, sanitization, and async execution as cross-cutting layers around the main flow
Main entry points: PostServiceImpl.java Post Service · JWTAuthFilter.java JWT Filter · UserServiceImpl.java User Service · migration Relational DB
Components 27
API Layer
REST entrypoints, request shaping, and security boundaries.
- Clients · Browsers, API clients, and external integrators calling the REST API.
- JWT Filter · Intercepts incoming requests, validates JWTs, and establishes authenticated context.
src/main/java/com/project/Blog_Management_System/Security/JWTAuthFilter.java - Web Security · Defines protected routes, auth rules, and filter wiring.
src/main/java/com/project/Blog_Management_System/Security/WebSecurityConfig.java - Auth API · Handles signup, login, and token refresh flows.
src/main/java/com/project/Blog_Management_System/Controllers/AuthController.java - User API · Exposes profile, password, email, and follow operations.
src/main/java/com/project/Blog_Management_System/Controllers/UserController.java - Category API · Handles category retrieval and management endpoints.
src/main/java/com/project/Blog_Management_System/Controllers/CategoryController.java - Post API · Handles posts, search, comments, likes, bookmarks, and feeds.
src/main/java/com/project/Blog_Management_System/Controllers/PostController.java - Admin API · Provides administrative category actions.
src/main/java/com/project/Blog_Management_System/Controllers/AdminController.java
Domain Services
Business logic organized by blog, user, and admin flows.
- Auth Service · Implements authentication workflows and token lifecycle support.
src/main/java/com/project/Blog_Management_System/Security/AuthService.java - User Service · Coordinates profiles, account updates, and follow graph behavior.
src/main/java/com/project/Blog_Management_System/Service/UserServiceImpl.java - Category Service · Implements category business rules and admin-facing operations.
src/main/java/com/project/Blog_Management_System/Service/CategoryServiceImpl.java - Post Service · Coordinates post CRUD, filtering, interaction actions, and feed views.
src/main/java/com/project/Blog_Management_System/Service/PostServiceImpl.java - View Cache · Stores or syncs fast-moving view counters using Redis-backed logic.
src/main/java/com/project/Blog_Management_System/Service/RedisViewCountServiceImpl.java
Data Layer
Persistence, dynamic querying, and backing stores.
- User Repo · Persists user entities and supports account lookups.
src/main/java/com/project/Blog_Management_System/Repositories/UserRepository.java - Category Repo · Persists categories and supports category queries.
src/main/java/com/project/Blog_Management_System/Repositories/CategoryRepository.java - Post Repo · Persists posts and supports search and feed data access.
src/main/java/com/project/Blog_Management_System/Repositories/PostRepository.java - Interaction Repos · Persistence for follows, likes, comments, and bookmarks.
- Relational DB · System of record managed by Flyway migrations and JPA entities.
src/main/resources/db/migration
Infrastructure
Events, email, scheduling, logging, and cross-cutting support.
- Domain Events · Application events for post publication and social interactions.
src/main/java/com/project/Blog_Management_System/Events - Email Listener · Consumes events and triggers notification email flows.
src/main/java/com/project/Blog_Management_System/Listeners/EmailEventListeners.java - Email Services · Renders templates and sends notification emails.
src/main/java/com/project/Blog_Management_System/Service/EmailServiceImpl.java - Publish Scheduler · Publishes staged posts on a schedule.
src/main/java/com/project/Blog_Management_System/Schedulers/PostPublishScheduler.java - View Sync Job · Synchronizes view counters and related read metrics.
src/main/java/com/project/Blog_Management_System/Schedulers/ViewSyncScheduler.java - User Batch Job · Runs batch-oriented user maintenance or reporting tasks.
src/main/java/com/project/Blog_Management_System/Schedulers/UserBatchScheduler.java - Response Advice · Normalizes successful API responses into a common wrapper.
src/main/java/com/project/Blog_Management_System/Advice/GlobalResponseHandler.java - Exception Advice · Maps domain exceptions into standardized API errors.
src/main/java/com/project/Blog_Management_System/Advice/GlobalExceptionHandler.java - Logging · Request logging and execution tracing around annotated methods.
src/main/java/com/project/Blog_Management_System/Logging
Connections 35
- Clients → JWT Filter: HTTP request · Incoming API traffic first passes through authentication filtering.
- JWT Filter → Web Security: auth rules · Security configuration defines how the filter and protected routes behave.
- JWT Filter → Auth API: public auth · Public authentication endpoints are allowed through the security boundary.
- JWT Filter → User API: secured API · Authenticated user requests proceed to user endpoints.
- JWT Filter → Category API: secured API · Authenticated category requests proceed to controller layer.
- JWT Filter → Post API: secured API · Authenticated post requests proceed to controller layer.
- JWT Filter → Admin API: secured API · Admin routes are protected by the security layer.
- Auth API → Auth Service: login/signup · Authentication controller delegates auth flows to the security service.
- User API → User Service: profile ops · User endpoints delegate business logic to the user service.
- Category API → Category Service: category ops · Category endpoints delegate to category service logic.
- Admin API → Category Service: admin category · Admin category actions reuse category service rules.
- Post API → Post Service: post ops · Post endpoints delegate CRUD, social, and feed behavior to the post service.
- Post Service → User Service: author/user context · Post operations depend on user identity and profile data.
- Auth Service → User Repo: account lookup · Auth workflows read and update user records.
- User Service → User Repo: user data · User service persists and reads user entities.
- Category Service → Category Repo: category data · Category service persists and reads category entities.
- Post Service → Post Repo: post data · Post service persists posts and queries feeds/search results.
- Post Service → Interaction Repos: social data · Likes, comments, follows, and bookmarks are managed through interaction repositories.
- Post Service → View Cache: fast views · View-heavy operations use Redis-backed counters or sync paths.
- User Service → Domain Events: follow events · User actions publish follower-related domain events.
- Post Service → Domain Events: post events · Post and social interactions publish domain events.
- Domain Events → Email Listener: consume · Listeners react to published domain events.
- Email Listener → Email Services: send mail · Event handling delegates to email rendering and delivery services.
- Email Services → Response Advice
- Publish Scheduler → Post Service: publish posts · Scheduled publication reuses the post service workflow.
- View Sync Job → View Cache: sync counters · Scheduled jobs reconcile cached views with durable storage.
- User Batch Job → User Service: batch users · Scheduled user maintenance uses user service logic.
- Post Service → Post Repo: spec queries · Dynamic filtering and search rely on specification-based post queries.
- Post Repo → Relational DB: persist · JPA repositories store data in the relational database schema.
- User Repo → Relational DB: persist · User entities are backed by the Flyway-managed database.
- Category Repo → Relational DB: persist · Category entities are backed by the Flyway-managed database.
- Interaction Repos → Relational DB: persist · Social interaction entities are backed by the relational database.
- Response Advice → Clients: API response · Responses are normalized before returning to API consumers.
- Exception Advice → Clients: API error · Exceptions are translated into standardized error payloads.
- Logging → Clients: trace · Request and execution logging cross-cut the external request path.