<?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: joonlee22</title>
    <description>The latest articles on DEV Community by joonlee22 (@joonlee22).</description>
    <link>https://dev.to/joonlee22</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%2F3971896%2F3a9848af-eb92-4f09-a258-075ea82d18ee.png</url>
      <title>DEV Community: joonlee22</title>
      <link>https://dev.to/joonlee22</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/joonlee22"/>
    <language>en</language>
    <item>
      <title>I Built a Production-Ready Node.js SaaS Boilerplate So You Don't Have To</title>
      <dc:creator>joonlee22</dc:creator>
      <pubDate>Sat, 06 Jun 2026 22:54:18 +0000</pubDate>
      <link>https://dev.to/joonlee22/i-built-a-production-ready-nodejs-saas-boilerplate-so-you-dont-have-to-58o2</link>
      <guid>https://dev.to/joonlee22/i-built-a-production-ready-nodejs-saas-boilerplate-so-you-dont-have-to-58o2</guid>
      <description>&lt;p&gt;Every time I started a new SaaS project, I spent the first 3 days building the same things.&lt;/p&gt;

&lt;p&gt;Auth. Billing. Database setup. Deployment config. Every. Single. Time.&lt;/p&gt;

&lt;p&gt;So I stopped. I packaged everything into a production-ready boilerplate and I'm never doing it again.&lt;/p&gt;

&lt;p&gt;Here's exactly what I built and how it works.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Stack
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Backend:&lt;/strong&gt; Node.js + Express&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Frontend:&lt;/strong&gt; Next.js 14 + Tailwind CSS&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database:&lt;/strong&gt; PostgreSQL + Prisma ORM&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Auth:&lt;/strong&gt; JWT (access + refresh tokens) + Google OAuth&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Billing:&lt;/strong&gt; Stripe subscriptions&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deployment:&lt;/strong&gt; Railway (backend) + Vercel (frontend)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Auth — Done Right
&lt;/h2&gt;

&lt;p&gt;Most tutorials show you JWT auth but skip the details that matter in production:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Access tokens expire in 7 days&lt;/li&gt;
&lt;li&gt;Refresh tokens are stored in the database and &lt;strong&gt;rotated on every use&lt;/strong&gt; — if a token is stolen and used, the original is invalidated&lt;/li&gt;
&lt;li&gt;Google OAuth creates or links accounts automatically&lt;/li&gt;
&lt;li&gt;bcrypt with 12 salt rounds for password hashing&lt;/li&gt;
&lt;li&gt;Rate limiting on auth routes (10 requests per 15 minutes) to block brute force attacks
&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="c1"&gt;// Refresh token rotation — prevents reuse after theft&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rotateRefreshToken&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rawRefresh&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;stored&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;prisma&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;refreshToken&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findUnique&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;rawRefresh&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;include&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&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="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;stored&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;stored&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;expiresAt&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&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="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Delete old token before issuing new one&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;prisma&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;refreshToken&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;stored&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&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="nf"&gt;issueTokens&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;stored&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="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Stripe Billing — The Parts Nobody Explains&lt;br&gt;
Stripe docs are good but they don't show you how to wire everything together in a real app. Here's what I set up:&lt;/p&gt;

&lt;p&gt;Checkout Sessions — user clicks upgrade, gets redirected to Stripe, comes back subscribed&lt;br&gt;
Customer Portal — one line of code lets users manage, upgrade, downgrade, or cancel themselves&lt;br&gt;
Webhooks — subscription changes sync to your database automatically&lt;br&gt;
Plan-gated routes — lock API endpoints behind a minimum plan level&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="c1"&gt;// Lock a route behind a plan — one line&lt;/span&gt;
&lt;span class="nx"&gt;router&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;/analytics&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;requireAuth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;requirePlan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;STARTER&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The webhook handler covers all the important events:&lt;/p&gt;

&lt;p&gt;customer.subscription.created — new subscriber&lt;br&gt;
customer.subscription.updated — plan change&lt;br&gt;
customer.subscription.deleted — cancellation, auto-downgrades to FREE&lt;br&gt;
Database Schema&lt;br&gt;
Three models — kept it simple:&lt;/p&gt;

&lt;p&gt;User — email, password hash, Google ID, Stripe customer ID&lt;br&gt;
Subscription — plan, status, billing period, Stripe subscription ID&lt;br&gt;
RefreshToken — token, user, expiry (enables token rotation and logout-all-devices)&lt;br&gt;
Deployment&lt;br&gt;
Both services have config files included:&lt;/p&gt;

&lt;p&gt;railway.json for the backend&lt;br&gt;
Vercel auto-detects Next.js&lt;br&gt;
The backend handles graceful shutdown on SIGTERM — Railway and Render send this signal on every deploy, so in-flight requests finish cleanly before the process exits.&lt;/p&gt;

&lt;p&gt;Live Demo&lt;br&gt;
You can see the full frontend running here:&lt;br&gt;
&lt;a href="https://saas-boilerplate-hsh5xrikl-johnolee15-9278s-projects.vercel.app" rel="noopener noreferrer"&gt;https://saas-boilerplate-hsh5xrikl-johnolee15-9278s-projects.vercel.app&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Landing page, auth, dashboard, billing — all working.&lt;/p&gt;

&lt;p&gt;Get the Code&lt;br&gt;
I packaged this up and listed it on Gumroad for $49:&lt;br&gt;
👉 &lt;a href="https://looneyjoons.gumroad.com/l/nodejs-saas-boilerplate" rel="noopener noreferrer"&gt;https://looneyjoons.gumroad.com/l/nodejs-saas-boilerplate&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Includes the full backend + frontend source, README with step-by-step setup, and .env.example with every variable documented.&lt;/p&gt;

&lt;p&gt;If you have any questions about the stack or implementation drop them in the comments — happy to help.&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
