Why I chose T3 stack as the full-stack to build the react app
Tags: webdev, nextjs, typescript, productivity
Published: 2022-12-06 10:02:25

# What is T3 stack?

The *"T3 Stack"* is a web development stack made by [Theo](https://twitter.com/t3dotgg) focused on **simplicity**, **modularity**, and **full-stack typesafety**. It consists of:

- [TypeScript](https://typescriptlang.org/)
- [Tailwind CSS](https://tailwindcss.com/)
- [Next.js](https://nextjs.org/)
- [NextAuth.js](https://next-auth.js.org/)
- [Prisma](https://prisma.io/)
- [tRPC](https://trpc.io/)

[create-t3-app](https://github.com/t3-oss/create-t3-app) is the simple CLI made by @nexxeln to scaffold a starter project using the t3 stack.  If you haven’t tried the stack yet, seeing the rocket rising curve of the star, which climb to more than 11k within six months,  how not to try it as a modern developer 😉

![T3 star](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j79dtqqc8cdx5ahlk2nr.png)


# Why it is perfect for me

Believe it or not,  I actually chose T3 stack before I was aware of it.  I was very happy to finally choose the ‘perfect’ full stack as the standard for the web apps I’m going to build after lots of research on the market.  Then all of sudden T3 rushed into my eyes, with everything perfectly matched, the feeling was kind of mixed like below:

![Mixed feeling](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/80u6njs0x7fj7c0sht3s.png)

I think the reason why I end up choosing the same stack as the T3 stack is that I totally agree with the **Axioms of T3.**

1. **Solve Problems**
    
    It's easy to fall into the trap of "adding everything" - we explicitly *don't* want to do that. Everything added to `create-t3-app` should solve a *specific* problem that exists within the core technologies included.
    
2. **Bleed Responsibly**
    
    We love our bleeding edge tech. The amount of speed and, honestly, *fun* that comes out of new shit is really cool. We think it's important to **bleed responsibly**, using riskier tech in the less risky parts.
    
3. **Typesafety Isn't Optional**
    
    The stated goal of `create-t3-app` is to provide the quickest way to start a new full-stack, typesafe web application. We take typesafety seriously in these parts as it improves our productivity and helps us ship fewer bugs.
    

Both 2 and 3 are important principles for me when choosing the stack.  

# What about alternatives?

“Every coin has two sides,” so why choose this over other alternatives? Well, generally speaking, I think it depends on what you have and what you believe.  I will show you mine one by one.

1. [TypeScript](https://typescriptlang.org/)
    
    Despite “**Typesafety Isn't Optional”** being the principle,  I don’t think we need to discuss TypeScript vs. JavaScript anymore. It’s 2022 already. 
    
2. [Tailwind CSS](https://tailwindcss.com/)
    
    As a long-time backend developer who recently came to the frontend world, CSS was always the most difficult monster for me.  After reading “[a few thousand words](https://adamwathan.me/css-utility-classes-and-separation-of-concerns/)” from Tailwind CSS’s creator Adam Wathan, my long-time fuzzy feeling about the CSS trouble is finally clear — the best way of managing CSS is not to write CSS at all. 
    
    Therefore, I totally got to buy in for the utility-first approach.  In that world, the only thing is worth mentioning is [Tachyons](http://tachyons.io/).   However, although it came way earlier than Tailwind, it is **[said to be feature-complete](https://github.com/tachyons-css/tachyons/issues/689#issuecomment-749820180),** and one cannot expect new features to be added or problems discussed. The latest release is almost [five years old](https://github.com/tachyons-css/tachyons/releases), which definitely violates the principle “**Bleed Responsibly**”.   You can also see that from the star trend:
    ![TailWind star](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4i1jslzuw8xfghxtxr46.png)
    
3. [Next.js](https://nextjs.org/)
    
    Originally I thought this one was another no need to discuss like Typescript as the dramatic fanfare Nextjs and Vercel brought to the frontend world.  But during writing this article, I noticed an upstart: [Remix](https://remix.run/).  
    
    To be honest, I don’t have too much information about Remix.  But Theo did make a point about the Remix in [one of his tweets](https://twitter.com/t3dotgg/status/1499896450737573889) as below:
    
    ![Remix vs Next](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b31tmhu9eon5nmddhfs6.png)
    Although the volume is not compared to Next.js now, it brings interesting experience improvements like Rewrite, Mutation, Unhandled Errors, etc. Also, it has a good rising trend. Maybe it would be another **bleeding edge**, so let’s keep an eye on it.

    ![Remix](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nhut87mr6q438tdc8nyt.png)
    
4. [NextAuth.js](https://next-auth.js.org/)
    
    > If you want a full-featured authentication system with built-in providers (Google, Facebook, GitHub…), JWT, JWE, email/password, magic links, and more… use `[next-auth](https://github.com/nextauthjs/next-auth-example)`.
    > 
    
    That’s specified in the [official document of Next.js](https://nextjs.org/docs/authentication#bring-your-own-database). 
    
5. [Prisma](https://prisma.io/)
    
    Since “**Typesafety Isn't Optional,”** ORM is mandatory.  
    
    Personally, this is the only area that comes with a real competitor: [TypeORM](https://typeorm.io/)
    
    ![Prisma vs TypeORM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mtrmzdzg45fj2r6jodbj.png)
    
    Leave alone the star trend,  Prisma’s lack of stability, as they made breaking changes for both version 2 and version 3,  is a major turnoff for some people.  
    
    Actually, I have been using TypeORM myself for several years, and everything works just fine. 
    
    **Then why change to Prisma?**
    
    The major reason is still the principle “**Typesafety Isn't Optional**.”  Because Prisma generates types for its queries on the fly, So there are [numerous situations](https://www.prisma.io/docs/concepts/more/comparisons/prisma-and-typeorm#type-safety) it can provide stronger guarantees for the types of query results than TypeORM.  
    
    Another consideration is that TypeORM is closer to mirroring SQL in its API like the ILike below:
    
    ```jsx
    const posts = await postRepository.find({
      where: {
        title: ILike('Hello World'),
      },
    })
    ```
    
    It is not a problem for a backend developer, but as a full-stack solution, it’s better to try to avoid the SQL concept at all.
    
6. [tRPC](https://trpc.io/)
    
    Looking at the headline of the website of tRPC,  you definitely know why I choose it.  
    
    ![tRPC](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wba6gjalc5974f0u7eul.png)
    
    Yes, still, “**Typesafety Isn't Optional**.”   
    
    If you are using GraphQL, you might think it also gets typesafety in the end because of the agreed schema between the frontend and backend.   It is probably best for the separated frontend and backend(which has an unavoided version management issue), but not for the full-stack monorepo.  It has to go through the code-generating process which comes with the price of a long time for type checking,  less intelligence support of IDE, and a larger client bundle size.  Furthermore, it indeed introduce a new non-trivial terminology, which means you need to first learn and understand it well before get it correct. 
    
    > tRPC instead relies on one very large assumption: Your server is written in TypeScript, and is co-located with the client code. tRPC has you define a server-side router for your procedures, then export the type of that which Typescript automatically infers, and then import that type to be used on the client side. Since types are automatically removed when Typescript code is compiled, there is no extra code added to the client bundle, and no extra types to slow down the type checker. Just type safety.
    > 
    
    It come from [a post](https://echobind.com/post/why-we-ditched-graphql-for-trpc) for a real case of switching from GraphQL to tRPC which elaborate in detail about the comparison between GraphQL and tRPC.  
    

# Confession

There is one thing I need to confess,  although I do consider using tRPC at first, I end up not using it.   

One reason is that since Prisma already generates CRUD for the backend, why not take one step further to generate the frontend query too?

Another reason is that client is not get to pick which fields it fetches compared to GraphQL.

I end up using the new toolkit [ZenStack](https://zenstack.dev/?utm_campaign=devto&utm_medium=organic&utm_content=why_I_choose T3_stack): **A toolkit for building secure CRUD apps with Next.js + Typescript.**  You will get typesafety hooks for every data type defined in the schema without having to define the API.  Moreover, it’s client who decide what the result looks like.

See the actual stack I’m using to build a SaaS app:

{% embed https://dev.to/zenstack/how-to-build-a-collaborative-saas-product-using-nextjs-and-zenstacks-access-control-policy-1nc1 %}