Most SaaS projects start the same way.
You scaffold a Node.js backend, then gradually add authentication, billing, database models, email notifications, background jobs, and API documentation.
After doing this repeatedly, I wanted a cleaner starting point for new projects. So I structured a backend foundation with the most common SaaS components already wired together.
This is the architecture I ended up with.
Tech Stack
The backend is built with:
- Node.js
- TypeScript
- Express
- PostgreSQL
- Drizzle ORM
- Stripe (billing)
- Resend (transactional email)
- Zod (validation)
- OpenAPI / Swagger (API docs)
The goal wasn't just to include these tools, but to organize them in a way that keeps business logic separate from infrastructure.
Folder Structure
This is the high-level folder structure used in the project:
The backend is organized into layers so business logic, infrastructure integrations, and the HTTP layer remain isolated.
API Documentation
The API is documented using OpenAPI, making it easy to explore and test endpoints during development.
Swagger UI exposes the available endpoints and request schemas for quick testing.
Example Request Flow
A typical API request flows like this:
- Express route receives the request
- Middleware applies rate limiting and authentication
- Controller calls the relevant module
- Module applies policy rules
- Infrastructure adapters interact with the database or external APIs
- Response is returned to the client
Keeping integrations behind adapters makes them easier to replace later.
Built-In SaaS Components
The backend includes several common pieces needed for SaaS applications:
- Authentication and user management
- Stripe billing with webhook handling
- PostgreSQL database setup
- Transactional email support
- API documentation via OpenAPI
- Structured error handling
- Rate limiting and security middleware
- End-to-end tests
These are things many SaaS projects end up implementing anyway.
Demo
I recorded a short demo showing the server startup and readiness checks.
You can see it here:
Final Thoughts
The goal was to create a backend structure that is easy to extend without mixing business logic with infrastructure code.
I'm curious how others structure Node.js backends for SaaS products.
Do you prefer layered architectures like this, or something simpler?


Top comments (0)