<?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: Azzam Faraj</title>
    <description>The latest articles on DEV Community by Azzam Faraj (@azzam_faraj).</description>
    <link>https://dev.to/azzam_faraj</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%2F1009854%2F79d5490f-a5f8-4a2c-8a83-528c76bfbbc1.png</url>
      <title>DEV Community: Azzam Faraj</title>
      <link>https://dev.to/azzam_faraj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/azzam_faraj"/>
    <language>en</language>
    <item>
      <title>Fastify, Prisma, Zod &amp; Swagger</title>
      <dc:creator>Azzam Faraj</dc:creator>
      <pubDate>Sat, 26 Jul 2025 18:45:31 +0000</pubDate>
      <link>https://dev.to/azzam_faraj/fastify-prisma-zod-swagger-1k06</link>
      <guid>https://dev.to/azzam_faraj/fastify-prisma-zod-swagger-1k06</guid>
      <description>&lt;h2&gt;
  
  
  Fastify Prisma Boilerplate — A Productive API Starter
&lt;/h2&gt;

&lt;p&gt;As someone who frequently spins up backend projects, I got tired of repeating the same setup. So I built a boilerplate that helps me get started faster with less boilerplate and more actual work.&lt;/p&gt;

&lt;p&gt;This project combines &lt;strong&gt;Fastify&lt;/strong&gt;, &lt;strong&gt;Prisma&lt;/strong&gt;, &lt;strong&gt;Zod&lt;/strong&gt;, and &lt;strong&gt;TypeScript&lt;/strong&gt; into a lightweight, type-safe, and efficient REST API starter — with auto-generated routes, a CLI, and built-in validation.&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://github.com/AZZIE2000/fastify-prisma-boilerplate" rel="noopener noreferrer"&gt;GitHub Repo&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;⚡ &lt;strong&gt;Fastify&lt;/strong&gt; for high-performance APIs&lt;/li&gt;
&lt;li&gt;🐘 &lt;strong&gt;Prisma&lt;/strong&gt; for type-safe DB access (PostgreSQL)&lt;/li&gt;
&lt;li&gt;✅ &lt;strong&gt;Zod&lt;/strong&gt; for schema validation and typing&lt;/li&gt;
&lt;li&gt;🔒 &lt;strong&gt;End-to-end type safety&lt;/strong&gt; with &lt;code&gt;fastify-type-provider-zod&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;📝 &lt;strong&gt;Swagger&lt;/strong&gt; auto-docs via &lt;code&gt;@fastify/swagger&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;🛠 &lt;strong&gt;CLI&lt;/strong&gt; to scaffold routes&lt;/li&gt;
&lt;li&gt;♻️ &lt;strong&gt;Auto-registration&lt;/strong&gt; of route files&lt;/li&gt;
&lt;li&gt;🌐 &lt;code&gt;.env&lt;/code&gt; support via &lt;code&gt;dotenv&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/AZZIE2000/fastify-prisma-boilerplate my-api
&lt;span class="nb"&gt;cd &lt;/span&gt;my-api
npm &lt;span class="nb"&gt;install
cp&lt;/span&gt; .env.example .env     &lt;span class="c"&gt;# Set DATABASE_URL&lt;/span&gt;
npx prisma migrate dev   &lt;span class="c"&gt;# Apply DB schema&lt;/span&gt;
npm run dev              &lt;span class="c"&gt;# Start server&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;API: &lt;code&gt;http://localhost:8080&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Docs: &lt;code&gt;http://localhost:8080/docs&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  CLI: Generate Routes Automatically
&lt;/h2&gt;

&lt;p&gt;The project includes a built-in CLI that creates new route files for you, based on what type of endpoints you want.&lt;/p&gt;

&lt;h3&gt;
  
  
  Usage
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run route &amp;lt;name&amp;gt; &amp;lt;crud combo&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run route product crud
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will generate &lt;code&gt;src/routes/product.ts&lt;/code&gt; with the following endpoints:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Letter&lt;/th&gt;
&lt;th&gt;Endpoint&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;c&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;POST /api/product&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;r&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;GET /api/product&lt;/code&gt; + &lt;code&gt;GET /:id&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;u&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;PATCH /:id&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;d&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;DELETE /:id&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;You can customize which APIs to include. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run route product &lt;span class="nb"&gt;cd&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Will generate only the &lt;code&gt;create&lt;/code&gt; and &lt;code&gt;delete&lt;/code&gt; routes. This helps you avoid unused code and stay focused.&lt;/p&gt;




&lt;h2&gt;
  
  
  Auto-Registration of Routes
&lt;/h2&gt;

&lt;p&gt;Any file you place in &lt;code&gt;src/routes&lt;/code&gt; is automatically registered by the server.&lt;br&gt;
The filename becomes the API path prefix. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/routes/user.ts → /api/user
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You don’t need to import or register anything manually. The server handles it for you.&lt;/p&gt;




&lt;h2&gt;
  
  
  Type Safety &amp;amp; Validation
&lt;/h2&gt;

&lt;p&gt;Each route uses &lt;strong&gt;Zod&lt;/strong&gt; for schema validation. When combined with &lt;code&gt;fastify-type-provider-zod&lt;/code&gt;, your schemas automatically become your TypeScript types.&lt;/p&gt;

&lt;p&gt;This means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Requests are &lt;strong&gt;validated&lt;/strong&gt; at runtime&lt;/li&gt;
&lt;li&gt;Your handlers get &lt;strong&gt;fully typed&lt;/strong&gt; &lt;code&gt;request.body&lt;/code&gt;, &lt;code&gt;request.params&lt;/code&gt;, etc.&lt;/li&gt;
&lt;li&gt;No need to manually define TypeScript interfaces for every route&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Project Structure
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.
├── prisma/             # Prisma schema
├── src/
│   ├── cli/            # Route generator logic
│   ├── plugins/        # Fastify plugins (e.g. db)
│   ├── routes/         # API endpoints
│   ├── utils/          # Shared utilities
│   └── index.ts        # Server entry
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Scripts
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;npm run dev&lt;/code&gt; – Start dev server&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;npm run build&lt;/code&gt; – Build TypeScript&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;npm run start&lt;/code&gt; – Start compiled server&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;npm run route &amp;lt;name&amp;gt; &amp;lt;crud&amp;gt;&lt;/code&gt; – Generate route file&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;This boilerplate helps reduce setup time and lets you focus on building features — with structure, type safety, and simplicity built in.&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://github.com/AZZIE2000/fastify-prisma-boilerplate" rel="noopener noreferrer"&gt;https://github.com/AZZIE2000/fastify-prisma-boilerplate&lt;/a&gt;&lt;/p&gt;

</description>
      <category>fastify</category>
      <category>prisma</category>
      <category>zod</category>
      <category>swagger</category>
    </item>
  </channel>
</rss>
