Engineering3 min read
Our default Next.js setup for production SaaS
The stack, structure and guardrails we start new SaaS products with, and why. Opinionated, boring in the best way, and easy for the next developer to pick up.
ALBy the Adviqlabs team
Every project is different, but the first week of a new SaaS product looks surprisingly similar each time. Having a default setup means we spend that week on your product instead of re-debating tooling. Here's what it looks like and the reasoning behind each choice.
The core
- Next.js (App Router) + React + TypeScript, strict mode on
- Tailwind CSS with a small set of design tokens, plus accessible headless components for complex UI like dialogs and menus
- PostgreSQL as the system of record
- Prisma or Drizzle for schema, migrations and typed queries
- Zod for validating anything that crosses a boundary: forms, API input, environment variables, webhook payloads
Nothing here is exotic. That's deliberate: mainstream tools are well documented, well supported and familiar to the next developer you hire.
Project structure
We keep the structure flat and predictable:
src/
app/ routes, layouts, server actions
components/ shared UI
features/ feature modules (billing, projects, members...)
lib/ db client, auth, email, utilities
server/ server-only logic and data access
Two rules make a big difference:
- Data access lives on the server. Components never talk to the database directly; they call functions in
server/that check permissions first. - Every server action validates its input and checks authorisation. A server action is a public endpoint, even if the button that calls it is hidden.
Multi-tenancy from day one
Most B2B SaaS products have organisations or workspaces. We model this from the first migration: every tenant-owned table has an organization_id, every query filters by it, and there's a single helper that returns the current user's organisation and role. Adding multi-tenancy later is one of the most painful refactors in SaaS, and it's cheap to do upfront.
Auth, billing and email
- Auth: a proven library or service, never hand-rolled password handling
- Billing: Stripe or Razorpay, with webhooks as the source of truth for subscription status
- Email: a transactional provider, with templates in code so they're versioned and reviewable
Quality gates
Every pull request runs:
- Type checking and linting
- Unit tests for business logic, and integration tests for critical paths such as sign-up, billing and permissions
- A production build
- A preview deployment with its own URL, so reviewers and clients can click through the change
Main is always deployable. Releases are small and frequent, which makes each one less risky.
Observability
From the first deploy:
- Error tracking with source maps, so exceptions arrive with a readable stack trace
- Structured logs with request IDs
- Uptime checks on key pages and the API
- Product analytics on the core loop, respecting privacy and consent requirements
Environments and secrets
- Separate development, staging and production environments, each with its own database
- Secrets in the hosting platform's secret store, never in the repository
- Environment variables validated at startup, so a missing key fails loudly on deploy instead of quietly at 2am
Backups
Automated daily backups with point-in-time recovery where the database supports it. And a restore test before launch, because a backup you've never restored is only a hope.
What we don't add on day one
- Microservices
- Kubernetes
- A separate API layer the product doesn't need yet
- Caching layers before there's a measured performance problem
Each of these has a place. None of them belongs in the first version of most products.
Starting a SaaS product? This is the foundation we'd build yours on. Let's talk.