<?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: Lê Công Tuấn</title>
    <description>The latest articles on Forem by Lê Công Tuấn (@tuanlc).</description>
    <link>https://forem.com/tuanlc</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%2F165634%2F78a467f6-26a0-473f-b56e-89d5830118de.jpeg</url>
      <title>Forem: Lê Công Tuấn</title>
      <link>https://forem.com/tuanlc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/tuanlc"/>
    <language>en</language>
    <item>
      <title>MongoError: E11000 duplicate key error collection ??</title>
      <dc:creator>Lê Công Tuấn</dc:creator>
      <pubDate>Fri, 30 Jul 2021 04:31:45 +0000</pubDate>
      <link>https://forem.com/tuanlc/mongoerror-e11000-duplicate-key-error-collection-587l</link>
      <guid>https://forem.com/tuanlc/mongoerror-e11000-duplicate-key-error-collection-587l</guid>
      <description>&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I've encountered the issue sometime in my developer path. So I decided to write down my experience and to firstly note to myself and secondly to help other developers/engineers who are a newbie in this topic.&lt;/p&gt;

&lt;p&gt;If you only need the fix, you can skip to the last part of this article!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;One of the most advantages of using NoSQL databases is the flexible feature that allows us to update the number of &lt;br&gt;
fields and their data types any time we want.&lt;/p&gt;

&lt;p&gt;I'm using Nodejs and Mongoose driver to connect to MongoDB. And in the very beginning phase of a project development &lt;br&gt;
life and this help us to able to update collections and their fields.&lt;/p&gt;

&lt;p&gt;However, I encountered an error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;MongoError: E11000 duplicate key error collection: companies index: code_1 dup key: &lt;span class="o"&gt;{&lt;/span&gt; code: null &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What happened here?&lt;/p&gt;

&lt;p&gt;To understand, I would go further a bit with Indexing and unique keys in Databases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Database Indexes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://en.wikipedia.org/wiki/Database_index"&gt;Wikipedia&lt;/a&gt; defines:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;A database index is a data structure that improves the speed of data retrieval operations on a database table at the cost of additional writes and storage space to maintain the index data structure. Indexes are used to quickly locate data without&lt;br&gt;
having to search every row in a database table every time a database table is accessed. Indexes can be created using one or more&lt;br&gt;
columns of a database table, providing the basis for both rapid random lookups and efficient access of ordered records. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you want to query a field or set of fields without iterating all the entries in a table/collection, you can create indexes for these fields.&lt;/p&gt;

&lt;p&gt;To understand more how indexes are created &amp;amp; organized to support efficient queries, you can check at&lt;a href="https://en.wikipedia.org/wiki/Database_index"&gt;this&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, the cost for indexes is not cheap, especially in the world of big data nowadays. Because to make queries on indexed fields efficient, these indexes need to be stored in a fast query memory (for example RAM). So, be careful when you want to add an index for a field, some factors should be put on the table to have good enough decisions: are data queried frequently? the user behaviors? regions that data are stored? etc&lt;/p&gt;

&lt;p&gt;And last but not least, an indexed field may be a non-unique value for each entry in the column. For example, you can have an index on the field "Region" where we can have multiple users in the same region.&lt;/p&gt;

&lt;h2&gt;
  
  
  Unique keys
&lt;/h2&gt;

&lt;p&gt;In the real-life, there are use cases that we want to limit the appearance of one or a set of values of factors. For example, you want there is only 1 email that is used to register per user, no more.&lt;/p&gt;

&lt;p&gt;So, unique keys help you to achieve this constrain by defining the rule in the schema. For example in mongoose:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userSchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Schema&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;unique&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see that the email attribute is unique. With this, you cannot add more than one user with the same email. If developers violate the rule, Mongodb will throw errors. This helps us preventing developer mistakes.&lt;/p&gt;

&lt;p&gt;Again, you can check more at &lt;a href="https://en.wikipedia.org/wiki/Unique_key"&gt;wikipedia&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  When Mongo DB schema become out of date with Mongoose schema
&lt;/h2&gt;

&lt;p&gt;Come back to the beginning error, let's me show you the mongoose schema that was defined by code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;companySchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Schema&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;location&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look good! right?&lt;/p&gt;

&lt;p&gt;But what makes the error?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;MongoError: E11000 duplicate key error collection: companies index: code_1 dup key: &lt;span class="o"&gt;{&lt;/span&gt; code: null &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's check a bit:&lt;/p&gt;

&lt;p&gt;I used mongo client by querying with the command line to check the existing keys for the &lt;code&gt;companies&lt;/code&gt; collection. And the result was:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; db.companies.getIndexes&lt;span class="o"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;
        &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="s2"&gt;"v"&lt;/span&gt; : 2,
                &lt;span class="s2"&gt;"key"&lt;/span&gt; : &lt;span class="o"&gt;{&lt;/span&gt;
                        &lt;span class="s2"&gt;"_id"&lt;/span&gt; : 1
                &lt;span class="o"&gt;}&lt;/span&gt;,
                &lt;span class="s2"&gt;"name"&lt;/span&gt; : &lt;span class="s2"&gt;"_id_"&lt;/span&gt;,
                &lt;span class="s2"&gt;"ns"&lt;/span&gt; : &lt;span class="s2"&gt;"project-name.companies"&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;,
        &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="s2"&gt;"v"&lt;/span&gt; : 2,
                &lt;span class="s2"&gt;"unique"&lt;/span&gt; : &lt;span class="nb"&gt;true&lt;/span&gt;,
                &lt;span class="s2"&gt;"key"&lt;/span&gt; : &lt;span class="o"&gt;{&lt;/span&gt;
                        &lt;span class="s2"&gt;"code"&lt;/span&gt; : 1
                &lt;span class="o"&gt;}&lt;/span&gt;,
                &lt;span class="s2"&gt;"name"&lt;/span&gt; : &lt;span class="s2"&gt;"code_1"&lt;/span&gt;,
                &lt;span class="s2"&gt;"ns"&lt;/span&gt; : &lt;span class="s2"&gt;"project-name.companies"&lt;/span&gt;,
                &lt;span class="s2"&gt;"background"&lt;/span&gt; : &lt;span class="nb"&gt;true&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yeah! There is an established index field for &lt;code&gt;code&lt;/code&gt; and it is set to unique. And once an index is set, it is there until you remove it, and the rule unique is still there also.&lt;/p&gt;

&lt;p&gt;And the reason is the schema was modified due to the product business has changed. The previous schema was:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;companySchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Schema&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;unique&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;location&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, this is a case when the Mongo schema becomes out date with the Mongoose schema that you defined in code.&lt;/p&gt;

&lt;p&gt;To fix this, I need to remove manually the unnecessary index key. Mongo query provides some methods to remove indexes manually:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note: You cannot drop the default index on the _id field.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://docs.mongodb.com/manual/reference/method/db.collection.dropIndex/"&gt;db.collection.dropIndex()&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; db.companies.dropIndex&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"code_1"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;a href="https://docs.mongodb.com/manual/reference/command/dropIndexes/#dropindexes"&gt;db.collection.dropIndexes&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This method will drop all non-_id indexes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; db.companies.dropIndexes&lt;span class="o"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can verify again by using the commandline:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;db.companies.getIndexes()&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And it works!&lt;/p&gt;




&lt;p&gt;Your comments &amp;amp; discussion are warmly welcomed!&lt;/p&gt;

&lt;p&gt;Enjoy your job!&lt;/p&gt;

</description>
      <category>database</category>
      <category>mongodb</category>
      <category>experiencelearning</category>
      <category>wfh</category>
    </item>
    <item>
      <title>GraphQL + Clean Architecture boilerplate</title>
      <dc:creator>Lê Công Tuấn</dc:creator>
      <pubDate>Sat, 03 Jul 2021 14:27:10 +0000</pubDate>
      <link>https://forem.com/tuanlc/graphql-clean-architectire-boilerplate-hog</link>
      <guid>https://forem.com/tuanlc/graphql-clean-architectire-boilerplate-hog</guid>
      <description>&lt;h2&gt;
  
  
  Inspiration
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html" rel="noopener noreferrer"&gt;Clean Architecture&lt;/a&gt; is an awesome guide for developers who desire to build a clean, structured and maintainable projects. The letter L in SOLID principal allows us to make depended components are easily replaced without touch to the business and the core of systems. For example of the web server where there are many frameworks out there (Expressjs, GraphQL, etc) and the chosen decision depends on the purpose of the business and the context.&lt;/p&gt;

&lt;p&gt;In this boilerplate guide scope we will go through how to make the core business immune with the change of the detailed technologies. Let's go!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You can find the implementation detail in this &lt;a href="https://github.com/tuanlc/graphql_clean-architecture_boilerplate" rel="noopener noreferrer"&gt;repository&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Boilerplate
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Code structure
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

.
├── package.json
├── package-lock.json
├── README.md
├── src
│   ├── application
│   │   ├── auth
│   │   │   └── index.ts
│   │   ├── graphql
│   │   │   ├── index.ts
│   │   │   ├── schemaShards
│   │   │   │   ├── index.ts
│   │   │   │   └── users.ts
│   │   │   ├── subscriptionManager.ts
│   │   │   └── utils
│   │   │       └── mergeRawSchemas.ts
│   │   └── index.ts
│   ├── dto
│   │   └── user.dto.ts
│   ├── entities
│   │   └── user.entity.ts
│   ├── index.ts
│   ├── IoC
│   │   ├── container.ts
│   │   ├── icradle.interface.ts
│   │   └── providers
│   │       ├── auth.provider.ts
│   │       └── user.provider.ts
│   ├── persistence
│   │   ├── auth.repository.ts
│   │   ├── constants.ts
│   │   ├── password.ts
│   │   └── user.repository.ts
│   ├── services
│   │   ├── auth.repository.interface.ts
│   │   ├── auth.service.ts
│   │   ├── user.repository.interface.ts
│   │   └── user.service.ts
│   └── __typedefs
│       ├── graphqlTypes.d.ts
│       └── schema.graphql
└── tsconfig.json


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The main folder is &lt;code&gt;src&lt;/code&gt; where contains the implementation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;application&lt;/strong&gt;: Application layer where we can use a backend web application framework. In this boilerplate is &lt;code&gt;GraphQL&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;service&lt;/strong&gt;: The business service layer where we defined the logic to handle application use cases. This layers also contains adapters that abstract the detailed actions, for example, access to database.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;entities&lt;/strong&gt;: This is the core component of the application where we define the application entities.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;persistence&lt;/strong&gt;: This is another detailed layer where we specify actions to communicate to database, message queue, etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;dto&lt;/strong&gt;: (stand for Data Transfer Object) defines communication contracts between layers. For example, what type of input param or return value that is used in methods of layers&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IoC&lt;/strong&gt;: (stand for Inversion of Control) is an implementation of the Dependency Injection, the letter D in the SOLID principal. Every time you create a new Service class, or a new repository class, or a new controller, you need to register them in this container. This boilerplate uses &lt;a href="https://github.com/jeffijoe/awilix" rel="noopener noreferrer"&gt;Awilix&lt;/a&gt; library to achieve the factor.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Communication Policies
&lt;/h3&gt;

&lt;p&gt;The communication policies between layers and domains compliant with the Clean Architecture. The directions of arrows in the following diagrams show the relation between components. For example, if an arrow direction from component X to component Y, it means component X depends on the component Y.&lt;/p&gt;

&lt;p&gt;1/ Dependency diagram&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe7u7rwrtwngewmywbhos.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe7u7rwrtwngewmywbhos.png" alt="Dependency diagram"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see in the diagram the dependency flow among layers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Entity is the core layer and does not depend on any component&lt;/li&gt;
&lt;li&gt;To inverse the dependency from the domain business layer to the repository layer, there is a repository interface in the domain business. This allows us to be able to implement and update this layer with the detailed technologies&lt;/li&gt;
&lt;li&gt;Application Controller depends in the services&lt;/li&gt;
&lt;li&gt;IoC container depends on services, repositories and application controllers because we need to register all of them to the container&lt;/li&gt;
&lt;li&gt;Application router depends on the IoC container that allows us to use registered application controllers to handle client requests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2/ Dependency between domains&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2f2te6dmpz0923l63vz9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2f2te6dmpz0923l63vz9.png" alt="Dependency between domains diagram"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In real-life projects, of course, there is not merely 1 domain. So, we need to define the communication rules between layers of them. &lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;There are some beginning available command lines is defined the &lt;code&gt;scripts&lt;/code&gt; part of the &lt;code&gt;package.json&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;1/ Install dependencies&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

npm i


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;2/ Run the application under the &lt;code&gt;dev&lt;/code&gt; mode with the hot reload feature&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

npm run dev


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;3/ Compile the application&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

npm run build


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;4/ Run the application under the &lt;code&gt;production&lt;/code&gt; mode. You need to compile the application before&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

npm run start


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;5/ Generate types for GraphQL schema. This action must be done each time you update the GraphQL schema to allow typescript compiler understand your schema:&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;p&gt;npm run generate-typedefs&lt;/p&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  References&lt;br&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html" rel="noopener noreferrer"&gt;The Clean Architecture Blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://anthonyriera.medium.com/you-just-found-the-best-node-typescript-mongodb-graphql-api-starter-kit-1f6f53d841cb" rel="noopener noreferrer"&gt;Node + Typescript + MongoDB GraphQL API Starter Kit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/tuanlc/graphql_clean-architecture_boilerplate" rel="noopener noreferrer"&gt;Implementation repository&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>graphql</category>
      <category>typescript</category>
      <category>cleanarchitecture</category>
      <category>boilerplate</category>
    </item>
  </channel>
</rss>
