# osopromadze/spring-boot-blog-rest-api architecture

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

- Interactive diagram: https://gitdiagram.com/osopromadze/spring-boot-blog-rest-api
- Repository: https://github.com/osopromadze/spring-boot-blog-rest-api

## Overview

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: [`src/main/java/com/sopromadze/blogapi/service`](https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/service) (Services), [`src/main/java/com/sopromadze/blogapi/security/JwtAuthenticationFilter.java`](https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/src/main/java/com/sopromadze/blogapi/security/JwtAuthenticationFilter.java) (JWT filter), [`src/main/java/com/sopromadze/blogapi/config/SecutiryConfig.java`](https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/src/main/java/com/sopromadze/blogapi/config/SecutiryConfig.java) (Security config), [`src/main/java/com/sopromadze/blogapi/model`](https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/model) (JPA entities)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_api["API layer"]
  node_node_auth_controller["Auth API<br/>controller"]
  node_node_resource_controllers["Resource APIs<br/>controllers"]
  node_node_payloads["DTOs<br/>payloads"]
end

subgraph group_group_core["Core runtime"]
  node_node_jwt_filter["JWT filter<br/>security filter"]
  node_node_jwt_provider["Token provider<br/>jwt service"]
  node_node_user_details["User details<br/>security bridge"]
  node_node_auth_domain{{"Identity model<br/>security model"}}
  node_node_service_layer["Services"]
  node_node_post_domain{{"Blog content<br/>domain model"}}
  node_node_media_domain{{"Media domain<br/>domain model"}}
  node_node_user_domain{{"User profile<br/>domain model"}}
  node_node_todo_domain{{"Todo domain<br/>domain model<br/>[Todo.java]"}}
  node_node_repositories["Repositories<br/>data access"]
  node_node_jpa_models[("JPA entities<br/>persistence model")]
end

subgraph group_group_infra["Infrastructure"]
  node_node_app(("Blog API<br/>Spring Boot app"))
  node_node_security_config["Security config"]
  node_node_exception_handler["Error handler<br/>exception mapping"]
  node_node_config["App config<br/>configuration"]
  node_node_utils["Utilities<br/>helpers"]
  node_node_db[("MySQL DB<br/>database<br/>[blogapi.sql]")]
  node_node_seed["SQL seed<br/>seed data<br/>[blogapi.sql]"]
end

node_node_app -->|"bootstraps"| node_node_security_config
node_node_security_config -->|"installs"| node_node_jwt_filter
node_node_security_config -->|"uses"| node_node_exception_handler
node_node_jwt_filter -->|"validates"| node_node_jwt_provider
node_node_jwt_filter -->|"loads user"| node_node_user_details
node_node_auth_controller -->|"issues token"| node_node_jwt_provider
node_node_auth_controller -->|"delegates"| node_node_service_layer
node_node_resource_controllers -->|"delegates"| node_node_service_layer
node_node_service_layer -->|"persists via"| node_node_repositories
node_node_repositories -->|"maps"| node_node_jpa_models
node_node_service_layer -->|"checks roles"| node_node_auth_domain
node_node_service_layer -->|"manages"| node_node_post_domain
node_node_service_layer -->|"manages"| node_node_media_domain
node_node_service_layer -->|"manages"| node_node_user_domain
node_node_service_layer -->|"manages"| node_node_todo_domain
node_node_resource_controllers -->|"contracts"| node_node_payloads
node_node_service_layer -->|"transforms"| node_node_payloads
node_node_exception_handler -->|"returns errors"| node_node_payloads
node_node_config -->|"enables auditing"| node_node_jpa_models
node_node_db -->|"seeded by"| node_node_seed
node_node_jpa_models -->|"stored in"| node_node_db
node_node_utils -.->|"supports"| node_node_service_layer

click node_node_app "https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/src/main/java/com/sopromadze/blogapi/BlogApiApplication.java"
click node_node_auth_controller "https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/src/main/java/com/sopromadze/blogapi/controller/AuthController.java"
click node_node_payloads "https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/payload"
click node_node_security_config "https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/src/main/java/com/sopromadze/blogapi/config/SecutiryConfig.java"
click node_node_jwt_filter "https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/src/main/java/com/sopromadze/blogapi/security/JwtAuthenticationFilter.java"
click node_node_jwt_provider "https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/src/main/java/com/sopromadze/blogapi/security/JwtTokenProvider.java"
click node_node_user_details "https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/src/main/java/com/sopromadze/blogapi/service/CustomUserDetailsService.java"
click node_node_auth_domain "https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/model/role"
click node_node_service_layer "https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/service"
click node_node_post_domain "https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/model"
click node_node_media_domain "https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/model"
click node_node_user_domain "https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/model/user"
click node_node_todo_domain "https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/src/main/java/com/sopromadze/blogapi/model/Todo.java"
click node_node_repositories "https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/repository"
click node_node_jpa_models "https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/model"
click node_node_exception_handler "https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/src/main/java/com/sopromadze/blogapi/exception/RestControllerExceptionHandler.java"
click node_node_config "https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/config"
click node_node_utils "https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/utils"
click node_node_db "https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/data/blogapi.sql"
click node_node_seed "https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/src/main/resources/blogapi.sql"

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_auth_controller,node_node_resource_controllers,node_node_payloads toneBlue
class node_node_jwt_filter,node_node_jwt_provider,node_node_user_details,node_node_auth_domain,node_node_service_layer,node_node_post_domain,node_node_media_domain,node_node_user_domain,node_node_todo_domain,node_node_repositories,node_node_jpa_models toneAmber
class node_node_app,node_node_security_config,node_node_exception_handler,node_node_config,node_node_utils,node_node_db,node_node_seed toneMint
```

## Components

### API layer

HTTP controllers and request/response contracts.

- [Auth API](https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/src/main/java/com/sopromadze/blogapi/controller/AuthController.java): controller · Signup, signin, and token issuance. · `src/main/java/com/sopromadze/blogapi/controller/AuthController.java`
- **Resource APIs**: controllers · REST endpoints for users, posts, comments, albums, photos, todos, categories, and tags.
- [DTOs](https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/payload): payloads · 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](https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/src/main/java/com/sopromadze/blogapi/security/JwtAuthenticationFilter.java): security filter · Inspects requests and populates authentication context. · `src/main/java/com/sopromadze/blogapi/security/JwtAuthenticationFilter.java`
- [Token provider](https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/src/main/java/com/sopromadze/blogapi/security/JwtTokenProvider.java): jwt service · Creates and validates JWT tokens. · `src/main/java/com/sopromadze/blogapi/security/JwtTokenProvider.java`
- [User details](https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/src/main/java/com/sopromadze/blogapi/service/CustomUserDetailsService.java): security bridge · Adapts user records to Spring Security. · `src/main/java/com/sopromadze/blogapi/service/CustomUserDetailsService.java`
- [Identity model](https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/model/role): security model · Roles and authenticated principal used for access control. · `src/main/java/com/sopromadze/blogapi/model/role`
- [Services](https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/service): business services · Business rules, ownership checks, validation, and orchestration. · `src/main/java/com/sopromadze/blogapi/service`
- [Blog content](https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/model): domain model · Posts, comments, categories, and tags. · `src/main/java/com/sopromadze/blogapi/model`
- [Media domain](https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/model): domain model · Albums and photos. · `src/main/java/com/sopromadze/blogapi/model`
- [User profile](https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/model/user): domain model · Users and embedded profile/address structures. · `src/main/java/com/sopromadze/blogapi/model/user`
- [Todo domain](https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/src/main/java/com/sopromadze/blogapi/model/Todo.java): domain model · Personal task entities. · `src/main/java/com/sopromadze/blogapi/model/Todo.java`
- [Repositories](https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/repository): data access · Spring Data JPA repositories for entity aggregates. · `src/main/java/com/sopromadze/blogapi/repository`
- [JPA entities](https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/model): persistence model · 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](https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/src/main/java/com/sopromadze/blogapi/BlogApiApplication.java): Spring Boot app · Application entry point and main runtime. · `src/main/java/com/sopromadze/blogapi/BlogApiApplication.java`
- [Security config](https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/src/main/java/com/sopromadze/blogapi/config/SecutiryConfig.java): security config · Security filter chain and authorization rules. · `src/main/java/com/sopromadze/blogapi/config/SecutiryConfig.java`
- [Error handler](https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/src/main/java/com/sopromadze/blogapi/exception/RestControllerExceptionHandler.java): exception mapping · Translates domain exceptions into HTTP error responses. · `src/main/java/com/sopromadze/blogapi/exception/RestControllerExceptionHandler.java`
- [App config](https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/config): configuration · Auditing and MVC wiring. · `src/main/java/com/sopromadze/blogapi/config`
- [Utilities](https://github.com/osopromadze/spring-boot-blog-rest-api/tree/main/src/main/java/com/sopromadze/blogapi/utils): helpers · Shared application constants and helpers. · `src/main/java/com/sopromadze/blogapi/utils`
- [MySQL DB](https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/data/blogapi.sql): database · Persisted application data seeded from SQL files. · `data/blogapi.sql`
- [SQL seed](https://github.com/osopromadze/spring-boot-blog-rest-api/blob/main/src/main/resources/blogapi.sql): seed data · Initial database seed scripts and resource SQL. · `src/main/resources/blogapi.sql`

## Connections

- 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.
