<?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: A R T I U M</title>
    <description>The latest articles on DEV Community by A R T I U M (@artiumws).</description>
    <link>https://dev.to/artiumws</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%2F1563479%2Fd1a68663-64bf-42ef-8a3e-97ec32a270b7.png</url>
      <title>DEV Community: A R T I U M</title>
      <link>https://dev.to/artiumws</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/artiumws"/>
    <language>en</language>
    <item>
      <title>Memory management and other weird blobs</title>
      <dc:creator>A R T I U M</dc:creator>
      <pubDate>Wed, 26 Jun 2024 21:39:59 +0000</pubDate>
      <link>https://dev.to/artiumws/memory-management-and-other-weird-blobs-36bj</link>
      <guid>https://dev.to/artiumws/memory-management-and-other-weird-blobs-36bj</guid>
      <description>&lt;p&gt;I always felt confused by the terms “Blob, Buffer, ArrayBuffer, Uint8Array.”&lt;/p&gt;

&lt;p&gt;Everyone has their own definition, but no one can clearly define them. It always ends up in a nonsensical technical explanation.&lt;/p&gt;

&lt;p&gt;Today, I’ll put a human-readable definition on these terms. This will help my future self and other engineers to have a better understanding.&lt;/p&gt;

&lt;p&gt;Let me introduce you to the strange world of memory management in JavaScript.&lt;/p&gt;




&lt;p&gt;Before we dive into the subject — if you have any questions during the lecture — feel free to ask me on Twitter: &lt;a href="https://twitter.com/ArtiumWs" rel="noopener noreferrer"&gt;@artiumWs&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Concepts
&lt;/h2&gt;

&lt;p&gt;Before starting, let’s define some basic concepts: Memory, Memory Span, Binary Data, and Raw Data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Memory
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Memory (RAM) is fast storage used by a computer to quickly access and store data.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Memory span
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;A memory span refers to a contiguous block of memory.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If memory is a street, a memory span would be neighbouring houses.&lt;/p&gt;

&lt;h3&gt;
  
  
  Binary data
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Binary data is the representation of information in binary form&lt;/em&gt; — &lt;em&gt;bunch of 0 and 1&lt;/em&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  Raw Data
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Raw data is the unprocessed information consumed by a program — text, images, files …&lt;/em&gt;&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwev5equ0txctkcuihifa.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%2Fwev5equ0txctkcuihifa.png" alt="Memory, Memory Span, Binary Data, and Raw Data"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep these definitions in mind.&lt;/strong&gt; They will be useful for understanding the following sections.&lt;/p&gt;

&lt;h2&gt;
  
  
  In-code object
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Blob object
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;A &lt;code&gt;Blob&lt;/code&gt; is an immutable object referencing raw data.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This is an object created in your code that contains raw data information like size in bytes and MIME type (&lt;code&gt;image/png&lt;/code&gt;, &lt;code&gt;application/pdf&lt;/code&gt;, &lt;code&gt;application/json&lt;/code&gt;, …).&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjowormjuiicwxjqd968q.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%2Fjowormjuiicwxjqd968q.png" alt="Blob object"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  File object
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;A &lt;code&gt;File&lt;/code&gt; extends from &lt;code&gt;Blob&lt;/code&gt; properties and is created when using an input element.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It’s a &lt;code&gt;Blob&lt;/code&gt; with more information like: last modified date and file name. This object is automatically created when a file is uploaded to your app using an input element or a drag-and-drop event.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx54kkp27pln7tp6cest5.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%2Fx54kkp27pln7tp6cest5.png" alt="File object"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Those object cannot be modified directly! They are the in-code reference to the raw data.&lt;/p&gt;

&lt;p&gt;This is to ensures their integrity when manipulating them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Manipulation
&lt;/h2&gt;

&lt;p&gt;Those objects provide two methods to access the data: &lt;code&gt;arrayBuffer&lt;/code&gt; and &lt;code&gt;stream&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  arrayBuffer
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;arrayBuffer&lt;/code&gt; is &lt;em&gt;method that load the binary data of the object in a memory span and return a in-code representation of a memory span.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This representation cannot be modified directly! We need to reference it first with a typed array to access its binary data. Typed arrays are defined later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Caution:&lt;/strong&gt; It loads the whole file in your memory at once. In case the file size is to big (&amp;gt;5Mb), this operation can freeze your app. In such case, use the next method.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0gsxjux9tdrbm3b8vgl9.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%2F0gsxjux9tdrbm3b8vgl9.png" alt="array buffer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  stream
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;&lt;code&gt;stream&lt;/code&gt; is a method that load the binary data in chunks. This process is called buffering.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Chunks returned are directly typed arrays so they can be directly manipulated to process you data on fly.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn3tume6rp3ch97qnmr1u.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%2Fn3tume6rp3ch97qnmr1u.png" alt="stream"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Typed array
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Typed array (&lt;code&gt;uInt8Array&lt;/code&gt;, &lt;code&gt;int16array&lt;/code&gt; …) references the &lt;code&gt;arrayBuffer&lt;/code&gt; to access and modify its binary data.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Multiple typed array can reference the same &lt;code&gt;arrayBuffer&lt;/code&gt;. In such cases, the latest modification will overwrite the previous ones.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7l4d358nzcev915drthk.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%2F7l4d358nzcev915drthk.png" alt="Typed array"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Buffer (Node.Js)
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Buffer&lt;/code&gt; is a Node.js object that extend from the typed array properties. It is designed to deal with communication features.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use case:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Buffers are designed to handle communication logic. &lt;br&gt;
&lt;strong&gt;eg:&lt;/strong&gt; Optimise data send through requests.&lt;/p&gt;

