# Bun Workspace Structure Standards
## Rule
Bun monorepos MUST use the workspaces field in the root package.json. Shared dependencies go in the root. Packages reference each other with workspace: protocol.
## Format
```json
{
"name": "my-monorepo",
"private": true,
"workspaces": ["packages/*", "apps/*"]
}
```
## Good Examples
```
my-monorepo/
├── package.json # workspaces: ["packages/*", "apps/*"]
├── bunfig.toml # Shared config
├── packages/
│ ├── shared/
│ │ └── package.json # "name": "@myapp/shared"
│ └── ui/
│ └── package.json # "name": "@myapp/ui"
└── apps/
├── web/
│ └── package.json # depends on "@myapp/shared": "workspace:*"
└── api/
└── package.json
```
```json
{
"name": "@myapp/web",
"dependencies": {
"@myapp/shared": "workspace:*",
"@myapp/ui": "workspace:*"
}
}
```
## Bad Examples
```json
{
"dependencies": {
"@myapp/shared": "file:../../packages/shared"
}
}
```
```json
{
"dependencies": {
"@myapp/shared": "1.0.0"
}
}
```
## Script Conventions
```bash
# Run from root for any workspace
bun run --filter '@myapp/web' dev
bun run --filter '@myapp/*' build
bun run --filter '*' test
```
## Enforcement
- `bun install` validates workspace configuration
- CI runs `bun install --frozen-lockfile` to verify lock consistency
- Use consistent script names across all packages: dev, build, test, lint