BlogV2 is a robust, production-ready RESTful API designed to power modern blogging platforms and content management systems. Built on the Java 17 and Spring Boot 3.x ecosystem, it provides a highly scalable backend solution with secure user authentication, advanced post and comment management, intelligent caching, seamless media integration, and enterprise-grade observability.
Whether you are building a headless CMS, a personal blog, or a large-scale publishing platform, BlogV2 provides the foundational architecture to support high traffic and complex data relationships.
- JWT & Refresh Tokens: Secure, stateless authentication using JSON Web Tokens. Access tokens are short-lived, while Refresh tokens are stored securely in HttpOnly cookies.
- Role-Based Access Control (RBAC): Fine-grained authorization differentiating between
USERandADMINroles. - Rate Limiting: Built-in API rate limiting using Bucket4j to prevent abuse and brute-force attacks.
- Input Sanitization: Cross-Site Scripting (XSS) prevention using OWASP Java HTML Sanitizer to cleanse all rich-text content before persistence.
- Posts Lifecycle: Create, Read, Update, and Delete (CRUD) operations for posts. Supports
DRAFTandPUBLISHEDstates. - Categories & Tagging: Organize content efficiently with predefined categories (e.g., TECH, TUTORIAL).
- SEO-Friendly Slugs: Automatic, collision-free URL slug generation from post titles.
- Rich Text & Images: Seamless integration with ImageKit for CDN-backed media storage, ensuring lightning-fast image delivery.
- Interactive Discussions: Users can comment on posts, edit their comments, and delete them.
- Moderation: Admins have overarching privileges to manage or remove any comments.
- Redis Caching: Aggressive caching of frequently accessed endpoints (like paginated post feeds and individual posts) using Redis to minimize database load.
- Pagination & Sorting: Efficient data retrieval using Spring Data JPA's Pageable interface, preventing memory bloat on large datasets.
- MapStruct: High-performance, compile-time object mapping between Entities and DTOs.
- Dockerized Architecture: Fully containerized environment orchestrating the API, PostgreSQL, and Redis via
docker-compose. - Metrics & Monitoring: Integrated Spring Boot Actuator with Micrometer. Exposes endpoints for Prometheus scraping.
- Structured JSON Logging: Centralized logging via Logback and SLF4J with MDC correlation ID tracing across all requests.
- Grafana Dashboards: Ready-to-use metrics pipeline to monitor JVM memory, HTTP request latency, and cache hit ratios.
- Swagger / OpenAPI 3: Interactive, auto-generated API documentation available out-of-the-box.
| Category | Technology | Version | Purpose |
|---|---|---|---|
| Core | Java | 17 | Primary Programming Language |
| Framework | Spring Boot | 3.x+ | Application Framework (Web, Data JPA, Security) |
| Database | PostgreSQL | 15+ | Relational Database Management System |
| Caching | Redis | 7-alpine | In-Memory Data Store for caching responses |
| Mapping | MapStruct | 1.5.5.Final | Entity-to-DTO Mapper |
| Security | Spring Security, JWT, Bucket4j | Latest | Auth & Rate Limiting |
| Media | ImageKit | 3.0.0 | Cloud Image Storage & CDN |
| Monitoring | Prometheus & Grafana | Latest | Telemetry & Observability |
| Logging | Logback & SLF4J | Latest | Structured JSON Logging & MDC Tracing |
| Containerization | Docker & Docker Compose | 3.8 | Orchestration |
| Documentation | Springdoc OpenAPI | 2.8.0 | Swagger UI |
- Docker and Docker Compose
- Java 17 & Maven (if running locally without Docker)
git clone https://github.com/yourusername/BlogV2.git
cd BlogV2Create a .env file in the root directory and populate it with your specific credentials:
# Database
DB_PASSWORD=your_secure_postgres_password
# Security
JWT_SECRET=your_super_secret_jwt_key_here_must_be_long
# ImageKit Configuration (Get these from your ImageKit dashboard)
IMAGEKIT_PUBLIC=your_imagekit_public_key
IMAGEKIT_PRIVATE=your_imagekit_private_key
IMAGEKIT_URL=https://ik.imagekit.io/your_endpointThe simplest way to start the entire infrastructure:
docker-compose up --build -dAccess Points:
- π API Base URL:
http://localhost:9080/api/v1 - π Swagger UI / API Docs:
http://localhost:9080/swagger-ui/index.html - π Grafana Dashboards:
http://localhost:3000(Default login:admin/admin)
Note: For a complete, interactive list of endpoints and request/response models, visit the Swagger UI.
| Method | Endpoint | Description | Access |
|---|---|---|---|
POST |
/register |
Register a new user account | Public |
POST |
/login |
Authenticate and receive JWT & Refresh tokens | Public |
POST |
/refresh |
Generate a new access token using a refresh token | Public |
| Method | Endpoint | Description | Access |
|---|---|---|---|
GET |
/ |
Get paginated posts (Cached) | Public |
GET |
/{id} |
Get post details by ID or Slug | Public |
GET |
/search/{keyword} |
Search posts by title | Public |
GET |
/category/{cat} |
Filter posts by category | Public |
POST |
/user/{userId} |
Create a new post | Auth (Owner) |
PUT |
/{id} |
Update an existing post | Auth (Owner) |
DELETE |
/{id} |
Delete a post | Auth (Owner/Admin) |
PATCH |
/{id}/cover-image |
Update the post's cover image | Auth (Owner) |
| Method | Endpoint | Description | Access |
|---|---|---|---|
GET |
/posts/{id}/comments |
Get all comments for a post | Public |
POST |
/posts/{id}/comments |
Add a comment to a post | Auth |
PUT |
/comments/{id} |
Update a specific comment | Auth (Owner) |
DELETE |
/comments/{id} |
Delete a comment | Auth (Owner/Admin) |
| Method | Endpoint | Description | Access |
|---|---|---|---|
GET |
/ |
List all users | Auth (Admin) |
GET |
/{id} |
Get user profile details | Public |
GET |
/{id}/posts |
Get all posts authored by a user | Public |
| Method | Endpoint | Description | Access |
|---|---|---|---|
POST |
/upload |
Upload an image to ImageKit | Auth |
Request: Fetching a Post
GET /api/v1/posts/1
Response: 200 OK
{
"success": true,
"message": "Post retrieved successfully",
"data": {
"id": 1,
"title": "Mastering Spring Boot 3",
"slug": "mastering-spring-boot-3",
"content": "<p>Spring Boot makes it easy to create stand-alone...</p>",
"coverImageUrl": "https://ik.imagekit.io/your_endpoint/spring.png",
"authorName": "Jane Doe",
"status": "PUBLISHED",
"categories": ["TECH", "TUTORIAL"],
"commentCount": 12,
"createdAt": "2026-07-20T10:00:00.000Z",
"comments": [
{
"id": 101,
"text": "Great article! Very helpful.",
"authorName": "John Smith",
"createdAt": "2026-07-21T08:30:00.000Z"
}
]
},
"timestamp": "2026-07-31T12:00:00.000Z"
}BlogV2 is designed with DevSecOps in mind. Out of the box, it provides a comprehensive monitoring stack.
- Spring Boot Actuator exposes
/actuator/prometheuscontaining JVM, Tomcat, HikariCP, and HTTP metrics. - Prometheus (configured via
prometheus.yml) periodically scrapes these metrics. - Grafana connects to Prometheus as a data source.
- To view metrics, navigate to
http://localhost:3000(admin/admin). - You can import community dashboards like JVM (ID:
4701) or Spring Boot Observability (ID:11378) to instantly visualize API health, latency, and throughput.
- To view metrics, navigate to
- JSON Format: Uses
logstash-logback-encoderto output logs in strict JSON format for easy ingestion by log aggregators (like ELK/EFK stack). - Log Routing: Automatically separates
application.log(INFO+) anderror.log(ERROR) into thelogs/directory. - MDC Correlation: A custom
MdcCorrelationFilterinjects a unique UUID (X-Correlation-Id) into every request. This ID is included in all business logic and exception logs, providing end-to-end traceability for any transaction.
- Controller-Service-Repository Pattern: Clean separation of concerns. Controllers handle HTTP layer, Services contain business logic, Repositories interact with the database.
- DTO (Data Transfer Object) Pattern: MapStruct is used to map Entities (which model database tables) to DTOs (which are returned to the client), preventing the exposure of sensitive data like passwords or internal IDs.
- Exception Handling: Global exception handling using
@ControllerAdviceensures consistent, well-formatted API error responses across all endpoints.
Contributions, bug reports, and feature requests are always welcome!
- Fork the repository.
- Create a branch (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'Add some AmazingFeature'). - Push to the branch (
git push origin feature/AmazingFeature). - Open a Pull Request.
This project is open-source and available under the MIT License. See the LICENSE file for more details.