Skip to main content

Monorepo Architecture — Bun + Turborepo

A monorepo keeps all your apps and shared code in one repository. With Bun workspaces and Turborepo task orchestration, you get fast installs, parallel builds, and type-safe package sharing.

badmin

Admin panel monorepo — web + server + docs + shared packages.

cyop

AI captioning monorepo — web + server + tRPC + auth + db packages.

fullstack

Template monorepo — web + docs + desktop + API + shared packages.

Standard Structure

All three projects follow the same pattern:

Workspace Configuration

Bun Workspaces (package.json)

Turborepo Pipeline (turbo.json)

The ^build syntax means “build all dependencies first.” Turborepo automatically parallelizes tasks that have no dependency between them — e.g., building packages/ui and packages/db can run simultaneously.

Biome (Lint + Format)

Biome replaces ESLint + Prettier with a single, faster tool:

Shared Packages

contracts — Zod + tRPC

Shared schemas keep frontend and backend type-synced:
The frontend imports LoginInput for form validation. The backend imports the same schema for request validation. One source of truth.

db — Drizzle Package

Isolate database logic in its own package:
Both apps/server and apps/web (for server functions) import from @repo/db.

ui — shadcn/ui Package

Shared components built on shadcn/ui:
Create a components.json in both apps/web and packages/ui so shadcn add places components in the right location.

Cross-App Type Safety

The key benefit of monorepo: runtime-free type sharing.

Environment Variables

Each app reads its own env vars. Service URLs can be overridden:
Default ports:
  • Web: 3000
  • Docs: 3001
  • API: 3002
  • Desktop: 1420

CI/CD with GitHub Actions

Turborepo caches build outputs, making CI fast:

Database Workflow

Run db:generate after every schema change. Drizzle Kit diffs the current schema against the previous migration and generates only the incremental SQL.

Best Practices

  1. apps/ + packages/ split — Apps are deployable units; packages are shared libraries
  2. Contracts package — Zod schemas + tRPC routers = type safety without code generation
  3. Biome over ESLint+Prettier — One tool, 30× faster, fewer config files
  4. Turbo caching^build dependency graph + remote cache = fast CI
  5. DB as a package — Schema, client, and migrations in one sharable package
  6. Environment overrides — Service URLs via .env, not hardcoded
  7. shadcn/ui in packages/ui — Share components across web and docs apps
  8. Tab indentation — Biome defaults to tabs — consistent, smaller diffs

References

Last modified on April 19, 2026