<?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 Jahangir Anwari on Medium]]></title>
        <description><![CDATA[Stories by Jahangir Anwari on Medium]]></description>
        <link>https://medium.com/@janwari?source=rss-e66764a3b128------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*aDwjfCUiv70LhFcDrEqkMA.jpeg</url>
            <title>Stories by Jahangir Anwari on Medium</title>
            <link>https://medium.com/@janwari?source=rss-e66764a3b128------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 08:52:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@janwari/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[Documentation: Yes, We Should!]]></title>
            <link>https://blog.tarkalabs.com/documentation-yes-we-should-c5ce8ddd4adf?source=rss-e66764a3b128------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5ce8ddd4adf</guid>
            <category><![CDATA[documentation]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[best-practices]]></category>
            <dc:creator><![CDATA[Jahangir Anwari]]></dc:creator>
            <pubDate>Wed, 09 Nov 2022 07:52:27 GMT</pubDate>
            <atom:updated>2023-05-09T13:59:18.538Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hwRH-tJXwC6PU29imTGDsw.png" /><figcaption>Original Image by <a href="https://medium.com/u/27bc603427b">Gaurav Singh</a></figcaption></figure><p>Imagine you recently joined a new team, and after a couple of weeks, you were assigned a bug ticket. You look at the ticket and decide to see if this issue surfaced in the past and so do a search in the bug tracking tool.</p><p>Success! A single search hit.</p><p>You get excited. This will be a quick fix. You’re just going to apply the solution in the ticket returned in the search result. Blinded by hubris, you open the ticket, and this is what you find:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*5R1tDNLAJYXLTIFZeYAtDQ.png" /></figure><p>Rather than finding anything useful that would guide you on your path to fixing your bug ticket, you find a single-word comment. Fixed. This single word now leads to so many questions in your mind:</p><ul><li>What was the cause?</li><li>Was it a frontend or backend issue?</li><li>Why does it only affect specific users?</li><li>Was it a code or a configuration-related issue?</li><li>How was it fixed?</li></ul><p>With a dejected feeling, you realize that, now, you would have to investigate this issue yourself.</p><h4>Future Us / Future You</h4><p>There is a very high likelihood that the code you have written today will be maintained by other engineers/developers in the future. They are the “<strong>Future Us.</strong>” And if you stay in the same company for a few years, “<strong>Future You</strong>” will end up maintaining the same code.</p><p>You spend a few hours identifying the cause, applying the fix, and, crucially, <strong>documenting the issue and the fix you rediscover</strong>. This pattern repeats as you work on more tickets.</p><h4>Documentation — Why Should We?</h4><p>One can give a wide variety of reasons why we should write documentation, but here are three reasons that are worth considering:</p><ul><li>Onboarding</li><li>Efficiency</li><li>Product Overview</li></ul><h4>Onboarding</h4><p>As a consultant at <a href="https://tarkalabs.com/">Tarka Labs</a>, most of the <a href="https://tarkalabs.com/projects">projects</a> we get to work on are <a href="https://synoptek.com/insights/it-blogs/greenfield-vs-brownfield-software-development/">brownfield</a>. Over the years, working on different brownfield projects for clients, a common thread we have observed is that, at the start, significant time is spent onboarding a new team member. Most of the time lost is due to the following:</p><ul><li>Challenges setting up local development environment due to out-of-date or incomplete README or setup instructions</li><li>Lack of clear understanding of the different workflows in the application</li><li>No documents highlighting the interactions/integrations with other third-party services</li></ul><p>Clear documentation can assist a new developer in quickly getting oriented with the application and significantly reducing the onboarding period.</p><h4>Efficiency</h4><p>The DRY (Don’t repeat yourself) principle in software development encourages us to avoid duplicating code/effort. Similarly, if we have good documentation of our application or investigation findings, it assists us in keeping things DRY and saves time for Future Us/You. Additionally, documenting the investigation findings can be a source of valuable information for the developer working on fixing the bug.</p><h4>Product Overview</h4><p>One can understand the features quickly without needing additional assistance for simple CRUD (create, read, update, delete) applications. However, there is more going on for more extensive, complex applications than the basic CRUD actions. Some aspects of a complex application are:</p><ul><li>Code is written in a specific paradigm.</li><li>Depending on the requirements, various design patterns are used.</li><li>Calls various third-party APIs</li><li>Implements custom algorithm for specific business needs</li></ul><p>It is possible to figure out everything that is going on while relying solely on source code, but it can be daunting. Therefore, documentation is an essential PART of coding and not something one does outside of coding.</p><h4>Arguments Against Documentation</h4><blockquote>Code is the source of truth.</blockquote><p>While there is no arguing that code is the source of truth, having documentation that gives an overview of how things work can save significant time for new team members in learning the application.</p><blockquote>Documentation quickly gets out of date.</blockquote><p>This is a consequence of documentation being an afterthought rather than a part of the software development process. As professional software developers/engineers, we should give the same love to keeping our documentation up to date as we do to keep our code clean.</p><blockquote>No time for writing documentation</blockquote><p>Similar to the previous point, we should consider documentation as part of our development process rather than something we do on the side.</p><blockquote>Writing documentation is boring.</blockquote><p>Fair point. However, it can become an incentive if we remind ourselves that we are doing this for Future Us. Also, just as in life, we wouldn’t always get to work on the fun and exciting stuff; sometimes, we have to do the boring stuff.</p><p>In conclusion, as professionals, it should be our responsibility to treat documentation as part of the coding process and write accurate, useful documentation for Future Us and Future You.</p><blockquote><strong>With more than 15 years of experience serving clients by building pragmatic and meaningful solutions that meet their needs. I’m </strong><a href="http://linkedin.com/in/janwari"><strong>Jahangir</strong></a><strong>. At </strong><a href="http://www.tarkalabs.com/"><strong>TarkaLabs</strong></a><strong>, I craft beautiful web experiences. I have a constant thirst to learn new things, but dogmatic about using Docker. Let’s talk!</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5ce8ddd4adf" width="1" height="1" alt=""><hr><p><a href="https://blog.tarkalabs.com/documentation-yes-we-should-c5ce8ddd4adf">Documentation: Yes, We Should!</a> was originally published in <a href="https://blog.tarkalabs.com/">Tarka Labs Blogs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring Headless CMS]]></title>
            <link>https://blog.tarkalabs.com/exploring-headless-cms-f94466b765a2?source=rss-e66764a3b128------2</link>
            <guid isPermaLink="false">https://medium.com/p/f94466b765a2</guid>
            <category><![CDATA[contentful]]></category>
            <category><![CDATA[sanity]]></category>
            <category><![CDATA[jamstack]]></category>
            <category><![CDATA[headless]]></category>
            <category><![CDATA[headless-cms]]></category>
            <dc:creator><![CDATA[Jahangir Anwari]]></dc:creator>
            <pubDate>Thu, 11 Mar 2021 11:22:41 GMT</pubDate>
            <atom:updated>2022-06-29T11:47:05.174Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ebvrXU-lDKWJ9frTMHASdg.png" /><figcaption>Source: <a href="https://rueblinger.com/?portfolio=178">Rueblinger</a></figcaption></figure><p>For the while now I have heard rumblings of <a href="https://jamstack.org/">Jamstack</a> and in particular the buzz around the world of headless CMS (Content Management System) so I decide to take a dive and explore what the hype is all about.</p><h4>Jamstack… what’s that?</h4><p>Jamstack is a software architecture based on three building blocks; <em>client-side </em>JavaScript, <em>reusable </em>API and <em>prebuilt</em> Markup. The underlying principle of Jamstack is to deliver your application as flat HTML as quickly as possible and achieve dynamic behaviour by calling various self-owned and third-party APIs. Headless CMS is one of the popular Jamstack approaches.</p><h4>What is a Headless CMS?</h4><p>Before diving in, it would be good to understand what really is a headless CMS. Here’s a definition found on <a href="https://en.wikipedia.org/wiki/Headless_content_management_system">Wikipedia</a>:</p><blockquote>A headless CMS is a <strong>back-end only</strong> content management system (CMS) built from the ground up as a <strong>content repository</strong> that makes content <strong>accessible via an API</strong> for display on any device.</blockquote><p>The three key points in the above definition are:</p><ul><li>back-end only</li><li>content repository</li><li>accessible via API</li></ul><p>Therefore, when working with a headless CMS we are focusing primarily on the content storage and retrieval and NOT the presentation of content. In other words, a headless CMS provides you with tools to manage content and an API to pull the content.</p><h3>Why use a “Headless” CMS?</h3><p>Before the smartphone revolution (circa 2007) content on the internet was primarily consumed using a browser. During those times a <em>traditional</em> CMS would consist a whole package that would include:</p><ul><li><strong>Backend</strong>: Database, Admin interface, Plugins</li><li><strong>Frontend</strong>: Templating engine, Views layer</li></ul><p>As technology evolved over the past decade consumption of digital content expanded to multiple viewports and devices like smartphones, tablets, smartwatches, etc. Although <em>traditional </em>CMS use of responsive design would accommodate different viewports it would fail for devices that are consuming content outside the realm of a browser. This is where headless CMS shines as it inherently separates the data layer from the presentation layer, it provides an API to pull content and delegates the concern of presentation to the frontend application.</p><h4>Minimum Viable Product (MVP)</h4><p>To facilitate the exploration I set myself a goal to build the backend for news publishing website. The MVP should includes the following features:</p><ol><li>Post story articles with image</li><li>For the home page provide the editor the ability to select from three layout variations for “Top Stories” section:</li></ol><ul><li>One large top story</li><li>Two top stories</li><li>Three top stories</li></ul><p>Here’s a visual representation of the above home page layout options</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BH4P9qFNjL-ffaJCuANoZw.jpeg" /></figure><h4>The Solutions</h4><p>Although the ecosystem of <a href="https://jamstack.org/headless-cms/">headless CMS</a> has a plethora of choices available, in the interest of time I decided to look at the following three solutions:</p><ul><li><a href="https://strapi.io/">Strapi</a></li><li><a href="https://www.sanity.io/">Sanity</a></li><li><a href="https://www.contentful.com/">Contentful</a></li></ul><h3>Strapi</h3><p><a href="https://strapi.io/">Strapi</a> is one of the most popular open source headless CMS. When compared to the other two headless CMSes (Sanity and Contentful) it gives you <em>complete control</em> over the backend storage and admin interface used.</p><p><strong>Setup</strong></p><p>Below is how we would quickly setup a Strapi project along with GraphQL plugin using <a href="https://strapi.io/documentation/developer-docs/latest/installation/cli.html">command line</a>.</p><pre>$ npx create-strapi-app strapi-publishing --quickstart<br>$ strapi install graphql</pre><p>Next we need to create an admin user by accessing: <a href="http://localhost:1337/admin">http://localhost:1337/admin</a>.</p><p><strong>Content Modeling</strong></p><p>Strapi has rich constructs to model entities in your system. There are two <strong>types </strong>of models:</p><ol><li>Content Types: Traditional models that represent an entities in your system like post, tags, etc..</li><li>Components: Represents a custom collection of information (e.g. card component containing an image, title and summary fields).</li></ol><p>The “Content Types” model are further categorized into two <strong>kinds</strong>:</p><ol><li>Collection Type: Allows multiple instances of the type (e.g. post).</li><li>Single Type: Allows only a single instance of the type (e.g. homepage).</li></ol><p>For our MVP we would need a “Content Type” type model that is of “Collection Type” kind called article. We will create is using CLI as follows:</p><pre>$ strapi generate:api article title:string summary:string body:richtext --draft-and-publish</pre><p>We would also like to add a cover image attribute to this model. But since this depends on strapi-plugin-upload it is easier to do this using the admin panel:</p><p><a href="https://drive.google.com/file/d/1HqgLM6vcMK0z6xtwKI6Abe75TOVe8Es3/view">adding-image-to-article.mp4</a></p><p>Next we need to model our home page. As the home page is primarily a collection of existing articles we would need to create a “Component” type model that is of “Single Type” kind called homepage. There is no CLI options provided to create this type so we can use the <a href="https://strapi.io/documentation/user-docs/latest/content-types-builder/introduction-to-content-types-builder.html">Content-Types Builder</a> in the admin panel to create this type.</p><p>First we build an ArticleCard component that would store the necessary information to display a story on the home page. This component would be reused to create the different layouts of the homepage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*qR6P5ympQpzQM4MFI9c1PA.png" /></figure><p>Next we would create three additional components for the three different layouts:</p><ul><li><strong>OneTopStory: </strong>Contains ArticleCard as single component.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*Jd7VyWj9oaLikKXOQrNODA.png" /></figure><ul><li><strong>TwoTopStories</strong>: Contains ArticleCard as repeatable component with validation rules of max and min value of 2.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*Ov6eoNn7Cw5AU6_rMR_C6w.png" /></figure><ul><li><strong>ThreeTopStories</strong>:Contains ArticleCard as repeatable component with validation rules of max and min value of 3.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*s0gLtSfwBj-nAgZtKM316A.png" /></figure><p>Strapi has a powerful native feature called <a href="https://strapi.io/blog/release-beta-18-dynamic-zones">Dynamic Zones</a> which allows you to create complex UI structure dynamically. Using Dynamic Zones we can quickly implement the feature that would allow the editor to choose between the three different layout without having to write any code.</p><p><a href="https://drive.google.com/file/d/1SGBURC-35XAok7qnIM8KuMMfMzGr1pwC/view">create-homepage.mp4</a></p><p><strong>Querying content</strong></p><p>With the content modelling completed for our MVP we can add content and query them in GraphQL playground at <a href="http://localhost:1337/graphql">http://localhost:1337/graphql</a></p><p><strong>A few additional learning:</strong></p><ul><li>The API endpoint and admin panel are the same code. This simplifies adding your own customization and business logic. The downside off course is that you are responsible for managing the API endpoint.</li><li>Strapi provides <a href="https://strapi.io/documentation/developer-docs/latest/concepts/models.html#lifecycle-hooks">lifecycle hooks</a> for models. This can be very helpful if you want to perform custom business logic before returning results.</li><li><a href="https://strapi.io/documentation/developer-docs/latest/concepts/policies.html#policies">Policies</a> allows you to implement cross-cutting concerns easily.</li><li>Limited document workflow. Currently, it only supports “Draft” and “Publish” workflow.</li><li>Deleting content types is not straightforward. It required manually deleting model/api files and restarting the server.</li></ul><h3>Sanity</h3><p><a href="https://www.sanity.io/">Sanity</a> is another popular headless CMS. Sanity manages the storage layer and provides a custom open source query language <a href="https://www.sanity.io/docs/overview-groq">GROQ</a> to query for content. Sanity Studio is used to work with content.</p><p><strong>Setup</strong></p><p>Below is how we would quickly setup a Sanity project using <a href="https://strapi.io/documentation/developer-docs/latest/installation/cli.html">command line</a>:</p><pre>$ npm install -g @sanity/cli<br>$ sanity init -y --create-project &quot;Sanity Publishing Demo&quot; \<br>  --dataset publishing-demo \<br>  --visibility private</pre><p><strong>Note</strong>: If you want to start from scratch for project template choose <em>“Clean project with no predefined schemas”</em></p><p>Next we start Sanity Studio</p><pre>$ sanity start</pre><p>Sanity Studio should now be accessible at <a href="http://localhost:3333/desk">http://localhost:3333/</a>. If you didn’t select any pre-existing template you would see the following message:</p><blockquote>Empty schema</blockquote><blockquote>Your schema does not contain any document types. If it did, those types would be listed here. Read more about how to add schema types.</blockquote><p>So let’s create our document types.</p><p><strong>Content Modeling</strong></p><p><a href="https://www.sanity.io/docs/content-modelling">Creating models</a> in Sanity is a manual process that requires creating JavaScript files to define the models in your system. Sanity supports a number of <a href="https://www.sanity.io/docs/schema-types">schema types</a>. The two important types that we will use are:</p><ul><li><a href="https://www.sanity.io/docs/document-type">document</a>: Traditional model that represent an entities in your system like post, tags, etc..</li><li><a href="https://www.sanity.io/docs/object-type">object</a>: Represents a custom collection of information (e.g. card component containing an image, title and summary fields).</li></ul><p>For our MVP we would need a document type called article. Inside schemas folder of your project create a file called article.js with following lines of code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf464368000ae55001d14db3049105d6/href">https://medium.com/media/cf464368000ae55001d14db3049105d6/href</a></iframe><p>Next we need to tell Sanity about our new document type by adding it to schemas/schema.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/923bf70d188f5365301e6a50c7907bff/href">https://medium.com/media/923bf70d188f5365301e6a50c7907bff/href</a></iframe><p>Sanity Studio reloads and now you should see the Article document type listed under “Content”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*3A4F8UJ8wqNdotByQ0BTTg.png" /></figure><p>Next we will replicate the steps we followed in Strapi by creating the necessary object types as follows:</p><ol><li><a href="https://gist.github.com/jahangiranwari/6b380ad5285fffeb2ed3b3001dcb12ba">articleCard</a>: contains headline , summary and cover attributes along with a reference to article</li><li><a href="https://gist.github.com/jahangiranwari/545e42fe3a6b109d846df7f8e1d75855">oneTopStory</a>: contains articleCard as single field.</li><li><a href="https://gist.github.com/jahangiranwari/33f1b0618e6a1a3c0c2a544599f0c60e">topTwoStories</a>: contains two articleCard as fields grouped in <a href="https://www.sanity.io/docs/object-type#fieldsets-b8b5507db1d3">fieldset</a>.</li><li><a href="https://gist.github.com/jahangiranwari/cdf70413a6ebd6813c648c0cfcc40a0d">topThreeStories</a>: contains three articleCard as fields grouped in <a href="https://www.sanity.io/docs/object-type#fieldsets-b8b5507db1d3">fieldset</a>.</li><li><a href="https://gist.github.com/jahangiranwari/a6f68e4742dc1cd33eaaf0b93b93733c">topStories</a>: applies <a href="https://www.sanity.io/guides/how-to-use-structured-content-for-page-building">page builder pattern</a> that allows editor to select one of the three layouts.</li></ol><p>With the required object types in place we can now create a homepagedocument type that has a single topStories field.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79fe3ea5ca2c19c027a54048946bfdf2/href">https://medium.com/media/79fe3ea5ca2c19c027a54048946bfdf2/href</a></iframe><p>After creating the required types our schema.js looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8da85090792dbed822523168a9d7e509/href">https://medium.com/media/8da85090792dbed822523168a9d7e509/href</a></iframe><p>Once Sanity reloads we can see our HomePage type available in Sanity Studio:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nFIkSmyKaJOAUdtDgHv9cA.png" /></figure><p><strong>Querying content</strong></p><p>With the content modelling completed for our MVP we can add content and query them in GraphQL playground. But before we can query in GraphQL we need to deploy</p><pre>$ sanity login<br>$ sanity graphql deploy</pre><p>Once the deployment completes the GraphQL playground is accessible at <a href="https://[projectId].api.sanity.io/v1/graphql/[dataset]/default">https://[projectId].api.sanity.io/v1/graphql/[dataset]/default</a></p><p><strong>A few additional learning:</strong></p><ul><li>To retrieve content Sanity provides multiple CDN backed endpoints (i.e. <a href="https://www.sanity.io/docs/api-cdn">API CDN</a>, <a href="https://www.sanity.io/docs/asset-cdn">Asset CDN</a>). This makes your backend robust. The downside is that your ability to perform customization on the backend is limited.</li><li>As Sanity Studio is a React app it can be easily extended.</li><li>Sanity Studio can be customized for complex layout <a href="https://www.sanity.io/docs/overview-structure-builder">Structure Builder</a>.</li><li>You can implement a <a href="https://www.sanity.io/docs/custom-workflows">custom document workflow</a>.</li><li><a href="https://www.sanity.io/docs/access-control#custom-access-control-ce4a077926aa">Custom access control</a> is available in enterprise plan.</li><li><a href="https://www.sanity.io/docs/localization">Localization</a> can be done at field or document level. But it requires some effort in getting it setup.</li></ul><h4>Contentful</h4><p><a href="https://www.contentful.com/">Contentful</a> is another well known headless CMS. Unlike Sanity and Strapi the admin interface is hosted by Contentful.</p><p><strong>Setup</strong></p><p>To create a Contentful application we first need to create a space. <a href="https://www.contentful.com/help/contentful-101/">This guide</a> provides a good explanation of setting up a space.</p><p><strong>Content Modeling</strong></p><p>Contentful support creating <a href="https://www.contentful.com/developers/docs/concepts/data-model/">custom types</a> and provides a number of field types. The <a href="https://github.com/contentful/contentful-cli/tree/master/docs">CLI tool</a> currently doesn’t support creating content types from command line. So we use the content management web app to create the models. Under “Content model” we create Article type with following fields:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*9Jcb51Wcqk5Wc0TnIkYu9A.png" /></figure><p>For home page content type tried to create reusable component like ArticleCardby following this <a href="https://www.contentful.com/blog/2019/01/11/building-flexible-content-models-budget/">blog post</a> but could not get it working. So ended up with a working but not ideal solution of creating a <em>1-many</em> reference to articles and a checkbox to select a layout. This solution has no validations and relies on editor making the correct selections.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zuyo8ORlGCkED-dteijVRQ.png" /></figure><p><strong>Querying content</strong></p><p>With the content modelling completed for our MVP we can add content and query them in GraphQL playground. To do that we would need to install the app first by going to <a href="https://app.contentful.com/spaces/[space-id]/apps?app=graphql-playground">https://app.contentful.com/spaces/[space-id]/apps?app=graphql-playground</a></p><p>After installation you can access the GraphQL playground at this URL: <a href="https://app.contentful.com/spaces/[space-id]/apps/app_installations/graphql-playground/graphql">https://app.contentful.com/spaces/[space-id]/apps/app_installations/graphql-playground/graphql</a></p><p><strong>A few additional learning:</strong></p><ul><li>Existing apps are available for installation from Contentful’s <a href="https://www.contentful.com/marketplace/">marketplace</a>.</li><li>Has rich validation and appearance options for fields.</li><li>Has <a href="https://www.contentful.com/developers/docs/tutorials/general/setting-locales/">localization</a> support out-of-the-box.</li><li>Adding custom behaviour to the admin interface requires developing a custom extension by following the painful approach of <a href="https://contentful.com/developers/docs/extensibility/app-framework/create-contentful-app/">creating a contentful app</a> and then installing it to your space.</li><li>Similar to Sanity, Contentful provides multiple <a href="https://www.contentful.com/developers/docs/concepts/apis/">CDN backed APIs</a> (e.g. Content Delivery API, Images API, etc.)</li><li>Running a few nested GraphQL queries to retrieve embedded entries information would too often result in TOO_COMPLEX_QUERY error. Could be because I was using a “free” space.</li></ul><h3>Conclusion</h3><p>Headless CMS provides a quick and flexible way of managing and pulling content. However, choosing between the different solutions available depends on specific requirements of the project. Below are a few requirements and suggestion on which would be the suitable CMSes.</p><ul><li>Full control: Strapi</li><li>Execute custom business logic when handling API query: Strapi</li><li>Ease of customization content management interface: Strapi / Sanity</li><li>Ease of creating custom types: Strapi / Contentful</li><li>Out-of-the-box CDN support for API endpoints: Sanity / Contentful</li><li>Localization: Contentful</li><li>Marketplace: Contentful / Sanity</li></ul><blockquote>Hello Montreal! We’ll be at the <a href="https://startupfestival.com/">Startupfest ’22</a> all three days, so drop by and say hi. We’d love to see what you’re building, and early birds get a free (limited) design audit or tech consultation. DM us on Twitter (<a href="https://twitter.com/tarkalabs">@tarkalabs</a>) and let’s talk.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f94466b765a2" width="1" height="1" alt=""><hr><p><a href="https://blog.tarkalabs.com/exploring-headless-cms-f94466b765a2">Exploring Headless CMS</a> was originally published in <a href="https://blog.tarkalabs.com/">Tarka Labs Blogs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Performance Tips: Docker Desktop on Mac]]></title>
            <link>https://blog.tarkalabs.com/performance-tips-docker-desktop-on-mac-e2afcef1e42?source=rss-e66764a3b128------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2afcef1e42</guid>
            <category><![CDATA[docker-for-mac]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-volume]]></category>
            <dc:creator><![CDATA[Jahangir Anwari]]></dc:creator>
            <pubDate>Thu, 23 Jul 2020 11:06:08 GMT</pubDate>
            <atom:updated>2020-07-23T11:06:08.782Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uj8Aob2NFLspMZBZVrG--w.png" /></figure><p>If you are a Mac OS user and use containers as part of your development you would most likely be using <a href="https://docs.docker.com/docker-for-mac/install/">Docker Desktop on Mac</a>. And if your application is large then you definitely have hit the the severe <a href="https://docs.docker.com/docker-for-mac/osxfs/#performance-issues-solutions-and-roadmap">performance issues</a> with mounted volumes. Below are couple of tips to improve performance of your containers.</p><h3>Native NFS</h3><p>A quick test reveals that we can see that we can extract ~100% performance improvement.</p><p><strong>Host mount</strong></p><pre>/home # dd if=/dev/zero of=./output bs=8k count=10k; rm ./output<br>10240+0 records in<br>10240+0 records out<br>83886080 bytes (80.0MB) copied, 3.084522 seconds, 25.9MB/s</pre><p><strong>Host (NFS volume) mount</strong></p><pre>/home # dd if=/dev/zero of=./output bs=8k count=10k; rm ./output<br>10240+0 records in<br>10240+0 records out<br>83886080 bytes (80.0MB) copied, 1.426896 seconds, 56.1MB/s</pre><p>If you prefer these tests can be performed locally on your machine <a href="https://github.com/jahangiranwari/docker-mac-perf">using docker-mac-perf</a> repo.</p><p>Thanks to <a href="https://gist.github.com/seanhandley/7dad300420e5f8f02e7243b7651c6657#file-setup_native_nfs_docker_osx-sh">this script</a> created by <a href="https://github.com/seanhandley">Sean Handley</a> we can quickly setup Native NFS on Mac OS. To enable NFS on your Mac run the below commands:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3a7d0ebc39a77a83d6167e203fb0b84/href">https://medium.com/media/e3a7d0ebc39a77a83d6167e203fb0b84/href</a></iframe><p>Now you can use an NFS mount in your docker-compose.yaml as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc704dd54b33461b05deb8efe8d786eb/href">https://medium.com/media/cc704dd54b33461b05deb8efe8d786eb/href</a></iframe><p>Another important detail to note is the <a href="https://docs.docker.com/storage/bind-mounts/#configure-mount-consistency-for-macos">mount consistency level</a>, in our case we opted for cached so that the mounted path on host is considered authoritative. With this setting changes made to our source files during development cycle would be reflected much quicker inside the container compared to the default value of consistent.</p><h3>Docker volumes</h3><p>Many frameworks generates files (e.g. cache, pid, log) that are stored in a folder nested within the application root folder that is usually mounted from host. This can result in a unnecessary overheads in syncing the files between container and host and negatively affects application performance which can lead to a frustrating developer experience.</p><p>One way to avoid these unnecessary syncs is to create separate Docker volumes and mount the volumes to the specific path inside the container where these file are generated.</p><p><strong>Example</strong><br>If you are running a Rails application the framework will generate various files in tmp and log folder inside your application root folder. To prevent these two folder being synced between host and container you can add the following to your docker-compose.yaml</p><pre>version: &#39;3&#39;<br>services:</pre><pre>  web:<br>    ....<br>    volumes:<br>      - web_tmp:/app/tmp<br>      - web_log:/app/log</pre><pre>....<br>volumes:<br>  web_tmp:<br>  web_log</pre><p>In the above configuration we are creating two Docker volumes web_tmp and web_log and mapping this inside the container to the tmp and log folders respectively. If you are interested you can inspect the volume using below command:</p><pre>$ docker inspect `docker volume ls  | awk &#39;/web_tmp|web_log/ { print $2 }&#39;`</pre><p>The Docker volumes configuration can be combined with NFS volume mount as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d14decb973fdffe04b6d4b69a49e6649/href">https://medium.com/media/d14decb973fdffe04b6d4b69a49e6649/href</a></iframe><p>With the above tips our development experience has been devoid of container performance issues.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2afcef1e42" width="1" height="1" alt=""><hr><p><a href="https://blog.tarkalabs.com/performance-tips-docker-desktop-on-mac-e2afcef1e42">Performance Tips: Docker Desktop on Mac</a> was originally published in <a href="https://blog.tarkalabs.com/">Tarka Labs Blogs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PDF Comparison in Pure Ruby]]></title>
            <link>https://blog.tarkalabs.com/pdf-comparison-in-pure-ruby-aba8a6a8f40b?source=rss-e66764a3b128------2</link>
            <guid isPermaLink="false">https://medium.com/p/aba8a6a8f40b</guid>
            <category><![CDATA[comparing]]></category>
            <category><![CDATA[pdf]]></category>
            <category><![CDATA[rubygems]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Jahangir Anwari]]></dc:creator>
            <pubDate>Fri, 05 Jul 2019 12:27:52 GMT</pubDate>
            <atom:updated>2023-02-27T06:49:23.035Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H70-CPl3AC9kc1vNHKlTlw.png" /></figure><p>In one of our projects we have to compare PDFs and the current solution for <a href="https://medium.com/tarkalabs/automated-testing-of-generated-pdfs-3d9b7d60b188">testing generated PDFs</a> works very well. Unfortunately, it takes too long for the tests to run because the PDFs are first converted into images using <a href="http://imagemagick.org/">ImageMagick</a> and then the images are compared to check for differences.</p><p>As part of continuous improvement we wanted to see how we can speed up the tests but at the same time not loose the benefits of our current solution. Couple of initial solutions considered were:</p><ul><li>Generate a hashes (e.g. SHA1) of the two PDF files and compare them.</li><li>Compare the byte streams of the two PDF files (using Ruby FileUtils.compare_file)</li></ul><p>However, neither solutions worked. Even though two PDF files are “visually identical” their byte streams are not. Some reasons for difference in PDFs byte steams are:</p><ul><li>Each PDF contains a unique file identifier (/ID) in the <a href="https://resources.infosecinstitute.com/pdf-file-format-basic-structure/#gref">trailer section</a> of the file. According to the specification (<a href="http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf">ISO 32000–1</a>) it is recommended that a PDF writer add this information: <em>The ID entry is optional but should be used.</em></li><li>The <a href="https://www.w3.org/TR/WCAG20-TECHS/PDF18.html">document information dictionary</a> (e.g. CreationDate , ModDate) would be different.</li><li>Different compressions algorithms used to reduce size of PDF</li></ul><p>As it became clear that comparing two PDF’s byte streams would not give an accurate comparison we then investigated the possibility of comparing the “contents” of the PDFs. After some experimentation we settled on using <a href="https://github.com/gettalong/hexapdf">HexaPDF</a> and <a href="https://github.com/yob/pdf-reader">PDF::Reader</a> to compare the “contents” of two PDFs page by page. With this solution there was significant improvement in overall execution time of our tests. If a test fails we then fallback to <a href="https://medium.com/tarkalabs/automated-testing-of-generated-pdfs-3d9b7d60b188">generating images and comparing them using ImageMagick</a>. The solution to comparing two PDFs content was packaged into a Ruby gem called <a href="https://github.com/jahangiranwari/identikal/">Identikal</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e7GAuKCqw9JOA7AlsEnbRg.png" /><figcaption>Tests execution times before and after Identikal</figcaption></figure><h3>Identikal</h3><p><a href="https://github.com/jahangiranwari/identikal/">Identikal</a> is a tiny Ruby gem that compares two given PDF files and returns <strong>true</strong> when their “contents” are identical and <strong>false</strong> otherwise.</p><p>Command line:</p><pre>$ identikal file_a.pdf file_b.pdf<br>true</pre><pre>$ identikal file_a.pdf file_c.pdf -t<br>false</pre><p>Ruby code:</p><pre>require &#39;identikal&#39;<br><br>base_path = File.expand_path(File.join(__dir__), &#39;/../pdfs&#39;)<br>pdf_a = File.join(base_path, &#39;report_a.pdf&#39;)<br>pdf_b = File.join(base_path, &#39;report_b.pdf&#39;)<br><br>if Identikal.files_same?(pdf_a, pdf_b)<br>  # some action when files are identical<br>else<br>  # another action when files are different<br>end</pre><p>Now that we have saved a few minutes with faster tests it’s time to get some coffee.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aba8a6a8f40b" width="1" height="1" alt=""><hr><p><a href="https://blog.tarkalabs.com/pdf-comparison-in-pure-ruby-aba8a6a8f40b">PDF Comparison in Pure Ruby</a> was originally published in <a href="https://blog.tarkalabs.com/">Tarka Labs Blogs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Run only newly added specs]]></title>
            <link>https://medium.com/tarkalabs-til/run-only-newly-added-specs-86e72e5fdacd?source=rss-e66764a3b128------2</link>
            <guid isPermaLink="false">https://medium.com/p/86e72e5fdacd</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[rspec]]></category>
            <dc:creator><![CDATA[Jahangir Anwari]]></dc:creator>
            <pubDate>Tue, 28 May 2019 11:42:27 GMT</pubDate>
            <atom:updated>2019-06-04T06:01:36.300Z</atom:updated>
            <content:encoded><![CDATA[<p>When working on a major feature it is common to have are a number of new test files associated with it. It can be a pain to manually specify each test file when testing to ensure that all the aspects of the new feature are working correctly. To eliminate the manual labour I use the below commands snippet to run Rspec on all newly added spec files in a feature branch:</p><pre>$ git log --name-only origin/master..HEAD | awk &#39;NF &amp;&amp; /spec.*rb/ &amp;&amp; !/support|factories/&#39; | uniq | xargs bundle exec rspec</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86e72e5fdacd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tarkalabs-til/run-only-newly-added-specs-86e72e5fdacd">Run only newly added specs</a> was originally published in <a href="https://medium.com/tarkalabs-til">TarkaLabs TIL</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker deployments to Heroku]]></title>
            <link>https://blog.tarkalabs.com/docker-deployments-to-heroku-5802b14df4fa?source=rss-e66764a3b128------2</link>
            <guid isPermaLink="false">https://medium.com/p/5802b14df4fa</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[heroku]]></category>
            <category><![CDATA[docker-compose]]></category>
            <dc:creator><![CDATA[Jahangir Anwari]]></dc:creator>
            <pubDate>Wed, 02 Jan 2019 12:58:02 GMT</pubDate>
            <atom:updated>2019-01-02T12:58:02.606Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Eedpq2e1wTsO4Mff4XthvQ.png" /></figure><p>Heroku by default deploys your application as a <a href="https://devcenter.heroku.com/articles/slug-compiler">slug</a> which is nothing more than a gzipped version of your application bundled with all its dependencies. Deploying your application is as simple as doing a <a href="https://devcenter.heroku.com/articles/git#deploying-code"><strong>git push</strong></a>.</p><h4>Why use Docker image in place of slug?</h4><p>If default Docker deployments are so straightforward why would one want to replace it with a Docker image. Below are a few reasons:</p><ul><li><strong>Slug size limit</strong>: The maximum slug size allowed by Heroku is <a href="https://devcenter.heroku.com/changelog-items/1145">500MB</a>. So if your application and all its dependencies exceed 500MB you are out of luck. This holds true for many Java application.</li><li><strong>Base OS layer and installed packages</strong>: By using Docker image we have full control over the underlying operating system and the various packages installed. This way you are not limited only to the packages installed by default in Heroku’s <a href="https://devcenter.heroku.com/articles/stack-packages">buildpack</a>. You can also create containers for languages and frameworks that don’t have an official buildpack.</li><li><strong>Dev/Prod parity</strong>: Using Docker guarantees the same container technology in development and production. This reduces the risk of a issues surfacing in production because the underlying containers are built using different tools.</li></ul><h4>Development with Docker container</h4><p>Let’s assume we want to containerize a Rails 5 application for deployment to Heroku. Rather than repeat the official documentation please see <a href="https://docs.docker.com/compose/rails/">here</a> for detailed steps on dockerizing a Rails application.</p><p>For this article we will use a plain vanilla Rails 5 application. To build a Docker image below is our Dockerfile :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc1efda868e552cfa7e84f4e3972c57f/href">https://medium.com/media/dc1efda868e552cfa7e84f4e3972c57f/href</a></iframe><p>Noteworthy points:</p><ul><li><strong>Lines #3 and #19</strong>: Two build arguments that gives us the flexibility of customizing the build for a particular environment.</li><li><strong>Lines #21-23:</strong> Clean up the gems to reduce the size of the Docker image.</li><li><strong>Line #27:</strong> Compile the assets only if<em> (deployed container)</em> environment is production.</li></ul><p><strong>Docker Compose<br></strong>To simplify the containers orchestration required for running a Rails application we will use <a href="https://docs.docker.com/compose/overview/">Docker Compose</a>.</p><p>Below is the docker-compose.ymlfile used to build the various dependent images and wire up the dependencies between the different containers (e.g. web and database containers)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ccd34106500c9f36b2803e4775a4638/href">https://medium.com/media/2ccd34106500c9f36b2803e4775a4638/href</a></iframe><p>Noteworthy points:</p><ul><li><strong>Line #6:</strong> Maps the location where the PostgreSQL database is stored on “host” machine. This is required so that the database content persists between container restarts.</li><li><strong>Line #8:</strong> Exposing and making available the db (PostgreSQL) container’s default database port (i.e. 5432) on port 6432 of the host machine. This is helpful if you want to avoid having to login to the db container to execute any SQL queries. You can also use a GUI tool like pgAdmin from host machine to view the database running inside the db container.</li><li><strong>Line #13: </strong>Customizing the development image to install additional packages that would be used during development.</li><li><strong>Line #16: </strong>The command to execute after the container boots up. This overrides the CMD line present in Dockerfile.</li><li><strong>Line #18: </strong>Similar to line #8 we are making the Rails application running inside the (web) container available on the host machine on port 3001.</li><li><strong>Line #22: </strong>Sets up dependency between the db service and web service. This will ensure that db container/service is up and running before attempting to start the web container/service.</li></ul><h4><strong>Initialize Rails inside container:</strong></h4><pre>$ docker-compose build<br>$ docker-compose run --rm web rails db:create<br>$ docker-compose up</pre><p>On your host machine your Rails application should now be accessible at <a href="http://localhost:3001/">http://localhost:3001</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*Pis4a0XjGtnM9Csl3TWWRA.png" /><figcaption>RoR 5.2 on local development machine</figcaption></figure><h4>Deployment to Heroku</h4><p>To retain the simplicity of Heroku deployment using <a href="https://devcenter.heroku.com/articles/git#deploying-code"><strong>git push</strong></a><strong> </strong>for Docker containers we need to add a new file called heroku.yml</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cbb6de62789de520e4cb83dc5d8a5c74/href">https://medium.com/media/cbb6de62789de520e4cb83dc5d8a5c74/href</a></iframe><p>Noteworthy points:</p><ul><li><strong>Line #3:</strong> Tells Docker how to build the image.</li><li><strong>Line #5: </strong>Specify additional bundler arguments so that it does not include gems that are required only for development and test.</li><li><strong>Line #8: </strong>The command to execute once the <em>web</em> dyno is up.</li><li><strong>Line #12: </strong>The Docker image to use to build the dyno for worker service.</li></ul><p>During deployment Heroku will use the information in heroku.yml file to build and configure the dyno.</p><p>To facilitate Docker container deployments to Heroku we have to use <a href="https://devcenter.heroku.com/articles/heroku-cli">Heroku CLI</a>. Go ahead and install it.</p><p>Once you have Heroku CLI installed on your machine let’s create a Heroku app and add the free PostgreSQL addon.</p><pre>$ heroku update beta  <br>$ heroku plugins:install @heroku-cli/plugin-manifest<br>$ heroku apps:create --manifest<br>$ heroku addons:create heroku-postgresql:hobby-dev</pre><p>Now that we have a Heroku application we can set the various environment variables that are needed to run a Rails 5.2 application in production.</p><pre>$ heroku config:set RAILS_MASTER_KEY=`cat config/master.key`<br>$ heroku config:set RACK_ENV=production RAILS_ENV=production<br>$ heroku config:set RAILS_SERVE_STATIC_FILES=enabled<br>$ heroku config:set WEB_CONCURRENCY=2<br>$ heroku config:set LANG=en_US.UTF-8</pre><p>Once the runtime environment variables are configured we can then deploy the container to Heroku and initialize the database.</p><pre>$ git push heroku master<br>$ heroku run rails --trace db:migrate</pre><p>After above steps are done, our application is now deployed and being served on Heroku.</p><pre>$ heroku open</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*dvlOPqZ0r3NdFNfagfA-DQ.png" /><figcaption>RoR 5.2 on Heroku</figcaption></figure><p>The Rails 5.2 application used for this article can be found <a href="https://github.com/jahangiranwari/rails5-docker-heroku">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5802b14df4fa" width="1" height="1" alt=""><hr><p><a href="https://blog.tarkalabs.com/docker-deployments-to-heroku-5802b14df4fa">Docker deployments to Heroku</a> was originally published in <a href="https://blog.tarkalabs.com/">Tarka Labs Blogs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>