<?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>DEV Community: Farhad Mehryari</title>
    <description>The latest articles on DEV Community by Farhad Mehryari (@ifarhad).</description>
    <link>https://dev.to/ifarhad</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%2F410817%2Fcdca7079-ddfe-4d00-8061-37df1482f10e.jpeg</url>
      <title>DEV Community: Farhad Mehryari</title>
      <link>https://dev.to/ifarhad</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ifarhad"/>
    <language>en</language>
    <item>
      <title>Implement Nuxt/Vue Micro-Service</title>
      <dc:creator>Farhad Mehryari</dc:creator>
      <pubDate>Sat, 08 May 2021 08:46:40 +0000</pubDate>
      <link>https://dev.to/ifarhad/implement-nuxt-vue-micro-service-1oo1</link>
      <guid>https://dev.to/ifarhad/implement-nuxt-vue-micro-service-1oo1</guid>
      <description>&lt;p&gt;Here I've explained the basics of micro-service architecture for the front end and how to choose your services.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/ifarhad" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F410817%2Fcdca7079-ddfe-4d00-8061-37df1482f10e.jpeg" alt="ifarhad"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/ifarhad/front-end-microservice-architecture-38" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Front-End MicroService Architecture&lt;/h2&gt;
      &lt;h3&gt;Farhad Mehryari ・ Apr 15 '21&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#microservices&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#vue&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#nuxt&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;In this post, we consider a shopping website that has three main parts and we name it myshop.com.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Account&lt;/li&gt;
&lt;li&gt;Shop&lt;/li&gt;
&lt;li&gt;Profile&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Account service will mount on myshop.com/account that has the following routes&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;/account/login&lt;/li&gt;
&lt;li&gt;/account/register&lt;/li&gt;
&lt;li&gt;/account/forget-password&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Shop service will mount on myshop.com/shop that has the following routes&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;/shop/products&lt;/li&gt;
&lt;li&gt;/shop/product/:id&lt;/li&gt;
&lt;li&gt;/shop/basket&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Profile service will mount on myshop.com/profile that has the following routes&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;/profile/orders&lt;/li&gt;
&lt;li&gt;/profile/edit-profile&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As we discussed before each service will be a Nuxt project. for the first step, we will create 3 Nuxt projects.&lt;/p&gt;

&lt;p&gt;I created in following directories&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;/home/farhad/projects/nuxt-account&lt;/li&gt;
&lt;li&gt;/home/farhad/projects/nuxt-shop&lt;/li&gt;
&lt;li&gt;/home/farhad/projects/nuxt-profile&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the next step, we need a router to handle each request with desired Nuxt project.&lt;/p&gt;

&lt;p&gt;I have developed this router and published it on npm.&lt;/p&gt;

&lt;p&gt;let's install it and see how to use it.&lt;/p&gt;

&lt;p&gt;create a new project&lt;br&gt;
install geshniz-router package&lt;br&gt;
create index.ts file and add the below code:&lt;/p&gt;

&lt;p&gt;‍‍‍&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;NuxtService&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;geshniz-router&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;App&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;0.0.0.0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;account&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NuxtService&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;evn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dev&lt;/span&gt;&lt;span class="dl"&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Account&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;mountPath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/account&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;rootPath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/home/farhad/projects/nuxt-account/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;shop&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NuxtService&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dev&lt;/span&gt;&lt;span class="dl"&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Shop&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;mountPath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/shop&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;rootPath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/home/farhad/projects/nuxt-shop&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;


&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;profile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NuxtService&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;start&lt;/span&gt;&lt;span class="dl"&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Profile&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;mountPath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/profile&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;rootPath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/home/farhad/projects/nuxt-profile&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;registerService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;account&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;registerService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;shop&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;registerService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Then run it with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ts-node index.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or compile it with the tsc and run it with node.&lt;/p&gt;

&lt;p&gt;Now If you check 127.0.0.1:4000/profile/orders, the response comes from the nuxt-profile project and as well as other requests.&lt;/p&gt;

&lt;p&gt;let's explain App class and NuxtService class&lt;/p&gt;

&lt;p&gt;App class instance accepts two parameters for creating a web server, Ports and hosts, respectively and has one method for registering NuxtService instance class in routes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NuxtService&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// dev or start&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Profile&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// only a name&lt;/span&gt;
    &lt;span class="na"&gt;mountPath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/profile&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="na"&gt;rootPath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/home/farhad/projects/nuxt-profile&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are working only on one service you can set others to be in production mode by setting env property to be 'start'&lt;br&gt;
