This repo follows a clean Model-View-Controller (MVC) design pattern. Keep the architecture predictable by following these conventions every time you add or change code.
- Security first: GitHub OAuth2 authentication and role-based access control.
- Clear layering: Strict separation between DTOs (Web), Services (Logic), and Entities (DB).
- Simplicity: No unnecessary abstraction layers (no Domain models or Ports/Adapters).
- Transactional Integrity: Business operations are wrapped in SQL transactions using
@Transactional.
- Java 25
- Spring Boot 4.0.4 (Web + Data JPA + Security OAuth2)
- PostgreSQL (Production) / H2 (Tests)
- Thymeleaf templates for the UI
- GitHub OAuth2 for Authentication
For every feature (e.g., "Case"), we maintain this consistent set of components:
- Role: Handles incoming HTTP requests (REST API or Thymeleaf Web).
- Location:
...presentation.restor...presentation.web - Responsibility: Thin logic only. Translates between HTTP and DTOs.
- Injected with:
*Service.
- Role: Data containers for web/API interaction.
- Location:
...presentation.dto - Responsibility: Prevents exposing internal database structures to the client.
- Role: The core business logic handler.
- Location:
...application.service - Responsibility: Handles
@Transactionalboundaries, business rules, and security checks. - Injected with:
*Repositoryand*Mapper.
- Role: Utility for object conversion.
- Location:
...application.service - Responsibility: Mapping
DTO <-> Entity.
- Role: JPA-mapped object representing the database schema.
- Location:
...infrastructure.persistence
- Role: Database access via Spring Data JPA.
- Location:
...infrastructure.persistence
src/main/java/
org/example/projektarendehantering/
common/ (Cross-cutting utilities: Actor, Exceptions, Roles)
application/
service/ (Services, Mappers)
presentation/
rest/ (REST Controllers)
web/ (UI Controllers)
dto/ (DTOs)
infrastructure/
persistence/ (Entities, Repositories)
config/ (Spring Security / OAuth2 Config)
security/ (Authentication/Authorization logic)
- Controllers: Suffix with
Controller(e.g.,CaseController). - Services: Suffix with
Service(e.g.,CaseService). - Mappers: Suffix with
Mapper(e.g.,CaseMapper). - DTOs: Suffix with
DTO(e.g.,CaseDTO). - Entities: Suffix with
Entity(e.g.,CaseEntity). - Repositories: Suffix with
Repository(e.g.,CaseRepository).
- Authentication: Handled via GitHub OAuth2.
- Authorization: Enforced in the
Servicelayer or via@PreAuthorize. - Identity: The current user is represented by the
Actorclass, derived from the OAuth2 session.
- Always use DTOs for public API communication.
- Never expose Entities directly to the web layer.
- Use Mappers to handle the translation between layers.
- Ensure @Transactional is used on Service methods that modify data.
- Verify changes with
mvnw compilebefore finishing. - No "Domain" classes: Logic belongs in Services or Entities.
- No "Ports/Adapters": Use direct Repository/Service injection.