<?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: Karol Wojdyła</title>
    <description>The latest articles on DEV Community by Karol Wojdyła (@k4wo).</description>
    <link>https://dev.to/k4wo</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%2F677476%2F763291dd-665d-4a78-9afa-184c49566754.jpeg</url>
      <title>DEV Community: Karol Wojdyła</title>
      <link>https://dev.to/k4wo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/k4wo"/>
    <language>en</language>
    <item>
      <title>How to setup the project in micro frontend architecture</title>
      <dc:creator>Karol Wojdyła</dc:creator>
      <pubDate>Wed, 17 Jul 2024 09:30:10 +0000</pubDate>
      <link>https://dev.to/k4wo/my-route-to-setting-up-microfronteds-3b9</link>
      <guid>https://dev.to/k4wo/my-route-to-setting-up-microfronteds-3b9</guid>
      <description>&lt;p&gt;The aim of this article is to show you how I designed a frontend application in micro fronteds architecture. At the beginning I would like to highlight all decisions I've made are based on my experience and in other environments might not be suitable, but I don't want to discuss what makes sense or not at every step of this series. My goal is to show the process of raising an application, starting at choosing tools and ending on deployment process. Simultaneously I'm curious about your opinions on what could be done better, which ideas will not work under given circumstances. Each and every comment is very appreciated, so please leave a comment on what you would do in another way.&lt;/p&gt;

&lt;p&gt;At the beginning I will say I base on real, commercial experience. The project was in the initial stage of development and there were three separate apps and each application had a dedicated backend service. I was given couple requirements. Consistent UI written in React by using MUI as system design, a user might have access to couple apps. This requirements made micro fronteds have a sense. I've saw pluses from perspective of end user. One URL, ease navigation between apps, the same UI. I saw advantages from developer point of view as well. Managing of code in the same way for all apps, we are not developing the same view for three different apps (eg. sign in, settings page). We are sharing components and themes easily. Of course like everything this approach has disadvantages - you must be aware of it - but I don't want to focus on that.&lt;/p&gt;

&lt;p&gt;Topics I would like to touch in this series:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Setting up the app&lt;/li&gt;
&lt;li&gt;Routing&lt;/li&gt;
&lt;li&gt;Internationalisation&lt;/li&gt;
&lt;li&gt;Common components and managing of themes&lt;/li&gt;
&lt;li&gt;API integration&lt;/li&gt;
&lt;li&gt;Authorisation and token refreshing&lt;/li&gt;
&lt;li&gt;Infrastructure and deployment&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1. Setting up the app
&lt;/h2&gt;

&lt;p&gt;I've decided to use NX to manage monorepo and apps. In the moment you will see that tool is doing a lot of things for you and you don't have to take care of webpack, eslint, etc (at least at the beginning). We use a couple commands and the backbone of the app will be created. This significantly speeds up and simplifies the process of building micro fronteds. Webpack is using module federation but nothing you have to do manually, because NX is doing the whole job us. Storing the entire codebase in one repo from my point of view turned out to be the best choice. It eliminated the process of releasing packages with shared code, linking of packages during development and a couple other issues.&lt;/p&gt;

&lt;p&gt;Let’s start with creating an NX workspace. At that moment we are not creating an app itself but just a directory with NX configuration. In the future NX will know that this space is dedicated to it and can work there without any obstacles.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-nx-workspace@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4w3synm1mihaopb1b90m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4w3synm1mihaopb1b90m.png" alt="Output of create nx workspace command" width="800" height="622"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a result of this command a new directory called &lt;code&gt;myorg&lt;/code&gt; will be created. Enter that workspace and we are starting from adding React plugin to NX.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx nx add @nx/react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just now we are ready to add React apps to our workspace. The name of them depends on you. I created a host app (called &lt;code&gt;portal-ui&lt;/code&gt;) and three remote apps. Please bear in mind the &lt;code&gt;directory&lt;/code&gt; directive, which tells NX to put everything into the &lt;code&gt;apps&lt;/code&gt; catalog. For me it’s easier to have all apps nested there but you can skip this parameter or name it in another way. I’ve decided to not add a library for styling and e2e tests.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx nx g @nx/react:host portal-ui &lt;span class="nt"&gt;--remotes&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;billing-ui,invoicing-ui,catalog-ui &lt;span class="nt"&gt;--directory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;apps/portal-ui
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ey799bh8fnirlubvgmk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ey799bh8fnirlubvgmk.png" alt="Output of adding the apps" width="800" height="492"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the ideal "Micro fronted Architecture" each micro fronted has its counterpart on the backend side. For the purposes of this article let’s assume we have one microservice written in Node.js and will be dedicated to &lt;code&gt;portal-ui&lt;/code&gt;. The rest of the apps have backend services hosted outside of our monnorepo.&lt;/p&gt;

