# Monorepo Structure

This quality-rails monorepo template supports the following structure:

```
monorepo/
├── apps/
│   ├── web/                  # Next.js frontend
│   │   ├── package.json
│   │   ├── tsconfig.json     # extends ../../tsconfig.base.json
│   │   └── .eslintrc.js      # extends ../../.eslintrc.strict.js
│   └── api/                  # NestJS backend
│       ├── package.json
│       ├── tsconfig.json
│       └── .eslintrc.js
├── packages/
│   ├── shared-types/         # Shared TypeScript types
│   ├── ui/                   # Shared UI components
│   └── config/               # Shared configuration
├── .husky/
│   └── pre-commit
├── .lintstagedrc.js          # Multi-package aware
├── .eslintrc.strict.js       # Root ESLint config
├── tsconfig.base.json        # Base TypeScript config
├── turbo.json                # TurboRepo configuration
├── pnpm-workspace.yaml       # pnpm workspaces
└── package.json              # Root package with scripts
```

## Package-Specific Configs

Each package extends the root configuration:

**apps/web/tsconfig.json:**

```json
{
  "extends": "../../tsconfig.base.json",
  "compilerOptions": {
    "lib": ["dom", "dom.iterable", "ES2022"],
    "jsx": "preserve",
    "noEmit": true,
    "paths": {
      "@/*": ["./*"]
    }
  },
  "include": ["**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules", ".next"]
}
```

**apps/api/tsconfig.json:**

```json
{
  "extends": "../../tsconfig.base.json",
  "compilerOptions": {
    "module": "commonjs",
    "outDir": "./dist",
    "rootDir": "./src",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "dist", "test"]
}
```

## Running Commands

**All packages:**

```bash
npm run lint        # Lint all packages
npm run type-check  # Type check all packages
npm run test        # Test all packages
npm run build       # Build all packages
```

**Single package:**

```bash
npm run lint --workspace=apps/web
npm run dev --workspace=apps/api
```

**With TurboRepo:**

```bash
turbo run build           # Build with caching
turbo run dev --parallel  # Run dev servers in parallel
```

## Pre-Commit Enforcement

lint-staged automatically detects which packages contain modified files and runs:

- ESLint on changed files
- TypeScript check on affected packages
- Prettier on all changed files

Only runs checks on packages that have changes (efficient).