&lt;p&gt;Typed arrays are designed to handle processing logic. &lt;br&gt;
&lt;strong&gt;eg:&lt;/strong&gt; Adding a filter to an image&lt;/p&gt;

&lt;h2&gt;
  
  
  Recap
&lt;/h2&gt;

&lt;p&gt;Let’s recap this article through the following use case: “Uploading an image on a web app”&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;An image is stored on the your computer (hard drive, SSD, …)&lt;/li&gt;
&lt;li&gt;Upload this image to your web app using an &lt;code&gt;&amp;lt;input type="file"&amp;gt;&lt;/code&gt; element&lt;/li&gt;
&lt;li&gt;The browser creates a &lt;code&gt;File&lt;/code&gt; object that references the image. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;4.a Use the &lt;code&gt;arrayBuffer&lt;/code&gt; method to load the image into memory span and reference it&lt;br&gt;
5.a Attach a typed array to this arrayBuffer to read or write binary data&lt;br&gt;
6.a Process the binary data&lt;/p&gt;

&lt;p&gt;4.b Use the &lt;code&gt;stream&lt;/code&gt; method to read chunk of stored image as a typed array&lt;br&gt;
5.b Process the binary data chunks &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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc23gxxjqyxfvegqlror7.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%2Fc23gxxjqyxfvegqlror7.png" alt="Uploading a image on a web app"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope this article helps you gain a clearer understanding of the topic. &lt;/p&gt;

&lt;p&gt;If you have any questions, feel free to ask me on Twitter: &lt;a href="https://twitter.com/ArtiumWs" rel="noopener noreferrer"&gt;@artiumWs&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://nodejs.org/api/buffer.html" rel="noopener noreferrer"&gt;https://nodejs.org/api/buffer.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Typed_arrays" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Typed_arrays&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Concepts" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Concepts&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Streams_API" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/API/Streams_API&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/File" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/API/File&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/API/Blob&lt;/a&gt;&lt;br&gt;
&lt;a href="https://stackoverflow.com/questions/11821096/what-is-the-difference-between-an-arraybuffer-and-a-blob#comment41489269_11821109" rel="noopener noreferrer"&gt;https://stackoverflow.com/questions/11821096/what-is-the-difference-between-an-arraybuffer-and-a-blob#comment41489269_11821109&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Backblaze B2: How to store a file</title>
      <dc:creator>A R T I U M</dc:creator>
      <pubDate>Sun, 16 Jun 2024 19:15:28 +0000</pubDate>
      <link>https://dev.to/artiumws/backblaze-b2-how-to-store-a-file-3obj</link>
      <guid>https://dev.to/artiumws/backblaze-b2-how-to-store-a-file-3obj</guid>
      <description>&lt;p&gt;Backblaze B2 is a cloud storage solution offering scalable and affordable data storage for individuals, developers, and businesses. Backblaze's B2 service aim for simplicity and cost-effectiveness. &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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feetb5uwr96osf9jgpuxg.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%2Feetb5uwr96osf9jgpuxg.png" alt="Backblaze's price comparison"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, users may find the documentation cumbersome to understand, which can be a hurdle for those new to the platform.&lt;/p&gt;

&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;This article introduce how to use the backblaze cloud storage solution to store private user file that can only be accessed by the owner.&lt;/p&gt;

&lt;p&gt;This article will cover:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to setup a bucket for your application&lt;/li&gt;
&lt;li&gt;How to authorise your application to access the bucket&lt;/li&gt;
&lt;li&gt;Upload a file to your bucket&lt;/li&gt;
&lt;li&gt;Download a file for a user with the right access&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Bucket
&lt;/h2&gt;

