{"id":19303047,"url":"https://github.com/asc-lab/better-code-with-ddd","last_synced_at":"2025-05-16T08:03:20.326Z","repository":{"id":48695344,"uuid":"227771882","full_name":"asc-lab/better-code-with-ddd","owner":"asc-lab","description":"This repository contains code that accompanies presentation ASC LAB team gave at meetup about “Creating better code with Domain Driven Design”.","archived":false,"fork":false,"pushed_at":"2024-11-26T19:05:05.000Z","size":239,"stargazers_count":319,"open_issues_count":0,"forks_count":65,"subscribers_count":18,"default_branch":"ef_core","last_synced_at":"2025-04-08T18:19:38.481Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.altkomsoftware.com/blog/better-code-using-domain-driven-design/","language":"C#","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/asc-lab.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-13T06:29:01.000Z","updated_at":"2025-02-24T05:22:14.000Z","dependencies_parsed_at":"2024-12-14T21:04:48.859Z","dependency_job_id":"78313b1a-8a8f-4990-b12a-abcc39c77af3","html_url":"https://github.com/asc-lab/better-code-with-ddd","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/asc-lab%2Fbetter-code-with-ddd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asc-lab%2Fbetter-code-with-ddd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asc-lab%2Fbetter-code-with-ddd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asc-lab%2Fbetter-code-with-ddd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/asc-lab","download_url":"https://codeload.github.com/asc-lab/better-code-with-ddd/tar.gz/refs/heads/ef_core","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254493381,"owners_count":22080126,"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":[],"created_at":"2024-11-09T23:24:49.467Z","updated_at":"2025-05-16T08:03:20.306Z","avatar_url":"https://github.com/asc-lab.png","language":"C#","funding_links":[],"categories":["Sample Projects"],"sub_categories":[".NET (C#/F#)"],"readme":"# Better code with DDD building blocks\n\n[![.NET](https://github.com/asc-lab/better-code-with-ddd/actions/workflows/dotnet.yml/badge.svg)](https://github.com/asc-lab/better-code-with-ddd/actions/workflows/dotnet.yml)\n\nThis repository contains code that accompanies presentation ASC LAB team gave at meetup about “Creating better code with Domain Driven Design”.\n\nCheck out our article on [Altkom Software \u0026 Consulting blog](https://www.altkomsoftware.com/blog/better-code-using-domain-driven-design/).\n\n## Business case\n\nDomain Driven Design tactical patterns are presented here using mortgage loan application processing use case.  Business wants to increase efficiency of mortgage loan application processing for individual customers by: automating application score calculation, combining information from online available sources, auto rejecting applications with RED score, having ability to relatively easy add new rules for scoring.\n\nThe process: \n* operator submits loan application with property information, customer data, loan information and attached documents provided by customer\n* system performs basic validation, required fields, correct formats\n* operator commands the system to calculates score based on rules\n* if score is RED application is rejected and explanation is provided\n* if score is GREEN then operator validates attached documents and accepts application or rejects it due to discrepancies between provided data and documents. System validates operator’s competence level\n\nThe rules:\n* property value must not exceed requested loan amount\n* customer age at the day of last loan installment must not exceed 65 years\n* customer must not be registered debtor in national debtors registry system\n* loan monthly installment must not exceed 15% of customer monthly income\n\n\n## Solutions\n\nRepository contains two solutions. First solution presents typical layered application building approach with anemic model and business logic scattered in services that reside in application layer. This solution also presents usage of generic repository and mixing read and write concerns in the same application service class. First solution is located in the LoanApplication.EnterpriseCake folder.\n\nSecond solution presents usage of DDD tactical patterns like: value objects, entities, repositories, factories, domain services and application services to achieve better readability and expressiveness of the code. Applying DDD patterns together with ubiquitous language closes the gap between language spoken by experts and the team and language used in the code.\nSolution with DDD building blocks applied is located in the LoanApplication.TacticalDdd folder.\n\n\n## Domain model\nDomain model is pretty simple. There are two aggregates LoanApplication and Operator. LoanApplication represenst, as you can guess, a loan application submitted for processsing.\nLoadApplication is composed of several value objects, which in turn are also composed from other value object.\nOperator represents a bank employee responsible for processing loan application.\n\n\u003ccenter\u003e\n\n![Domain model - aggregates](https://raw.githubusercontent.com/asc-lab/better-code-with-ddd/ef_core/LoanApplication.TacticalDdd/Docs/class_model_aggregates.png)\nDomain mode - aggregates\n\n\u003c/center\u003e\n\n\nThe core functionality of our service is loan application evaluation. Each rule is implemented as a separate class that implements IScoringRule interface. A domain service is created to encapsulate rules and score calculation.\n\n\u003ccenter\u003e\n\n![Domain model - rules](https://github.com/asc-lab/better-code-with-ddd/blob/ef_core/LoanApplication.TacticalDdd/Docs/class_model_scoring_rules.png?raw=true)\nDomain mode - business rules\n\n\u003c/center\u003e\n\nApplication services are clients of domain model. We have three application services one that is responsible for loan application submission, second that evaluates applications and third one that lets users accept or reject application.\nDiagram below presents dependencies between one sample application service and domain model parts. It also presents dependency between infrastructure layer and domain model, where infrastructure layer provides implementations for interfaces defined as part of the domain model (for example for repositories).  \n\n\n\u003ccenter\u003e\n\n![Application services interaction with the domain model](https://github.com/asc-lab/better-code-with-ddd/blob/ef_core/LoanApplication.TacticalDdd/Docs/class_model_decision_services.png?raw=true)\nApplication services interaction with the domain model\n\n\u003c/center\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasc-lab%2Fbetter-code-with-ddd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasc-lab%2Fbetter-code-with-ddd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasc-lab%2Fbetter-code-with-ddd/lists"}