{"id":22831332,"url":"https://github.com/tmslpm/hello-spring-layered-architecture","last_synced_at":"2026-03-15T18:37:35.877Z","repository":{"id":267181365,"uuid":"900473083","full_name":"tmslpm/hello-spring-layered-architecture","owner":"tmslpm","description":" A Spring Boot project structured with Gradle subprojects, following a layered design (DAL, BLL, PL) with centralized version management using Gradle Version Catalog. Each layer is isolated for simplicity and maintainability.","archived":false,"fork":false,"pushed_at":"2025-03-24T02:28:26.000Z","size":197,"stargazers_count":2,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T01:48:19.621Z","etag":null,"topics":["gradle","junit5","layered-architecture","lombok","mapstruct","mockito","multi-project","spring-boot"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tmslpm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/contributing.md","funding":null,"license":"license.md","code_of_conduct":".github/code_of_conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-08T21:14:19.000Z","updated_at":"2025-02-10T15:10:34.000Z","dependencies_parsed_at":"2024-12-08T22:26:33.643Z","dependency_job_id":"0f9dedd0-0f7f-4720-89f3-1aedbd37f1ff","html_url":"https://github.com/tmslpm/hello-spring-layered-architecture","commit_stats":null,"previous_names":["tmslpm/hello-spring-layered-architecture"],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmslpm%2Fhello-spring-layered-architecture","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmslpm%2Fhello-spring-layered-architecture/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmslpm%2Fhello-spring-layered-architecture/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmslpm%2Fhello-spring-layered-architecture/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tmslpm","download_url":"https://codeload.github.com/tmslpm/hello-spring-layered-architecture/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252748060,"owners_count":21798250,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gradle","junit5","layered-architecture","lombok","mapstruct","mockito","multi-project","spring-boot"],"created_at":"2024-12-12T20:20:06.124Z","updated_at":"2026-03-15T18:37:30.842Z","avatar_url":"https://github.com/tmslpm.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hello Spring Layered Architecture\n\n- run\n\n````\ngradlew :src:app:bootRun\n````\n- build\n\n````\ngradlew :src:app:bootJar\n````\n\u003e output build: `./src/app/build/libs/{rootProject.name}-app-{version}.jar`\n\n## Intro\n\nI created this template to practice working with Gradle subprojects. I decided to build a Gradle project composed \nof subprojects representing each layer of a typical Spring application (**DAL**, **BLL**, **PL**) since this pattern \nis often recommended for large, complex projects. With this in mind, I designed the template for scalability. \n\nTo simplify dependency management, I centralized version control using Gradle's **Version Catalogs**, except for versions \nalready managed by Spring Boot. \n\nEach layer is implemented as an independent subproject, with a dedicated subproject serving as the single entry point \nfor the application. This entry point aggregates the three layers, forming the complete application. Gradle's configuration\nenforces strict separation between layers: for example, the **PL** cannot access the **DAL** directly, requiring the \n**BLL** as an intermediary. This setup ensures clear responsibilities, simplifies testing and enables several developers\nto work simultaneously on different layers without interference, provided proper groundwork is laid.\n\n\nTo streamline the setup of all subprojects, I created a custom Gradle plugin in the buildSrc directory.\n- `./buildSrc/src/main/groovy/project-setup.gradle` \u003c- plugin\n\nThis plugin centralizes common configurations such as dependency management, repository settings, Java toolchain definitions, \nand encoding options. It ensures consistency across all subprojects by applying standardized configurations like: \n- JUnit and Mockito for testing\n- MapStruct for mapping\n- Lombok for code generation \n\nAdditionally, it simplifies Java compatibility settings and optimizes compilation with UTF-8 encoding and target \ncompatibility enforcement. This approach minimizes repetitive configuration and ensures a cohesive setup across the entire project.\n\n### Key Technical Points:\n\n1. **Layer Independence**\n    - Each layer is completely independent, ensuring easy testing and project scalability.\n    - Dependencies between layers are explicit and strictly limited to authorized interactions, enforcing a modular \n      architecture.\n\n2. **Strict Separation of Concerns**\n    - The **Presentation Layer (PL)** cannot directly access entities defined in the **Data Access Layer (DAL)**.\n    - The **DAL** has no knowledge of business logic or presentation-related components.\n\n3. **Data Transfer Objects (DTOs)**\n    - **DTOs** are used to encapsulate data exchanged between the presentation and business logic layers.\n    - JPA entities are never exposed directly in JSON responses, ensuring better security and encapsulation.\n\n4. **Automatic Mapping with MapStruct**\n    - MapStruct is used to automate the conversion between entities (DAL) and DTOs (PL), reducing boilerplate code.\n\n5. **Code Generation with Lombok**\n    - Lombok simplifies development by automatically generating getters, setters, constructors, and other utilities.\n\n6. **Strict Gradle Configuration**\n    - Gradle enforces strict separation between subprojects, ensuring module independence and eliminating circular \n      dependencies.\n    - This configuration strengthens the isolation and interoperability of the layers.\n\n7. **Centralized Dependency Management**\n    - All dependency versions, except those managed by Spring, are centralized in a **Gradle Version Catalog**.\n    - This ensures consistency across modules and simplifies version updates.\n \n## Project Structure\n\n### project root\n\n\u003cpre\u003e\u003ccode\u003e\nroot\n|- buildSrc\n|  \\- ... (💡\u003ca href=\"https://docs.gradle.org/current/userguide/writing_plugins.html#pre_compiled_script_plugin\"\u003ePre-compiled Script Plugin\u003c/a\u003e)\n|\n|- gradle\n|  |- wrapper/...\n|  \\- libs.versions.toml (💡\u003ca href=\"https://docs.gradle.org/current/userguide/version_catalogs.html\"\u003eVersion Catalogs\u003c/a\u003e)\n|\n|- src (💡\u003ca href=\"https://spring.io/\"\u003eSpring Application\u003c/a\u003e)\n|   |--- app\n|   |    \\- src/main/../../Main.java (Spring Entry)\n|   |\n|   |--- bll\n|   |    |- src/main/..\n|   |    |- src/test/..\n|   |    \\- build.gradle\n|   |     \n|   |--- dal\n|   |    |- src/main/..\n|   |    |- src/test/..\n|   |    \\- build.gradle\n|   |\n|   \\--- pl\n|        |- src/main/..\n|        |- src/test/..\n|        \\- build.gradle\n|\n\\- ...\n\u003c/code\u003e\u003c/pre\u003e\n\n\n- `App`:\n  The \"**app**\" subproject is the main entry point for your Spring Boot applications.\n  All other subprojects inherit the dependencies of this project.\n- `BLL`:\n  The \"**bll**\" subproject is the \"**B**usiness **L**ogic **L**ayer\" of your application.\n  It typically contains classes that implement the business logic, including business rules, data processing algorithms,\n  and more.\n- `DAL`:\n  The \"**dal**\" subproject is the \"**D**ata **A**ccess **L**ayer\" of your application.\n  It is responsible for data access, including database interactions and communication\n  with other data sources. It usually contains classes for performing data read/write\n  operations, executing database queries, managing connections, and handling related tasks.\n- `PL`\n    The \"**pl**\" subproject is the \"**P**resentation **L**ayer\" of your application, where\n    the user interface (UI) is typically implemented. This layer may include classes for UI\n    components, user input handling, data display, and other related functionalities.\n\n### project logic\n\n```txt\n   ┌───────────────────────────┐\n   │                           │\n   │           A P P           │\n   │                           │\n   │      ┌─────────────┐      │\n   │      │             │      │ \n   │      │     P L     │      │ \n   │      │             │      │ \n   │      └─┬─────────▲─┘      │ \n   │        │         │        │ \n   │      ┌─▼─────────┴─┐      │ \n   │      │             │      │ \n   │      │     BLL     │      │ \n   │      │             │      │ \n   │      └─┬─────────▲─┘      │ \n   │        │         │        │ \n   │      ┌─▼─────────┴─┐      │ \n   │      │             │      │ \n   │      │     DAL     │      │ \n   │      │             │      │ \n   │      └─────────────┘      │ \n   │                           │  \n   └───────────────────────────┘              \n```\n\n## Project Dependency Management\n\nThe project uses Gradle's **Versions Catalog** functionality\nto manage its dependency versions centrally and efficiently.\n\nThis ensures consistency and avoids version conflicts.\n\nFor the version catalog file, see the `libs.versions.toml` file located in the \n`./gradle/libs.versions.toml` directory. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmslpm%2Fhello-spring-layered-architecture","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftmslpm%2Fhello-spring-layered-architecture","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmslpm%2Fhello-spring-layered-architecture/lists"}