&lt;p&gt;When setting up the bucket make sure the following options are checked:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Private
This will ensure your files won’t be accessible without the correct permission&lt;/li&gt;
&lt;li&gt;Encryption
This will ensure your file are properly encrypted. Make sure there is no sensitive informations in the name or metadata of the files. Those won’t be encrypted!&lt;/li&gt;
&lt;li&gt;Object lock (optional)
This will ensure your file won’t be altered for the selected timeframe.
In my case that wasn’t needed so I left it unchecked&lt;/li&gt;
&lt;/ul&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0bpnlpfpr1anp27x4xl2.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%2F0bpnlpfpr1anp27x4xl2.png" alt="Backblaze create bucket"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Application keys
&lt;/h2&gt;

&lt;p&gt;To access your bucket you will need to setup application keys. You can use the master application keys but I won’t advise it as it have all right for all bucket. &lt;br&gt;
You should consider creating a dedicated application key for your bucket this will prevent any interaction with other buckets.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn19tso7zs534b4cbt83v.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%2Fn19tso7zs534b4cbt83v.png" alt="Backblaze application key"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once created you should have access to your application key id and application key.&lt;/p&gt;

&lt;p&gt;Save them for later use as they will be hidden as soon as you leave the page!&lt;/p&gt;

&lt;p&gt;In case that happened no worries just delete and recreate your application key.&lt;/p&gt;

&lt;h2&gt;
  
  
  Authorise your application
&lt;/h2&gt;

&lt;p&gt;To setup authorisation in your application you will need to fetch the following endpoint.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;https://api.backblazeb2.com/b2api/v3/b2_authorize_account&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authorisation header&lt;/strong&gt;&lt;br&gt;
To access this endpoint you will need the application key id and application key setup earlier. Concatenate them in a string, encode them to Base64 and prefix them with &lt;code&gt;Basic&lt;/code&gt; .&lt;br&gt;
Here is a pseudo code example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Basic Base64({application_key_id}:{application_key})&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Returned data&lt;/strong&gt;&lt;br&gt;
This endpoint will return data related to your application key. Here is the list of required datas for the next step:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Api url&lt;/li&gt;
&lt;li&gt;Bucket id&lt;/li&gt;
&lt;li&gt;Bucket name&lt;/li&gt;
&lt;li&gt;Authorisation token (1) from application key&lt;/li&gt;
&lt;li&gt;Download url&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;More infos&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.backblaze.com/apidocs/b2-authorize-account" rel="noopener noreferrer"&gt;https://www.backblaze.com/apidocs/b2-authorize-account&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Upload a file
&lt;/h2&gt;

&lt;p&gt;Uploading a file is done in 2 steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Get the upload url&lt;/li&gt;
&lt;li&gt;Upload the file&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  1) Get the upload url
&lt;/h3&gt;

&lt;p&gt;This endpoint will return you the data needed to upload your files. You will need the Api url, Bucket id and Authorisation token from the previous endpoint.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;{api_url}/b2api/v3/b2_get_upload_url?bucketId={bucket_id}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authorisation header&lt;/strong&gt;&lt;br&gt;
Pass the Authorisation token &lt;strong&gt;from application key&lt;/strong&gt; to the Authorisation header:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Authorisation {authorisation_token_1}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Returned data&lt;/strong&gt;&lt;br&gt;
This endpoint will return data required to upload a file:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Upload url&lt;/li&gt;
&lt;li&gt;Authorisation token (2) to upload a file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;More infos&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.backblaze.com/apidocs/b2-get-upload-url" rel="noopener noreferrer"&gt;https://www.backblaze.com/apidocs/b2-get-upload-url&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2) Upload a file
&lt;/h3&gt;

&lt;p&gt;This endpoint will upload a file to your bucket. You will need the Upload url and Authorisation token from the previous endpoint. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;{upload_url}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Use the url previously returned.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authorisation header&lt;/strong&gt;&lt;br&gt;
Pass the Authorisation token &lt;strong&gt;to upload a file&lt;/strong&gt; directly to the Authorisation header:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Authorisation {authorisation_token_2}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Headers&lt;/strong&gt;&lt;br&gt;
You will need to pass header related to your file metadata.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;X-Bz-File-Name&lt;/code&gt; 
The name of your file in the bucket. 
NB: In case you want to separate your file per users you can use this syntax:
&lt;code&gt;{user_id}/{file_name}&lt;/code&gt; 
This will store the file related to your user in a dedicated folder to prevent other users accessing it.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Content-Type&lt;/code&gt; 
The MIME type of your file. eg: &lt;code&gt;image/png&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Content-Length&lt;/code&gt;
The size of you file in bytes.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;X-Bz-Content-Sha1&lt;/code&gt;
The Sha1 of your file to ensure integrity of the file. This need to be generated in your code. 
In development environment you can pass &lt;code&gt;do_not_verify&lt;/code&gt; this will skip the integrity validation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;More infos&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.backblaze.com/apidocs/b2-upload-file" rel="noopener noreferrer"&gt;https://www.backblaze.com/apidocs/b2-upload-file&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Download a file
&lt;/h2&gt;

