<?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: Yogesh Galav</title>
    <description>The latest articles on DEV Community by Yogesh Galav (@yogeshgalav7).</description>
    <link>https://dev.to/yogeshgalav7</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%2F905614%2F82b0ec35-b511-4c0b-974b-41a79c9cb8d4.jpg</url>
      <title>DEV Community: Yogesh Galav</title>
      <link>https://dev.to/yogeshgalav7</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yogeshgalav7"/>
    <language>en</language>
    <item>
      <title>Repository vs Service Pattern</title>
      <dc:creator>Yogesh Galav</dc:creator>
      <pubDate>Tue, 30 Dec 2025 16:32:08 +0000</pubDate>
      <link>https://dev.to/yogeshgalav7/repository-vs-service-pattern-4hhk</link>
      <guid>https://dev.to/yogeshgalav7/repository-vs-service-pattern-4hhk</guid>
      <description>&lt;p&gt;Hello Developers!!&lt;/p&gt;

&lt;p&gt;There's a long outstanding debate between Repository Pattern and Service Pattern. What should we use and where?&lt;br&gt;
Take a look at below given idea, Nobody is being talking about it but ever since I implemented it in enterprise grade application, the things become easy to implement especially in Laravel.&lt;/p&gt;

&lt;p&gt;Repository Pattern&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Business logic &lt;/li&gt;
&lt;li&gt;Database queries &lt;/li&gt;
&lt;li&gt;Model abstraction &lt;/li&gt;
&lt;li&gt;Keeps controllers thin &lt;/li&gt;
&lt;li&gt;No inheritance, just direct static method calls&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Service Pattern&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Third-party integrations &lt;/li&gt;
&lt;li&gt;SMS, Email, Payment gateway&lt;/li&gt;
&lt;li&gt;External APIs &lt;/li&gt;
&lt;li&gt;Infrastructure logic &lt;/li&gt;
&lt;li&gt;Interface or abstract class necessary for changing service in future&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F00wijdxh9cc6re0xe3um.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F00wijdxh9cc6re0xe3um.png" alt=" " width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Please Like and Share if you found this insightful. &lt;br&gt;
Thanks and Regards!&lt;br&gt;
Yogesh Galav &lt;/p&gt;

&lt;p&gt;Please Like and Share if you found this insightful&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>php</category>
      <category>product</category>
    </item>
    <item>
      <title>Ideal Testing framework app</title>
      <dc:creator>Yogesh Galav</dc:creator>
      <pubDate>Thu, 04 Dec 2025 07:01:51 +0000</pubDate>
      <link>https://dev.to/yogeshgalav7/ideal-testing-framework-app-3gfi</link>
      <guid>https://dev.to/yogeshgalav7/ideal-testing-framework-app-3gfi</guid>
      <description>&lt;p&gt;Hello friends!!&lt;/p&gt;

&lt;p&gt;Hope you are doing well, This post is mainly for QA guys who writes E2E testing code in playwright or puppeteer or any other framework. Before moving any further let's start with problems or motivation that occur while writing these tests.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Long running Tests.&lt;/li&gt;
&lt;li&gt;Complicated test flows.&lt;/li&gt;
&lt;li&gt;Duplicate Code.&lt;/li&gt;
&lt;li&gt;No track of regression or future tests.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These all problems can be shorted with simple architecture adaptions in the code. I will explain in points.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Keep Index file or entry file which declares all tests in one place.&lt;/li&gt;
&lt;li&gt;Keep tests in order Insertion, Updation then Deletion.&lt;/li&gt;
&lt;li&gt;Write regressions or future tests in same file as commented code or ToDo.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Thanks and Have a Nice Day.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>e2etesting</category>
      <category>playwright</category>
      <category>puppeteer</category>
    </item>
    <item>
      <title>Why I fed up with Inertia?</title>
      <dc:creator>Yogesh Galav</dc:creator>
      <pubDate>Sat, 23 Aug 2025 06:10:54 +0000</pubDate>
      <link>https://dev.to/yogeshgalav7/why-i-fed-up-with-inertia-1oc2</link>
      <guid>https://dev.to/yogeshgalav7/why-i-fed-up-with-inertia-1oc2</guid>
      <description>&lt;p&gt;In recent times while working as Tech lead, I was very much obssesed with optimizing loading time of website and our product website literally took 10-15 secs to load.&lt;br&gt;
That's a good reason of frustration right?&lt;br&gt;
Our Team had done many efforts to resolve the same but all in wain.&lt;br&gt;
We purchased CDN, optimized queries, defer loaded resources, but nothing decreased that FCP time. BTW each optimization has it's own benifit and other then FCP they really bring calculative changes. &lt;/p&gt;

&lt;p&gt;But from user perspective we have done nothing for months😔&lt;/p&gt;

&lt;p&gt;Hence it was the time to remove the culprit we always avoided, because it was love of otwell and people always defended it including me😅&lt;br&gt;
You guessed it right, the culprit was inertia itself. and it's drawback which can never be cured is server call before every page load.&lt;/p&gt;

&lt;p&gt;Suppose I'm sitting in India and server is located in USA, then here's what will happen.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First the DNS will resolve then our server code from usa will run and return html result to India.&lt;/li&gt;
&lt;li&gt;After loading Html your browser will know, Ohh! it uses Inertia I need to again request to server if I can open this route or is there any prop I need to load before loading and executing anything else.&lt;/li&gt;
&lt;li&gt;Then our holy grail inertia request goes to USA and fetch little props and check conditions which most of the time is not present on get routes.&lt;/li&gt;
&lt;li&gt;After this long awaited time in which we can do nothing, Now our browser in India will start loading css,js files mentioned in html from USA or CDN.&lt;/li&gt;
&lt;li&gt;Now the time comes when our js will execute and render the page to user.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can understand better if you use inertia and look in network tab.&lt;/p&gt;

&lt;p&gt;Inertia lovers will suggest solutions to problems generated by inertia itself but I will argue with them one by one.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First as I mention all the solutions are to coverup drawbacks of inertia which were never present in first place.&lt;/li&gt;
&lt;li&gt;From Inertia 2 there are solution like load resources on hover of link or load before user's intention. It will always work if you have rich pocket, but what if server is already busy with loading resources and pages of 100 other users at the same time and with php you know the condition, right?&lt;/li&gt;
&lt;li&gt;If you use api's only atleast you can load and execute frontend and show loaders.&lt;/li&gt;
&lt;li&gt;If you want to save effort of writing routes 2 times, with packages like uplugin-vue, you wouldn't have to write your url even once and at the same time you can maintain folder structure for frontend with file based routing.&lt;/li&gt;
&lt;li&gt;Last but not the least, if you need roles and permission on every route, or need some initial data as alternative to HandleInertia, You can do that via window variable.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Every technology has it's own pros and cons but I think every B2C product has heavy traffic or busy server and want to save costs, hence take your decisions accordingly. A single inertia request before page load wouldn't cost you but thousands and millions will. &lt;/p&gt;

