Clean Architecture Next.js
— NextJS, Architecture, Clean Code, Typescript — 2 min read
Clean Architecture in Next.js – How I Build Large Projects That Are Easy to Maintain in 2026
Hey everyone,
The longer I code, the more I realize that folder structure and architecture matter far more than how fancy the tech stack you're using is.
This year I did a lot of refactoring on large projects using a Clean Architecture + Feature-Sliced Design approach. Here's how I structure my Next.js projects now:
1. The Folder Structure I Use
/src /app → Next.js App Router (route handlers, pages) /features → Main features (user, invoice, dashboard, etc.) /entities → Business entities (User, Order, Invoice, etc.) /shared → Components, utils, hooks, UI library /lib → Config, database, auth, third-party /server → Server actions, repositories, services2. Feature-Sliced Design (My Favorite)
Each feature has its own structure:
/features/invoice /ui → Invoice-specific UI components /api → Route handlers & server actions /model → Types, schemas (Zod), entities /lib → Business logic & services /hooks → Custom hooks3. Architecture Layers
- Entities → Pure business logic, unaware of the framework
- Use Cases / Services → Application logic
- Adapters → Concrete implementations (database, external API)
- Framework → Next.js, React, etc. at the outermost layer
4. Benefits I've Experienced
- Easy onboarding for new developers
- Very easy to test (unit & integration)
- Logic can be reused across features
- Scalable as the project grows bigger
- Frontend & backend logic are more decoupled
Conclusion
Clean Architecture isn't just "cool on paper." In real projects, it's made my team and me much faster at developing new features, and we rarely run into spaghetti code.
If your project has started to feel "heavy" and hard to change, maybe it's time to refactor the structure.
A question for you all: What folder structure does your project use? Have you tried Clean Architecture or Feature-Sliced Design? How was your experience?
Share your thoughts in the comments, I really enjoy discussing architecture!
— Ady Rahmansyah Software Engineer | Tech Blogger | Coffee Addict