&lt;p&gt;Downloading a file is done in 2 steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Get the download authorisation&lt;/li&gt;
&lt;li&gt;Get the file&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  1) Get the download authorisation
&lt;/h3&gt;

&lt;p&gt;This endpoint will generate a download authorisation for a / some files. You will need the Api url, Authorisation token and Bucket id from the first authorisation endpoint.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;{api_url}/b2api/v3/b2_get_download_authorization?bucketId={bucket_id}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authorisation header&lt;/strong&gt;&lt;br&gt;
Pass the Authorisation token &lt;strong&gt;from application key&lt;/strong&gt; to the Authorisation header:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Authorisation {authorisation_token_1}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Query params&lt;/strong&gt;&lt;br&gt;
This endpoint will require some more query params to work properly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;fileNamePrefix&lt;/code&gt;
The prefix (folder) previously used to store our files. In our case that was the &lt;code&gt;user_id&lt;/code&gt; .
This will generate authorisation only for the chosen folder.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;validDurationInSeconds&lt;/code&gt;
The number of seconds before your authorisation expire.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After passing those query params your endpoint will look something like:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;{api_url}/b2api/v3/b2_get_download_authorization?bucketId={bucket_id}&amp;amp;fileNamePrefix={user_id}&amp;amp;validDurationInSeconds={duration_in_sec}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Returned data&lt;/strong&gt;&lt;br&gt;
This endpoint will return data required to download a file:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Authorisation token (3) to download a file&lt;/li&gt;
&lt;li&gt;File name prefix in our case user id&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;More infos&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.backblaze.com/apidocs/b2-get-download-authorization" rel="noopener noreferrer"&gt;https://www.backblaze.com/apidocs/b2-get-download-authorization&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2) Get a file by name
&lt;/h3&gt;

&lt;p&gt;This endpoint will download a file from your bucket based on its name. You will need the Download url, Bucket name from first authorisation endpoint. Authorisation token and File name prefix in our case user id from previous endpoint.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;{download_url}/file/{bucket_name}/{user_id}/{file_name}?Authorization={authorisation_token_3}&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;This link can be used to fetch a file for a specific user with an expiration limit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;More infos&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.backblaze.com/apidocs/b2-download-file-by-name" rel="noopener noreferrer"&gt;https://www.backblaze.com/apidocs/b2-download-file-by-name&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Schema
&lt;/h2&gt;

&lt;p&gt;To have a better overview of the implementation here is an explication schema:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhwxv2k3birh2u4vsf4tx.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%2Fhwxv2k3birh2u4vsf4tx.png" alt="backblaze upload download schema"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Modular Monolith: A disruptive guide to architecting your React app</title>
      <dc:creator>A R T I U M</dc:creator>
      <pubDate>Sun, 09 Jun 2024 18:52:19 +0000</pubDate>
      <link>https://dev.to/artiumws/modular-monolith-a-disruptive-guide-to-architecting-your-react-app-2gji</link>
      <guid>https://dev.to/artiumws/modular-monolith-a-disruptive-guide-to-architecting-your-react-app-2gji</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;This writing was inspired by the article: “&lt;a href="https://dev.to/alexanderop/how-to-structure-vue-projects-20i4"&gt;How to Structure Vue Projects&lt;/a&gt;”. &lt;/p&gt;

&lt;p&gt;It explains various front-end application structures. It’s really insightful and can be applied to other front-end frameworks.&lt;/p&gt;

&lt;p&gt;A year ago, my team and I started a new project from scratch. The discussion about its structure and stack became crucial. We decided on a modular monolithic architecture.&lt;/p&gt;

&lt;p&gt;I will detail what motivated our choices and hope these insights will inspire you for your future projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  context
&lt;/h2&gt;

&lt;p&gt;Through my experience, I have worked on several projects. Each with its unique specificities which can be classified into these categories:&lt;/p&gt;

&lt;h3&gt;
  
  
  Monolithic
&lt;/h3&gt;

&lt;p&gt;A monolithic architecture is an all-in-one project containing all application functionalities.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Advantages:&lt;/strong&gt; Easy to onboard new team members, maintain, update dependencies, and add new features. Deployment is straightforward and depends on one CI/CD pipeline.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Disadvantages:&lt;/strong&gt; As the engineering team grows, it leads to more conflict management. Deployment can bottleneck when two teams try to release simultaneously. There is no clear ownership of features.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In short, it doesn’t scale well.&lt;/p&gt;

&lt;h3&gt;
  
  
  Micro-front end
&lt;/h3&gt;

