A comprehensive RESTful API backend for a blogging platform, built with Spring Boot. This project powers the Onneshon Blog, supporting user authentication, blog management, categories, comments, and more. The UI is available as a separate React application: Onneshon React UI.
- Features
- Tech Stack
- Project Structure
- Database Schema
- Setup & Installation
- Environment Configuration
- API Endpoints
- Running the Application
- Connecting the UI
- Contributing
- License
- User registration, authentication (JWT), and role-based authorization
- Blog CRUD (Create, Read, Update, Delete)
- Category management
- Commenting system
- File upload for user avatars and blog images
- Pagination, sorting, and search for blogs
- Exception handling and validation
- API documentation with Swagger/OpenAPI
- Backend: Java 17, Spring Boot 3, Spring Data JPA, Spring Security, JWT
- Database: MySQL/MariaDB
- API Docs: Springdoc OpenAPI/Swagger
- Frontend: React (separate repo)
src/main/java/com/onneshon/blog/
├── controllers/ # REST controllers (User, Blog, Category, Auth, Comment)
├── entities/ # JPA entities (User, Blog, Category, Comment, Role)
├── repositories/ # Spring Data JPA repositories
├── services/ # Service interfaces
├── servicesImple/ # Service implementations
├── payloads/ # DTOs and API response models
├── exceptions/ # Custom exceptions and handlers
├── helpers/ # Utility classes (file upload, validation)
├── configs/ # Security, JWT, and CORS configuration
└── OnneshonBlogApisApplication.java
The main tables are:
users(id, name, email, password, about, image)roles(id, role)users_roles(user_id, roles_id)blogs(id, blog_title, blog_content, blog_image, added_date, category_id, user_id)categories(category_id, category_title, category_description)comments(comment_id, content, blog_id, user_id)
See onneshon.sql for the full schema and sample data.
- Java 17+
- Maven
- MySQL or MariaDB
git clone https://github.com/yourusername/onneshon-blog-api.git
cd onneshon-blog-api- Create a database (e.g.,
onneshonortest_db). - Import the schema and sample data:
mysql -u root -p onneshon < onneshon.sql
Edit src/main/resources/application-dev.properties and application-prod.properties for your DB credentials:
spring.datasource.url=jdbc:mysql://localhost:3306/onneshon
spring.datasource.username=root
spring.datasource.password=yourpassword
mvn clean installapplication.propertiessets common configs (file upload, security, etc.)application-dev.propertiesandapplication-prod.propertiesset DB and port for dev/prod- Switch profiles via
spring.profiles.active=devorprod
# For dev profile (default)
mvn spring-boot:run
# Or run the jar
java -jar target/onneshon-blog-api-0.0.1-SNAPSHOT.jar- The API will be available at
http://localhost:1234/(dev) or:5000(prod)
POST /api/v1/auth/register— Register a new user (multipart/form-data)POST /api/v1/auth/login— Login and receive JWT
POST /api/user/— Add user (multipart/form-data)PUT /api/user/{userId}— Update userDELETE /api/user/{userId}— Delete user (admin only)GET /api/user/{userId}— Get user by IDGET /api/users/— List all users
POST /api/blog— Add blog (multipart/form-data)PUT /api/blog/{blogId}— Update blogDELETE /api/blog/{blogId}— Delete blogGET /api/blog/{blogId}— Get blog by IDGET /api/blogs— List all blogs (pagination, sorting)GET /api/user/{userId}/blogs— Blogs by userGET /api/category/{catId}/blogs— Blogs by categoryGET /api/blogs/results?search_query=...— Search blogs
POST /api/category/— Add categoryPUT /api/category/{catId}— Update categoryDELETE /api/category/{catId}— Delete categoryGET /api/category/{catId}— Get category by IDGET /api/category/all— List all categories
POST /api/blog/{blogId}/comment— Add commentDELETE /api/comment/{commentId}— Delete commentGET /api/comment/blog/{blogId}— Get comments for a blog
- Swagger UI:
http://localhost:1234/swagger-ui/index.html
The official React frontend is available at: https://github.com/ShubratoDn/onneshon-react
- Clone and run the UI repo for a complete full-stack experience.
- The UI expects the backend to be running at the configured API base URL (see
.envin the UI repo).
Pull requests are welcome! Please open issues for bugs or feature requests.
This project is licensed under the MIT License.
- Name: Shubrato Debnath
- Email: shubratodn44985@gmail.com
- Phone: +880 1759458961