How osopromadze/spring-boot-blog-rest-api works
1. This is a single Spring Boot backend application that exposes a REST API for a blog-and-user-management domain. The main runtime is Java/Spring Boot, with persistence through Spring Data JPA/Hibernate and a MySQL database seeded by the SQL files in src/main/resources and data/.
2. The application is organized in a classic layered structure:
- controller handles HTTP endpoints.
- service / service.impl contains business logic.
- repository provides database access.
- model contains JPA entities.
- payload contains request/response DTOs.
- security, config, exception, and utils hold cross-cutting concerns.
3. The HTTP API is split by resource: auth, users, posts, comments, albums, photos, todos, categories, and tags. Each resource has its own controller, and most of them support CRUD plus a few domain-specific actions like marking todos complete or assigning admin privileges.
4. The core request flow is controller → service → repository → database, then back through DTO/payload objects. Controllers do not appear to talk directly to repositories; the services encapsulate ownership checks, validation-related logic, and domain rules before persisting changes.
5. Authentication and authorization are centralized in the security package. The app uses JWT-based stateless auth with:
- JwtAuthenticationFilter to inspect incoming requests,
- JwtTokenProvider to create/validate tokens,
- JwtAuthenticationEntryPoint for unauthorized access handling,
- CustomUserDetailsService / UserPrincipal to integrate user data with Spring Security.
The AuthController is the entry point for signup/signin and token issuance.
6. Ownership and role-based access are important architectural boundaries. Many endpoints are protected so only the resource owner or an admin can update/delete, and some operations are admin-only. The domain model includes roles (Role, RoleName) and user identity helpers, which are used by the security layer and service logic.
7. The domain model is split into a few related groups:
- blog content: Post, Comment, Category, Tag
- media/collections: Album, Photo
- user profile/account: User plus nested Address, Company, Geo
- personal tasks: Todo
Audit base classes (DateAudit, UserDateAudit) add created/updated metadata across entities.
8. DTOs in payload define the external API contract and prevent controllers from exposing entities directly. There are separate request/response shapes for login/signup, posts, photos, albums, comments, paged lists, and user profiles. This means the API layer is intentionally decoupled from the persistence model.
9. Error handling is centralized in exception. Custom exceptions like ResourceNotFoundException, BadRequestException, UnauthorizedException, and AccessDeniedException are translated by RestControllerExceptionHandler into consistent HTTP error responses (ExceptionResponse, ResponseEntityErrorException, etc.). That gives the API a uniform failure boundary.
10. config contains application-wide wiring:
- SecurityConfig sets the security rules and filter chain,
- AuditingConfig enables JPA auditing support,
- WebMvcConfig likely handles MVC-related setup such as CORS or formatters.
These are the main infrastructure seams that shape request processing and persistence behavior.
11. The repositories are mostly straightforward Spring Data interfaces, one per entity aggregate. The repo structure suggests the database schema is fairly normalized, with relationships handled by JPA mappings rather than custom query infrastructure.
12. Deployment and local execution are container-friendly. The repository includes a Dockerfile, docker-compose.yml, Maven wrapper, and GitHub Actions workflow files for build automation. The README indicates the app is meant to run locally against MySQL and can be started via Maven or containerized setup.
13. For diagramming, the most important boundaries are:
- client/API consumer outside the system,
- Spring Security filter chain at the request ingress,
- controller layer as the HTTP facade,
- service layer as business-policy enforcement,
- repository/database boundary as persistence,
- exception handler as the outbound error path.
Most domain complexity lives in the service layer, not the controllers or repositories.
Main entry points: service Services · JwtAuthenticationFilter.java JWT filter · SecutiryConfig.java Security config · model JPA entities
Components 21
API layer
HTTP controllers and request/response contracts.
- Auth API · Signup, signin, and token issuance.
src/main/java/com/sopromadze/blogapi/controller/AuthController.java - Resource APIs · REST endpoints for users, posts, comments, albums, photos, todos, categories, and tags.
- DTOs · External request and response shapes for the REST API.
src/main/java/com/sopromadze/blogapi/payload
Core runtime
Security, service, persistence, and domain model.
- JWT filter · Inspects requests and populates authentication context.
src/main/java/com/sopromadze/blogapi/security/JwtAuthenticationFilter.java - Token provider · Creates and validates JWT tokens.
src/main/java/com/sopromadze/blogapi/security/JwtTokenProvider.java - User details · Adapts user records to Spring Security.
src/main/java/com/sopromadze/blogapi/service/CustomUserDetailsService.java - Identity model · Roles and authenticated principal used for access control.
src/main/java/com/sopromadze/blogapi/model/role - Services · Business rules, ownership checks, validation, and orchestration.
src/main/java/com/sopromadze/blogapi/service - Blog content · Posts, comments, categories, and tags.
src/main/java/com/sopromadze/blogapi/model - Media domain · Albums and photos.
src/main/java/com/sopromadze/blogapi/model - User profile · Users and embedded profile/address structures.
src/main/java/com/sopromadze/blogapi/model/user - Todo domain · Personal task entities.
src/main/java/com/sopromadze/blogapi/model/Todo.java - Repositories · Spring Data JPA repositories for entity aggregates.
src/main/java/com/sopromadze/blogapi/repository - JPA entities · Entities and auditing base classes mapped to MySQL.
src/main/java/com/sopromadze/blogapi/model
Infrastructure
Application wiring, error handling, and runtime configuration.
- Blog API · Application entry point and main runtime.
src/main/java/com/sopromadze/blogapi/BlogApiApplication.java - Security config · Security filter chain and authorization rules.
src/main/java/com/sopromadze/blogapi/config/SecutiryConfig.java - Error handler · Translates domain exceptions into HTTP error responses.
src/main/java/com/sopromadze/blogapi/exception/RestControllerExceptionHandler.java - App config · Auditing and MVC wiring.
src/main/java/com/sopromadze/blogapi/config - Utilities · Shared application constants and helpers.
src/main/java/com/sopromadze/blogapi/utils - MySQL DB · Persisted application data seeded from SQL files.
data/blogapi.sql - SQL seed · Initial database seed scripts and resource SQL.
src/main/resources/blogapi.sql
Connections 22
- Blog API → Security config: bootstraps · Starts the application with configured security and MVC wiring.
- Security config → JWT filter: installs · Adds the JWT authentication filter into the request chain.
- Security config → Error handler: uses · Wires unauthorized and access-denied handling.
- JWT filter → Token provider: validates · Extracts and verifies bearer tokens.
- JWT filter → User details: loads user · Resolves authenticated users from stored accounts.
- Auth API → Token provider: issues token · Generates JWT responses after signup or signin.
- Auth API → Services: delegates · Uses application services for authentication and account creation.
- Resource APIs → Services: delegates · Routes CRUD and domain actions into business services.
- Services → Repositories: persists via · Reads and writes through Spring Data repositories.
- Repositories → JPA entities: maps · Repository operations are backed by JPA entities.
- Services → Identity model: checks roles · Enforces ownership and admin-only access rules.
- Services → Blog content: manages · Encapsulates blog content behavior.
- Services → Media domain: manages · Encapsulates album and photo behavior.
- Services → User profile: manages · Handles user profile and account operations.
- Services → Todo domain: manages · Handles todo state transitions such as completion.
- Resource APIs → DTOs: contracts · Accepts requests and returns DTO responses.
- Services → DTOs: transforms · Converts between entities and API-facing shapes.
- Error handler → DTOs: returns errors · Produces consistent error response bodies.
- App config → JPA entities: enables auditing · Turns on auditing support for entity metadata.
- MySQL DB → SQL seed: seeded by · Database content is initialized from SQL scripts.
- JPA entities → MySQL DB: stored in · Entities are persisted in the MySQL database.
- Utilities → Services: supports · Provides shared constants and helper functions.