&lt;p&gt;A micro-front end architecture is a spliced application where each feature lives in a separate project, owned by a dedicated team.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Advantages:&lt;/strong&gt; Each team can add new features without conflict or deployment bottlenecks. Each micro-front end has its own CI/CD pipeline, allowing specific actions for each project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Disadvantages:&lt;/strong&gt; Harder to onboard new team members and update dependencies. It requires more configuration and maintenance, often necessitating a dedicated DevOps team.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In short, it scales well — until it doesn’t. &lt;/p&gt;

&lt;p&gt;What happens when you need to scale down? &lt;br&gt;
In 2023, team reductions due to layoffs lead to shared ownership and less-maintained parts. Usually pipelines and configurations, leading to poor developer experience and slowing down the entire process.&lt;/p&gt;

&lt;p&gt;I wouldn't advise any company smaller than FAANG size to go for it.&lt;/p&gt;

&lt;p&gt;With that said, let’s introduce the architecture we decided to use.&lt;/p&gt;
&lt;h2&gt;
  
  
  Challenges:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Enabling multiple teams to work on the project without conflicts&lt;/li&gt;
&lt;li&gt;Maintaining the project by one or several teams&lt;/li&gt;
&lt;li&gt;Having a single project that is easy to maintain&lt;/li&gt;
&lt;li&gt;Ensuring low complexity for easy onboarding&lt;/li&gt;
&lt;li&gt;Scalable architecture that can scale both up and down&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Modular monolith
&lt;/h2&gt;

&lt;p&gt;A modular monolith is an all-in-one project where each feature lives in a separate shell.&lt;/p&gt;

&lt;p&gt;In other words, each feature has its own folder and does not share any components, state, or logic with other features. If shared logic, state, or components are needed, they are stored at the root of the project.&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%2Fu9k8zgivbm6d9khek9ht.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%2Fu9k8zgivbm6d9khek9ht.png" alt="modular monolith project structure" width="678" height="1382"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This architecture is flexible and can be adapted to your stack and needs. &lt;br&gt;
For example, you can add &lt;code&gt;layouts&lt;/code&gt; if you need layouts for your pages or &lt;code&gt;containers&lt;/code&gt; if you are working with Redux.&lt;/p&gt;
&lt;h2&gt;
  
  
  Architecture details
&lt;/h2&gt;

&lt;p&gt;I will detail the choices made for our stack and the conventions implemented to address the challenges.&lt;/p&gt;
&lt;h2&gt;
  
  
  Conventions
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Avoid the trend tech syndrome:&lt;/strong&gt;
New JavaScript libraries are released frequently, making it hard to stay focused on a stack. It might seem like there's always a library that solves an issue in a more elegant way. 
Don’t fall into this trap. Stick to the stack you have defined.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Avoid nesting in components folder (The atomic design trap):&lt;/strong&gt;
It's common for people to store components related to a parent component within its folder. Leading to a very nested structure that is hard to navigate for newcomers. 
Prefer a flat structure within your components folder.&lt;/li&gt;
&lt;/ul&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%2F8zsffrx89ccnr18ffxae.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%2F8zsffrx89ccnr18ffxae.png" alt="nested structure vs flat structure" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Put Logic in Hooks:&lt;/strong&gt;
Start by writing the logic within your component. When the logic takes up too much space, move it to a hook. 
This approach is subjective and may vary for each individual.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Place testable logic in utils:&lt;/strong&gt;
Separate logic that requires native hooks (useState…) from the logic that doesn't. Move the latter to a utils file if it needs to be tested. 
More details about this are in the testing section.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maximise the utility of third-party dependencies:&lt;/strong&gt;
Avoid adding a dependency that can handle multiple things if you only use one of its features. 
For example, using RxJS to handle simple HTTP requests when the Fetch API can do it just as well.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Stacks
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Shared state (&lt;code&gt;stores&lt;/code&gt; in structure diagram)
&lt;/h3&gt;

&lt;p&gt;Shared state management is always a highly opinionated topic. There are different preferences based on various factors:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Redux:&lt;/strong&gt; Preferred by those who like a stricter pattern, a strong community, and solid debugging tools.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MobX:&lt;/strong&gt; Preferred by those who prefer more freedom in implementation and a fine-grained updating system to improve optimisation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;New Trends (Jutai or Zustand):&lt;/strong&gt; Preferred by those who enjoy new trends because they are hook-like and easy to implement.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Our choice was &lt;strong&gt;React Context&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Some may argue that React Context, if not memoized, will re-render all children, and the syntax can be cumbersome.&lt;/p&gt;

&lt;p&gt;They would be right.&lt;/p&gt;

&lt;p&gt;However, it is native to React, has a low learning curve, and in version 19, the syntax will be simplified.&lt;/p&gt;

&lt;p&gt;The Virtual DOM (VDOM) is performant, and re-rendering all children rarely causes issues. If it does, just memoize it properly. React has announced their new React-Compiler (see &lt;a href="https://dev.to/artiumws/react-compiler-when-react-becomes-svelte-5969"&gt;React-Compiler: When react becomes Svelte&lt;/a&gt;), which will optimise during build time.&lt;/p&gt;
&lt;h3&gt;
  
  
  Styles
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;CSS-in-JS (styled-components)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Should I really explain why it’s a bad idea ?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Size of the documentation:&lt;/strong&gt; Why do we have migration guide when dealing with CSS ?&lt;/li&gt;
&lt;/ul&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%2F0lsptp2gb8ndjmgl3d0o.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%2F0lsptp2gb8ndjmgl3d0o.png" alt="Styled component migration guide" width="618" height="328"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;JS handling CSS:&lt;/strong&gt; Why Javascript would be better than CSS at handling CSS ?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Component instead of class:&lt;/strong&gt; Why do we need to create a component to apply border styles ?&lt;/li&gt;
&lt;/ul&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%2Ft4693lprw3txc4h2s4bu.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%2Ft4693lprw3txc4h2s4bu.png" alt="styled component tomato button" width="800" height="248"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Don’t recommend to use it in a project&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tailwind&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Inline styling done with elegance&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Locality of behaviour:&lt;/strong&gt; Styles are directly within the component&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Easy syntax:&lt;/strong&gt; Simple and intuitive&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optimised:&lt;/strong&gt; Minification and network compression&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I highly recommend Tailwind for any project. &lt;/p&gt;

&lt;p&gt;However, newcomers may face a small learning curve to memorise each classes. To onboard people quickly and easily, we decided to go with the following:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inline-style&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The easiest way to handle CSS&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Locality of behaviour:&lt;/strong&gt; Styles are directly within the component&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Super easy:&lt;/strong&gt; Straightforward and quick to implement&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If we needed selectors or animations, we used:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CSS modules&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Namespaced css&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Local to your component:&lt;/strong&gt; Namespaces classes to your component&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Native css syntax:&lt;/strong&gt; Uses regular CSS syntax&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Tests
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Unit test (components)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I strongly believe that unit testing components is a waste of time and energy. &lt;/p&gt;

&lt;p&gt;Components will be tested manually with or without unit tests. Testing things that can be easily spotted by eye is meaningless.&lt;/p&gt;

&lt;p&gt;The only case where I’ve seen a benefit is when working on a UI library that serves several projects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Unit test (logic)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As previously mentioned, if you need to test logic, extract it from a custom hook and place it in a utils file. Separate the logic from native hooks (e.g., &lt;code&gt;useState&lt;/code&gt;, &lt;code&gt;useEffect&lt;/code&gt;) and test the logic itself.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
If a custom hook formats data before storing it in a state, extract the format data logic into a utils file and test it there.&lt;/p&gt;

&lt;p&gt;Testing a function is easier than testing a hook.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;End 2 end testing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I strongly believe that unit testing components is a waste of time and energy &lt;strong&gt;because&lt;/strong&gt; of E2E testing.&lt;/p&gt;

&lt;p&gt;Testing a user scenario covers more than just components. It checks if all features of your application are well-implemented together.&lt;/p&gt;

&lt;p&gt;E2E testing ensures that critical user paths are working properly: logging in, buying, liking, sharing, etc., depending on your application's business model. &lt;/p&gt;

&lt;p&gt;These tests are directly linked to the value of your product. It is more crucial than making sure a FAQ button dispatches an event properly.&lt;/p&gt;
&lt;h2&gt;
  
  
  conclusion
&lt;/h2&gt;

&lt;p&gt;Each project has its own specificities, and each team has its familiarities with stacks. This architecture and stack won’t fit every project.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The best stack is the one you know&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;An expert in JavaScript will build a better app in JavaScript than in Rust, even if Rust is known for its performances.&lt;/p&gt;

&lt;p&gt;We were a team of five (designer, product manager, engineering manager, and engineers) working on this project. This was aimed to be an internal tool used by our company and it works great.&lt;/p&gt;

&lt;p&gt;The workflow is really smooth, and other teams can implement features without difficulties.&lt;/p&gt;

&lt;p&gt;The success of choosing a architecture for your project relies on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What you want to achieve with it ?&lt;/li&gt;
&lt;li&gt;Who will work on it ?&lt;/li&gt;
&lt;li&gt;Who will maintaining it ?&lt;/li&gt;
&lt;li&gt;Are all member of the team aligned with it ?&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;I hope you enjoyed this article. &lt;/p&gt;

&lt;p&gt;If so, don’t hesitate to keep in contact with me:&lt;br&gt;
&lt;a href="https://x.com/ArtiumWs" class="ltag_cta ltag_cta--branded"&gt;Stay in touch on X (Twitter)&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;If not, please feel free to add your critiques in the comments.&lt;/p&gt;




