DEV Community

Cover image for How I Structure a Production Next.js App in 2026
Syed Bilal Hassan Bukhari
Syed Bilal Hassan Bukhari

Posted on • Originally published at bilalshah.dev

How I Structure a Production Next.js App in 2026

The Next.js Project Structure I Use for Production Apps in 2026

If you're building a serious Next.js app in 2026, project structure is no longer just a folder preference. It affects maintainability, onboarding, performance, SEO, debugging, and how confidently you can ship new features.

Next.js has evolved into a complete full-stack framework with App Router, Server Components, Route Handlers, metadata APIs, streaming, caching, and file-based conventions. One of the biggest mistakes developers make is treating production applications like demo projects.

A scalable application needs a structure that clearly separates routing, business logic, validation, UI, database access, and SEO concerns without becoming over-engineered.

My Production Next.js Structure

For most production applications, I prefer a src-based architecture:

src/
  app/
    (site)/
    admin/
    api/
    layout.tsx
    sitemap.ts
    robots.ts
  actions/
  components/
    ui/
    forms/
    cards/
    dashboard/
  config/
  hooks/
  lib/
  models/
  types/
  utils/
  validations/

public/
Enter fullscreen mode Exit fullscreen mode

This structure keeps the App Router focused on routing and rendering while the rest of the application handles reusable logic, data access, validation, and UI.


1. Keep Routes Inside app, Not Everything

The app directory should describe your route tree.

app/
  (site)/
    page.tsx
    blogs/
    projects/
    services/
    contact/
  admin/
    auth/
    dashboard/
  api/
    emails/
    projects/
  layout.tsx
  sitemap.ts
  robots.ts
Enter fullscreen mode Exit fullscreen mode

Route groups such as (site) help organize layouts without affecting URLs.

For example:

app/(site)/blogs/page.tsx
Enter fullscreen mode Exit fullscreen mode

Still becomes:

/ blogs
Enter fullscreen mode Exit fullscreen mode

This separation makes public pages, admin sections, and APIs easy to navigate.


2. Use Server Components by Default

My default rule in 2026 is simple:

Use Server Components unless you specifically need client-side interactivity.

Good Server Component Examples

  • Blog listing pages
  • Project pages
  • Service pages
  • Metadata generation
  • Database-backed dashboards

Good Client Component Examples

  • Search inputs
  • Theme toggles
  • Infinite scroll
  • React Hook Form forms
  • Interactive carousels
  • Command palettes

This approach reduces JavaScript sent to the browser and improves SEO because meaningful content can be rendered before hydration.


3. Put Business Logic in actions

I avoid placing database mutations directly inside pages.

Instead:

actions/
  blogActions.ts
  projectActions.ts
  serviceActions.ts
  authActions.ts
  inquiryActions.ts
Enter fullscreen mode Exit fullscreen mode

Pages should call actions.

Actions should:

  1. Connect to the database
  2. Validate input
  3. Read or mutate data
  4. Return serialized responses
  5. Revalidate affected pages

For example, updating a blog post may require revalidating:

  • Blog detail page
  • Blog listing page
  • Sitemap
  • Dashboard views

Keeping that logic centralized makes maintenance easier.


4. Keep Validation Separate

Validation deserves its own layer.

validations/
  blogSchema.ts
  projectSchema.ts
  serviceSchema.ts
  inquirySchema.ts
Enter fullscreen mode Exit fullscreen mode

I typically use Zod and keep all rules in one place.

Benefits include:

  • Better security
  • Consistent validation
  • Easier maintenance
  • Reusable schemas across forms, APIs, and actions

If a blog title requires a minimum length of 10 characters, that rule should exist only once.


5. Separate Database Models from UI

For MongoDB applications:

models/
  Blog.ts
  Project.ts
  Service.ts
  Email.ts
  User.ts
Enter fullscreen mode Exit fullscreen mode

Components shouldn't care how data is stored.

Their job is simple:

  • Receive data
  • Render UI

Database access should remain inside actions and models.

