A Spring Boot backend service for a blog platform with JWT authentication, PostgreSQL persistence, and Redis caching.
This repository contains the API layer, security setup, and data access logic for a blog app where users can create posts, leave comments, and search content.
The service supports:
- user registration and login with JWT
- role-based access control for users and admins
- CRUD operations for posts and comments
- text search, pageable post listings, and sorting
- Redis caching for post retrieval
- Swagger/OpenAPI documentation for the API
This project demonstrates backend application design using Spring Boot, Spring Security, Redis, PostgreSQL, and Docker. was built to practice secure Spring Boot architecture and API design.
- Java 17
- Spring Boot 3.3.2
- Spring Security
- Spring Data JPA + Hibernate
- PostgreSQL 15
- Redis 7
- JWT with jjwt
- Docker + Docker Compose
- Springdoc OpenAPI / Swagger UI
git clone <repository-url>
cd Blog-management-system
cp .env.example .env
# update .env with your values
docker compose up --buildThen open:
http://localhost:8080for the APIhttp://localhost:8080/swagger-ui.htmlfor docs
- Start PostgreSQL and Redis locally.
- Create the database:
createdb blogdb- Create
.envin the project root with the required values. - Run the service:
mvn clean install
mvn spring-boot:runPOST /api/auth/registerPOST /api/auth/loginPOST /api/auth/refresh
GET /api/posts/paginated/allGET /api/posts/searchGET /api/posts/author/{id}GET /api/posts/{id}POST /api/postsPUT /api/posts/{id}DELETE /api/posts/{id}
GET /api/posts/{postId}/commentsPOST /api/posts/{postId}/commentsPUT /api/posts/{postId}/comments/{commentId}DELETE /api/posts/{postId}/comments/{commentId}
A default admin user is created on first startup:
Blog-management-system/
├── src/
│ ├── main/
│ │ ├── java/com/blog/management/
│ │ │ ├── config/
│ │ │ ├── controller/
│ │ │ ├── service/
│ │ │ ├── repository/
│ │ │ ├── entity/
│ │ │ ├── dto/
│ │ │ ├── exception/
│ │ │ ├── security/
│ │ │ └── util/
│ │ └── resources/
│ │ └── application.yml
│ └── test/
├── docker-compose.yml
├── Dockerfile
├── pom.xml
└── .env.example
- JWT for stateless auth
- BCrypt for password hashing
- Role-based access control
- Sensitive settings loaded from environment variables
Create a .env file with:
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_NAME=blogdb
DATABASE_USERNAME=postgres
DATABASE_PASSWORD=postgres
EMAIL_USERNAME=your-email@gmail.com
EMAIL_PASSWORD=your-app-password
REDIS_HOST=localhost
REDIS_PORT=6379
JWT_SECRET=your-secret-keyFor Gmail email delivery, use an app password and enable 2FA on your Google account.
The API docs are available at http://localhost:8080/swagger-ui.html.
MIT License.