Before implementing business logic, we must decide how the source code will be organized.
For small project, a single application repository if often sufficient.
Example:
project/
├── frontend
└── backendHowever, as the system grows, multiple problems emerge:
- Code duplication
- Shared type mismatches
- Dependency management issues
- Difficult deployments
- Version synchronization problems.
PeerDrop is designed to scale beyong a simple MVP.
Future plans include:
- Web application
- Mobile application
- Desktop application
- Multiple backend services
- Shared SDKs
- Shared UI libraries
Because of these goals, we use a Monorepo Architecture.
What is a Monorepo?
A monorepo (Monolithic Repository) is a repository that contains multiple applications and packages inside a single source control repository.
Instead of:
peerdrop-web
peerdrop-api
peerdrop-mobile
peerdrop-sharedWe maintain:
peerdrop/
├── apps
├── packages
└── toolingEverything evolves together.
Monorepo Benefits
Benefit 1: Shared Code
Instead of:
Copy Pastewe use:
import { JoinSessionDto } from '@peerdrop/shared';Benefit 2: Easier Refactoring
Suppose:
sessionId: stringbecomes:
sessionCode: stringIn a monorepo:
One changeaffects all consumers.
Benefit 3: Atomic Changes
Frontend change:
+Backend change:
+Shared package change
can all be committed together.
Benefit 4: Better Developer Experience
Single command:
pnpm installBenefit 5: Future Scalability
Future applications:
Web
Mobile
Desktop
CLI
Admin Panelcan all live in the same repository.
Workspace Structure
Current project structure:
ThePeerDrop/
├── apps/
│ ├── api/
│ └── web/
│
├── packages/
│
├── docs/
│
├── pnpm-workspace.yaml
├── package.json
└── turbo.jsonUnderstanding the Apps Directory
The apps directory contains executable applications.
apps/api
Backend service:
NestJS
Socket.IO
TypeScriptResponsibilties:
Signaling
Sessions
WebSocket CommunicationStructure:
apps/api/
├── src
├── test
├── dist
├── package.json
├── tsconfig.json
└── nest-cli.jsonapps/web
Frontend application
Technology:
Next.js
React
TypeScriptResponsibilities:
UI
WebRTC
User InteractionStructure:
apps/web/
├── app
├── public
├── package.json
└── next.config.tsUnderstanding the Packages Directory
Packages contain reusable code.
Current state:
packages/Empty.
Future structure:
packages/
├── shared/
├── ui/
├── sdk/
├── config/
└── types/Shared Package
Future package:
packages/sharedPurpose:
DTOs
Interfaces
Constants
ValidatorsExample:
export interface JoinSessionDto {
sessionId: string;
}Used by:
Frontend
Backendsimultaneously.
UI Package
Future package:
packages/uiContains:
Buttons
Cards
Inputs
Modals
Progress BarsExample:
<Button />shared across:
Web
Desktop
MobileSDK Package
Future package:
packages/sdkContains:
Socket Client
API Client
Session Client
WebRTC HelpersExample:
import { PeerDropClient }
from '@peerdrop/sdk';Configuration Package
Future package:
package/configContains:
ESLint
Prettier
TypeScript ConfigExample:
Shared linting rulesfor every application.
Workspace Configuration
The monorepo is managed by PNPM Workspaces.
File:
pnpm-workspace.yamlExample:
packages:
- apps/*
- packages/*Meaning:
All apps
All packagesbecomes workspace members.
Root Package.json
The root package.json controls the entire repository.
Example:
{
"name": "the-peer-drop",
"private": true
}Important:
"private": trueprevents accidental publication to npm.
Why We Use PNPM
Several package managers exist.
Examples:
npm
yarn
pnpmWe chose PNPM because:
Faster Installation
PNPM uses a global package store.
Instead of:
Project A
Project B
Project C
Three CopiesPNPM stores:
One Copyand creates links.
Lower Disk Usage
Traditional:
node_modulescan become enormous.
PNPM significantly reduces storage usage.
Better Workspace Support
PNPM was designed with monorepos in mind.
Why We Use Turbo
As the monorepo grows:
Web
API
Shared Packagesneed coordinated builds.
Turbo helps manage:
Builds
Tests
Linting
Cachingacross all applications.
Current Development Workflow
When working on PeerDrop:
Install dependencies:
pnpm installRun backend:
pnpm --filter api start:devRun frontend
pnpm --filter web devBuild all applications:
pnpm buildLeave a comment
Your email address will not be published. Required fields are marked *
