How martinsjavacode/springboot-kotlin-clean-arch works
Project Type and Purpose
• The README clearly states that this project (“user-api”) is a CRUD system for users. It is built using Kotlin on the JVM (Java 11) and employs the Clean Architecture pattern.
• The project also includes integration components with GitHub (as seen in both the “amartins/kotlin” and “user/api” packages), indicating that it not only handles user CRUD operations but also integrates or fetches data from an external GitHub service.
File Structure
• Two main application entry points can be identified:
• br/com/amartins/kotlin/KotlinApplication.kt
• br/com/user/api/UserApiApplication.kt
• The “br/com/user/api” package is clearly dedicated to the user API, containing configuration, controllers, converters, domain models, exceptions, integrations, repositories, and use cases. This neatly reflects Clean Architecture’s emphasis on separation of concerns.
• The core directories represent the following layers in Clean Architecture:
• Controllers (under “controller” and “controller/resource”) manage incoming HTTP requests (e.g., UserController, GithubController).
• Use Cases (under “usecase” and “usecase/impl”) encapsulate business logic like Save, Update, Delete operations and GitHub integration use cases.
• Domain models (under “domain”) define the key business entities such as User and Github.
• Integration layers (under “integration” and “integration/impl”) handle communication with external APIs (GitHub).
• Repository layers (under “repository” and its converters/impl) manage persistence and conversions.
• Configuration packages (with ModelMapperConfig, SwaggerConfig, SpringFoxConfig, FeignClientConfig) are there for cross-cutting concerns and external configuration.
Components and Their Relationships
• Main Components:
• API Layer/Controllers: Expose endpoints for user operations (CRUD) and potentially GitHub lookups.
• Use Case Layer: Contains business logic that takes input from controllers and processes it using domain rules.
• Domain Layer: Contains the core business entities such as User and Github.
• Repository/Adapter Layer: Abstracts data persistence and provides implementations (and conversions) for storing/fetching Users.
• Integration Layer: Provides services to integrate with GitHub such as fetching user details externally.
• Configuration: Manages application settings, Swagger documentation, mapping strategies, and HTTP client configurations.
• Relationships:
• Controllers call Use Cases.
• Use Cases interact with Domain models.
• Use Cases communicate with both the Repository Layer (for persistence) and the Integration Layer (to fetch GitHub data).
• Converters are applied between API resources and domain entities in the API, integration, and repository layers.
• External Requests/Responses from GitHub are funneled through dedicated gateways and converter components before affecting the domain.
Architectural Patterns and Key Principles
• Each major functionality (Users, GitHub) is divided into its own bounded contexts, meaning you have distinct components for handling user data and external GitHub interactions.
• Use of Dependency Inversion is implied by how controllers and use cases depend on abstractions (interfaces) rather than on concrete classes (as seen with the gateways and converters).