&lt;p&gt;Our server will be written in Express and therefore we gonna start from adding appropriate plugin to NX:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx nx add @nx/node
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Below command creates a &lt;code&gt;portal-svc&lt;/code&gt;, dedicated to &lt;code&gt;portal-ui&lt;/code&gt; backend service.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx nx g @nx/node:app portal-svc &lt;span class="nt"&gt;--directory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;apps/portal-svc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxww7mysx3qzjvr90h4hy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxww7mysx3qzjvr90h4hy.png" alt="Output of creating backend microservice" width="800" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’m pretty sure you have noticed I’ve added a postfix for every app. For React it’s &lt;code&gt;ui&lt;/code&gt; and for Express it’s &lt;code&gt;svc&lt;/code&gt;. On the first glimpse it might seem redundant but when in monorepo there will be more apps and fronted counterparts in the backend then you see that adding it to the name at the end makes sense. You can easily distinguish which app is frontend and which is backend. Of course you can add your own postfixes but in general I think adding it to each app is very good practice.&lt;/p&gt;

&lt;p&gt;If you are going step by step with this article, the project structure should look like in the below image. All apps are nested in the &lt;code&gt;apps&lt;/code&gt; directory. Each and every app has its own &lt;code&gt;project.json&lt;/code&gt; file, which contains all settings of the project. Among others, starting of the app, building, etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc5e847s8vspf47snk9cd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc5e847s8vspf47snk9cd.png" alt="Project structure" width="658" height="1120"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The last step in that section of the article is running the app&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx nx serve portal-ui
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default the portal will be accessible at &lt;code&gt;http://localhost:4200&lt;/code&gt; address. When you enter there you will see NX provides basic UI and working routing. In the coming articles we will touch everything and adopt it to our requirements.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe4ysg2ngxz7p5ten38v3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe4ysg2ngxz7p5ten38v3.png" alt="NX default page" width="800" height="960"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>microfrontends</category>
      <category>react</category>
      <category>nx</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Free alternative to GSuite</title>
      <dc:creator>Karol Wojdyła</dc:creator>
      <pubDate>Mon, 24 Jan 2022 07:53:47 +0000</pubDate>
      <link>https://dev.to/k4wo/free-alternative-to-gsuite-1d8b</link>
      <guid>https://dev.to/k4wo/free-alternative-to-gsuite-1d8b</guid>
      <description>&lt;p&gt;Google closes GSuite and from now all accounts will be transferred to Google Workspace, and therefore will cease to be free. Many people used GSuite only because it was a free service and you could connect your own domain to it. Probably some of you have asked yourself what to do in this situation - buy a paid account or look for another solution.&lt;/p&gt;

&lt;p&gt;If for some reason you don't want to pay for Workspace, I am here to help. You can look for other email provider that allows you to connect your own domain. I used to use Yandex mail - but some emails ended up in spam, so I gave up. This time I would like to use GMail so I decided to use an alias. I just need to put a contact on the website and it's nice if it's on the mayann.app domain. I know that if I answer an email, it will be from the GMail domain, but that is not so important to me.&lt;/p&gt;

&lt;p&gt;This solution gives me all the advantages of GMail and I use my domain. This is definitely not a perfect solution, the message passes through additional servers, so someone can know the content of the email and we are addicted to this intermediary. However, this does not discourage me, initially I used &lt;a href="https://improvmx.com/" rel="noopener noreferrer"&gt;improvmx.com&lt;/a&gt; and everything worked great, but after some time I decided to move to Cloudflare for two reasons - it is a large company, so there is less risk of a failure and I have everything in one place. Both sites are free, so you can try them out and choose a better solution.&lt;/p&gt;

&lt;p&gt;Setting up &lt;a href="https://developers.cloudflare.com/email-routing/enable-email-routing" rel="noopener noreferrer"&gt;Cloudflare Email Routing&lt;/a&gt; is easy. You enter the alias and the address to which the email will be redirected, and basically that's it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.mayann.app%2Fassets%2Fimages%2Fcloudflare_email_routing.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%2Fblog.mayann.app%2Fassets%2Fimages%2Fcloudflare_email_routing.png" alt="Cloudflare Email Routing page screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is an article from the series on how to maintain an indie startup at a minimum cost, in the next episode I will write how I keep a blog for free. Everything I write about is tested on my &lt;a href="https://mayann.app" rel="noopener noreferrer"&gt;random data generator&lt;/a&gt; indie startup.&lt;/p&gt;

&lt;h4&gt;
  
  
  #shortAndToThePoint
&lt;/h4&gt;

</description>
      <category>devjournal</category>
      <category>devops</category>
      <category>productivity</category>
      <category>shortandtothepoint</category>
    </item>
  </channel>
</rss>
