DEV Community

lamaizi hajar
lamaizi hajar

Posted on

I packaged my go-to Node.js/TypeScript backend setup into a boilerplate

Every time I started a new backend project, I rebuilt the same things: JWT auth, CSRF protection, Docker setup, and, when a client needed it, invoicing. After doing it one time too many, I packaged it all into a boilerplate. Here's what's inside and the choices I made.

The stack

  • Node.js + TypeScript + Express
  • Prisma + PostgreSQL
  • Docker Compose (nginx + api + db), ready to deploy
  • Headless: no frontend included, so it works with web, mobile, or nothing at all

Auth: JWT + CSRF

Authentication uses JWT with CSRF protection, covered by integration tests. Role-based access (USER / ADMIN) is built in, so protected routes like "create a product" are restricted to admins from day one.

A billing module (the part I'm most happy with)

Most boilerplates stop at auth. I added a billing flow:

Company settings → Client → Product → Order → Invoice (PDF)

Two design decisions worth sharing:

  1. Price snapshots. When an order is created, the product's price and VAT rate are copied into the order line. Changing the catalog price later never alters past orders.
  2. Idempotent invoicing. Calling "generate invoice" twice on the same order returns the same invoice instead of creating a duplicate, so the sequential invoice numbering never gets a gap or a duplicate (a legal requirement in Morocco).

Invoices are generated as PDFs with the legal mentions required in Morocco (ICE, IF, RC, patente, HT/TVA/TTC totals). The structure is generic enough to adapt to other markets.

Bonus modules for Morocco/MENA

  • SMS/OTP phone verification via EnvoiSMS.ma, tested with real SMS.
  • PayZone and CMI payment gateway integrations. Be aware these need your own merchant account to activate, and I have not been able to validate them against live gateways. They are documented, but treat them as a solid starting point rather than a finished integration.

What's not included

No frontend, no hosting setup beyond Docker, and no merchant accounts for the payment modules.

Get it

It's $29 on Gumroad: https://hajarlmz.gumroad.com/l/noduk

I'd really like feedback: is the feature set right? What would you want added? Let me know in the comments.

Top comments (0)