<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Sanat Serikuly</title>
    <description>The latest articles on Forem by Sanat Serikuly (@boson42).</description>
    <link>https://forem.com/boson42</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F260625%2Ffd1c3826-3a4a-4044-afb8-913fc927d511.png</url>
      <title>Forem: Sanat Serikuly</title>
      <link>https://forem.com/boson42</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/boson42"/>
    <language>en</language>
    <item>
      <title>Introduction to C4</title>
      <dc:creator>Sanat Serikuly</dc:creator>
      <pubDate>Wed, 20 Oct 2021 00:00:00 +0000</pubDate>
      <link>https://forem.com/viezly/introduction-to-c4-k99</link>
      <guid>https://forem.com/viezly/introduction-to-c4-k99</guid>
      <description>&lt;p&gt;Recently, I joined a new project with a lot of legacy (not old, but legacy) code. The project kicked off only 6 months ago, but the chosen architecture was at least unusual. "Yay, something new" I said to myself and started digging through the code and architecture.&lt;/p&gt;

&lt;p&gt;Quickly, I realized that it is really hard to keep everything in mind. In fact, humans can keep only &lt;a href="https://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two"&gt;7(+-2) things in short-term memory&lt;/a&gt;. I had some experience with visualization tools like &lt;a href="https://www.diagrams.net/"&gt;diagrams.net&lt;/a&gt; (formerly draw.io) or &lt;a href="https://excalidraw.com/"&gt;Excalidraw&lt;/a&gt;, but the problem is that I was jumping between different levels of detailing and it was drawing me off.&lt;/p&gt;

&lt;h2&gt;
  
  
  C4
&lt;/h2&gt;

&lt;p&gt;Surfing the web around, I bumped into a C4 model and &lt;a href="https://youtu.be/x2-rSnhpw0g"&gt;this video&lt;/a&gt; on YouTube (highly recommended). C4 is a framework that allows abstract modelling and diagraming to a certain level of details.  Would you care about a specific controller when you model complex user journeys with multiple systems involved? Probably not. C4 provides a very simple (but powerful) way to be at just the right level of abstraction.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EmF4zQpp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://c4model.com/img/c4-overview.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EmF4zQpp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://c4model.com/img/c4-overview.png" alt="C4 Model"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;(Illustrations are from the &lt;a href="https://c4model.com/"&gt;C4 Model website&lt;/a&gt;)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The framework provides the following abstractions at its core:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Person&lt;/strong&gt; - any user of your system. For example, actors, roles, personas etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Software System&lt;/strong&gt; is the system the person interacts with. In many cases, the software system is owned by a single software development team. For example, a digital bank, an internet shop or a video-streaming service.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Container&lt;/strong&gt; (not a Docker!) represents an application or a data store. The main thing about containers in the C4 model is that they are separately deployable/runnable at runtime. For example, server-side applications, client-side applications, mobile apps, microservices, databases etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Component&lt;/strong&gt; is a grouping of related functionality encapsulated behind an interface. Typically, components are running in the same process space of the container. The main difference between component and container is that components are not separately deployable units. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code&lt;/strong&gt; is actually a class diagram of the application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using abstractions it is possible to build different views on a software system on different levels.&lt;/p&gt;

&lt;p&gt;C4 provides 4 levels of the software system. Let’s have a quick look at them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Level 1: System Context diagram
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9evhox7e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://c4model.com/img/bigbankplc-SystemContext.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9evhox7e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://c4model.com/img/bigbankplc-SystemContext.png" alt="System Context diagram"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the system context diagram the focus is on a software system as a whole. Any people using the system would also be a good fit for this diagram. It gives a good perspective on a big picture of the software that is being built.&lt;/p&gt;

&lt;p&gt;The System Context diagram could be helpful to present to very broad and generic audiences.&lt;/p&gt;

&lt;h2&gt;
  
  
  Level 2: Container diagram
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lPW1P9xC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://c4model.com/img/bigbankplc-Containers.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lPW1P9xC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://c4model.com/img/bigbankplc-Containers.png" alt="Container diagram"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once it is clear how the software system fits into the whole environment, a useful step is to zoom in a little bit. This is where you can see databases, microservices, modules and how they communicate with each other. Container diagrams reflect high-level architecture of the software system.&lt;/p&gt;

&lt;p&gt;The Container diagram would be helpful for discussions with architects, product owners and business analysts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Level 3: Component diagram
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fkQQAi92--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://c4model.com/img/bigbankplc-Components.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fkQQAi92--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://c4model.com/img/bigbankplc-Components.png" alt="Component diagram"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After laying down high-level architecture, it is possible to zoom in even further and look at actual components of the container. Here we have major structural blocks like interfaces, endpoints, business logic components etc. This type of diagram is very helpful when the architecture is explained to software developers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Level 4: Code diagram
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wb5lbvKR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://c4model.com/img/bigbankplc-Classes.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wb5lbvKR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://c4model.com/img/bigbankplc-Classes.png" alt="Code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, if we zoom in even more, we’ll see actual classes, controllers, repositories etc. This level is not recommended for most teams since the level of details is too high. It might be useful though in some specific cases when the code-lever architecture is very complex.&lt;/p&gt;

&lt;p&gt;Even though C4 highlights only 4 levels, it might not be true for every project. You might end up with 5, 6 or even 7 layers in your project. Just make sure you choose the right zoom depending on the audience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;In the modern software development world, where systems become more complex and complex, engineers need something to structurise the work. C4 provides a simple, but powerful framework that is easily understandable. &lt;/p&gt;

&lt;p&gt;If you are interested in automating the C4 Component Level, you can look at &lt;a href="https://viezly.com/"&gt;Viezly&lt;/a&gt;. We automatically generate a diagram of the changes and provide an advanced tooling for a code review.&lt;/p&gt;

&lt;p&gt;In the next article, I am going to provide a practical example of how to use the C4 model and what tools are available. Stay tuned.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>modelling</category>
      <category>diagrams</category>
      <category>c4</category>
    </item>
  </channel>
</rss>
