{"id":13932543,"url":"https://github.com/Creditas/kotlin-ddd-sample","last_synced_at":"2025-07-19T16:31:44.138Z","repository":{"id":41203148,"uuid":"133300494","full_name":"Creditas/kotlin-ddd-sample","owner":"Creditas","description":"A sample DDD/CQRS project using KOTLIN :beer:","archived":true,"fork":false,"pushed_at":"2020-08-06T17:19:47.000Z","size":339,"stargazers_count":284,"open_issues_count":1,"forks_count":50,"subscribers_count":158,"default_branch":"master","last_synced_at":"2024-08-08T21:18:26.952Z","etag":null,"topics":["axonframework","cqrs","ddd","kotlin"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Creditas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-14T03:31:29.000Z","updated_at":"2024-08-04T18:46:08.000Z","dependencies_parsed_at":"2022-09-13T10:00:46.877Z","dependency_job_id":null,"html_url":"https://github.com/Creditas/kotlin-ddd-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Creditas%2Fkotlin-ddd-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Creditas%2Fkotlin-ddd-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Creditas%2Fkotlin-ddd-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Creditas%2Fkotlin-ddd-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Creditas","download_url":"https://codeload.github.com/Creditas/kotlin-ddd-sample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226643758,"owners_count":17662966,"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":["axonframework","cqrs","ddd","kotlin"],"created_at":"2024-08-07T21:01:07.240Z","updated_at":"2024-11-26T23:30:38.092Z","avatar_url":"https://github.com/Creditas.png","language":"Kotlin","funding_links":[],"categories":["Kotlin"],"sub_categories":[],"readme":"# Kotlin DDD Sample\n\n**Kotlin DDD Sample** is a open-source project meant to be used as a start point, or an inspiration, for those who want to build Domain Driven Design applications in Kotlin. The domain model was inspired by [this](https://github.com/mcapanema/ddd-rails-example) repo where we built a sample project using Rails.\n\n**NOTE:** This is NOT intended to be a definitive solution or a production ready project\n\n# Technologies/frameworks/tools involved\n\n- Spring\n- Axon Framework\n  - CommandGateway (Command Handlers)\n  - EventBus (Event Handlers)\n- Gradle\n\n# Architecture overview\n\n## Layers\n- **Web**: Spring controllers and actions\n- **Application**: Orchestrates the jobs in the domain needed to be done to accomplish a certain \"use case\"\n- **Domain**: Where the business rules resides\n- **Infrastructure**: Technologies concerns resides here (database access, sending emails, calling external APIs)\n\n## CQRS\n\nCQRS splits your application (and even the database in some cases) into two different paths: **Commands** and **Queries**.\n \n### Command side\n\nEvery operation that can trigger an side effect on the server must pass through the CQRS \"command side\". I like to put the `Handlers` (commands handlers and events handlers) inside the application layer because their goals are almost the same: orchestrate domain operations (also usually using infrastructure services). \n \n![command side](docs/images/command_side_with_events.jpg)\n\n### Query side\n\nPretty straight forward, the controller receives the request, calls the related query repo and returns a DTO (defined on infrastructure layer itself). \n\n![query side](docs/images/query_side.jpg)\n\n# The domain (problem space)\n\nThis project is based on a didactic domain that basically consists in maintaining an Order (adding and removing items in it). The operations supported by the application are:\n\n* Create an order \n* Add products ta a given order\n* Change product quantity\n* Remove product\n* Pay the order (this operation fires an Event for the shipping bounded context) \n * Shipping (side effect of the above event): ships product and notify user\n\nPretty simple, right? \n\n# Setup\n\n**Linux/MacOS:** \n\n```\n./gradlew build\n```\n\n**Windows:**\n\n```\ngradlew.bat build\n```\n\n### RabbitMQ setup\n\nThere is a file named `AMQPRabbitConfiguration` in this repo (located [here](https://github.com/fabriciorissetto/kotlin-ddd-sample/blob/master/web/src/main/configuration/injection/AMQPRabbitConfiguration.kt)) where the configuration needed by axon to integrate with RabbitMQ (to send end receive persistent messages) is stored. To use that, just remove the comments. \n\nYou need a running rabbit, you can start one in a docker container using the following commands:\n\n```bash\ndocker pull rabbitmq\ndocker run -d --hostname my-rabbit --name some-rabbit rabbitmq:3-management\n```\n\nYou can access the rabbit UI by this url: [http://172.17.0.2:15672](http://172.17.0.2:15672).\n\n* **User**: guest\n* **Password**: guest\n \nThat's it. You don't need to do anything else, the setup in the `AMQPRabbitConfiguration` class will create the necessary queue and exchange in Rabbit and also configure axon accordingly. Note that if you customize something in your rabbit server you need to adjust the `application.properties` file (here we are using the default ports, ips, etc).\n\nThis both dependencies are used just for Rabbit:\n * `org.springframework.boot:spring-boot-starter-amqp`: enables AMQP in Spring Boot\n * `org.axonframework:axon-amqp`: configures some beans for axon to integrate with `SpringAMQPMessageSource` class from the above dependency\n\nIf you don't want o use an AMQP you can remove this dependencies from the web project gradle's file.\n\n# Tests\n\n```\n./gradlew test\n```\n\n### Postman requests\n\nYou can trigger all the operations of this project using the requests inside [this json](https://github.com/fabriciorissetto/kotlin-ddd-sample/blob/master/docs/postman_example_requests.json) (just import it on your local postman).\n\n# Backlog\n- [x] Implement Unit Tests examples (Domain layer)\n- [ ] Implement Integrated Tests examples (Web layer)\n- [ ] Include docker container with JDK and gradle configured\n- [ ] Configure Swagger and Swagger UI\n- [ ] Include a Event Sourced bounded context or Aggregate\n- [ ] Domain Notifications instead of raising exceptions\n- [ ] Implement concrete repositories with JPA (the current implementations just returns fake instances)\n- [ ] Configure JPMS (java 9 modules)\n\nContributions are welcome! :heartbeat:\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCreditas%2Fkotlin-ddd-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCreditas%2Fkotlin-ddd-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCreditas%2Fkotlin-ddd-sample/lists"}