# sudeshnapathak/blog_management_system architecture

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

- Interactive diagram: https://gitdiagram.com/sudeshnapathak/blog_management_system
- Repository: https://github.com/sudeshnapathak/blog_management_system

## Overview

1. **Application type and runtime**
   - This is a **Spring Boot** backend built with **Maven**.
   - The core runtime is a layered Java service exposing REST APIs for blog administration, content, and user management.

2. **Primary request flow**
   - Requests enter through the **controller layer** under `Controllers/`.
   - Controllers delegate to `Service` implementations, which coordinate business rules, persistence, security checks, and side effects.
   - Responses are normalized through `Advice/GlobalResponseHandler`, while failures are mapped by `Advice/GlobalExceptionHandler`.

3. **Domain boundaries**
   - The main domain entities are `UserEntity`, `PostEntity`, `CategoryEntity`, `CommentEntity`, `LikeEntity`, `FollowEntity`, and `BookmarkEntity`.
   - DTOs are used extensively to separate API contracts from persistence models, covering authentication, posts, users, follows, likes, comments, and categories.

4. **Persistence layer**
   - Repositories in `Repositories/` provide data access for each major entity.
   - The domain model is backed by database migrations in `src/main/resources/db/migration`, indicating schema management is handled explicitly rather than ad hoc.
   - `Specifications/PostFilterSpecification` suggests dynamic query filtering for post search/listing.

5. **Business services**
   - `PostServiceImpl`, `UserServiceImpl`, and `CategoryServiceImpl` hold the main domain logic.
   - The `Service/Interfaces/` package defines service boundaries, while implementation classes encapsulate orchestration and validation.
   - `RedisViewCountServiceImpl` is a separate service, showing that view counting is treated as a distinct data path from standard relational persistence.

6. **Security and authentication**
   - Authentication is JWT-based, with `JWTService`, `JWTAuthFilter`, and `WebSecurityConfig` forming the security boundary.
   - `AuthService` handles login/signup/refresh token workflows exposed through `AuthController`.
   - `SecurityUtils` and `SecurityConfigUtils` support request/user context handling, likely for current-user access in services and controllers.

7. **Event-driven side effects**
   - The system publishes internal application events such as `CommentAddedEvent`, `NewPostPublishedEvent`, `PostLikedEvent`, and `NewFollowerEvent`.
   - `Listeners/EmailEventListeners` consumes these events and triggers email-related side effects.
   - This decouples core business actions from notification delivery, which is an important architectural boundary.

8. **Email templating and notification delivery**
   - Email content is rendered from FreeMarker templates in `src/main/resources/templates/`.
   - `EmailTemplateServiceImpl` and `EmailServiceImpl` form the email subsystem, with template models in `TemplateModels/`.
   - This subsystem is fed by domain events rather than direct controller calls, so notifications are asynchronous by design.

9. **Scheduled/background jobs**
   - `Schedulers/` contains background processes for post publication, user batch processing, and Redis-to-database view synchronization.
   - `PostPublishScheduler` likely handles scheduled publication of queued posts.
   - `ViewSyncScheduler` is the bridge between fast in-memory view tracking and durable storage, showing a deliberate split between write-heavy metrics and relational data.

10. **Cross-cutting concerns**
   - Logging is handled by both an AOP aspect (`LoggingAspect`) and an HTTP filter (`RequestLoggingFilter`).
   - Input sanitization is reinforced by custom deserializers in `Deserializers/`, which is relevant for safe handling of HTML/string content in post/comment fields.
   - `AsyncConfig`, `MapperConfig`, `MessageSourceConfig`, and `SwaggerConfig` are supporting configuration for async work, object mapping, i18n/messages, and API documentation.

11. **API conventions and constants**
   - `Constants/ApiRoutes.java` centralizes endpoint paths, which helps keep controller mappings consistent.
   - Other constants cover regex validation and Redis key naming, suggesting shared rules for routing, input validation, and cache structure.

12. **Infrastructure and operational tooling**
   - `docker-compose.yml`, `Dockerfile`, and the `elk-config/` directory show the project is packaged for containerized deployment with log shipping into an **ELK** stack via Filebeat/Logstash.
   - `logback-spring.xml` supports structured application logging.
   - Swagger screenshots in the README and `SwaggerConfig` indicate API documentation is first-class.
   - `src/test/` contains controller, service, repository, scheduler, listener, security, and utility tests, reflecting coverage across the whole architecture rather than only the API layer.

Main entry points: [`src/main/java/com/project/Blog_Management_System/Controllers`](https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Controllers) (Controllers), [`src/main/java/com/project/Blog_Management_System/Service/PostServiceImpl.java`](https://github.com/sudeshnapathak/blog_management_system/blob/main/src/main/java/com/project/Blog_Management_System/Service/PostServiceImpl.java) (Post Service), [`src/main/java/com/project/Blog_Management_System/Service/UserServiceImpl.java`](https://github.com/sudeshnapathak/blog_management_system/blob/main/src/main/java/com/project/Blog_Management_System/Service/UserServiceImpl.java) (User Service), [`src/main/java/com/project/Blog_Management_System/Repositories`](https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Repositories) (Repositories)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_api["API Layer"]
  node_node_app(("Application<br/>Spring Boot app"))
  node_node_controllers["Controllers<br/>REST endpoints"]
  node_node_advice["Response Advice<br/>HTTP advice"]
  node_node_logging["Request Logging<br/>AOP/filter logging"]
end

subgraph group_group_core["Core Domain"]
  node_node_post_service["Post Service<br/>domain orchestration"]
  node_node_user_service["User Service<br/>domain orchestration"]
  node_node_category_service["Category Service<br/>domain orchestration"]
  node_node_interfaces["Service Contracts<br/>service interfaces"]
  node_node_viewcount[("View Counts<br/>redis counter service")]
  node_node_spec["Post Filter<br/>query specification"]
  node_node_entities["Entities<br/>JPA models"]
  node_node_dto["DTOs<br/>api contracts"]
  node_node_repos[("Repositories<br/>data access")]
end

subgraph group_group_security["Security"]
  node_node_security["Security Layer<br/>JWT security"]
  node_node_authsvc["Auth Service<br/>auth workflow<br/>[AuthService.java]"]
end

subgraph group_group_notifications["Notifications"]
  node_node_events{{"Domain Events<br/>application events"}}
  node_node_listeners["Email Listeners<br/>event listeners"]
  node_node_email["Email Service<br/>template email delivery"]
  node_node_templates["Email Templates<br/>freemarker views"]
end

subgraph group_group_ops["Operations"]
  node_node_schedulers["Schedulers<br/>background jobs"]
  node_node_migrations["Migrations<br/>db schema"]
  node_node_config["Config"]
  node_node_deploy["Deploy Assets<br/>container/logging ops<br/>[docker-compose.yml]"]
end

node_node_app -->|"hosts"| node_node_controllers
node_node_controllers -->|"returns via"| node_node_advice
node_node_controllers -->|"auth calls"| node_node_authsvc
node_node_controllers -->|"uses"| node_node_post_service
node_node_controllers -->|"uses"| node_node_user_service
node_node_controllers -->|"uses"| node_node_category_service
node_node_controllers -->|"observed by"| node_node_logging
node_node_post_service -->|"persists via"| node_node_repos
node_node_user_service -->|"persists via"| node_node_repos
node_node_category_service -->|"persists via"| node_node_repos
node_node_post_service -->|"filters with"| node_node_spec
node_node_post_service -->|"maps to"| node_node_entities
node_node_user_service -->|"maps to"| node_node_entities
node_node_category_service -->|"maps to"| node_node_entities
node_node_repos -->|"backed by"| node_node_migrations
node_node_authsvc -->|"secured by"| node_node_security
node_node_security -->|"protects"| node_node_controllers
node_node_post_service -->|"publishes"| node_node_events
node_node_user_service -->|"publishes"| node_node_events
node_node_events -->|"consumed by"| node_node_listeners
node_node_listeners -->|"triggers"| node_node_email
node_node_email -->|"renders"| node_node_templates
node_node_listeners -->|"uses models"| node_node_templates
node_node_schedulers -->|"emits"| node_node_events
node_node_schedulers -->|"syncs"| node_node_viewcount
node_node_config -->|"configures"| node_node_security
node_node_config -->|"configures"| node_node_email
node_node_deploy -->|"ships logs"| node_node_logging

click node_node_app "https://github.com/sudeshnapathak/blog_management_system/blob/main/src/main/java/com/project/Blog_Management_System/BlogManagementSystemApplication.java"
click node_node_controllers "https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Controllers"
click node_node_advice "https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Advice"
click node_node_logging "https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Logging"
click node_node_post_service "https://github.com/sudeshnapathak/blog_management_system/blob/main/src/main/java/com/project/Blog_Management_System/Service/PostServiceImpl.java"
click node_node_user_service "https://github.com/sudeshnapathak/blog_management_system/blob/main/src/main/java/com/project/Blog_Management_System/Service/UserServiceImpl.java"
click node_node_category_service "https://github.com/sudeshnapathak/blog_management_system/blob/main/src/main/java/com/project/Blog_Management_System/Service/CategoryServiceImpl.java"
click node_node_interfaces "https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Service/Interfaces"
click node_node_viewcount "https://github.com/sudeshnapathak/blog_management_system/blob/main/src/main/java/com/project/Blog_Management_System/Service/RedisViewCountServiceImpl.java"
click node_node_spec "https://github.com/sudeshnapathak/blog_management_system/blob/main/src/main/java/com/project/Blog_Management_System/Specifications/PostFilterSpecification.java"
click node_node_entities "https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Entities"
click node_node_dto "https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Dto"
click node_node_repos "https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Repositories"
click node_node_security "https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Security"
click node_node_authsvc "https://github.com/sudeshnapathak/blog_management_system/blob/main/src/main/java/com/project/Blog_Management_System/Security/AuthService.java"
click node_node_events "https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Events"
click node_node_listeners "https://github.com/sudeshnapathak/blog_management_system/blob/main/src/main/java/com/project/Blog_Management_System/Listeners/EmailEventListeners.java"
click node_node_email "https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Service"
click node_node_templates "https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/resources/templates"
click node_node_schedulers "https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Schedulers"
click node_node_migrations "https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/resources/db/migration"
click node_node_config "https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Config"
click node_node_deploy "https://github.com/sudeshnapathak/blog_management_system/blob/main/docker-compose.yml"

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_node_app,node_node_controllers,node_node_advice,node_node_logging toneBlue
class node_node_post_service,node_node_user_service,node_node_category_service,node_node_interfaces,node_node_viewcount,node_node_spec,node_node_entities,node_node_dto,node_node_repos toneAmber
class node_node_security,node_node_authsvc toneMint
class node_node_events,node_node_listeners,node_node_email,node_node_templates toneRose
class node_node_schedulers,node_node_migrations,node_node_config,node_node_deploy toneIndigo
```

## Components

### API Layer

HTTP entrypoints, response handling, and request logging

- [Application](https://github.com/sudeshnapathak/blog_management_system/blob/main/src/main/java/com/project/Blog_Management_System/BlogManagementSystemApplication.java): Spring Boot app · Main application bootstrap for the blog management system · `src/main/java/com/project/Blog_Management_System/BlogManagementSystemApplication.java`
- [Controllers](https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Controllers): REST endpoints · Admin, auth, post, category, and user HTTP controllers · `src/main/java/com/project/Blog_Management_System/Controllers`
- [Response Advice](https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Advice): HTTP advice · Normalizes success responses and maps exceptions to API errors · `src/main/java/com/project/Blog_Management_System/Advice`
- [Request Logging](https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Logging): AOP/filter logging · Cross-cutting request and execution logging · `src/main/java/com/project/Blog_Management_System/Logging`

### Core Domain

Business services, entities, DTOs, and query logic

- [Post Service](https://github.com/sudeshnapathak/blog_management_system/blob/main/src/main/java/com/project/Blog_Management_System/Service/PostServiceImpl.java): domain orchestration · Core post creation, publishing, filtering, reactions, and comments · `src/main/java/com/project/Blog_Management_System/Service/PostServiceImpl.java`
- [User Service](https://github.com/sudeshnapathak/blog_management_system/blob/main/src/main/java/com/project/Blog_Management_System/Service/UserServiceImpl.java): domain orchestration · User profile, follow, and account-related business rules · `src/main/java/com/project/Blog_Management_System/Service/UserServiceImpl.java`
- [Category Service](https://github.com/sudeshnapathak/blog_management_system/blob/main/src/main/java/com/project/Blog_Management_System/Service/CategoryServiceImpl.java): domain orchestration · Category management and validation logic · `src/main/java/com/project/Blog_Management_System/Service/CategoryServiceImpl.java`
- [Service Contracts](https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Service/Interfaces): service interfaces · Service boundaries for posts, users, categories, email, and view counts · `src/main/java/com/project/Blog_Management_System/Service/Interfaces`
- [View Counts](https://github.com/sudeshnapathak/blog_management_system/blob/main/src/main/java/com/project/Blog_Management_System/Service/RedisViewCountServiceImpl.java): redis counter service · Fast view tracking separate from relational persistence · `src/main/java/com/project/Blog_Management_System/Service/RedisViewCountServiceImpl.java`
- [Post Filter](https://github.com/sudeshnapathak/blog_management_system/blob/main/src/main/java/com/project/Blog_Management_System/Specifications/PostFilterSpecification.java): query specification · Dynamic filtering and search criteria for posts · `src/main/java/com/project/Blog_Management_System/Specifications/PostFilterSpecification.java`
- [Entities](https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Entities): JPA models · User, post, category, comment, like, follow, and bookmark entities · `src/main/java/com/project/Blog_Management_System/Entities`
- [DTOs](https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Dto): api contracts · Request and response models for auth, posts, users, follows, likes, comments, categories, and email · `src/main/java/com/project/Blog_Management_System/Dto`
- [Repositories](https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Repositories): data access · Persistence repositories for the major domain entities · `src/main/java/com/project/Blog_Management_System/Repositories`

### Security

JWT authentication and request authorization

- [Security Layer](https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Security): JWT security · Authentication, token handling, request filtering, and security configuration · `src/main/java/com/project/Blog_Management_System/Security`
- [Auth Service](https://github.com/sudeshnapathak/blog_management_system/blob/main/src/main/java/com/project/Blog_Management_System/Security/AuthService.java): auth workflow · Login, signup, and token refresh coordination · `src/main/java/com/project/Blog_Management_System/Security/AuthService.java`

### Notifications

Events and email delivery

- [Domain Events](https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Events): application events · Events for post publication, comments, likes, followers, and scheduled publication · `src/main/java/com/project/Blog_Management_System/Events`
- [Email Listeners](https://github.com/sudeshnapathak/blog_management_system/blob/main/src/main/java/com/project/Blog_Management_System/Listeners/EmailEventListeners.java): event listeners · Consumes domain events and triggers notification side effects · `src/main/java/com/project/Blog_Management_System/Listeners/EmailEventListeners.java`
- [Email Service](https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Service): template email delivery · Renders templates and sends notification emails · `src/main/java/com/project/Blog_Management_System/Service`
- [Email Templates](https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/resources/templates): freemarker views · FreeMarker templates for notification emails · `src/main/resources/templates`

### Operations

Scheduling, persistence migrations, and deployment support

- [Schedulers](https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Schedulers): background jobs · Scheduled publication, user batch processing, and view synchronization · `src/main/java/com/project/Blog_Management_System/Schedulers`
- [Migrations](https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/resources/db/migration): db schema · Flyway migrations and initial data scripts · `src/main/resources/db/migration`
- [Config](https://github.com/sudeshnapathak/blog_management_system/tree/main/src/main/java/com/project/Blog_Management_System/Config): app configuration · Async, mapper, message source, and Swagger configuration · `src/main/java/com/project/Blog_Management_System/Config`
- [Deploy Assets](https://github.com/sudeshnapathak/blog_management_system/blob/main/docker-compose.yml): container/logging ops · Docker packaging and ELK shipping configuration · `docker-compose.yml`

## Connections

- Application → Controllers: hosts · Application exposes REST controllers
- Controllers → Response Advice: returns via · Controllers rely on shared response and error handling
- Controllers → Auth Service: auth calls · Auth endpoints delegate login and token workflows
- Controllers → Post Service: uses · Post endpoints delegate business operations
- Controllers → User Service: uses · User endpoints delegate account operations
- Controllers → Category Service: uses · Category endpoints delegate category operations
- Controllers → Request Logging: observed by · HTTP requests are logged through filters and aspects
- Post Service → Repositories: persists via · Post workflows read and write relational data
- User Service → Repositories: persists via · User workflows read and write relational data
- Category Service → Repositories: persists via · Category workflows read and write relational data
- Post Service → Post Filter: filters with · Post listing/search uses dynamic specifications
- Post Service → Entities: maps to · Services operate on persistent domain entities
- User Service → Entities: maps to · User and relation entities model the domain
- Category Service → Entities: maps to · Categories are represented as JPA entities
- Repositories → Migrations: backed by · Repository schema is created and evolved through Flyway migrations
- Auth Service → Security Layer: secured by · JWT filter and security config define the access boundary
- Security Layer → Controllers: protects · Security layer sits in front of API endpoints
- Post Service → Domain Events: publishes · Business actions emit domain events
- User Service → Domain Events: publishes · User actions emit follower-related events
- Domain Events → Email Listeners: consumed by · Listeners react to application events
- Email Listeners → Email Service: triggers · Email side effects are delegated to the email subsystem
- Email Service → Email Templates: renders · Notification content is produced from templates
- Email Listeners → Email Templates: uses models · Listeners pass template models into email rendering
- Schedulers → Domain Events: emits · Scheduled jobs can publish background events
- Schedulers → View Counts: syncs · View counts are synchronized from Redis to durable storage
- Config → Security Layer: configures · Configuration supports security and request processing
- Config → Email Service: configures · Configuration supports object mapping, async work, and messaging
- Deploy Assets → Request Logging: ships logs · Container tooling forwards logs to ELK
