How much layering makes sense in a Next.js boilerplate?

November 16, 2026 5 answers
Asked by _m42~corksignal.8

My React and Express projects use API, service, repository, and database layers. For a reusable Next.js boilerplate, should I keep that structure, start with server actions, or use API routes from the beginning?

I might want a mobile client later, but I don't want to maintain duplicate business logic or build layers I won't need.

Answers

n.391+velcrohook

Start with server actions if the web app is the only client you need right now. Keep the actual business logic in service functions, with actions handling the web-facing input and calling those functions.

If a mobile client becomes real, add route handlers that call the same services. You'll still have two entry points to maintain, but the rules and database work don't have to be duplicated. Make sure each entry point handles validation and authorization rather than assuming the other one has done it.

JuniperStatic:

That also leaves room to share validation schemas where the inputs are the same, while keeping each entry point responsible for checking its own requests.

Reply to this answer
Tavrin.3x

A service and repository layer isn't automatically overengineering. If those boundaries make database access easier to test and keep SQL or ORM details out of your business logic, they can be worth having from the start.

I wouldn't add a repository interface for every trivial query just because the boilerplate has a slot for one, though. Let the complexity of the feature decide how much abstraction earns its keep.

Reply to this answer
_d46+tagpocket.8

If you already know the project will have several clients, an API-first setup is reasonable too. Web and mobile can both use the same API contract, so you avoid building equivalent actions and endpoints for every operation. The tradeoff is that you give up some of the convenience of calling server-side code directly from the Next.js app.

Reply to this answer
_g44!mosaicspool.2

There's also the question of whether Next.js is the right starting point at all. For an API-heavy application, a separate React client and backend can be a simpler fit than shaping everything around Next.js conventions. If the goal is specifically a Next.js boilerplate, though, that's a framework choice rather than a reason to rebuild the whole architecture.

Reply to this answer
VelvetIndex

Another option is a monorepo with separate client and server apps plus shared packages for database code, validation, or API client functions. That's useful when those pieces really do need to be shared. For a small boilerplate, a single app with clear module boundaries may be plenty.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions