Monorepo layout for full-stack projects
Put Taskboard's client, API and shared code in one repo with npm workspaces, and see why it removes the copy-paste that makes two repos drift apart.
Monorepo layout for full-stack projects
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- A monorepo keeps the client, the API and shared code in one repository so one commit can change all three together.
- A workspace package is a folder with its own package.json that other packages can import by name.
- A shared package is the place for what both sides must agree on, such as schemas and types, and nothing else.
- Workspaces link packages with symlinks, so an edit to shared code is visible to the client and the API with no publish step.
- A task runner like Turborepo or Nx is optional and only earns its place once builds or tests are slow.
The copy-paste problem
Start with two repositories: taskboard-web and taskboard-api. The API returns a task as { id, title, status }. The client has a Task type that says the same thing, typed by hand. It works until someone adds dueDate to the API. The client doesn’t know. The compiler can’t tell you, because it only sees one repo at a time. The bug turns up in production as a blank column.
Two repos mean two histories, so one change that should be atomic ships in two steps, with a window in between where the halves disagree. A monorepo closes that window. One repository holds the client, the API and the code they share, so a single commit changes all of them and a single type-check covers all of them.
The layout
Here is Taskboard’s layout, which I built and ran:
taskboard/
package.json ← the root: lists the workspaces
tsconfig.base.json ← compiler settings every package shares
tsconfig.json
apps/
api/ ← Hono server
package.json
src/
web/ ← React client
package.json
src/
packages/
shared/ ← schemas and types both sides use
package.json
src/index.ts
The convention: apps/ holds things you deploy, and packages/ holds things other code imports. The root package.json is short:
{
"name": "taskboard",
"private": true,
"type": "module",
"workspaces": ["apps/*", "packages/*"]
}
"workspaces" tells the package manager that each matching folder with its own package.json is a workspace package. private: true stops you publishing the root to npm by accident.
How packages find each other
The shared package gives itself a name and says what it exports:
{
"name": "@taskboard/shared",
"version": "0.0.0",
"private": true,
"type": "module",
"exports": { ".": "./src/index.ts" },
"dependencies": { "zod": "^4.6.7" }
}
The API and the client list it as a dependency ("@taskboard/shared": "*"). After npm install, I looked inside node_modules/@taskboard/:
api -> ../../apps/api
shared -> ../../packages/shared
web -> ../../apps/web
They are symlinks back into the repo. There is no copy and no publish step. When you edit packages/shared/src/index.ts, the API and the client see the change immediately. (I ran this with npm 11.20.0 on Node 26.13.1. pnpm and Yarn have workspace features of their own with different details; the Node roadmap covers npm workspaces and monorepos, and the TypeScript roadmap covers project references for larger repos.)
Running TypeScript source directly
Notice "exports": { ".": "./src/index.ts" }. The package points at TypeScript source, not at a compiled dist/ folder. The usual worry is that Node can’t run .ts. On Node 26 it can strip the types itself, and I confirmed that the API, importing the shared package through the symlink, ran with plain node:
$ node try.ts
201 { id: 1, projectId: 1, title: 'Write docs', status: 'todo' }
422 { errors: [ { path: 'title', message: 'Give the task a title' } ] }
For this to work the code has to use only syntax that can be erased, with no enum and no constructor parameter properties, so the compiler option erasableSyntaxOnly is on to catch slips. The client side goes through Vite, which handles TypeScript source in its own way. The benefit is that “compile shared first” is not a step you maintain. The cost is that this only holds while every consumer can read TypeScript; a package you publish for outsiders still needs a build.
Type-checking the whole thing at once
One root tsconfig.json that includes every package’s src folder lets one command check the client, the API and the shared code together:
$ npx tsc -p tsconfig.json
This is where the monorepo pays off. When I passed the client a task with a string projectId and a status that doesn’t exist, that one command reported both errors (TypeScript 7.0.2). Change a type in shared, and every place that breaks lights up in one run.
What goes in shared, and what doesn’t
This package is a magnet for junk, so be strict. It is for what both sides must agree on:
- Zod schemas for request bodies, and the types inferred from them.
- Constants such as the list of task statuses.
- Small pure helpers with no environment assumptions.
It is not for code that touches the database (server only), code that touches window (browser only), or secrets. If the client imports something from shared that pulls in a database driver, you have just shipped a database driver to the browser. The next lesson, shared types and code between client and server, is about getting this boundary right.
Do you need Turborepo or Nx?
Not at first. Workspaces give you linking and a single install. What Turborepo and Nx add is task running: they cache the results of builds and tests, and run only what a change affects. On a repo with three packages and a ten-second test run, that saves nothing. On a repo where CI takes twenty minutes, it saves a lot. Add one when you feel the pain, not before.
Trade-offs
A monorepo is not free. Everyone clones everything. Access control is per repo, so you can’t give someone only the client. CI has to learn to run only what changed. A team that wants separate release cycles for the client and the API will find one repo mildly annoying. For one small team shipping one product, though, the guarantee that the halves can’t silently drift is usually worth more than all of that.
What the video covers
Syntax’s “Monorepos - What, Why, When and How | Full Stack React + Hono Example” runs about 33 minutes. Its chapters open with what a monorepo is, why people use one, when not to, and real-world examples, then move to tools for creating workspaces. The second half walks through an example app in a full-stack React and Hono monorepo, with chapters on workspace setup, namespaces, shared TypeScript and ESLint settings, path aliases, proxying API requests, sharing Hono types and restricting exports. It is the closest match here to Taskboard’s own React and Hono layout. It uses pnpm, where this lesson uses npm workspaces, so expect small command differences. I could not read a transcript, so the chapter titles are all I am relying on. Fireship’s 2021 overview of Turborepo and Nx and Jilles’ pnpm workspaces video are linked below as extras.
Where this fits
The repo has a home for shared code. What goes into it, and how you keep the two sides honest, is the next question: shared types and code between client and server.
Check yourself
Why does a monorepo help when the client and the API must agree on a type?
One commit can change the type and both users of it, and the compiler can check both together, so they cannot drift apart between releases.
What does an npm workspaces entry like "workspaces": ["apps/*", "packages/*"] do?
It tells npm to treat each matching folder with a package.json as a package, install their dependencies together, and link them by name into node_modules.
What belongs in the shared package?
Things both client and server must agree on, such as validation schemas and data types. Server-only or browser-only code does not belong there.
When should you add Turborepo or Nx?
When builds, tests or lint runs get slow enough that caching and running only what changed would save real time. A small repo does not need one.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.