This separation becomes increasingly valuable as applications grow.


6. Build UI in Layers

Avoid dumping hundreds of components into one folder.

Instead:

components/
  ui/
  forms/
  cards/
  dashboard/
  layout/
  blog-toc.tsx
  search-input.tsx
Enter fullscreen mode Exit fullscreen mode

ui/

Contains reusable design-system primitives:

  • Button
  • Input
  • Dialog
  • Sheet
  • Badge
  • Table

Feature Components

Examples include:

  • Blog cards
  • Project cards
  • Dashboard widgets
  • Inquiry rows

This keeps the design system consistent across the application.


7. Treat SEO as a First-Class Feature

SEO should never be an afterthought.

Every production application should include:

  • Dynamic metadata
  • Canonical URLs
  • Open Graph images
  • Twitter cards
  • JSON-LD structured data
  • Sitemap generation
  • Robots configuration
  • SEO-friendly slugs
  • Internal linking

Next.js makes this much easier through metadata APIs, Open Graph support, sitemap.ts, and robots.ts.

If organic traffic matters, SEO deserves dedicated architecture from day one.


8. Use Route Handlers for Real API Boundaries

Route Handlers are excellent for:

  • Webhooks
  • Public APIs
  • Third-party integrations
  • External form submissions

Example:

app/api/
  emails/route.ts
  projects/route.ts
  admin/activity/route.ts
Enter fullscreen mode Exit fullscreen mode

My rule is simple:

  • Internal mutations → Server Actions
  • External consumers → Route Handlers

Choosing the right boundary keeps applications cleaner.


9. Add Loading, Error, and Not Found States

Production apps should account for more than happy paths.

app/
  loading.tsx
  error.tsx
  not-found.tsx

  blogs/
    [slug]/
      page.tsx
Enter fullscreen mode Exit fullscreen mode

Good UX requires:

  • Loading states
  • Error handling
  • Custom 404 pages

These improve both user experience and SEO.


10. Keep Utilities Small and Boring

I separate infrastructure code from simple helpers.

lib/

lib/
  db.ts
  metadata.ts
  rate-limit.ts
  spam-protection.ts
  serialize.ts
Enter fullscreen mode Exit fullscreen mode

utils/

utils/
  formatDateAndTime.ts
  pagination.ts
  validateData.ts
Enter fullscreen mode Exit fullscreen mode

My rule:

  • Infrastructure-related code → lib
  • Simple formatting or transformation helpers → utils

Avoid turning these folders into dumping grounds.


11. Design for Pagination and Search Early

Even if your application starts small, assume it will grow.

Resources such as:

  • Blogs
  • Projects
  • Services
  • Dashboard records
  • Emails

Should support:

  • Pagination
  • Search
  • Sorting

A common pattern I use:

  • First page rendered on the server
  • Search handled through Server Actions
  • Infinite scrolling for additional pages
  • Exclude large content fields from list queries

This improves performance while maintaining a great user experience.


12. My Production Structure Rule

A good structure should answer these questions quickly:

  • Where is this route rendered?
  • Where is this data fetched?
  • Where is this input validated?
  • Where is this model defined?
  • Where is this component reused?
  • Where is SEO generated?
  • What gets revalidated after a mutation?

If a new developer can answer those questions within minutes, the architecture is doing its job.


Final Thoughts

Modern Next.js applications are far more than React frontends.

They're a combination of:

  • Routing
  • Rendering
  • APIs
  • Metadata
  • Validation
  • Database access
  • SEO
  • Analytics
  • Deployment

The best structure isn't the most complex one.

It's the one that keeps responsibilities clear.

Keep:

  • Routes in app
  • Business logic in actions
  • Validation in validations
  • Database models in models
  • Reusable UI in components
  • Infrastructure code in lib

Do that consistently, and your application becomes easier to scale, debug, and optimize over time.


How do you structure your Next.js projects in 2026? I'd love to hear your approach and any patterns that have worked well in production.

Top comments (0)