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 schemapackages/ui: Shared React componentspackages/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.
Related Articles
Microservices vs Monolith: How to Actually See Your Architecture
Monolith or microservices? The real question is: can you see what you actually have? Learn how to visualize, compare, and decide with confidence.
Continue readingHow to Detect Circular Dependencies in Your TypeScript Project (and Fix Them)
Learn 3 practical methods to detect circular dependencies in TypeScript: madge CLI, ESLint import/no-cycle, and automated PR checks with ReposLens. Includes fix patterns.
Continue readingMonorepo Dependency Management: Visualize Before It's Too Late
Learn how to manage internal dependencies in a monorepo. Discover common pitfalls like circular deps and god packages, and tools to visualize your architecture.
Continue reading