also, nuxt projects could out main project's directory.&lt;/p&gt;

&lt;p&gt;After registering the new Nuxt service instance with the App class, &lt;strong&gt;all incoming requests for the mountPath route will be handled by this service&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I took the cover photo myself, a beautiful park in Tabriz.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>nuxt</category>
      <category>typescript</category>
      <category>microservices</category>
    </item>
    <item>
      <title>Front-End MicroService Architecture</title>
      <dc:creator>Farhad Mehryari</dc:creator>
      <pubDate>Thu, 15 Apr 2021 06:51:51 +0000</pubDate>
      <link>https://dev.to/ifarhad/front-end-microservice-architecture-38</link>
      <guid>https://dev.to/ifarhad/front-end-microservice-architecture-38</guid>
      <description>&lt;p&gt;Whenever I read about MicroService Architecture, it was for the back-end but today I will explain how to implement this architecture in the front end.&lt;/p&gt;

&lt;h3&gt;
  
  
  What should be considered as Service?
&lt;/h3&gt;

&lt;p&gt;The first principle about microservice architecture indicates that each service should be independent of others so the first step is to separate independent parts of our front-end. One of the good approaches that we can separate our independent parts is considering layouts.&lt;/p&gt;

&lt;p&gt;For example, consider a simple shopping website. Most authentication layouts including login, register, forget the password, etc differ from the home page so authentication pages could be considered as one of our services. &lt;/p&gt;

&lt;p&gt;We will create a new Nuxt project which has the below pages:&lt;br&gt;
(all are under /auth scope)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;/login&lt;/li&gt;
&lt;li&gt;/register&lt;/li&gt;
&lt;li&gt;/forget-password&lt;/li&gt;
&lt;li&gt;/confirm-email&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will create another Nuxt project that has other pages of our shopping such as home page, basket, product, categories, etc.&lt;/p&gt;

&lt;p&gt;Up to here, we were able to decomposite our front-end into two services still we can move one more step forward and consider all pages under profile scope to be another service so we will create a new Nuxt project including the below pages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;/orders&lt;/li&gt;
&lt;li&gt;/orders/view/:id&lt;/li&gt;
&lt;li&gt;/addresses&lt;/li&gt;
&lt;li&gt;/addresses/:id&lt;/li&gt;
&lt;li&gt;/info&lt;/li&gt;
&lt;li&gt;/info/update&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  How to run 3 projects?
&lt;/h3&gt;

&lt;p&gt;At this point, we have 3 Nuxt projects that could be developed by different people and we need a parent router to keep these projects under one HTTP server and allocate requests to the project based on defined routes.&lt;/p&gt;

&lt;p&gt;For example, when the browser hits&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;http://127.0.0.1:3000/auth/login&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;the router will assign this request to the first Nuxt project and when the URL is&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;http://127.0.0.1:3000/profile/orders&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;the outer will give this request to the last Nuxt project to handle it.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I'm developing this router and after publishing at npm I'll write a new post to explain how to use it&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;you won't face the memory leak of watching a large number of files in development.&lt;/li&gt;
&lt;li&gt;services could be in development or production mode independently &lt;/li&gt;
&lt;li&gt;each service has its own assets&lt;/li&gt;
&lt;li&gt;better teamwork experience&lt;/li&gt;
&lt;li&gt;work one service A while others are in production mode and running.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Disadvantages
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;If you don't have a different layout it is useless&lt;/li&gt;
&lt;li&gt;Based on the UI, maybe you have repeated components in different services&lt;/li&gt;
&lt;li&gt;Maybe you have repeated peace of codes or functions (i.e function to generate random int between 2 number)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Final Notes
&lt;/h3&gt;

&lt;p&gt;Implementing microservice architecture is recommended IF your project is on a large scale.&lt;/p&gt;

&lt;p&gt;Thanks for your reading, It's just architecture and how to implement it.&lt;/p&gt;

&lt;p&gt;here is the &lt;a href="https://dev.to/ifarhad/implement-nuxt-vue-micro-service-1oo1"&gt;part II&lt;/a&gt; (implementing in nuxt project)&lt;br&gt;
Any comments or criticisms are welcome&lt;/p&gt;

</description>
      <category>microservices</category>
      <category>vue</category>
      <category>nuxt</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
