Skip to content

braintelligencePL/project-manager-kotlin

 
 

Repository files navigation

Build Status 🛠

Journey from layered (n-tier) architecture to hexagonal architecture in Kotlin 💪

Project-Manager is a simple application for managing projects at company. You can create teams and add members to it. You can create, modify projects and assing teams to them. More you'll find below.

We'll go from traditional layered architecture to hexagonal architecture A.K.A. Ports and Adapters architecture.

Working with Project-Manager

./gradlew bootRun - to run application.
./gradlew test - to run unit tests.
./gradlew clean build test- one to rule them all 💍

Implementation step-by-step

Idea is to see how does project changes while time passes with each branch there some change to the project structure or just new features that were implemented.

Quick Start

  • Look at endpoints here: /infrastructure/adapter/incoming/rest/

  • Checkout tests. In domain package you have unit tests that do tests of application core. They are isolated from framework and outside world. Tests are made on repository implemented as HashMap.


1️⃣ branch: step-1-team

🏠 Architecture: Layered Architecure

  • POST: /teams - create a team.
  • POST: /teams/:teamName/members - add members to the team.
  • GET: /teams - show teams.

Needs and constraints:

  • Team cannot be created if already exists
  • How many projects team has?

2️⃣ branch: step-2-projects

🏠 Architecture: Layered Architecure

  • POST: /projects/drafts - create project draft (only project name).
  • POST: /projects - create full project (project with features📊).
  • GET: /projects - show draft projects

Needs and constraints:

  • JobPosition must be valid (Developer, Scrum Master...)
  • Team can have no more than 3 projects at the time

3️⃣ branch: step-3-refactor

🏠 Architecture: Hexagonal Architecure

Things done:

  • Moving from layered (n-tier) architecture to Hexagonal Architecture (ports and adapters). 😎
  • Introduced idea of shared-kernel from DDD

Improved tests:

  • Unit tests without touching IO. Domain is tested with unit tests. Idea of InMemoryRepository as HashMap.
  • Only the main paths (happy paths) are integration tests because sad path was tested with unit tests.
  • We also have acceptance tests that are practically similar to above, but shows complete flow of bounded-context.

4️⃣ branch: step-4-refactor

Refactor introducing simple CQRS.

5️⃣ branch: step-5-projects

🏠 Architecture: Hexagonal Architecure

  • GET: /projects/:id - show project (project not project draft)
  • PUT: /projects/:id - change/update project
  • PATCH: /projects/:id/started - start team when team assigned
  • PATCH: /projects/:id/ended - close project when features are done


5️⃣ branch: step-5-zoo-of-microservices

🏠 Architecture: Hexagonal Architecture (modularization on package level)
🕳 Tests: Integration/Acceptance/Unit
Backing-Services from Twelve-Factor-App methodology.

Services from our zoo:
🦓 user-autorization-service - authentication gateway that protects back-end resources. There is two kinds of resources protected and unprotected. First one requires user-level authentication and second one is just read-only such as listing of offers/products.

🐼 edge-service - gives possibility to expose unified REST API from all of ours backend services. To be able to do this, the Edge Service matches a request route’s URL fragment from a front-end application to a back-end microservice through a reverse proxy to retrieve the remote REST API response.

🐰 discovery-service - Edge-service matches a request route’s URL fragment from a front-end application to a back-end microservice through a reverse proxy to retrieve the remote REST API response.

🐿 centralized-configuration-server - Spring Cloud application that centralizes external configurations using various methodologies of building twelve-factor applications.


#️⃣ branch: will-be-more

  • monitoring, grafana, actuator, performance tests with gatling



Technologies used:

  • Kotlin with spring
  • Spock (groovy) for tests
  • ArchUnit (kotlin) for architecture tests
  • Gradle to build project

Materials from mine blog:

Materials from outside world: