<?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: Xavier Carrera Gimbert</title>
    <description>The latest articles on DEV Community by Xavier Carrera Gimbert (@xavier_carreragimbert).</description>
    <link>https://dev.to/xavier_carreragimbert</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%2F1589131%2F8010a324-ac9b-4fe5-b7f2-e4d3b928f6a9.jpg</url>
      <title>DEV Community: Xavier Carrera Gimbert</title>
      <link>https://dev.to/xavier_carreragimbert</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/xavier_carreragimbert"/>
    <language>en</language>
    <item>
      <title>Hexagonal Architecture: Simple Introduction + Real-World Example</title>
      <dc:creator>Xavier Carrera Gimbert</dc:creator>
      <pubDate>Wed, 26 Nov 2025 22:59:16 +0000</pubDate>
      <link>https://dev.to/xavier_carreragimbert/hexagonal-architecture-simple-introduction-real-world-example-49n1</link>
      <guid>https://dev.to/xavier_carreragimbert/hexagonal-architecture-simple-introduction-real-world-example-49n1</guid>
      <description>&lt;p&gt;Hexagonal Architecture is very popular these days. However, I have seen that a lot of the resources out there that try to teach it do so in a very abstract and technical way. While that is great for understanding all the details, it makes for a poor introduction.&lt;/p&gt;

&lt;p&gt;So, in this article, I would like to address this issue. I would like to make a simple and straightforward introduction to HA (Hexagonal Architecture) and give you some other resources for further learning, including a public repo that applies HA that I created for this article.&lt;/p&gt;

&lt;p&gt;So let's begin!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Hexagonal Architecture?
&lt;/h2&gt;

&lt;p&gt;Hexagonal Architecture is a design paradigm that focuses on separating the core of the application from everything else and specifying rules on how these two parts should interact.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the "core of the app"? What is "everything else"?
&lt;/h2&gt;

&lt;p&gt;The core of the app is the business logic. All the things that make your app &lt;em&gt;your app&lt;/em&gt;, no matter what external tools you use.&lt;/p&gt;

&lt;p&gt;For example, if you are making a todo app, you want to be able to create todos, update todos, and remove todos. This is the core of the app.&lt;/p&gt;

&lt;p&gt;Your app would still be a todo app if, instead of Postgres, you used SQLite; if instead of Prisma, you used Drizzle; or if instead of getting requests via a NestJS server, you used a CSV processor. These things that are not the core are "everything else".&lt;/p&gt;

&lt;h2&gt;
  
  
  According to HA, how should the "core of the app" interact with "everything else"?
&lt;/h2&gt;

&lt;p&gt;By using ports.&lt;/p&gt;

&lt;p&gt;Ports are the contracts that the core of the app establishes with "everything else" to work.&lt;/p&gt;

&lt;p&gt;So, for example, if you want to create a todo, a port would specify that the core app needs a JSON object that provides a title and a description. It doesn't matter if this object comes from an HTTP request, a CSV file, or whatever. The app needs what the port specifies.&lt;/p&gt;

&lt;p&gt;To follow this example, a tool like NestJS could get a &lt;code&gt;POST&lt;/code&gt; request that a user sent and pass the relevant information following the port contract to the app.&lt;/p&gt;

&lt;p&gt;Of course, in this example, we need something to get the request, manage the validation, and send it to the core app following the port contract. This is called the adapter. It's an adapter because it adapts the incoming information into something the core app can use.&lt;/p&gt;

&lt;p&gt;To create a little diagram:&lt;/p&gt;

&lt;p&gt;User sends request $\rightarrow$ NestJS controller gets it, validates it, and sends it to the core app by obeying a port contract (Adapter) $\rightarrow$ App processes the request (Core App)&lt;/p&gt;

&lt;p&gt;The same process is followed for outgoing requests from the core app.&lt;/p&gt;

&lt;p&gt;To put an example:&lt;/p&gt;

&lt;p&gt;Imagine the core app, once it has received the correct data to create a todo, wants to store it in the database. The core app would send the correct information to the ORM/Database adapter by obeying a port contract, and the adapter would process the todo saving.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Notice that adapters not only adapt incoming information (driving side), they also adapt information from the app to the necessities of external services like an ORM (driven side).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Are there any other rules? That seems easy.
&lt;/h2&gt;

&lt;p&gt;The core concept is not hard to grasp, but the implementation can get tricky.&lt;/p&gt;

&lt;p&gt;For example, it is important to not mix the core of the app with the rest, which is easy to say but hard to do.&lt;/p&gt;

&lt;p&gt;You do not want the business logic to depend on the ORM, for example. If you are using Prisma as your ORM and then decide to change it to Drizzle, you should not need to change the business logic. If you do, you have not implemented HA correctly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where can I learn more about HA?
&lt;/h2&gt;

&lt;p&gt;I highly recommend these two articles to begin with. I think they offer a great explanation.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;This one is a great follow-up reading. It is easy to read but gives more specific details about HA: &lt;a href="https://dev.to/xoubaman/understanding-hexagonal-architecture-3gk"&gt;Understanding Hexagonal Architecture - DEV Community&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This other one is great because it gives a TS example of HA: &lt;a href="https://devcookies.medium.com/a-detailed-guide-to-hexagonal-architecture-with-examples-042523acb1db" rel="noopener noreferrer"&gt;A Detailed Guide to Hexagonal Architecture with Examples | by Dev Cookies | Medium&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Is there any real-world example code I can check?
&lt;/h2&gt;

&lt;p&gt;Yes! I have created a project that follows the patterns of HA as strictly as I could: &lt;a href="https://github.com/Xalsar/user-posts-backend" rel="noopener noreferrer"&gt;Xalsar/user-posts-backend&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Good bye! 👋
&lt;/h2&gt;

&lt;p&gt;Hope you liked this little introduction to the topic. Feel free to ask questions or give feedback in the comments if you have it.&lt;/p&gt;

&lt;p&gt;Cheers! And happy coding!&lt;/p&gt;

</description>
      <category>cleancode</category>
      <category>designpatterns</category>
      <category>softwareengineering</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Abstract Factory Pattern: Explained for Humans</title>
      <dc:creator>Xavier Carrera Gimbert</dc:creator>
      <pubDate>Mon, 24 Nov 2025 17:28:15 +0000</pubDate>
      <link>https://dev.to/xavier_carreragimbert/abstract-factory-pattern-explained-for-humans-41a5</link>
      <guid>https://dev.to/xavier_carreragimbert/abstract-factory-pattern-explained-for-humans-41a5</guid>
      <description>&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;We have the classes &lt;code&gt;Payment&lt;/code&gt; and &lt;code&gt;Refund&lt;/code&gt;. We use these classes to process and refund transactions, as the names imply.&lt;/p&gt;

&lt;p&gt;However, we use different payment providers. So, each of the mentioned classes will be instantiated differently depending on the provider, even though they will perform the same core job.&lt;/p&gt;

&lt;p&gt;How do we tackle this code problem in a clean way?&lt;/p&gt;

&lt;p&gt;By using the Abstract Factory pattern.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution: The Abstract Factory Pattern
&lt;/h2&gt;

&lt;p&gt;First, we create the interfaces that will define the core functionality of the classes we need.&lt;br&gt;
&lt;/p&gt;

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

interface Payment {
  pay(amount: number): Promise&amp;lt;void&amp;gt;;
}

