How should I structure a reusable Next.js app without over-engineering it?

August 10, 2026 4 answers
Asked by io7.wait
I'm building a reusable Next.js boilerplate and am trying to choose an architecture that stays practical without creating duplicate code. In a React and Express project, I typically use Web โ†’ API โ†’ Service โ†’ Repository โ†’ Database, which makes it straightforward to replace the web client with Android or iOS later. With Next.js, I'm considering Web โ†’ Server Action โ†’ Service โ†’ Repository โ†’ Database using Prisma, and then adding a separate API layer only if another client actually becomes necessary. I'm concerned that supporting both server actions and API routes could mean maintaining two adapters that perform the same work. Do you generally use server actions first, skip them in favor of route handlers, or organize the application another way? Should I follow YAGNI and wait until another client exists before adding an API?

Answers

miter saw setup
For a larger product, a monorepo can work well: separate the web and server apps, then share packages for validation, database access, authentication, API clients, UI components, and utilities. A typed validation layer and a shared API contract are especially useful when multiple clients are expected. Iโ€™d still start with only the packages and boundaries you actually need.
Reply to this answer
!watch the serve
A layered structure like API โ†’ service โ†’ repository โ†’ database isnโ€™t automatically over-engineering. Keeping persistence behind a repository can make testing and future database changes easier. The important part is to avoid adding layers that donโ€™t provide a clear boundary or benefit in your current application.
Reply to this answer
FIFTH COLUMN
Next.js is convenient for applications where the UI and backend are closely integrated, but complex API-heavy systems may be clearer as a dedicated backend plus a separate client. Server actions are useful for operations initiated directly by the Next.js UI; route handlers or a standalone API make more sense when the same capabilities must serve mobile apps, third parties, or several frontends.
Reply to this answer
35mm-frame
Donโ€™t design around a hypothetical mobile app. Keep the business rules in shared service modules, and make server actions or route handlers thin adapters around those services. If a mobile client or another integration becomes real, add an API at that point instead of maintaining two interfaces from day one.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions