<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pasindu Hewagamage on Medium]]></title>
        <description><![CDATA[Stories by Pasindu Hewagamage on Medium]]></description>
        <link>https://medium.com/@pasinduhewagamage?source=rss-b911a92c0293------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*M-1Qbix5exSnTXXF8bayMg.jpeg</url>
            <title>Stories by Pasindu Hewagamage on Medium</title>
            <link>https://medium.com/@pasinduhewagamage?source=rss-b911a92c0293------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 06:41:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pasinduhewagamage/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Clean Architecture on Spring Boot]]></title>
            <link>https://medium.com/@pasinduhewagamage/clean-architecture-on-spring-boot-da3ff7bdcc7?source=rss-b911a92c0293------2</link>
            <guid isPermaLink="false">https://medium.com/p/da3ff7bdcc7</guid>
            <category><![CDATA[clean-architecture]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Pasindu Hewagamage]]></dc:creator>
            <pubDate>Mon, 11 May 2020 16:04:14 GMT</pubDate>
            <atom:updated>2020-05-25T07:17:52.531Z</atom:updated>
            <content:encoded><![CDATA[<p>Here I’m trying to give a way for a Spring Boot project with Clean Architecture based on Uncle Bob’s Clean Architecture concept and my personal experiences. But there is a quiet difference in the way which I built this demo project with the Uncle Bob’s guide.</p><p>I recommend you to get an idea about SOLID principles before following the Clean concept. Here I’m not going to give any explanation about SOLID Principles.</p><p>This will be a good read for SOLID principles: <a href="https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design">https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design</a></p><p><strong>Clean Architecture</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fhgWH-zMWac5i7zSiMFaOg.png" /><figcaption>layers view — diagram 1.0</figcaption></figure><p>When you search in Google you can easily find above image. According to uncle Bobs’s Clean concept your project can be separated for four layers.</p><ol><li>Entities</li><li>Use Cases</li><li>Framework/Application</li><li>External</li></ol><p>In my case I divide project in to three separate layers</p><ol><li>App</li><li>Domain</li><li>External</li></ol><p>Use Cases include business rules, Entities define for business entities and these entities are manipulated by use case. I’m using these two layers together in Domain layer as core layer of the project. However, entities are free to transfer between all layers. Application layer acts as a delivery layer. It is responsible for framework utilities such as handle request response, exception handling, alarm generating. Third party libraries and external things such as UI, DB, Web clients belongs to External. Domain belongs to most inner circle and external belongs to most outer circle as shown in the diagram 1.0. Domain components tightly couple with business rules and external component can be change eventually. However, Domain layer should not depend on external and application layers.</p><p><strong>Key concepts in Clean Architecture</strong></p><ol><li>every component should include in its natural layer. eg: business rules should include in domain, database transactions belongs to external.</li><li>domain layer should be independent from each other layers. To satisfy this concept,need a clear understand about dependency inversion rule in SOLI<strong>D </strong>principles. Any dependency doesn’t exist in inner circle which belongs to any other layer and outer layer dependencies injection direction should from inner layer to outer layer. In fact, business rules simply don’t know anything at outside the world.</li><li>Unit Testing should perform in each layer separately. Then business rules can be tested without UI, DB, Web clients.</li></ol><p>You can learn more about Clean Architecture in here <a href="https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html">https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html</a></p><p>You can find demo project <a href="https://github.com/pasindu-15/libro">https://github.com/pasindu-15/libro</a> which is a sample CRUD operation project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*lEGdKFbR1Bs2i585W4WLCA.png" /><figcaption>project structure — diagram 1.1</figcaption></figure><p><strong>Communication between layers</strong></p><p>Application →Domain</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/58be6062db0115e77c9726afc61757be/href">https://medium.com/media/58be6062db0115e77c9726afc61757be/href</a></iframe><p>Before transferring request object from controller to use case it should map to a domain object. Otherwise use-case can not act independently.</p><p>Domain →External</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cb91e84989a782096285388d84d4642/href">https://medium.com/media/3cb91e84989a782096285388d84d4642/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f9e9499d40b7bb06dd32d86d7c86bd5/href">https://medium.com/media/1f9e9499d40b7bb06dd32d86d7c86bd5/href</a></iframe><p>Above example shows BookRepositoryInterface.java and it belongs to domain/boundary. Even domain/use-case can persist data without any visibility regarding external repository or DB. Only external repository is responsible for data persistence.</p><p><strong>Testing</strong></p><p>You are able to independently test each layer in a clean project. Testing and debugging both will be easy tasks under this concept.</p><p>In Spring Boot I’m using <strong>Mockito </strong>framework for mocking beans and <strong>WireMock </strong>for mocking external servers such as web clients.</p><p>we can perform unit tests for business rules without depending any other layers. Application and e<em>xternal layer components also can be tested </em>without existing any other layers<em>.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/927137b21af4e0621d6d59788abe17fd/href">https://medium.com/media/927137b21af4e0621d6d59788abe17fd/href</a></iframe><p><strong>Control flow</strong></p><p>Entire project control flow can be represented as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DENWJehfnjIK3UJ7a_H4lw.png" /><figcaption>control flow — diagram 1.2</figcaption></figure><p><strong>Conclusion</strong></p><p>Adding new feature to the project, removing or modifying features, validation, bug fixing, testing, error handling, project handover become more easier with clean architecture.</p><p>But clean Architecture is not recommended for small projects, because it naturally use more classes(components) and it’s a reason for increasing the code complexity and decreasing the efficiency. In programming we should balance following factors in our code.</p><ol><li>maintainability</li><li>complexity</li><li>efficiency</li><li>readability</li><li>best practices</li></ol><p>In some cases, while We are following the clean concept, above factors can be deviated from normal manner. In my personal opinion, we should give a higher priority for above factors than clean code. However, the best way is ensuring all above factors while following clean concept.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da3ff7bdcc7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>