&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;p&gt;What is locality of behaviour:&lt;br&gt;
&lt;a href="https://htmx.org/essays/locality-of-behaviour/"&gt;https://htmx.org/essays/locality-of-behaviour/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What is modular monolith:&lt;br&gt;
&lt;a href="https://www.milanjovanovic.tech/blog/what-is-a-modular-monolith"&gt;https://www.milanjovanovic.tech/blog/what-is-a-modular-monolith&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How to structure a vue project:&lt;br&gt;
&lt;a href="https://dev.to/alexanderop/how-to-structure-vue-projects-20i4"&gt;https://dev.to/alexanderop/how-to-structure-vue-projects-20i4&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Documentation about react-hooks-testing-library:&lt;br&gt;
&lt;a href="https://github.com/testing-library/react-hooks-testing-library"&gt;https://github.com/testing-library/react-hooks-testing-library&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Documentation about styled components:&lt;br&gt;
&lt;a href="https://styled-components.com/"&gt;https://styled-components.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Documentation about atomic design:&lt;br&gt;
&lt;a href="https://atomicdesign.bradfrost.com/chapter-2/"&gt;https://atomicdesign.bradfrost.com/chapter-2/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How tailwind optimise for production:&lt;br&gt;
&lt;a href="https://tailwindcss.com/docs/optimizing-for-production"&gt;https://tailwindcss.com/docs/optimizing-for-production&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What is css modules:&lt;br&gt;
&lt;a href="https://github.com/css-modules/css-modules"&gt;https://github.com/css-modules/css-modules&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>react</category>
    </item>
    <item>
      <title>React-Compiler: When React becomes Svelte</title>
      <dc:creator>A R T I U M</dc:creator>
      <pubDate>Sun, 02 Jun 2024 17:34:17 +0000</pubDate>
      <link>https://dev.to/artiumws/react-compiler-when-react-becomes-svelte-5969</link>
      <guid>https://dev.to/artiumws/react-compiler-when-react-becomes-svelte-5969</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;The React ecosystem is evolving, and the React Compiler is a game-changer. Here’s a comprehensive look at how this new tool enhances performance by automating optimisations.&lt;br&gt;
Check out my insights and predictions.&lt;/p&gt;

&lt;p&gt;I believe hyperlinks in articles can be distracting. You will find the sources that helped my reflections at the end of this article.&lt;/p&gt;

&lt;p&gt;With that said, let’s dive into the context.&lt;/p&gt;
&lt;h3&gt;
  
  
  React
&lt;/h3&gt;

&lt;p&gt;In 2013, browsers were inefficient at updating the DOM. The React team developed a new approach called the Virtual DOM (VDOM). Elements are first updated in the VDOM before being passed to the actual DOM.&lt;/p&gt;

&lt;p&gt;Reactivity in React is handled at run time. When a component re-renders, it updates the view along with its nested components. This process can be optimised using techniques such as hooks (&lt;code&gt;useCallback&lt;/code&gt; and &lt;code&gt;useMemo&lt;/code&gt;) and memoization (&lt;code&gt;memo&lt;/code&gt;).&lt;/p&gt;
&lt;h3&gt;
  
  
  Svelte
&lt;/h3&gt;

&lt;p&gt;By 2016, browsers had evolved, and updating the DOM directly was no longer as slow. Svelte compiles the code into optimised JavaScript that interacts directly with the DOM.&lt;/p&gt;

&lt;p&gt;Reactivity in Svelte is handled at build time. Svelte compiler binds state to elements, allowing for more fine-grained updates.&lt;/p&gt;
&lt;h3&gt;
  
  
  Reactivity
&lt;/h3&gt;

&lt;p&gt;Everyone seems to have their own definition of it. So here is mine:&lt;br&gt;
&lt;em&gt;Reactivity is the way the view responds to a change in the state&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The relation between state and the view is as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;state&lt;/strong&gt; is logical representation of a &lt;strong&gt;view&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;view&lt;/strong&gt; is visual manifestation of a &lt;strong&gt;state&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s consider the following example:&lt;br&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%2Fzr6wo61rya92d1orqqg1.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%2Fzr6wo61rya92d1orqqg1.png" alt="The relation between state and the view" width="800" height="394"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is how both frameworks will handle reactivity if a new task is added to the list:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;React&lt;/strong&gt;&lt;br&gt;
React will update the parent (&lt;code&gt;TodoList&lt;/code&gt;) state (&lt;code&gt;todos&lt;/code&gt;) to add a new task. It will re-render the parent which will trigger each child (&lt;code&gt;Task&lt;/code&gt;) to re-render.&lt;/p&gt;

