Back to blog
by DevOps Team

Monorepo Guide: Turborepo, Next.js and NestJS

Why move to a Monorepo?

Monorepo architecture (all code in a single Git repository) has become the standard for full-stack TypeScript applications.

Our Ideal Stack

At ReposLens, we use:

  • Turborepo: For task orchestration and remote caching.
  • Pnpm: For fast dependency management (workspaces).
  • Apps:
    • apps/web: Next.js (Frontend)
    • apps/api: NestJS (Backend)
  • Packages:
    • packages/database: Shared Prisma schema
    • packages/ui: Shared React components
    • packages/typescript-config: Shared TS configs

The Killer Feature: End-to-End Type Safety

The killer advantage is type sharing. Your DTO (Data Transfer Object) defined in the backend can be imported directly into the frontend. If you change a field in the API, the Frontend breaks at build time. No more production bugs due to unsynced API changes.

Deploying a Monorepo

Deployment can be scary. The trick is to use Docker with "pruning". Example of a Dockerfile optimized for Turbo:

FROM node:18-alpine AS base
FROM base AS builder
WORKDIR /app
RUN npm install turbo --global
COPY . .
RUN turbo prune --scope=web --docker
# ... build steps

This ensures only necessary files for the target app are copied, reducing the final Docker image size.