&lt;p&gt;I hope you enjoyed reading this,&lt;br&gt;
Thanks and have a nice day.  &lt;/p&gt;

</description>
      <category>laravel</category>
      <category>inertia</category>
      <category>frontend</category>
      <category>fcp</category>
    </item>
    <item>
      <title>How to manage large env files?</title>
      <dc:creator>Yogesh Galav</dc:creator>
      <pubDate>Tue, 06 May 2025 08:57:43 +0000</pubDate>
      <link>https://dev.to/yogeshgalav7/how-to-manage-large-env-files-475o</link>
      <guid>https://dev.to/yogeshgalav7/how-to-manage-large-env-files-475o</guid>
      <description>&lt;p&gt;Hello friends,&lt;/p&gt;

&lt;p&gt;I'm Yogesh Galav and currently working as Technical Product Manager at InstaWP, Recently I came across a problem of manually managing env file for multiple environments so I tried to came up with cost effective solution to it, I hope you read it with open mind.&lt;br&gt;
The topic of this blog could also be:&lt;/p&gt;

&lt;h2&gt;
  
  
  How I managed to decrease the size of env with 400+ keys to just 40 keys.
&lt;/h2&gt;

&lt;p&gt;Like most of you at first I faced hurdle from my team mates of opposing dynamism or quick change culture, but after application was still running smoothly in develop/staging env I was able to gain their trust, hence looking forward to gain yours too.&lt;/p&gt;

&lt;p&gt;Some of you might have heard of solution to this problem like Infisical, Vault, AWS Parameter Store, Google Secret Manager but they involves cost in some form like money or work or maintenance.&lt;br&gt;
Hence I tried to came up with solution which involves one time change of one person. It was like setting up a new culture. I know setting into a new culture is hard but Software development is all about it.&lt;/p&gt;

&lt;p&gt;Let's now move directly to the point. Pros and Cons of ENV file management&lt;/p&gt;

&lt;p&gt;Pros:&lt;br&gt;
Env file is not shared with version control like git. &lt;br&gt;
Cons:&lt;br&gt;
Manual management is too much risky and keys sharing is still needed.&lt;/p&gt;

&lt;p&gt;Pros:&lt;br&gt;
Env keys are kept as secret. &lt;br&gt;
Cons:&lt;br&gt;
Developers add keys which are not even a secret like urls.&lt;/p&gt;

&lt;p&gt;Pros:&lt;br&gt;
Env allows to make quick change like Christmas discount.&lt;br&gt;
Cons:&lt;br&gt;
Quick change sometime can break things in unknown way.&lt;/p&gt;

&lt;p&gt;If you only sees pros mentioned above and not the cons then you may purchase solutions in market. No hard feelings.&lt;/p&gt;

&lt;p&gt;But if you also understand the cons mentioned above then your brain might be searching for solution and strategy to implement it.&lt;br&gt;
Here's what I did in step by step manner.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First of all you need intermediate files like const.js/const.php
which will provide all the keys to your application as destination and also will have fallback value if not present in source env file.
If you are using framework like laravel it already provide config files which can use env keys and fallbacks.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;DISCOUNT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DISCOUNT&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;5%&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Replace env values with const values imported from intermediate file. You can transfer some of the logic to that file as well. Most values in this file will be decided by app environment i.e. local, staging, production etc
&lt;/li&gt;
&lt;/ol&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;DISCOUNT&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;const.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;userDiscount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;DISCOUNT&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Categorize ENV keys, with help of your team you can categorize your ENV keys into Unused/depreciated, Unique values, Same value for all env, different value only for prod. I personally used slack canvas for it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Delete Unused/depreciated ENV keys.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Delete ENV keys which holds insensitive values like urls or text. And hardcode it in intermediate file. In most of the cases this values will never change neither they are sensitive which abuse dev can make use of,&lt;br&gt;
hence it's better to reduce load.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;TERM_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/term&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;If you are using same values for local and prod, how is that a secret?&lt;br&gt;
Hence you can hardcode that in intermediate file as well.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Last remaining items will be Unique values. Your local env will be smallest then dev or stage, Prod env will still hold much key values because they are secrets which can't be shared. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By reaching here, you and your team has removed lot of pain by reducing ENV size and changing the culture.&lt;/p&gt;

&lt;p&gt;BTW If you depend on too much services, It might increase your cost so try to reduce those services as well.&lt;/p&gt;

&lt;p&gt;Thanks for the read,&lt;br&gt;
Yogesh Galav  &lt;/p&gt;

</description>
      <category>programming</category>
      <category>management</category>
      <category>productivity</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Husky pre-commit for Laravel &amp; Vuejs.</title>
      <dc:creator>Yogesh Galav</dc:creator>
      <pubDate>Sun, 09 Feb 2025 14:40:55 +0000</pubDate>
      <link>https://dev.to/yogeshgalav7/husky-pre-commit-for-laravel-vuejs-4eij</link>
      <guid>https://dev.to/yogeshgalav7/husky-pre-commit-for-laravel-vuejs-4eij</guid>
      <description>&lt;p&gt;This configuration will help you maintain ideal code quality in Laravel and Vuejs application. The best part is this configuration will help you better the code quality day by day by each developer so you don't have to do code freeze for months just to improve code quality.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. First let's start by adding "Duster" package to Laravel
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require tightenco/duster &lt;span class="nt"&gt;--dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Now let's also add &lt;a href="https://github.com/phpstan/phpstan" rel="noopener noreferrer"&gt;PHPstan&lt;/a&gt; and &lt;a href="https://github.com/larastan/larastan" rel="noopener noreferrer"&gt;Larastan&lt;/a&gt; for laravel
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require &lt;span class="nt"&gt;--dev&lt;/span&gt; phpstan/phpstan
composer require &lt;span class="nt"&gt;--dev&lt;/span&gt; &lt;span class="s2"&gt;"larastan/larastan:^3.0"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now add configuration file for phpstan with name of "phpstan.neon"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;includes:
    - vendor/larastan/larastan/extension.neon
    - vendor/nesbot/carbon/extension.neon

parameters:

    paths:
        - app/

    &lt;span class="c"&gt;# Level 10 is the highest level&lt;/span&gt;
    level: 5

&lt;span class="c"&gt;#    ignoreErrors:&lt;/span&gt;
&lt;span class="c"&gt;#        - '#PHPDoc tag @var#'&lt;/span&gt;
&lt;span class="c"&gt;#&lt;/span&gt;
&lt;span class="c"&gt;#    excludePaths:&lt;/span&gt;
&lt;span class="c"&gt;#        - ./*/*/FileToBeExcluded.php&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. For Frontend eslint is enough so let's add that
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; husky eslint eslint-plugin-vue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following lines to package.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"lint"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"eslint . --fix --ignore-pattern .gitignore"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"prepare"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"husky"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"lint-staged"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"*.{vue,js}"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"eslint --fix"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's add eslint configuration for Vue in latest format&lt;br&gt;
create a file on root with name "eslint.config.js"&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="nx"&gt;globals&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;globals&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;pluginJs&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@eslint/js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;pluginVue&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;eslint-plugin-vue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;files&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;**/*.{js,mjs,cjs,vue}&lt;/span&gt;&lt;span class="dl"&gt;"&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;span class="na"&gt;languageOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;globals&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;globals&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;browser&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="nx"&gt;pluginJs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;configs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;recommended&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;pluginVue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;configs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;flat/recommended&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue/html-indent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;error&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;attribute&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;baseIndent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;closeBracket&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;alignAttributesVertically&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;}],&lt;/span&gt;
            &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;vue/html-closing-bracket-newline&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;error&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;singleline&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;never&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;multiline&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;always&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
            &lt;span class="p"&gt;}],&lt;/span&gt;
            &lt;span class="c1"&gt;// override/add rules settings here, such as:&lt;/span&gt;
            &lt;span class="c1"&gt;//   'vue/no-unused-vars': 0,&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;h2&gt;
  
  
  4. Finally let's configure &lt;a href="https://typicode.github.io/husky/get-started.html" rel="noopener noreferrer"&gt;Husky&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;The husky pre-commit file will only run above linting tools on staged files and will not stop commit if these command fails with errors.&lt;br&gt;
If you want to fail commit if any error occurs then just remove "|| true" part.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx husky init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# .husky/pre-commit&lt;/span&gt;
./vendor/bin/duster fix &lt;span class="nt"&gt;--dirty&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;true
&lt;/span&gt;npx lint-staged &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt;

&lt;span class="c"&gt;# Get list of staged PHP files&lt;/span&gt;
&lt;span class="nv"&gt;STAGED_FILES&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;git diff &lt;span class="nt"&gt;--cached&lt;/span&gt; &lt;span class="nt"&gt;--name-only&lt;/span&gt; &lt;span class="nt"&gt;--diff-filter&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;AM | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="s1"&gt;'\.php$'&lt;/span&gt; | &lt;span class="nb"&gt;tr&lt;/span&gt; &lt;span class="s1"&gt;'\n'&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$STAGED_FILES&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="c"&gt;# Run PHPStan only on staged PHP files&lt;/span&gt;
  composer phpstan &lt;span class="nv"&gt;$STAGED_FILES&lt;/span&gt;  &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;true
&lt;/span&gt;&lt;span class="k"&gt;else
  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"No PHP files to analyze."&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>laravel</category>
      <category>vue</category>
      <category>husky</category>
      <category>phpstan</category>
    </item>
    <item>
      <title>Husky pre-commit configuration for Laravel Vuejs.</title>
      <dc:creator>Yogesh Galav</dc:creator>
      <pubDate>Sun, 09 Feb 2025 14:36:58 +0000</pubDate>
      <link>https://dev.to/yogeshgalav7/husky-pre-commit-configuration-for-laravel-vuejs-3d6o</link>
      <guid>https://dev.to/yogeshgalav7/husky-pre-commit-configuration-for-laravel-vuejs-3d6o</guid>
      <description></description>
      <category>laravel</category>
      <category>vue</category>
    </item>
    <item>
      <title>How to optimize Vite app?</title>
      <dc:creator>Yogesh Galav</dc:creator>
      <pubDate>Sat, 07 Dec 2024 06:48:43 +0000</pubDate>
      <link>https://dev.to/yogeshgalav7/how-to-optimize-vite-app-i89</link>
      <guid>https://dev.to/yogeshgalav7/how-to-optimize-vite-app-i89</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fvite.dev%2Flogo.svg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fvite.dev%2Flogo.svg" alt="Vite" width="410" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hello guys!!&lt;/p&gt;

&lt;p&gt;Currently as a tech lead I got task of optimizing &lt;strong&gt;Vite&lt;/strong&gt; App which was also using vue and inertia. I read many blogs but they all were either made for webpack or didn't made reasonable output, &lt;br&gt;
After lot of research I had implemented some solutions which you must use.&lt;br&gt;
Vite is awesome tool for bundling which already implements multiple strategies like &lt;strong&gt;chunking, versioning, compression&lt;/strong&gt; for optimizing you app, so we can save some hard work.&lt;br&gt;
Hence, if you are not using Vite you must look forward for new technology.&lt;br&gt;
In my case the project was already big enough so the code written by different developers wasn't implementing ways to decrease load of app.&lt;/p&gt;

&lt;p&gt;So for summary here's what I'm going to implement&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Common bundle for legacy packages.&lt;/li&gt;
&lt;li&gt;API defer.&lt;/li&gt;
&lt;li&gt;Third party script async and defer.&lt;/li&gt;
&lt;li&gt;Lazy load Modals and charts.&lt;/li&gt;
&lt;li&gt;Use ES6 modules.&lt;/li&gt;
&lt;li&gt;Vite plugins.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's discuss them in detail&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Common bundle for legacy packages.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Vite already separates pages and components into different bundles which you can see in network tab but some of those bundles are still size heavy, hence take much time. &lt;/li&gt;
&lt;li&gt;Vite also implements versioning so each time you release new version users have to download those heavy bundles again.&lt;/li&gt;
&lt;li&gt;Also they have to download images again. All this effort can be saved with browser cache. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Only thing is you must know what to put in browser cache and what not.&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;For suggestion, you may choose all images to not included in versioning.&lt;/li&gt;
&lt;li&gt;And for packages which you may choose legacy packages like moment and package you will not update in coming years.&lt;/li&gt;
&lt;li&gt;Although it's not suggested to use legacy packages but in reality for large or legacy project it's not an easy job.&lt;/li&gt;
&lt;li&gt;You can also identify big chunks or packages from visualizer plugin of Vite, link given below.&lt;/li&gt;
&lt;li&gt;Here's the code you can attach in vite.config.js for having more control over versioning.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="nx"&gt;build&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;rollupOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;entryFileNames&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`assets/[name]-[hash].js`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;assetFileNames&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;assetInfo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="c1"&gt;// Get the name from the array of names (usually the first/only entry)&lt;/span&gt;
                    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fileName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;assetInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="p"&gt;?.[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

                    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.(&lt;/span&gt;&lt;span class="sr"&gt;png|jpg|jpeg|gif|svg|webp&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="sr"&gt;$/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fileName&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`images/[name][extname]`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;
                    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`css/[name]-[hash][extname]`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="p"&gt;},&lt;/span&gt;
                &lt;span class="na"&gt;chunkFileNames&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;chunkInfo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;is_manual_chunk&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;chart&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;quill&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;datepicker&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;moment&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;jsoneditor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;chunkInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
                    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;is_manual_chunk&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`js/[name].js`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;
                    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`js/[name]-[hash].js`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="p"&gt;},&lt;/span&gt;
                &lt;span class="na"&gt;manualChunks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="na"&gt;core&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@inertiajs/vue3&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@sentry/vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                    &lt;span class="na"&gt;chart&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@j-t-mcc/vue3-chartjs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;chart.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                    &lt;span class="na"&gt;quill&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@vueup/vue-quill&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                    &lt;span class="na"&gt;datepicker&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@vuepic/vue-datepicker&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                    &lt;span class="na"&gt;jsoneditor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@json-editor/json-editor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                    &lt;span class="na"&gt;moment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;moment&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;moment-timezone&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;moment-duration-format&lt;/span&gt;&lt;span class="dl"&gt;'&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;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;h2&gt;
  
  
  2. API defer.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;This second step looks so easy but brings a great difference to app load. All you have to do load important API's first and non-important API's at last.&lt;/li&gt;
&lt;li&gt;For the API's which you wanna load first, call them from created hook or setup initial lines in vue3 of layout file.&lt;/li&gt;
&lt;li&gt;A bad approach would be to call it from entry-file because it blocks app mounting, but you may use it if necessary.&lt;/li&gt;
&lt;li&gt;The API's which you wanna load in last, keep them in &lt;code&gt;defineAsyncComponent&lt;/code&gt; in vue. For react you can use async component via composition but it's difficult so react lover please give some suggestion in comment.&lt;/li&gt;
&lt;li&gt;The API's you wanna load in between, try to put them in mounted or useEffect hook part not created hook or directly in script part. &lt;/li&gt;
&lt;li&gt;Try to use less API call, as it will take some time to go through DNS, then server, then firewall, then your code Middlewares and with some extra code dependencies. In my case I combined multiple API into initial-data API.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  3. Third party script async and defer.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Your project may be using third party scripts in main HTML element like google analytics, chat plugin etc.&lt;/li&gt;
&lt;li&gt;If you define this scripts in head section then they will block further scripts and load first which is not needed at all. If your user can't interact with app quickly what's the point of all other tools.&lt;/li&gt;
&lt;li&gt;Try to use these scripts in bottom body part instead of head section.&lt;/li&gt;
&lt;li&gt;Now we have to decide between defer and acync script for those who don't know defer will call your script after page loads and async will load script in parallel thread non-blocking you main app JS. &lt;/li&gt;
&lt;li&gt;In my case I used async for loading third party scripts
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt; &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;async&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://www.googletagmanager.com/gtag/js?id=G-DNJN1PF3CS"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;and defer for executing those script
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;defer&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dataLayer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dataLayer&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;gtag&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;&lt;span class="nx"&gt;dataLayer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;);}&lt;/span&gt;
&lt;span class="nf"&gt;gtag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

&lt;span class="nf"&gt;gtag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;config&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;G-XXXXXXX&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  4. Lazy load Modals and charts.
&lt;/h2&gt;

&lt;p&gt;In other blogs this part may be on top but I kept it below because it may not bring significant difference in app load unless you modal is calling some API's or is using large/heavy component&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Please don't lazy load modal component itself but the component that's used inside it, In most case it would be passed by slot.&lt;/li&gt;
&lt;li&gt;You can also lazy load chart components and other benefit you may find with it is suspense component till main component is loaded.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  5. Use ES6 modules.
&lt;/h2&gt;

&lt;p&gt;For those who don't know there's two type of js module, CommonJs and ES6, there is fight going on between them but most probably ES6 will win, because it's newer and have benefit of tree-shaking which we want to make use of.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This step also might not bring significant difference to your app bundle size but it's good to have. For me it was 12kb.&lt;/li&gt;
&lt;li&gt;For those old packages which are created in CommonJS does not provide tree-shaking and hence increases the bundle size.&lt;/li&gt;
&lt;li&gt;Most common use case is lodash which is used in many projects, some developers even use it in new projects so the alternative is &lt;code&gt;lodash-es&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;and you must use it in correct way otherwise it wont make any difference. Even I spent hours on figuring out why it isn't working 😅.
&lt;/li&gt;
&lt;/ul&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;flatten&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;l_flatten&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reduce&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;l_reduce&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="s2"&gt;lodash-es&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;h2&gt;
  
  
  6. Vite plugins.
&lt;/h2&gt;

&lt;p&gt;Vite provides various other packages to enhance your app. some of the packages I will mention here with link so you can read in detail about them, if you know others please mention them in comment&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/vbenjs/vite-plugin-compression" rel="noopener noreferrer"&gt;ViteCompression&lt;/a&gt; from "vite-plugin-compression"&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/vite-pwa/vite-plugin-pwa" rel="noopener noreferrer"&gt;VitePWA&lt;/a&gt; from "vite-plugin-pwa"&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/btd/rollup-plugin-visualizer" rel="noopener noreferrer"&gt;Visualizer&lt;/a&gt; from "rollup-plugin-visualizer"&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/gatsbylabs/vite-plugin-unused" rel="noopener noreferrer"&gt;pluginUnused&lt;/a&gt; from "@gatsbylabs/vite-plugin-unused"&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/unplugin/unplugin-vue-components" rel="noopener noreferrer"&gt;AutoImport&lt;/a&gt; from "unplugin-vue-components/vite"&lt;/li&gt;
&lt;li&gt;Also please try to use import.meta.env&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  7. Use CDN
&lt;/h2&gt;

&lt;p&gt;I have written this in last as it comes at a cost but for the cost being paid it provide massive improvement in loading time of your Vite bundle assets. and all you have to do is add one simple static line of code to vite config file.&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;CDN_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;CDN_URL&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
  &lt;span class="na"&gt;base&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;CDN_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;//cdn.example.com&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;h2&gt;
  
  
  8. Optimize Inertia, if you use it
&lt;/h2&gt;

&lt;p&gt;Last but not the least tip, if you use Inertia, please don't make HandleInertiaMiddleware heavy, either store and load the data in session if necessary, else keep it lightweight. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thanks for read and Have a great day.&lt;/strong&gt; ❤️&lt;br&gt;
&lt;strong&gt;Please give your love and support to this post.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>vite</category>
      <category>vue</category>
      <category>react</category>
    </item>
    <item>
      <title>Why Laravel is better then NodeJs/Express?</title>
      <dc:creator>Yogesh Galav</dc:creator>
      <pubDate>Sun, 07 Jul 2024 06:33:00 +0000</pubDate>
      <link>https://dev.to/yogeshgalav7/why-laravel-is-better-then-nodejsexpress-19lo</link>
      <guid>https://dev.to/yogeshgalav7/why-laravel-is-better-then-nodejsexpress-19lo</guid>
      <description>&lt;p&gt;Hello WebDevs,&lt;br&gt;
First thing first, JS devs have more salary then PHP devs on average.&lt;br&gt;
I've come from Laravel background and recently due to less salary in php environment I switched to JS environment NodeJs/Express. You can get more salary in php but that require other knowledge like DSA, SQL or Project Management. &lt;/p&gt;

&lt;p&gt;If you are a Startup which has less time to go to market, want's less overhead tension and want cheaper employees then always prefer Laravel.&lt;/p&gt;

&lt;p&gt;The major drawback of using JS is there's no batteries included framework in JS, you have to search a good package with good documentation and actively maintain. Then learn that library. Then if in future it's not maintained or any security issue came then repeat the process again.&lt;br&gt;
While in batteries included framework majority of features will be maintained till lifetime of framework so we don't have to worry a bit.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The reality of tech world is you get more money to work on complex technology, Even if the simpler solution is more Robust.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Woof that was lot from my heart and not to be made public but will help you guys make the right decision.&lt;/p&gt;

&lt;p&gt;I will share my real world experience of onboarding to Express project. &lt;br&gt;
Let's compare implementation difference both the frameworks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Language&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Laravel is created from PHP one of the most used programming language in backend.&lt;/li&gt;
&lt;li&gt;Express is created in JS, a functional programming language made for browsers running frontend.&lt;/li&gt;
&lt;li&gt;Although you can do functional programming in PHP and OOP in JS, it's not that much supportive and easy.&lt;/li&gt;
&lt;li&gt;The only major benefit of JS is speed due to it's asynchronous nature.&lt;/li&gt;
&lt;li&gt;You can return the response while not waiting for other functions like logging or saving record/file&lt;/li&gt;
&lt;li&gt;But as con part you have to take care of async-await as well in JS, for the same reason.&lt;/li&gt;
&lt;li&gt;Php will just perform task synchronously, There's no such concept of promises or async/await here. Also due to same reason PHP is more easy to grab then JS.&lt;/li&gt;
&lt;li&gt;For performing background task in Laravel, We have Jobs and Queues.&lt;/li&gt;
&lt;li&gt;Another major difference between both languages is PHP provides optional type checking, while JS doesn't provide any type checking or else you have to use strict type checking with TypeScript.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Routes&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Express provides mostly routing features.&lt;/li&gt;
&lt;li&gt;Both frameworks provide use of separate files with name, middleware and prefix.
&lt;/li&gt;
&lt;li&gt;Laravel provide Route grouping and in node you have to use another package and learn it.&lt;/li&gt;
&lt;li&gt;Laravel provide RouteBinding in controller parameters, It can even throw 404 if data not found in database. In Express you have to do it manually and add that data to request body, there's no concept of controller parameter binding or DB checking.&lt;/li&gt;
&lt;li&gt;Laravel provide clear separation between web, api, console and channel route, A backend application generally needs all this. While in express you have to learn and implement all by yourself. If a beginner don't know what channel and console routes are Laravel will give opportunity to learn while express will not push him/her for learning.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Middleware&lt;/strong&gt;&lt;br&gt;
In Express every callback you provide to route is middleware, there's no clear difference between controller and middleware part.&lt;br&gt;
A controller business logic is always unique for some request while middleware is peace of common to multiple request and always need to be run first before or after controller. If you give express to beginner they may put middleware after request validation or controller in Express but in Laravel it's not possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Request validation&lt;/strong&gt;&lt;br&gt;
Laravel provides simple yet powerful solution for request validation like FormRequest which provides feature like authorization, validation messages, pre-validation request update and post-validation, &lt;br&gt;
While in Express you have to choose, learn and implement a package.&lt;br&gt;
then also you will not find features like FormRequest in same package.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. ORM&lt;/strong&gt;&lt;br&gt;
Express provide no ORM. When I started express I searched for good query builder and ended up with Sequalize, then learned it via documentation, then struggled a lot to implement it. then my friend told me it's not actively maintained. And then I find out recent commits in github were done by bots. Then again I found another query builder like knex, then learnt it, then also it was not as good as Eloquent ORM and Laravel DB query builder provided by default.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Logging&lt;/strong&gt;&lt;br&gt;
Last but not least logging, Laravel provide default and simple logging while I have to struggle a lot to implement logging via another third party package called winston. then for keeping separate files for separate dates I have to again install another package called daily-rotate. In both framework you can install extra package to log into other channels like email or slack.&lt;/p&gt;

&lt;p&gt;In the end both are legendary frameworks, there's no hate for any framework, I only shared my experience, your experience and use case might be different. Please let me know If I'm wrong anywhere.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed reading this.&lt;br&gt;
Thanks and regards,&lt;br&gt;
Yogesh Galav&lt;/p&gt;

</description>
      <category>node</category>
      <category>php</category>
      <category>laravel</category>
      <category>express</category>
    </item>
    <item>
      <title>What are Api Standards or REST Style?</title>
      <dc:creator>Yogesh Galav</dc:creator>
      <pubDate>Sun, 30 Jun 2024 17:08:28 +0000</pubDate>
      <link>https://dev.to/yogeshgalav7/what-are-api-standards-or-rest-style-39i5</link>
      <guid>https://dev.to/yogeshgalav7/what-are-api-standards-or-rest-style-39i5</guid>
      <description>&lt;p&gt;Hello WebDevs,&lt;br&gt;
I bet whichever framework you have been working on, you must have crossed your roads with API's and would have stuck for moment what should be the standard path for the URL you could use for that API.&lt;/p&gt;

&lt;p&gt;Naming is the most difficult or brain consuming task for programmers, and when it comes to full url it becomes more difficult because they are not scoped by any block, they are all global and can be confusing if not used correctly.&lt;/p&gt;

&lt;p&gt;For this Purpose some elite member of society ( Roy Fielding ) created a framework or architectural style called REST. It's very small concept but it becomes difficult when you start using it in real world project and brain consumption becomes equal. Hence I'm writing this blog to simplify the things for you, Let's Start.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is REST?
&lt;/h2&gt;

&lt;p&gt;REST(Representational State Transfer) is a standard that guides the design and development of processes for interacting with data stored on web servers. It simplifies communication by providing various HTTP methods (such as GET, POST, PUT, DELETE) that allow us to perform CRUD operations (Create, Read, Update, Delete) on server data. Think of REST as the set of rules that govern how we communicate with servers using the HTTP protocol.&lt;/p&gt;

&lt;p&gt;In simple words,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It tells us how to change the state of our resource(db tables, files) on server with help of standard API pattern. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here server means, machine from which we are requesting to change the state of our resources.&lt;/p&gt;

&lt;p&gt;Now let's jump to real world example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Fetch Data: Get Request&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you want a list of items like list of users or post, or excel/csv containing list then we will always use Get request.&lt;/li&gt;
&lt;li&gt;If you want to filter or apply condition to the same list just use query parameters in get request. &lt;/li&gt;
&lt;li&gt;Even if you have large form for filter, try to pass only id's. but use get request. This will help you retain filter and pagination when you navigate back and forth on website.&lt;/li&gt;
&lt;li&gt;Example 1: /users/list?paginate=3&amp;amp;email=mr.yogesh.galav&amp;amp;name=yogesh&lt;/li&gt;
&lt;li&gt;Example 2: /users/:id/details&lt;/li&gt;
&lt;li&gt;Example 3: /users/:id/orders/csv&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Create Data: Post Request&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It's the most common type of web request, but real purpose of this type is to create resources on server, like create db row, create user in registration, create token in login, create or save some file like profile pic/resume, etc.&lt;/li&gt;
&lt;li&gt;If you want some operation like createOrFind, updateOrCreate then also use post request.&lt;/li&gt;
&lt;li&gt;If you don't know what type of request it should be, but want to send lot of data to server like form data or file, then use this.&lt;/li&gt;
&lt;li&gt;Example 1: /users/create&lt;/li&gt;
&lt;li&gt;Example 2: /users/:id/orders/create&lt;/li&gt;
&lt;li&gt;Example 3: /users/:id/profile-pic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Update Data: Patch Request&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For updating resources on server Patch request is used. Most of the time we may think that create and update may share same controller or business logic, but as our business logic grows it becomes harder to maintain both at same place, hence a separate route/url with patch request is beneficial.&lt;/li&gt;
&lt;li&gt;If you want update some record on database on server then use this. &lt;/li&gt;
&lt;li&gt;Example 1: /users/update&lt;/li&gt;
&lt;li&gt;Example 2: /users/:id/orders/update&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. Replace Data: Put Request&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unlike Database resources, files are generally replaced on server when it comes to update operation.&lt;/li&gt;
&lt;li&gt;If you want replace some file on server then use this. &lt;/li&gt;
&lt;li&gt;Example 1: /users/:id/profile-pic/replace&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Delete Data: Delete Request&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is most simple type of web request, as the name suggests, it is used to delete resources on server.&lt;/li&gt;
&lt;li&gt;If you want to delete some database record or file or token while logout use this. &lt;/li&gt;
&lt;li&gt;Example 1: /logout&lt;/li&gt;
&lt;li&gt;Example 2: /users/:id/delete&lt;/li&gt;
&lt;li&gt;Example 2: /users/:id/history/delete&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;These are only standards and not any hard and fast rule which will throw error somewhere so you can bend it like your choice but fundamentals should remain same so that url is clearly understandable without having to look into context or code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Please Note that I have used suffix like create, details, update, replace, delete in above api's, It was personally easy for me to manage routes this way in framework, If you like not to use them then also fine, but then you had to take care of route ordering otherwise your framework will read&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/users/create&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 as&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;/users/:id&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;I hope you enjoyed reading this.&lt;br&gt;
Thanks &amp;amp; Regards,&lt;br&gt;
Yogesh Galav &lt;/p&gt;

</description>
      <category>api</category>
      <category>rest</category>
      <category>restapi</category>
      <category>standard</category>
    </item>
    <item>
      <title>What are Composable Function?</title>
      <dc:creator>Yogesh Galav</dc:creator>
      <pubDate>Fri, 03 May 2024 18:51:11 +0000</pubDate>
      <link>https://dev.to/yogeshgalav7/what-are-composable-function-4ili</link>
      <guid>https://dev.to/yogeshgalav7/what-are-composable-function-4ili</guid>
      <description>&lt;p&gt;Since last year, I came across the concept of Composable function couple of times while learning about Vue3. When I searched on google found nothing about it, hence I might be the first person writing about it. I didn't fully understand this concept until I created my own Package &lt;a href="https://dev.to/yogeshgalav7/validate-fields-in-vuejs-1ahn"&gt;VueNiceValidate&lt;/a&gt;.&lt;br&gt;
Hence today I want to share my knowledge about composable function in this blog, which I attained from practical implementation. &lt;/p&gt;

&lt;p&gt;If I comprise my understanding in one line then it's like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Composable Function are functional representation of Class.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Yes, in OOP language like Java, Dart or even Php we have to create class and objects for declaring and using entities. Let's take example of person and fist implement in class way and then functional way. &lt;/p&gt;

&lt;p&gt;Suppose you want to have many persons in your application with same properties as name and age. Also you want a common function &lt;br&gt;
&lt;code&gt;displayInfo&lt;/code&gt; for each person.&lt;br&gt;
How would you do it? 99% of you would end up answering class and object, because that has been the way since the born of c++ and Java. Even the JavaScript which was suppose to focus on functional paradigm implemented class for the same reason.&lt;/p&gt;

&lt;p&gt;Here's how the Person class will look like in JS. In all the language class concept at core will remain the same.&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;class&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// class variables&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// constructor&lt;/span&gt;
    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;displayInfo&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;is &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; years old!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;return&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;ul&gt;
&lt;li&gt;We will have class name declaration&lt;/li&gt;
&lt;li&gt;Then class private variable declaration like name and age.&lt;/li&gt;
&lt;li&gt;Then we will implement constructor function for defining private variables at the time of creation of object, so no person can be created without name or age.&lt;/li&gt;
&lt;li&gt;At last we will implement all our functions or methods we want to operate over person.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now let's see how will we create object from this class&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;firstPerson&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;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Yogesh&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;29&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;firstPerson&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;displayInfo&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;secondPerson&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;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Piyush&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;secondPerson&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;displayInfo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I know till here was just the lame part you already now even if you have small experience with programming languages.&lt;/p&gt;

&lt;p&gt;Now What if we want to implement the same concept in functional way without using the class. &lt;br&gt;
If you are a beginner you might think why can't we just make a single file with name and age variable and export the functions.&lt;br&gt;
But it would actually create a common state like state management tool or like static variables and function. The real answer is Composable function.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Composable function are just regular function used in a way so that it creates a new copy of object each time we call it.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As per common notation we start composable function name with &lt;code&gt;use&lt;/code&gt; word. &lt;em&gt;In our case &lt;code&gt;usePerson&lt;/code&gt; will be the composable function which will create new object of person each time we will call it.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  How to implement Composable Function
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;usePerson&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;personName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;personAge&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;personName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;personAge&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;displayInfo&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;is &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; years old!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;displayInfo&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;ul&gt;
&lt;li&gt;We will create our composable function with the name of usePerson&lt;/li&gt;
&lt;li&gt;This function will take same parameters or arguments which we passed to constructor in class format. Hence it doesn't require any constructor concept.&lt;/li&gt;
&lt;li&gt;We will declare our public or private variable as simple scoped variables inside our composable function. To initialize this variables like constructor we simply initialize them at place of declaration.&lt;/li&gt;
&lt;li&gt;Then we will implement our public or private functions as simple functions.&lt;/li&gt;
&lt;li&gt;At last we will return an object including public properties. The variables and function we don't return will act as private properties, that's it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now let's see how will we create object from this composable function.&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;firstPerson&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;usePerson&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Yogesh&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;29&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;firstPerson&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;displayInfo&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;secondPerson&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;usePerson&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Piyush&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;secondPerson&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;displayInfo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we are creating firstPerson and secondPerson object by just calling usePerson function. This composable function will create new copy of name, age, displayInfo each time it will be called.&lt;/p&gt;

&lt;p&gt;It's even more simpler then class way or OOP way because it doesn't include concept like constructor or public, private variables, Just function, function and function. That's the beauty of functional programming.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed reading this and fully understood the concept of composable functions.&lt;/p&gt;

&lt;p&gt;Thanks and Regards,&lt;br&gt;
Yogesh Galav&lt;/p&gt;

</description>
      <category>composable</category>
      <category>functional</category>
      <category>javascript</category>
      <category>vue3</category>
    </item>
    <item>
      <title>Stop using Try-Catch everywhere!</title>
      <dc:creator>Yogesh Galav</dc:creator>
      <pubDate>Sat, 20 Apr 2024 03:22:34 +0000</pubDate>
      <link>https://dev.to/yogeshgalav7/stop-using-try-catch-everywhere-30im</link>
      <guid>https://dev.to/yogeshgalav7/stop-using-try-catch-everywhere-30im</guid>
      <description>&lt;p&gt;Yes, you read it write. Here I will only share my experience and if you agree or convinced with it give it a like so it could reach to more people.&lt;br&gt;
I'm a Full Stack developer with 6 years of experience, and in this tenure I mostly worked with Rest Api's. I have seen my fellow developers write try catch in every controller or api code.&lt;br&gt;
And also on frontend side in all api requests. &lt;br&gt;
Now I will explain one by one why this is redundant code.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why we need to stop using Try-catch block
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. It stops the error to be shown or debugged.&lt;/strong&gt;&lt;br&gt;
Let's suppose you have error coming in your browser console&lt;br&gt;
&lt;code&gt;Cannot read response of undefined&lt;/code&gt;&lt;br&gt;
I hope most of you will have seen this error. When we debug, we will find out that it's coming from catch block of 'fetch' or 'axios' promise api call.&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="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/my-api&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;//some error code&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;user_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;full_name&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="c1"&gt;//do this&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;422&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="c1"&gt;//do this&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;Now last developer want to secure the 500 error by using try catch but guess what, it takes more effort for current developers to figure where's the error in then block, most of junior developers are not even able to recognize the above error.&lt;br&gt;
Now you may argue all it takes is console statement in catch, but if that can't be pushed due to linting rules, that's extra effort as well, Isn't it?&lt;/p&gt;

&lt;p&gt;Now move on to our next effort, sorry next step.&lt;br&gt;
let's suppose the error is user property is not present in api, now we have to debug  backend for that, Let's suppose our backend controller or logic code is written in this way&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;function&lt;/span&gt; &lt;span class="nf"&gt;myApiFunction&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="k"&gt;try&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;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;({});&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;locals&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;people&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;log&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`An error occurred at controller.myApiFunction &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;err&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;An error occurred&lt;/span&gt;&lt;span class="dl"&gt;'&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;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now first thing is if you return or next from inside try block it will never reach to catch. Now actual problem here is we are returning variable with people not user. &lt;/p&gt;

&lt;p&gt;Now Let's suppose the second scenario that there really was some error in our 'myApiFunction'. All we will get in frontend is &lt;br&gt;
'An error occurred'. What did the frontend guy will understand from it. if you have made extra effort to not show error to user, you could have diverted that effort to make your code error free.&lt;/p&gt;

&lt;p&gt;If you use Modern backend frameworks, you can define common error handler and you get structured error response anyway, so why did you put extra effort to write that try catch block.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. It is repeating code, which violates DRY rule.&lt;/strong&gt;&lt;br&gt;
Now let's jump to second problem statement.&lt;br&gt;
99% of time you will write same code in catch block in every controller and in every frontend api catch block.&lt;br&gt;
The solution for this problem is using &lt;a href="https://axios-http.com/docs/interceptors" rel="noopener noreferrer"&gt;interceptors&lt;/a&gt; for package like axios in frontend and in backend, most modern frameworks provide elegant way to handle all your 500, 422, 401 etc errors at one place. You can even configure it for web and api request separately. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. It is non Testable.&lt;/strong&gt;&lt;br&gt;
Most developers in my community or in my region don't write tests,&lt;br&gt;
But the people who do realises how difficult it is complete code coverage. &lt;br&gt;
For the developers who don't know what is code coverage it's representation of what part of your code is covered in test cases.&lt;br&gt;
&lt;em&gt;You can never cover catch block.&lt;/em&gt; Because if you know where error will occur you will fix it, you will not ship the error to client right?&lt;br&gt;
The typescript and typed parameters in languages in php makes it further difficult for error to induce inside the function.&lt;/p&gt;
&lt;h2&gt;
  
  
  Where should we use try catch
&lt;/h2&gt;

&lt;p&gt;Now I'm not saying we should never use try-catch, only want to save you effort and want to reduce your code. At some places it becomes necessary to use try-catch, Here we will discuss them&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Function with multiple DB insertion and update queries.&lt;/strong&gt;&lt;br&gt;
Sometimes you have to run multiple queries for insertion and updation in your logic part, If any thing in between broke then some queries which already ran will be successful and will create garbage data. In this case we can use database transactions with try catch, here how it looks like&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;function&lt;/span&gt; &lt;span class="nf"&gt;myApiFunction&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;beginTransaction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// multiple insertion and updation queries&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;commit&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rollback&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;finally&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;end&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;something&lt;/span&gt;&lt;span class="dl"&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;in above code we start declare db transaction, then executes all our queries then if all things successful we commit the results which finally changes the state of our database, else if any error occurs we can do rollback, and our database will return to original state before starting the transaction.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Third party Api call&lt;/strong&gt;&lt;br&gt;
Third party code is always a mystery, what error they return in which case we have to code it all, since we can't do all that in beginning we should must use try catch to catch all possible errors from third party api call.&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;try&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;stripe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;doThis&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;twillio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;doThat&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error occured in stripe while doing this.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&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;&lt;strong&gt;3. Handling external resource like file Handling.&lt;/strong&gt;&lt;br&gt;
Similarly like third party services, we also don't know about external resources like files. In our application when we read document or media files we must take in scenario that this file may not be in format we assume,&lt;br&gt;
For example you have csv import api, there's lot of uncertainty in this case.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The CSV may not be in correct format.&lt;/li&gt;
&lt;li&gt;The file extension may not be correct.&lt;/li&gt;
&lt;li&gt;The file may be corrupt or in other asci/utf code.&lt;/li&gt;
&lt;li&gt;Query for importing or updating csv item may fail for some item.
Hence we need to cover this all factors in separate try catch. 
Hope you enjoyed this post. Please support my post with like and if you have job reference please pass onto my linkedin profile.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. Running heavy tasks in background or in loop&lt;/strong&gt;&lt;br&gt;
Heavy tasks like heavy file import, bulk email etc. can be done efficiently in background and off course there will be loop involved in it, So whole job shouldn't terminate if there's error in any single item or task, therefore we need to use try-catch for safe continuation of background job or loop.&lt;/p&gt;
&lt;h2&gt;
  
  
  bonus tip: Async-Await
&lt;/h2&gt;

&lt;p&gt;If you use Promises in JS or Dart with async-await syntax then you must be using try-catch block with it and hence you might totally disagree with post, therefore I'm writting this bonus tip for improving your code quality. Consider the following code which is general case for calling api's in your 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="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;firstApiCall&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
  &lt;span class="nf"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;secondApiCall&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
  &lt;span class="nf"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;thirdApiCall&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
  &lt;span class="nf"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&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;As you can see there's lot of repeating code or try-catch here, hence we will standardize our code to escape this hell. The only condition here is you have to use same response format on both frontend and backend.&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;async&lt;/span&gt; &lt;span class="nc"&gt;ApiCall&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;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;success&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;respectiveApiCall&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;success&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&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;This is my personal choice however if you don't like it or it doesn't fit you your case you can refer to this short video as well by Firship.io.&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=ITogH7lJTyE" rel="noopener noreferrer"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hAfwirhe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://img.youtube.com/vi/ITogH7lJTyE/0.jpg" alt="Step Image" width="480" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks and Regards,&lt;br&gt;
Yogesh Galav&lt;/p&gt;

</description>
      <category>development</category>
      <category>developer</category>
      <category>fullstack</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Use MVCRSH instead of MVC.</title>
      <dc:creator>Yogesh Galav</dc:creator>
      <pubDate>Mon, 11 Mar 2024 16:28:27 +0000</pubDate>
      <link>https://dev.to/yogeshgalav7/use-mvcsh-instead-of-mvc-i92</link>
      <guid>https://dev.to/yogeshgalav7/use-mvcsh-instead-of-mvc-i92</guid>
      <description>&lt;p&gt;There is a famous style of programming which most of you already knew "MVC" it's even inbuild in frameworks like Laravel and ROR.&lt;br&gt;
You can also apply this style to frontend framework like flutter, Vue and React for better productivity.&lt;br&gt;
Today I want to share an extended version of MVC which we all should use instead of MVC to keep code clean and healthy. &lt;br&gt;
&lt;strong&gt;It's MVCRSH - Model, View, Controller, Routes, Services and Helpers.&lt;/strong&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  What is MVC?
&lt;/h2&gt;

&lt;p&gt;MVC (Model, View, Controller) is architecture for dividing our code in application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why we need to extend it?
&lt;/h2&gt;

&lt;p&gt;MVC might be an good style for keeping things separated but there will be sometimes when you will get confused if the particular piece of code should be put in Controller or Model. &lt;/p&gt;

&lt;h2&gt;
  
  
  Model
&lt;/h2&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%2Freblozmc9dqbps6t42ic.jpeg" 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%2Freblozmc9dqbps6t42ic.jpeg" alt="Models" width="800" height="800"&gt;&lt;/a&gt;&lt;br&gt;
Model should contain only definition of entity or database table, The field it contains, type of fields, foreign-key etc.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To define our list of fields we can define an array or object. In array you can only suggest field names while in object you can also provide their data types.&lt;/li&gt;
&lt;li&gt;We can define relationship with help of functions to fetch related data, In most ORM we can define what kind of relationship do we want with other entities and fetch data accordingly.&lt;/li&gt;
&lt;li&gt;We can also define Accessor or Mutator to run some condition before fechting or saving data.&lt;/li&gt;
&lt;li&gt;Here's the list of famous ORM w.r.t frameworks which provide model functionality, for Laravel it's Eloquent, for Node it's Drizzle or prism, for Flutter it's Sqflite.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  View
&lt;/h2&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%2Fecdql5r87aoqd8c488t6.jpg" 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%2Fecdql5r87aoqd8c488t6.jpg" alt="Views" width="560" height="449"&gt;&lt;/a&gt;&lt;br&gt;
View should only contain UI part, which user sees or interact with. For web It ultimately compiles to HTML, CSS and JS.&lt;br&gt;
Hence all the files related to it come inside view.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We can define which layout do we wan to use.&lt;/li&gt;
&lt;li&gt;When using frontend framework, reactive data and js methods also comes into picture.&lt;/li&gt;
&lt;li&gt;Along with it, more complex things like frontend routing and state management start to fill the view part. 
With tools like Inertia or File based routing we can eliminate frontend routing code.&lt;/li&gt;
&lt;li&gt;Here's the list of famous templating engine w.r.t frameworks which provide UI functionality, for Laravel it's Blade, for Express it's pug, for Flutter it's Flutter.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Controller
&lt;/h2&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%2Fq126cgfvhqub0qqq3rx6.jpg" 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%2Fq126cgfvhqub0qqq3rx6.jpg" alt="Controllers" width="800" height="800"&gt;&lt;/a&gt;&lt;br&gt;
Controller as we know should only contain business logic but there's lot of logic like validation, running big query, sending email, generating csv or excel and using services like Twilio, stripe, gmap etc.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We should only call functions to above all use cases inside controller, the way we call model inside controller.&lt;/li&gt;
&lt;li&gt;Validation can be call before executing controller function like middleware. Framework like Laravel provide dependency injection for doing the same.&lt;/li&gt;
&lt;li&gt;Rest of the things will move to services and helpers.&lt;/li&gt;
&lt;li&gt;Controllers should contain only single word functions like create, update, delete, index, show, download, csv, excel etc&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Routes
&lt;/h2&gt;

&lt;p&gt;Routes as we all know are starting point of user entry in application, hence it's most simple and absolute one.&lt;br&gt;
Most framework provide routing by default, In framework like flutter you can use get_router or getx to define routes. &lt;/p&gt;

&lt;h2&gt;
  
  
  Services
&lt;/h2&gt;

&lt;p&gt;Services should be made in way, so that they can be used in any other project like ApiService, CsvExport, ExcelImport, TwilioSms, Mailchimp.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The code in services should always be reusable so it can be used in any project.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Helpers
&lt;/h2&gt;

&lt;p&gt;Last but not the least, Helpers provide help to controller and model. The logic or function which makes controller bulky should be moved to helpers instead of models. Most developers confuse between Utils and helpers but they are not the same.&lt;br&gt;
In frontend frameworks, state management tools are kind of helpers only. In backend frameworks you need to create one otherwise you would end up writing most of the bulky logic inside controller or model. Helper pattern can be better alternative to repository pattern here's how:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Helper class should extend particular modal class. Hence we can use helpers instead of models everywhere with extended functionality without breaking the quality of models.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;App\Helpers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App\Models\User&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserHelper&lt;/span&gt; &lt;span class="n"&gt;extend&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;We should not use Services and Jobs inside helpers, same as model, We can however access other helpers to perform dependency operation.&lt;/li&gt;
&lt;li&gt;The meaning of this class is to help model entity perform tasks, the controller methods are more of crud operation, and models methods are limited to database only, hence we need human readable and doable tasks in form of methods inside helpers.
For eg. UserHelper will contain methods like
getFriendsList, getPhotos, getRecentPosts&lt;/li&gt;
&lt;li&gt;While working between multiple models/helpers, most beginners get confused and create duplicate methods like 
PostHelper-&amp;gt;getRecentPostsForUser
While doing so we must remember which primary or single entity we want data for. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I hope you find this post useful for whatever framework you use.&lt;br&gt;
Thank you and have a nice day!&lt;/p&gt;

</description>
      <category>programming</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
