HomeBlogHow to Structure a Large React...

Engineering Guide · 9 min read · June 9, 2026

How to Structure a Large React and Node.js Project for Scalability

Grouping files by technical type works at 10 files and collapses at 500. Learn how to structure a large React and Node.js codebase using a pnpm monorepo, feature-sliced domain modules, shared Zod contracts, and automated boundary rules.

Author
Smit Desai
Published
June 9, 2026
Read time
9 min read
Topic
Full-Stack Web
Services
Custom Web · Mobile Apps · All Services

Almost every large React and Node.js repository starts with the exact same well-intentioned layout: src/components, src/hooks, src/services, and on the backend, controllers/, models/, and routes/.

By month six—around 60 API endpoints and 300 React components—that neat symmetry becomes a productivity tax. Fixing one bug in the invoicing flow requires jumping across eight top-level directories, editing shared utility files you are afraid to refactor because twelve unrelated screens import them, and guessing whether a change in a Node response field silently broke a frontend form.

Scalability at the codebase level is not about preparing for ten million requests per second on day one. It is about ensuring ten engineers can ship features in parallel without stepping on each other's imports.


Organizing by Domain Instead of Technical Layer

Layer-based folders group files by what technology they use (controller, hook, component) instead of what business problem they solve (billing, onboarding, inventory). When features evolve, business domains change together while unrelated domains should remain decoupled.

Switch to a workspace monorepo with feature-based modules:

├── apps/
│   ├── web/                          # React + Vite / Next.js frontend
│   │   └── src/
│   │       ├── app/                  # Router, providers, global error boundaries
│   │       ├── modules/
│   │       │   ├── billing/          # Components, hooks, API queries for billing
│   │       │   ├── auth/
│   │       │   └── projects/
│   │       └── shared/               # Truly generic UI primitives (Button, Modal)
│   └── api/                          # Node.js HTTP server + queue workers
│       ├── src/
│       │   ├── modules/
│       │   │   ├── billing/          # routes, use-cases, repo, billing.public.ts
│       │   │   └── projects/
│       │   ├── worker.ts             # Async job consumer entrypoint
│       │   └── server.ts             # HTTP entrypoint
└── packages/
    └── contracts/                    # Shared Zod schemas & inferred TS DTOs

The goal is simple: if a developer asks "Where does invoice generation live?", 90% of the answer sits inside apps/api/src/modules/billing and apps/web/src/modules/billing, bridged by one explicit contract in packages/contracts.


Architecture Options Compared

Structure Refactor Speed Type Safety Across Stack Infra Overhead When It Breaks
Layer-Based Folders Slow after ~50 files Weak (manual types) Low Cross-cutting edits cause merge conflicts
Feature-Sliced Monorepo Fast (localized modules) Strong (shared schemas) Low–Moderate Breaks only if cross-module imports aren't policed
Multi-Repo Microservices Slowest for full-stack changes Fragile without codegen High (CI, tracing, versioning) Small teams drown in DevOps plumbing

Unless you have dozens of autonomous teams deploying on incompatible release cadences, a feature-sliced modular monolith inside a pnpm or Turborepo workspace—a pattern widely discussed in Vercel's monorepo tooling guides and Martin Fowler's architectural writing—delivers microservices-grade modularity with single-PR deployments.


Sharing Contracts Without Leaking Database Models

A common mistake in TypeScript monorepos is exporting Prisma or Drizzle database table types directly to the React app. The moment you rename a database column or add an internal stripe_webhook_secret field, you either leak backend internals to the browser or trigger unnecessary frontend builds.

Keep ORM models private to each backend module. Expose only explicit API Data Transfer Objects (DTOs) in packages/contracts using Zod:

// packages/contracts/src/billing.ts
import { z } from 'zod';

export const CreateInvoiceSchema = z.object({
  organizationId: z.number().int().positive(),
  currency: z.enum(['USD', 'EUR', 'GBP']),
  lineItems: z.array(
    z.object({
      description: z.string().min(1).max(200),
      amountCents: z.number().int().positive(),
    })
  ).min(1),
});

export type CreateInvoiceInput = z.infer<typeof CreateInvoiceSchema>;

The Node route validates incoming JSON with CreateInvoiceSchema.parse(req.body), while the React form validates user input against the exact same schema before sending the request. Zero drift, zero OpenAPI build step failures.


Keeping the React Frontend Fast and Predictable

Large React apps rarely become slow because React itself is slow; they slow down because global state, data fetching, and giant barrel files entangle every screen.

Separate Server State from Client State

Do not mirror API responses inside Redux or giant React Context providers. Use TanStack Query (or SWR) for server cache—handling retries, deduplication, and invalidation—and keep local UI state (isModalOpen, selected filter tabs) close to the component that owns it.

Enforce Unidirectional Module Imports

To keep modules/billing from reaching into the internal components of modules/projects, enforce import boundaries automatically using eslint-plugin-boundaries or eslint-plugin-import:

  • app/ may import from modules/* and shared/.
  • modules/billing/ may import from shared/ and packages/contracts, plus explicit public entrypoints (modules/auth/public.ts).
  • shared/ must never import from modules/*.

Also skip broad index.ts barrel files across shared/ui. Importing @/shared/ui/Button directly keeps Vite dev-server startups crisp and prevents circular dependency chains.


Structuring the Node.js Backend for Reliability

Inside apps/api, split each domain module into three strict layers:

  1. HTTP Transport (billing.routes.ts): Parses params, runs auth middleware, validates payload against CreateInvoiceSchema, maps service errors to HTTP status codes (400, 403, 409). Zero SQL here.
  2. Use Cases / Services (createInvoice.service.ts): Holds business rules, idempotency checks, and transaction boundaries. Accepts plain TypeScript objects—never req or res—so the exact same function can be called by HTTP routes, CLI scripts, or background queue workers.
  3. Repository (billing.repo.ts): Encapsulates SQL/ORM queries and row-to-domain mapping.

Protect the Node Event Loop

Node.js excels at I/O concurrency, not heavy synchronous computation. Offload PDF generation, image resizing, CSV exports, and LLM orchestration into Redis-backed workers (apps/api/src/worker.ts) via BullMQ or an external queue. If an incoming HTTP handler parses a 50MB spreadsheet synchronously, every concurrent user on that pod freezes until JSON.parse or the loop finishes.

If you are migrating an existing legacy codebase toward these exact module boundaries, our walkthrough on refactoring monolithic PHP to modular architecture covers the incremental strangler patterns that work equally well in Node and TypeScript.


Need Help Untangling or Scaling a Growing Codebase?

Architectural rot rarely arrives overnight—it accumulates one hurried sprint at a time until every minor feature takes twice as long to test and ship. Across 170+ shipped engagements since 2017, I work directly inside client repositories to establish clean module boundaries, split out background workers, eliminate circular imports, and build high-velocity React and Node.js foundations.

You can bring in focused senior engineering support through an hourly developer engagement, lock in dedicated capacity at $55/day (8–9 hours) or $1,999/month, or review our full-stack services. Dealing with a codebase that is slowing your team down? Send a note via the contact page and let's review your repository structure together.

Written by Smit Desai · Principal Full-Stack & FDSE

8+ years shipping production systems · 171 case studies · 300+ WordPress servers managed for Finland partners.

Next Steps and Recommended Resources

Next Steps · Recommended Resources

Pillar 1 · Custom Web & SaaS

Custom Web Application Development

Production Laravel, Next.js, API, and multi-tenant SaaS systems engineered end to end at $55/day (8–9 hrs) or $1,999/mo.

Comparison · Buyer Guide

SmitDev vs Software Agencies

See side-by-side economics, senior code ownership, and onboarding speed vs traditional dev shops and marketplaces.

01 — Frequently asked questions

full-stack web

Should I split a growing React and Node.js app into microservices?

Not until independent team scaling or starkly different compute profiles demand it. A modular monolith inside a single monorepo gives you strict domain boundaries without distributed network latency, duplicated CI pipelines, or multi-repo schema drift.

Why do barrel files (index.ts) slow down large React codebases?

Re-exporting dozens of modules through root index.ts files makes it harder for bundlers and test runners like Vite, Webpack, and Vitest to tree-shake unused code, often triggering circular imports and sluggish hot module replacement.

How do React and Node.js share types without coupling UI to database models?

Keep database entities private inside your API modules, and place request/response schemas (for example, Zod schemas with inferred TypeScript types) inside a shared packages/contracts workspace. Both client and server validate against the same contract.

Where should background jobs live in a large Node.js backend?

Run queue workers (BullMQ, SQS consumers, cron tasks) as separate worker entrypoints in the same backend app or dedicated apps/worker package, importing the exact same domain services as your HTTP routes so business logic is never duplicated.

03 — Have an engineering need?

hire the right expertise

Let's talk tech.

Deciding between an embedded forward deployed engineer or a senior full stack developer? Share your technical context and timeline.

Solitaire Corporate Park, Makarba, Ahmedabad, Gujarat 380015, India · IST (UTC+5:30) · --:-- IST · Mon–Fri 09:00–18:00 IST · US & EU overlap daily

No newsletter, no CRM. Just a reply.