&lt;p&gt;This operation can be optimised with hooks to prevent unnecessary re-renders.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Svelte&lt;/strong&gt;&lt;br&gt;
Svelte will add an new items to the state and append a new DOM element to the list.&lt;/p&gt;

&lt;p&gt;No optimisation required.&lt;/p&gt;
&lt;h3&gt;
  
  
  React compiler
&lt;/h3&gt;

&lt;p&gt;The previous example highlights the need to optimise React code to prevent unnecessary re-renders. As a developer, it feels like you need to handle the framework's optimisation yourself.&lt;/p&gt;

&lt;p&gt;This can be cumbersome and lead to two patterns I’ve observed in my career:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Those who never use optimisation hooks. Waiting for a optimisation issue to appear and investigating and fixing them (my approach)&lt;/li&gt;
&lt;li&gt;Those who overuse optimisation hooks. Wrapping all functions and computations into hooks to reduce the chance of optimisation issues.  Reducing at the same time the readability and maintainability of  the code base.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Those twos opposing approaches often lead to arguments in PRs, slowing down the overall workflow.&lt;/p&gt;

&lt;p&gt;React compiler solve this issue by analysing your code and applying optimisation at build time. &lt;br&gt;
An interesting aspect is optimisation will use Javascript primitives and not hooks.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;the compiler memoizes using low-level primitives, not via &lt;code&gt;useMemo&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you already used hooks to optimise your code base. Don’t worry, the compiler will keep your optimisations, allowing you to implement it granularly.&lt;/p&gt;

&lt;p&gt;One last thing to keep in mind is that the React Compiler will skip components that don’t respect React rules. To ensure your codebase respect these rules, you can add this linting rule — &lt;code&gt;react-compiler/react-compiler&lt;/code&gt; — created for this purpose.&lt;/p&gt;

&lt;p&gt;This will ensure your codebase is future-proof and can use React Compiler once it’s released.&lt;/p&gt;
&lt;h3&gt;
  
  
  Future
&lt;/h3&gt;

&lt;p&gt;The first version of React compiler focuses on  hooks (&lt;code&gt;useCallback&lt;/code&gt; and &lt;code&gt;useMemo&lt;/code&gt;) and memoization (&lt;code&gt;memo&lt;/code&gt;) to facilitate optimisation. It optimise the code using Javascript primitives to achieve what they call "&lt;em&gt;fine-grained reactivity&lt;/em&gt;".&lt;br&gt;
This approach is very similar to what Svelte compiler already provides.&lt;/p&gt;

&lt;p&gt;In the future, React may not only optimise during compilation but also build an optimised Javascript that interacts directly with the DOM, removing the VDOM abstraction leading to improved performances.&lt;/p&gt;



&lt;p&gt;I hope you enjoyed this article. &lt;/p&gt;

&lt;p&gt;If so, don’t hesitate to keep in contact with me:&lt;br&gt;
&lt;a href="https://x.com/ArtiumWs" class="ltag_cta ltag_cta--branded"&gt;Stay in touch on X (Twitter)&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;If not, please feel free to add your critiques in the comments.&lt;/p&gt;




&lt;h3&gt;
  
  
  Sources
&lt;/h3&gt;

&lt;p&gt;As promised, here are all the sources for more information on the topic.&lt;/p&gt;

&lt;p&gt;What is the Virtual Dom:&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/reactjs-virtual-dom/"&gt;https://www.geeksforgeeks.org/reactjs-virtual-dom/&lt;/a&gt;&lt;br&gt;
Conference about React philosophy:&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=x7cQ3mrcKaY"&gt;https://www.youtube.com/watch?v=x7cQ3mrcKaY&lt;/a&gt;&lt;br&gt;
Why Virtual Dom is not the best approach:&lt;br&gt;
&lt;a href="https://svelte.dev/blog/virtual-dom-is-pure-overhead"&gt;https://svelte.dev/blog/virtual-dom-is-pure-overhead&lt;/a&gt;&lt;br&gt;
Conference about Svelte philosophy:&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=AdNJ3fydeao"&gt;https://www.youtube.com/watch?v=AdNJ3fydeao&lt;/a&gt;&lt;br&gt;
React-compiler linting rules:&lt;br&gt;
&lt;a href="https://www.npmjs.com/package/eslint-plugin-react-compiler"&gt;https://www.npmjs.com/package/eslint-plugin-react-compiler&lt;/a&gt;&lt;br&gt;
React-compiler doc:&lt;br&gt;
&lt;a href="https://react.dev/learn/react-compiler"&gt;https://react.dev/learn/react-compiler&lt;/a&gt;&lt;br&gt;
React-compiler github discussion:&lt;br&gt;
&lt;a href="https://github.com/reactwg/react-compiler/discussions/5"&gt;https://github.com/reactwg/react-compiler/discussions/5&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>react</category>
    </item>
  </channel>
</rss>