interface Refund {
  refund(transactionId: string): Promise&amp;lt;void&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;ℹ️ We call these interfaces "Product interfaces" because the classes that are going to implement these interfaces are the &lt;strong&gt;products&lt;/strong&gt; of (or instantiated by) factory methods.&lt;/p&gt;

&lt;p&gt;ℹ️ A factory is simply a function (or a method or a class) that instantiates a class.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now we define the interface that the factory class will use to instantiate these products.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Abstract Factory interface

interface PaymentAbstractFactory {
  createPayment(): Payment;
  createRefund(): Refund;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We then define the specific product classes we will instantiate using the interfaces created previously:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Concrete Products for Stripe

class StripePayment implements Payment {
  async pay(amount: number): Promise&amp;lt;void&amp;gt; {
    console.log(`Processing payment of $${amount} via Stripe...`);
    // Stripe payment logic here
  }
}

class StripeRefund implements Refund {
  async refund(transactionId: string): Promise&amp;lt;void&amp;gt; {
    console.log(
      `Processing refund for transaction ${transactionId} via Stripe...`,
    );
    // Stripe refund logic here
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now we create the factory that will create the products:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Concrete Factory for Stripe

class StripeFactory implements PaymentAbstractFactory {
  createPayment(): Payment {
    return new StripePayment();
  }

  createRefund(): Refund {
    return new StripeRefund();
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And finally, we use it in the client!&lt;br&gt;
&lt;/p&gt;

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

const processTransaction = async (
  factory: PaymentAbstractFactory,
  amount: number,
) =&amp;gt; {
  const payment = factory.createPayment();
  await payment.pay(amount);
};

const refundTransaction = async (
  factory: PaymentAbstractFactory,
  transactionId: string,
) =&amp;gt; {
  const refund = factory.createRefund();
  await refund.refund(transactionId);
};

const stripeFactory = new StripeFactory();
processTransaction(stripeFactory, 100);
refundTransaction(stripeFactory, 'stripe_tx_12345');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What have we done here?
&lt;/h2&gt;

&lt;p&gt;We have created an interface (the Abstract Factory) that we use to create factories. These factories, in turn, create a &lt;strong&gt;family&lt;/strong&gt; of product classes that share a common relationship (e.g., all belonging to the Stripe provider).&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is this pattern useful?
&lt;/h2&gt;

&lt;p&gt;It allows us to have factories that generate classes which have a common relationship.&lt;/p&gt;

&lt;p&gt;In this case, we are able to have a factory that generates classes that work for a common payment service.&lt;/p&gt;

&lt;p&gt;We could easily create another factory for a different payment service and use it too:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Concrete Factory for PayPal

class PayPalFactory implements PaymentAbstractFactory {
  createPayment(): Payment {
    return new PayPalPayment();
  }

  createRefund(): Refund {
    return new PayPalRefund();
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Where can I learn more about this pattern?
&lt;/h2&gt;

&lt;p&gt;You can ask your trustworthy LLM, drop a comment, or visit one of the most famous resources to learn about design patterns: Refactoring Guru.&lt;/p&gt;

&lt;p&gt;Here is the specific article about this design pattern: &lt;a href="https://refactoring.guru/design-patterns/abstract-factory" rel="noopener noreferrer"&gt;Abstract Factory&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Goodbye!
&lt;/h2&gt;

&lt;p&gt;I hope this article helped you understand this design pattern better! Feel free to leave a comment if you have any questions or feedback.&lt;/p&gt;

&lt;p&gt;Thanks!&lt;/p&gt;

</description>
      <category>designpatterns</category>
      <category>cleancode</category>
      <category>typescript</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>The Factory Method Design Pattern Explained for Humans</title>
      <dc:creator>Xavier Carrera Gimbert</dc:creator>
      <pubDate>Thu, 20 Nov 2025 11:45:12 +0000</pubDate>
      <link>https://dev.to/xavier_carreragimbert/the-factory-method-design-pattern-explained-for-humans-cae</link>
      <guid>https://dev.to/xavier_carreragimbert/the-factory-method-design-pattern-explained-for-humans-cae</guid>
      <description>&lt;p&gt;Design patterns are often explained in a very complicated way, which makes it hard for casual readers to understand.&lt;/p&gt;

&lt;p&gt;So today, I would like to explain to you how I understand the &lt;strong&gt;Factory Method Pattern&lt;/strong&gt; in the simplest way possible—and with a real-world example!&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem we are trying to solve
&lt;/h2&gt;

&lt;p&gt;Let's assume we are trying to support multiple payment methods in our app. It should be easy but in reality it is very cumbersome to implement. All the methods allow users to do the same operations (pay for an order, get a refund, etc.), but each service does it in a different way. You do not process a payment with Stripe in the same way you do with PayPal, for example.&lt;/p&gt;

&lt;p&gt;Also, we want to be able to expand the code in the future without breaking the existing one. Our app may need to support Google Pay in the near future. Who knows!&lt;/p&gt;

&lt;h2&gt;
  
  
  The solution: The Factory Method
&lt;/h2&gt;

&lt;p&gt;We first define the interface that all our payment methods have to follow. In this case, each payment method has to allow users to process a payment and do a refund. No matter if we use Stripe, PayPal or whatever, users have to be able to perform these two operations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface PaymentProcessor {
  processPayment(
    amount: number,
  ): Promise&amp;lt;{ success: boolean; transactionId: string }&amp;gt;;
  refund(transactionId: string): Promise&amp;lt;boolean&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we define each processor.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;ℹ️ I use the word &lt;strong&gt;processor&lt;/strong&gt; rather than method because in this code context I think it makes more sense.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class StripeProcessor implements PaymentProcessor {
  async processPayment(
    amount: number,
  ): Promise&amp;lt;{ success: boolean; transactionId: string }&amp;gt; {
    console.log(`Processing $${amount} via Stripe...`);
    // Stripe API call
    return { success: true, transactionId: 'stripe_tx_12345' };
  }

  async refund(transactionId: string): Promise&amp;lt;boolean&amp;gt; {
    console.log(`Refunding Stripe transaction ${transactionId}`);
    return true;
  }
}

class PayPalProcessor implements PaymentProcessor {
  async processPayment(
    amount: number,
  ): Promise&amp;lt;{ success: boolean; transactionId: string }&amp;gt; {
    console.log(`Processing $${amount} via PayPal...`);
    // PayPal API call
    return { success: true, transactionId: 'paypal_tx_67890' };
  }

  async refund(transactionId: string): Promise&amp;lt;boolean&amp;gt; {
    console.log(`Refunding PayPal transaction ${transactionId}`);
    return true;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have to also specify our &lt;strong&gt;creator&lt;/strong&gt;, or in other words, the class that will have the &lt;strong&gt;factory method&lt;/strong&gt; that will instantiate the specific processors and orchestrate their methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract class PaymentService {
  abstract createProcessor(): PaymentProcessor; // The Factory Method

  async checkout(amount: number): Promise&amp;lt;void&amp;gt; {
    const processor = this.createProcessor();
    const result = await processor.processPayment(amount);

    if (result.success) {
      console.log(
        `Payment successful! Transaction ID: ${result.transactionId}`,
      );
    }
  }

  async refund(transactionId: string): Promise&amp;lt;void&amp;gt; {
    const processor = this.createProcessor();
    const success = await processor.refund(transactionId);

    if (success) {
      console.log(`Refund successful for Transaction ID: ${transactionId}`);
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;😨 Are you confused? Don't worry, bear with me; once we finish, you will understand.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now we create the different implementations of the services by extending the creator class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class StripePaymentService extends PaymentService {
  createProcessor(): PaymentProcessor {
    return new StripeProcessor();
  }
}

class PayPalPaymentService extends PaymentService {
  createProcessor(): PaymentProcessor {
    return new PayPalProcessor();
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And finally we apply it in our app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function processCheckout(paymentMethod: 'stripe' | 'paypal', amount: number) {
  const service =
    paymentMethod === 'stripe'
      ? new StripePaymentService()
      : new PayPalPaymentService();

  service.checkout(amount);
}

processCheckout('stripe', 99.99);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Wait, I do not understand, what happened here?
&lt;/h2&gt;

&lt;p&gt;We have created the classes &lt;code&gt;StripePaymentService&lt;/code&gt; and &lt;code&gt;PayPalPaymentService&lt;/code&gt; which extend the creator class &lt;code&gt;PaymentService&lt;/code&gt;. This creator class uses a &lt;strong&gt;factory method&lt;/strong&gt; &lt;code&gt;createProcessor&lt;/code&gt; to create an instance of each the payment processor and use it to orchestrate the &lt;code&gt;checkout&lt;/code&gt; and the &lt;code&gt;refund&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Notice that the creator class does not care which payment processor are we using. It simply orchestrates the one it is provided.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is this pattern useful?
&lt;/h2&gt;

&lt;p&gt;It allows us to execute different variants (Stripe, PayPal) of a process (processing payments and refunds) with minimal code changes.&lt;/p&gt;

&lt;p&gt;We simply instantiate the class we need (&lt;code&gt;StripePaymentService&lt;/code&gt; or &lt;code&gt;PayPalPaymentService&lt;/code&gt;) and the creator class orchestrates all the different logic.&lt;/p&gt;

&lt;p&gt;If in the future we want to add new payment processors it is also very easy to do: we simply create a new processor and extend the creator class (&lt;code&gt;PaymentService&lt;/code&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Where does this pattern shine?
&lt;/h2&gt;

&lt;p&gt;When we have a structure that is repeated multiple times with different implementations.&lt;/p&gt;

&lt;p&gt;Like a payment system. The core functionality is the same for all the variants but the implementation changes significantly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where is this pattern used?
&lt;/h2&gt;

&lt;p&gt;It is used for example in ORMs that support a lot of database types.&lt;/p&gt;

&lt;p&gt;The ORM has the same functionality (query a database, create an item...) for all the databases, but the implementation changes a lot if we use PostgreSQL or MongoDB, for example.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where can I learn more about this pattern?
&lt;/h2&gt;

&lt;p&gt;Go to one of the most reputable resources to learn about architectural patterns. &lt;a href="https://refactoring.guru/design-patterns/factory-method" rel="noopener noreferrer"&gt;Refactoring Guru&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Good bye!
&lt;/h2&gt;

&lt;p&gt;Hope this article helped you! If you have any doubts, please let me know in the comments.&lt;/p&gt;

</description>
      <category>designpatterns</category>
      <category>cleancode</category>
      <category>typescript</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>Setting Up NestJS with Prisma (Without the Headache)</title>
      <dc:creator>Xavier Carrera Gimbert</dc:creator>
      <pubDate>Tue, 18 Nov 2025 21:20:14 +0000</pubDate>
      <link>https://dev.to/xavier_carreragimbert/setting-up-nestjs-with-prisma-without-the-headache--47n2</link>
      <guid>https://dev.to/xavier_carreragimbert/setting-up-nestjs-with-prisma-without-the-headache--47n2</guid>
      <description>&lt;p&gt;Starting a project with NestJS and Prisma should be easy, right? They’re both popular technologies and a great match. There are even official articles &lt;a href="https://docs.nestjs.com/recipes/prisma" rel="noopener noreferrer"&gt;(1)&lt;/a&gt;&lt;a href="https://www.prisma.io/blog/nestjs-prisma-rest-api-7D056s1BmOL0" rel="noopener noreferrer"&gt;(2)&lt;/a&gt; explaining how to integrate them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Wrong.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For some reason, those articles are outdated. So here I am, writing this guide to save you a serious headache when setting up your project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Get to It
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 &lt;a href="https://github.com/Xalsar/nestjs-prisma-setup-tutorial" rel="noopener noreferrer"&gt;Here is the final code of this set up project.&lt;/a&gt; Use it if you get stuck.&lt;/p&gt;

&lt;p&gt;💡 I’ll be using &lt;strong&gt;pnpm&lt;/strong&gt; for this project, but feel free to use any package manager you prefer.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  1. Create the Project
&lt;/h3&gt;

&lt;p&gt;You’ll be prompted to choose a package manager. Select &lt;strong&gt;pnpm&lt;/strong&gt; if you want to follow this guide without changes. Otherwise, adapt as needed.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 At the time of writing, the latest version of @nestjs/cli appears to have a bug, so I'm using an older version. This may have been resolved by the time you're reading.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm dlx @nestjs/cli@11.0.0 new nestjs-prisma-test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Set Up PostgreSQL with Docker
&lt;/h3&gt;

&lt;p&gt;Create a Docker file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;docker-compose.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# docker-compose.yml&lt;/span&gt;

&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;3.8'&lt;/span&gt;
&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;postgres&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;postgres:13.5&lt;/span&gt;
    &lt;span class="na"&gt;restart&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;always&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;POSTGRES_USER=myuser&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;POSTGRES_PASSWORD=mypassword&lt;/span&gt;
    &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;postgres:/var/lib/postgresql/data&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;5432:5432'&lt;/span&gt;

&lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;postgres&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the container and keep the terminal open:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker-compose up
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Install Prisma
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm add prisma &lt;span class="nt"&gt;-D&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initialize Prisma:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm dlx prisma init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Configure Environment Variables
&lt;/h3&gt;

&lt;p&gt;Install &lt;code&gt;dotenv&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm add dotenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update your config files to load environment variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// prisma.config.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dotenv/config&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// rest of the file...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/main.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dotenv/config&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// rest of the file...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update your &lt;code&gt;.env&lt;/code&gt; file (remove any comments):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DATABASE_URL="postgres://myuser:mypassword@localhost:5432"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. Define Your Models
&lt;/h3&gt;

&lt;p&gt;Edit &lt;code&gt;prisma/schema.prisma&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model User {
  id        Int      @id @default(autoincrement())
  email     String   @unique
  name      String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the initial migration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm dlx prisma migrate dev &lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="s2"&gt;"init"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  6. Install Prisma Client
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm add @prisma/client
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;💡 You don’t need to run &lt;code&gt;generate&lt;/code&gt; now - Prisma does it automatically when installing the client. But for future schema changes, run:&lt;/p&gt;


&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm dlx prisma generate
&lt;/code&gt;&lt;/pre&gt;

&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  7. Create the Prisma Service
&lt;/h3&gt;

&lt;p&gt;Note: We import from &lt;code&gt;/client&lt;/code&gt;, not as shown in the official docs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/services/prisma.service.ts&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Injectable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;OnModuleInit&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;@nestjs/common&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;PrismaClient&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;generated/prisma/client&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="nd"&gt;Injectable&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PrismaService&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;PrismaClient&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;OnModuleInit&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;onModuleInit&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;$connect&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;h3&gt;
  
  
  8. Register the Prisma Service
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/app.module.ts&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Module&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;@nestjs/common&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;AppController&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;./app.controller&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;PrismaService&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;./services/prisma.service&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="nd"&gt;Module&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;imports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
  &lt;span class="na"&gt;controllers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;AppController&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;PrismaService&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AppModule&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  9. Use the Prisma Service
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/app.controller.ts&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Controller&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Get&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;@nestjs/common&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;PrismaService&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;./services/prisma.service&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="nd"&gt;Controller&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AppController&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nx"&gt;prismaService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PrismaService&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="nd"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;getUsers&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prismaService&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="nf"&gt;findMany&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;blockquote&gt;
&lt;p&gt;💡 This is a minimal setup and not production-ready. In a real app, you shouldn’t call a service directly from the controller. But this is a Prisma + NestJS set up tutorial - so I don’t care.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  10. Run the Server
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm run start:dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that’s it! Populate your database and test the endpoint.&lt;/p&gt;

&lt;p&gt;If you run into any issues, let me know in the comments. Hope you enjoyed the ride!&lt;/p&gt;

</description>
      <category>nestjs</category>
      <category>prisma</category>
      <category>webdev</category>
      <category>fullstack</category>
    </item>
    <item>
      <title>Your app idea is probably trash</title>
      <dc:creator>Xavier Carrera Gimbert</dc:creator>
      <pubDate>Thu, 02 Oct 2025 15:37:57 +0000</pubDate>
      <link>https://dev.to/xavier_carreragimbert/why-your-app-idea-is-probably-trash-45kg</link>
      <guid>https://dev.to/xavier_carreragimbert/why-your-app-idea-is-probably-trash-45kg</guid>
      <description>&lt;p&gt;Video version of this article: &lt;a href="https://youtu.be/7xWl97seDIc?si=FkAh0ml6TCNcw5Om" rel="noopener noreferrer"&gt;https://youtu.be/7xWl97seDIc?si=FkAh0ml6TCNcw5Om&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All developers at some point in their lives have had this thought:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“I am gonna make an app and it is gonna be a success. I had an idea that no one else has had. I wonder how this amazing app does not exist already. It must be that I am the first to have it and have the determination to bring it to life. This is gonna be a great success!”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Sorry to break it to you, but you are probably gonna miserably fail with that. Unfortunately, you are probably not a genius. Sorry.&lt;/p&gt;

&lt;p&gt;But let me explain to you why I think so.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;You probably do not understand what the competition offers&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;All the apps and services that you use have a lot of issues for sure, but we sometimes tend to forget the things they do extremely well.&lt;/p&gt;

&lt;p&gt;Maybe there is a very popular app with a clearly outdated interface that, on the other hand, offers great customer service and has great logistics! Or maybe there is an app that is slow and buggy but offers a product that you can only obtain there, and people are willing to deal with the shenanigans just because they really like the product.&lt;/p&gt;

&lt;p&gt;Or maybe it is just that the app is old and it is used by a lot of people, so people do not want to switch because they prefer to deal with an imperfect app they trust than risk it with something they do not know about. Sometimes people are just not very brave.&lt;/p&gt;

&lt;p&gt;There are even cases where the only thing the app offers compared to the competition is a big community of people using it. So consumers deal with the not-so-good parts of the app simply because they want to be part of a community. You do not want to be the guy with the most private, secure, and efficient messaging app that has no one to speak to because no one uses that app besides you.&lt;/p&gt;

&lt;p&gt;So when comparing your idea to the existing ones, do not focus only on the things you can do better than the competition. But try to be realistic and think of the things the competition does better than you.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Things are more difficult than what you think&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Products are not as easy to build as a lot of people want you to believe. It is very probable that you are underestimating the problems you will face down the road and overestimating your capabilities.&lt;/p&gt;

&lt;p&gt;Building a product is not just the code. It is the infrastructure, it is the marketing, it is the design, it is the product part (establishing prices, conditions), it is the legal problems, it is the psychological aspect (I am sure you are very motivated now, but what about in a couple of months?).&lt;/p&gt;

&lt;p&gt;As you can see, there are a lot of things that can go wrong, and if we acknowledge Murphy’s Law—“if something can go wrong, it will go wrong”—we will rapidly realize that a lot of things will go completely south during the app-building process.&lt;/p&gt;

&lt;p&gt;So, please, before quitting your job to become the next Mark Zuckerberg, take into account the real effort you will have to deal with and all the problems that are surely gonna pop up.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Consumers do not know what they want&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;It is a fact of life. People (including me) love to talk about how things are bad and how things could be better if someone did what we just want. But in reality, when people face the consequences of what they want, you see that they clearly did not know what they wanted.&lt;/p&gt;

&lt;p&gt;This especially happens with things related to privacy. Everyone will tell you how much they value privacy, but when we have to face reality and pick between privacy and comfort, we forget our higher values.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Black swans are more common than what you would think&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Okay, let us consider that you are amazing, that you have been able to cover a necessity with a great app, and that you have been able to deal with all the problems involved with its creation and maintenance.&lt;/p&gt;

&lt;p&gt;You are still not safe—you can encounter a black swan at any moment. What is a black swan, you may be asking yourself? According to Wikipedia:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“The black swan theory or theory of black swan events is a metaphor that describes an event that comes as a surprise, has a major effect, and is often inappropriately rationalized after the fact with the benefit of hindsight .”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In other words, the terrifying unexpected.&lt;/p&gt;

&lt;p&gt;You may be developing the greatest app possible, but maybe one day you wake up and realize that some family member is ill and needs money for treatment, or maybe your house gets burned down, or maybe the relationship with your beautiful partner does not work out and now you have to deal with lawyers and a lot of mental stress.&lt;/p&gt;

&lt;p&gt;But black swans are not only personal things. Maybe the app you are developing is great, but one day you wake up and realize that someone has just released a very similar app that does something very similar to yours. Or maybe you hire some employees and one day they all leave at once because they were contacted by a recruiter, and now suddenly you do not have a team anymore!&lt;/p&gt;

&lt;p&gt;Or maybe a new technological breakthrough pops up that renders your product obsolete. Now what?!&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I am by no means telling you not to follow your dreams—in fact, I would like to make another video complementing this one telling you to precisely do that.&lt;/p&gt;

&lt;p&gt;What I want to avoid is you getting yourself ruined or in a great mess just because you did not think realistically.&lt;/p&gt;

&lt;p&gt;So, in conclusion, follow your dreams, but please, do not ignore reality.&lt;/p&gt;

&lt;p&gt;Thank you so much for watching this video! I really hope you like it.&lt;/p&gt;

&lt;p&gt;And now it is time to say goodbye.&lt;/p&gt;

&lt;p&gt;I send you a very big kiss, a very big hug, I remind you to never forget to be a good person, and I wish you happy coding.&lt;/p&gt;

&lt;p&gt;Chao Chao!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>career</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>Svelte vs React. Which one would I pick?</title>
      <dc:creator>Xavier Carrera Gimbert</dc:creator>
      <pubDate>Tue, 04 Mar 2025 17:23:05 +0000</pubDate>
      <link>https://dev.to/xavier_carreragimbert/svelte-vs-react-which-one-would-i-pick-24gf</link>
      <guid>https://dev.to/xavier_carreragimbert/svelte-vs-react-which-one-would-i-pick-24gf</guid>
      <description>&lt;p&gt;As a React developer, I’ve always been curious about Svelte. Everyone speaks highly of it, but I never had the chance to try it—until now.&lt;/p&gt;

&lt;p&gt;In this blog post, I’ll share my first impressions of Svelte compared to React and discuss which one I’d pick for my next project.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Similarities
&lt;/h2&gt;

&lt;p&gt;Let’s start with what makes both frameworks similar.&lt;/p&gt;

&lt;p&gt;The most important similarity is that they both rely on state, which, when changed, updates the DOM.&lt;/p&gt;

&lt;p&gt;Of course, they use different syntax to declare and modify state, but the core principle remains the same.&lt;/p&gt;

&lt;p&gt;For instance:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;useState&lt;/code&gt; in React is $state in Svelte.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;useEffect&lt;/code&gt; in React is $effect in Svelte.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Core Differences
&lt;/h2&gt;

&lt;p&gt;The key difference, in my opinion, is that React is essentially "JavaScript on steroids," whereas Svelte, thanks to its compiler, enables powerful functionality with minimal effort.&lt;/p&gt;

&lt;p&gt;To illustrate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In React, when you change the state, the component updates the Virtual DOM, compares it with the real DOM, and applies the necessary changes. If not handled properly, unnecessary Virtual DOM updates can be triggered, which isn’t a problem for small apps but can lead to performance issues in larger ones.&lt;/li&gt;
&lt;li&gt;In Svelte, you don’t need hooks or special functions—just update a variable like any other, and Svelte applies changes directly to the DOM without the overhead of a Virtual DOM.&lt;/li&gt;
&lt;li&gt;With React, you have to think in terms of re-renders. In Svelte, you simply update variables, and the framework takes care of the rest.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s an example of the same logic implemented in React and Svelte so you can see how much simpler Svelte can be.&lt;/p&gt;

&lt;p&gt;Svelte&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;
    let name = $state("")

    function submitForm(event) {
        event.preventDefault()

        alert(`Your name is ${name}`)
    }
&amp;lt;/script&amp;gt;

&amp;lt;form onsubmit={submitForm}&amp;gt;
    &amp;lt;label for="name"&amp;gt;Enter your name:&amp;lt;/label&amp;gt;
    &amp;lt;input id="name" bind:value={name} /&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;React&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from "react";

export default function NameForm() {
  const [name, setName] = useState("");

  const submitForm = (event) =&amp;gt; {
    event.preventDefault();
    alert(`Your name is ${name}`);
  };

  return (
    &amp;lt;form onSubmit={submitForm}&amp;gt;
      &amp;lt;label htmlFor="name"&amp;gt;Enter your name:&amp;lt;/label&amp;gt;
      &amp;lt;input
        id="name"
        value={name}
        onChange={(e) =&amp;gt; setName(e.target.value)}
      /&amp;gt;
      &amp;lt;button type="submit"&amp;gt;Submit&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, with Svelte, we declare the state using a simple variable, bind it to an input, and that’s all.&lt;/p&gt;

&lt;p&gt;With React, we have to use hooks. In this case, it doesn’t make the code significantly more complex, but as the app grows and more advanced data structures like arrays and objects are used, hooks can become more cumbersome to manage.&lt;/p&gt;

&lt;h2&gt;
  
  
  So, Is Svelte Better?
&lt;/h2&gt;

&lt;p&gt;From the example above, it might seem that Svelte is clearly superior. However, there’s a trade-off.&lt;/p&gt;

&lt;p&gt;Its Unique Syntax&lt;/p&gt;

&lt;p&gt;Since React is essentially JavaScript, once you learn its quirks, it feels natural to use. Svelte, on the other hand, has its own syntax and peculiarities that take time to learn.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In React, passing components as children is straightforward, you can have multiple components in a single file, and extracting reusable logic into hooks is easy.&lt;/li&gt;
&lt;li&gt;In Svelte, having multiple components in a file requires workarounds, components can’t be passed as props, and separating logic from HTML requires specific conventions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  "That Doesn’t Seem Like a Big Deal!"
&lt;/h2&gt;

&lt;p&gt;You’re right—learning a new syntax isn’t a huge issue, especially if it allows you to build logic more easily than React.&lt;/p&gt;

&lt;p&gt;But there’s another drawback that makes me lean toward React for my next project.&lt;/p&gt;

&lt;h2&gt;
  
  
  React Has a Massive Ecosystem—Svelte Doesn’t
&lt;/h2&gt;

&lt;p&gt;Because React is so popular, you can find a library for almost anything. With Svelte, it can be trickier.&lt;/p&gt;

&lt;p&gt;Yes, Svelte’s ecosystem is growing, with tools like SvelteKit (which functions similarly to Next.js for React) and support for many JavaScript libraries. However, React's ecosystem is vast, with countless libraries, tutorials, and community resources.&lt;/p&gt;

&lt;p&gt;For now, this makes React my go-to framework for larger projects.&lt;br&gt;
So, Which One Should You Pick?&lt;/p&gt;

&lt;p&gt;At the end of the day, the best tool is the one that helps you achieve your goals.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If your team is experienced in jQuery and PHP, those are the best tools for you.&lt;/li&gt;
&lt;li&gt;If your team masters Svelte, use Svelte.&lt;/li&gt;
&lt;li&gt;If you’re comfortable with React, stick with React.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both React and Svelte are excellent frameworks, each with its strengths and weaknesses. Choose the one that fits your needs.&lt;/p&gt;

&lt;p&gt;And if team composition and previous background don’t matter to you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pick React if having a big ecosystem of tutorials and libraries is important to you.&lt;/li&gt;
&lt;li&gt;Pick Svelte if you highly value a more straightforward syntax.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Which One Will I Pick?
&lt;/h2&gt;

&lt;p&gt;For big projects, I’ll stick with React because I know it well, and it has the largest ecosystem of libraries and tutorials.&lt;/p&gt;

&lt;p&gt;However, I’ll continue exploring Svelte. I really enjoyed working with it, and who knows? Maybe I’ll discover I was wrong and end up using Svelte for my big projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;React is king when it comes to libraries, tutorials, and community support.&lt;/li&gt;
&lt;li&gt;Svelte is clean, efficient, and has less boilerplate but comes with its own quirks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Try both and decide for yourself!&lt;/p&gt;

&lt;h2&gt;
  
  
  Additional Resources
&lt;/h2&gt;

&lt;p&gt;Here are the best Svelte tutorials I found:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=8DQailPy3q8" rel="noopener noreferrer"&gt;Svelte Crash Course&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=aYyZUDFZTrM" rel="noopener noreferrer"&gt;Svelte &amp;amp; SvelteKit Introduction&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Other:&lt;br&gt;
&lt;a href="https://github.com/Xalsar/svelte-todo-app" rel="noopener noreferrer"&gt;Simple todo app I build in svelte&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Acknowledgments
&lt;/h2&gt;

&lt;p&gt;Photo by Andres  Ayrton: &lt;a href="https://www.pexels.com/photo/woman-showing-apple-and-bitten-doughnut-6551415/" rel="noopener noreferrer"&gt;https://www.pexels.com/photo/woman-showing-apple-and-bitten-doughnut-6551415/&lt;/a&gt;&lt;/p&gt;

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