@baselane/packs 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/dist/aliases.js +1 -0
  2. package/package.json +2 -2
  3. package/packs/database-review/pack.json +75 -9
  4. package/packs/database-review/rendered/.claude/agents/database-reviewer.md +75 -2
  5. package/packs/database-review/rendered/.claude/commands/migration-review.md +6 -0
  6. package/packs/database-review/rendered/.claude/settings.json +11 -0
  7. package/packs/database-review/rendered/.claude/skills/database-migrations/SKILL.md +431 -0
  8. package/packs/database-review/rendered/.claude/skills/mysql-patterns/SKILL.md +414 -0
  9. package/packs/database-review/rendered/.claude/skills/postgres-patterns/SKILL.md +149 -0
  10. package/packs/database-review/rendered/.github/copilot-instructions.md +1096 -14
  11. package/packs/database-review/rendered/AGENTS.md +45 -16
  12. package/packs/database-review/rendered/CLAUDE.md +4 -0
  13. package/packs/database-review/rendered/GEMINI.md +987 -0
  14. package/packs/go-rules/pack.json +65 -9
  15. package/packs/go-rules/rendered/.claude/agents/go-build-resolver.md +90 -0
  16. package/packs/go-rules/rendered/.claude/agents/go-reviewer.md +72 -2
  17. package/packs/go-rules/rendered/.claude/commands/go-build.md +6 -0
  18. package/packs/go-rules/rendered/.claude/commands/go-review.md +1 -1
  19. package/packs/go-rules/rendered/.claude/commands/go-test.md +6 -0
  20. package/packs/go-rules/rendered/.claude/settings.json +9 -0
  21. package/packs/go-rules/rendered/.claude/skills/golang-patterns/SKILL.md +673 -0
  22. package/packs/go-rules/rendered/.claude/skills/golang-testing/SKILL.md +719 -0
  23. package/packs/go-rules/rendered/.github/copilot-instructions.md +1783 -7
  24. package/packs/go-rules/rendered/AGENTS.md +244 -8
  25. package/packs/go-rules/rendered/CLAUDE.md +5 -0
  26. package/packs/go-rules/rendered/GEMINI.md +1394 -0
  27. package/packs/python-rules/pack.json +87 -10
  28. package/packs/python-rules/rendered/.claude/agents/django-reviewer.md +159 -0
  29. package/packs/python-rules/rendered/.claude/agents/fastapi-reviewer.md +70 -0
  30. package/packs/python-rules/rendered/.claude/agents/python-reviewer.md +92 -2
  31. package/packs/python-rules/rendered/.claude/commands/django-review.md +6 -0
  32. package/packs/python-rules/rendered/.claude/commands/fastapi-review.md +6 -0
  33. package/packs/python-rules/rendered/.claude/commands/python-review.md +1 -1
  34. package/packs/python-rules/rendered/.claude/settings.json +1 -1
  35. package/packs/python-rules/rendered/.claude/skills/django-security/SKILL.md +642 -0
  36. package/packs/python-rules/rendered/.claude/skills/django-tdd/SKILL.md +728 -0
  37. package/packs/python-rules/rendered/.claude/skills/fastapi-patterns/SKILL.md +512 -0
  38. package/packs/python-rules/rendered/.claude/skills/python-patterns/SKILL.md +749 -0
  39. package/packs/python-rules/rendered/.claude/skills/python-testing/SKILL.md +815 -0
  40. package/packs/python-rules/rendered/.github/copilot-instructions.md +3815 -12
  41. package/packs/python-rules/rendered/AGENTS.md +73 -13
  42. package/packs/python-rules/rendered/CLAUDE.md +9 -0
  43. package/packs/python-rules/rendered/GEMINI.md +3448 -0
  44. package/packs/security-review/pack.json +51 -7
  45. package/packs/security-review/rendered/.claude/agents/security-reviewer.md +29 -2
  46. package/packs/security-review/rendered/.claude/settings.json +11 -0
  47. package/packs/security-review/rendered/.claude/skills/security-review/SKILL.md +302 -0
  48. package/packs/security-review/rendered/.claude/skills/security-review/cloud-infrastructure-security.md +171 -0
  49. package/packs/security-review/rendered/.claude/skills/security-scan-config/SKILL.md +56 -0
  50. package/packs/security-review/rendered/.github/copilot-instructions.md +658 -15
  51. package/packs/security-review/rendered/AGENTS.md +283 -17
  52. package/packs/security-review/rendered/CLAUDE.md +2 -0
  53. package/packs/security-review/rendered/GEMINI.md +352 -0
  54. package/packs/software-engineer-harness/pack.json +249 -13
  55. package/packs/software-engineer-harness/rendered/.claude/agents/build-error-resolver.md +15 -0
  56. package/packs/software-engineer-harness/rendered/.claude/agents/code-explorer.md +67 -0
  57. package/packs/software-engineer-harness/rendered/.claude/agents/performance-optimizer.md +444 -0
  58. package/packs/software-engineer-harness/rendered/.claude/agents/pr-test-analyzer.md +43 -0
  59. package/packs/software-engineer-harness/rendered/.claude/agents/refactor-cleaner.md +12 -0
  60. package/packs/software-engineer-harness/rendered/.claude/agents/silent-failure-hunter.md +16 -0
  61. package/packs/software-engineer-harness/rendered/.claude/agents/tdd-guide.md +16 -0
  62. package/packs/software-engineer-harness/rendered/.claude/commands/feature-dev.md +6 -0
  63. package/packs/software-engineer-harness/rendered/.claude/commands/fix-build.md +6 -0
  64. package/packs/software-engineer-harness/rendered/.claude/commands/hunt-silent-failures.md +6 -0
  65. package/packs/software-engineer-harness/rendered/.claude/commands/tdd.md +6 -0
  66. package/packs/software-engineer-harness/rendered/.claude/settings.json +29 -0
  67. package/packs/software-engineer-harness/rendered/.claude/skills/api-design/SKILL.md +522 -0
  68. package/packs/software-engineer-harness/rendered/.claude/skills/architecture-decision-records/SKILL.md +178 -0
  69. package/packs/software-engineer-harness/rendered/.claude/skills/backend-patterns/SKILL.md +560 -0
  70. package/packs/software-engineer-harness/rendered/.claude/skills/codebase-onboarding/SKILL.md +232 -0
  71. package/packs/software-engineer-harness/rendered/.claude/skills/deployment-patterns/SKILL.md +426 -0
  72. package/packs/software-engineer-harness/rendered/.claude/skills/docker-patterns/SKILL.md +363 -0
  73. package/packs/software-engineer-harness/rendered/.claude/skills/e2e-testing/SKILL.md +325 -0
  74. package/packs/software-engineer-harness/rendered/.claude/skills/tdd-red-green-refactor/SKILL.md +20 -0
  75. package/packs/software-engineer-harness/rendered/.claude/skills/tdd-workflow/SKILL.md +580 -0
  76. package/packs/software-engineer-harness/rendered/.github/copilot-instructions.md +3948 -2
  77. package/packs/software-engineer-harness/rendered/AGENTS.md +194 -4
  78. package/packs/software-engineer-harness/rendered/CLAUDE.md +20 -0
  79. package/packs/software-engineer-harness/rendered/GEMINI.md +3208 -0
  80. package/packs/typescript-rules/pack.json +68 -5
  81. package/packs/typescript-rules/rendered/.claude/agents/react-reviewer.md +165 -0
  82. package/packs/typescript-rules/rendered/.claude/agents/type-design-analyzer.md +48 -0
  83. package/packs/typescript-rules/rendered/.claude/commands/react-review.md +6 -0
  84. package/packs/typescript-rules/rendered/.claude/settings.json +9 -0
  85. package/packs/typescript-rules/rendered/.claude/skills/react-patterns/SKILL.md +340 -0
  86. package/packs/typescript-rules/rendered/.claude/skills/react-performance/SKILL.md +573 -0
  87. package/packs/typescript-rules/rendered/.claude/skills/react-testing/SKILL.md +422 -0
  88. package/packs/typescript-rules/rendered/.github/copilot-instructions.md +2459 -53
  89. package/packs/typescript-rules/rendered/AGENTS.md +893 -17
  90. package/packs/typescript-rules/rendered/CLAUDE.md +6 -0
  91. package/packs/typescript-rules/rendered/GEMINI.md +1335 -0
@@ -0,0 +1,232 @@
1
+ ---
2
+ name: codebase-onboarding
3
+ description: Analyze an unfamiliar codebase and generate a structured onboarding guide with architecture map, key entry points, conventions, and a starter CLAUDE.md. Use when joining a new project or setting up this harness for the first time in a repo.
4
+ ---
5
+
6
+ # Codebase Onboarding
7
+
8
+ Systematically analyze an unfamiliar codebase and produce a structured onboarding guide. Designed for developers joining a new project or setting up Claude Code in an existing repo for the first time.
9
+
10
+ ## When to Use
11
+
12
+ - First time opening a project with Claude Code
13
+ - Joining a new team or repository
14
+ - User asks "help me understand this codebase"
15
+ - User asks to generate a CLAUDE.md for a project
16
+ - User says "onboard me" or "walk me through this repo"
17
+
18
+ ## How It Works
19
+
20
+ ### Phase 1: Reconnaissance
21
+
22
+ Gather raw signals about the project without reading every file. Run these checks in parallel:
23
+
24
+ ```
25
+ 1. Package manifest detection
26
+ → package.json, go.mod, Cargo.toml, pyproject.toml, pom.xml, build.gradle,
27
+ Gemfile, composer.json, mix.exs, pubspec.yaml
28
+
29
+ 2. Framework fingerprinting
30
+ → next.config.*, nuxt.config.*, angular.json, vite.config.*,
31
+ django settings, flask app factory, fastapi main, rails config
32
+
33
+ 3. Entry point identification
34
+ → main.*, index.*, app.*, server.*, cmd/, src/main/
35
+
36
+ 4. Directory structure snapshot
37
+ → Top 2 levels of the directory tree, ignoring node_modules, vendor,
38
+ .git, dist, build, __pycache__, .next
39
+
40
+ 5. Config and tooling detection
41
+ → .eslintrc*, .prettierrc*, tsconfig.json, Makefile, Dockerfile,
42
+ docker-compose*, .github/workflows/, .env.example, CI configs
43
+
44
+ 6. Test structure detection
45
+ → tests/, test/, __tests__/, *_test.go, *.spec.ts, *.test.js,
46
+ pytest.ini, jest.config.*, vitest.config.*
47
+ ```
48
+
49
+ ### Phase 2: Architecture Mapping
50
+
51
+ From the reconnaissance data, identify:
52
+
53
+ **Tech Stack**
54
+ - Language(s) and version constraints
55
+ - Framework(s) and major libraries
56
+ - Database(s) and ORMs
57
+ - Build tools and bundlers
58
+ - CI/CD platform
59
+
60
+ **Architecture Pattern**
61
+ - Monolith, monorepo, microservices, or serverless
62
+ - Frontend/backend split or full-stack
63
+ - API style: REST, GraphQL, gRPC, tRPC
64
+
65
+ **Key Directories**
66
+ Map the top-level directories to their purpose:
67
+
68
+ <!-- Example for a React project — replace with detected directories -->
69
+ ```
70
+ src/components/ → React UI components
71
+ src/api/ → API route handlers
72
+ src/lib/ → Shared utilities
73
+ src/db/ → Database models and migrations
74
+ tests/ → Test suites
75
+ scripts/ → Build and deployment scripts
76
+ ```
77
+
78
+ **Data Flow**
79
+ Trace one request from entry to response:
80
+ - Where does a request enter? (router, handler, controller)
81
+ - How is it validated? (middleware, schemas, guards)
82
+ - Where is business logic? (services, models, use cases)
83
+ - How does it reach the database? (ORM, raw queries, repositories)
84
+
85
+ ### Phase 3: Convention Detection
86
+
87
+ Identify patterns the codebase already follows:
88
+
89
+ **Naming Conventions**
90
+ - File naming: kebab-case, camelCase, PascalCase, snake_case
91
+ - Component/class naming patterns
92
+ - Test file naming: `*.test.ts`, `*.spec.ts`, `*_test.go`
93
+
94
+ **Code Patterns**
95
+ - Error handling style: try/catch, Result types, error codes
96
+ - Dependency injection or direct imports
97
+ - State management approach
98
+ - Async patterns: callbacks, promises, async/await, channels
99
+
100
+ **Git Conventions**
101
+ - Branch naming from recent branches
102
+ - Commit message style from recent commits
103
+ - PR workflow (squash, merge, rebase)
104
+ - If the repo has no commits yet or only a shallow history (e.g. `git clone --depth 1`), skip this section and note "Git history unavailable or too shallow to detect conventions"
105
+
106
+ ### Phase 4: Generate Onboarding Artifacts
107
+
108
+ Produce two outputs:
109
+
110
+ #### Output 1: Onboarding Guide
111
+
112
+ ```markdown
113
+ # Onboarding Guide: [Project Name]
114
+
115
+ ## Overview
116
+ [2-3 sentences: what this project does and who it serves]
117
+
118
+ ## Tech Stack
119
+ <!-- Example for a Next.js project — replace with detected stack -->
120
+ | Layer | Technology | Version |
121
+ |-------|-----------|---------|
122
+ | Language | TypeScript | 5.x |
123
+ | Framework | Next.js | 14.x |
124
+ | Database | PostgreSQL | 16 |
125
+ | ORM | Prisma | 5.x |
126
+ | Testing | Jest + Playwright | - |
127
+
128
+ ## Architecture
129
+ [Diagram or description of how components connect]
130
+
131
+ ## Key Entry Points
132
+ <!-- Example for a Next.js project — replace with detected paths -->
133
+ - **API routes**: `src/app/api/` — Next.js route handlers
134
+ - **UI pages**: `src/app/(dashboard)/` — authenticated pages
135
+ - **Database**: `prisma/schema.prisma` — data model source of truth
136
+ - **Config**: `next.config.ts` — build and runtime config
137
+
138
+ ## Directory Map
139
+ [Top-level directory → purpose mapping]
140
+
141
+ ## Request Lifecycle
142
+ [Trace one API request from entry to response]
143
+
144
+ ## Conventions
145
+ - [File naming pattern]
146
+ - [Error handling approach]
147
+ - [Testing patterns]
148
+ - [Git workflow]
149
+
150
+ ## Common Tasks
151
+ <!-- Example for a Node.js project — replace with detected commands -->
152
+ - **Run dev server**: `npm run dev`
153
+ - **Run tests**: `npm test`
154
+ - **Run linter**: `npm run lint`
155
+ - **Database migrations**: `npx prisma migrate dev`
156
+ - **Build for production**: `npm run build`
157
+
158
+ ## Where to Look
159
+ <!-- Example for a Next.js project — replace with detected paths -->
160
+ | I want to... | Look at... |
161
+ |--------------|-----------|
162
+ | Add an API endpoint | `src/app/api/` |
163
+ | Add a UI page | `src/app/(dashboard)/` |
164
+ | Add a database table | `prisma/schema.prisma` |
165
+ | Add a test | `tests/` matching the source path |
166
+ | Change build config | `next.config.ts` |
167
+ ```
168
+
169
+ #### Output 2: Starter CLAUDE.md
170
+
171
+ Generate or update a project-specific CLAUDE.md based on detected conventions. If `CLAUDE.md` already exists, read it first and enhance it — preserve existing project-specific instructions and clearly call out what was added or changed.
172
+
173
+ ```markdown
174
+ # Project Instructions
175
+
176
+ ## Tech Stack
177
+ [Detected stack summary]
178
+
179
+ ## Code Style
180
+ - [Detected naming conventions]
181
+ - [Detected patterns to follow]
182
+
183
+ ## Testing
184
+ - Run tests: `[detected test command]`
185
+ - Test pattern: [detected test file convention]
186
+ - Coverage: [if configured, the coverage command]
187
+
188
+ ## Build & Run
189
+ - Dev: `[detected dev command]`
190
+ - Build: `[detected build command]`
191
+ - Lint: `[detected lint command]`
192
+
193
+ ## Project Structure
194
+ [Key directory → purpose map]
195
+
196
+ ## Conventions
197
+ - [Commit style if detectable]
198
+ - [PR workflow if detectable]
199
+ - [Error handling patterns]
200
+ ```
201
+
202
+ ## Best Practices
203
+
204
+ 1. **Don't read everything** — reconnaissance should use Glob and Grep, not Read on every file. Read selectively only for ambiguous signals.
205
+ 2. **Verify, don't guess** — if a framework is detected from config but the actual code uses something different, trust the code.
206
+ 3. **Respect existing CLAUDE.md** — if one already exists, enhance it rather than replacing it. Call out what's new vs existing.
207
+ 4. **Stay concise** — the onboarding guide should be scannable in 2 minutes. Details belong in the code, not the guide.
208
+ 5. **Flag unknowns** — if a convention can't be confidently detected, say so rather than guessing. "Could not determine test runner" is better than a wrong answer.
209
+
210
+ ## Anti-Patterns to Avoid
211
+
212
+ - Generating a CLAUDE.md that's longer than 100 lines — keep it focused
213
+ - Listing every dependency — highlight only the ones that shape how you write code
214
+ - Describing obvious directory names — `src/` doesn't need an explanation
215
+ - Copying the README — the onboarding guide adds structural insight the README lacks
216
+
217
+ ## Examples
218
+
219
+ ### Example 1: First time in a new repo
220
+ **User**: "Onboard me to this codebase"
221
+ **Action**: Run full 4-phase workflow → produce Onboarding Guide + Starter CLAUDE.md
222
+ **Output**: Onboarding Guide printed directly to the conversation, plus a `CLAUDE.md` written to the project root
223
+
224
+ ### Example 2: Generate CLAUDE.md for existing project
225
+ **User**: "Generate a CLAUDE.md for this project"
226
+ **Action**: Run Phases 1-3, skip Onboarding Guide, produce only CLAUDE.md
227
+ **Output**: Project-specific `CLAUDE.md` with detected conventions
228
+
229
+ ### Example 3: Enhance existing CLAUDE.md
230
+ **User**: "Update the CLAUDE.md with current project conventions"
231
+ **Action**: Read existing CLAUDE.md, run Phases 1-3, merge new findings
232
+ **Output**: Updated `CLAUDE.md` with additions clearly marked
@@ -0,0 +1,426 @@
1
+ ---
2
+ name: deployment-patterns
3
+ description: Deployment workflows, CI/CD pipeline patterns, Docker containerization, health checks, rollback strategies, and production readiness checklists for web applications.
4
+ ---
5
+
6
+ # Deployment Patterns
7
+
8
+ Production deployment workflows and CI/CD best practices.
9
+
10
+ ## When to Activate
11
+
12
+ - Setting up CI/CD pipelines
13
+ - Dockerizing an application
14
+ - Planning deployment strategy (blue-green, canary, rolling)
15
+ - Implementing health checks and readiness probes
16
+ - Preparing for a production release
17
+ - Configuring environment-specific settings
18
+
19
+ ## Deployment Strategies
20
+
21
+ ### Rolling Deployment (Default)
22
+
23
+ Replace instances gradually — old and new versions run simultaneously during rollout.
24
+
25
+ ```
26
+ Instance 1: v1 → v2 (update first)
27
+ Instance 2: v1 (still running v1)
28
+ Instance 3: v1 (still running v1)
29
+
30
+ Instance 1: v2
31
+ Instance 2: v1 → v2 (update second)
32
+ Instance 3: v1
33
+
34
+ Instance 1: v2
35
+ Instance 2: v2
36
+ Instance 3: v1 → v2 (update last)
37
+ ```
38
+
39
+ **Pros:** Zero downtime, gradual rollout
40
+ **Cons:** Two versions run simultaneously — requires backward-compatible changes
41
+ **Use when:** Standard deployments, backward-compatible changes
42
+
43
+ ### Blue-Green Deployment
44
+
45
+ Run two identical environments. Switch traffic atomically.
46
+
47
+ ```
48
+ Blue (v1) ← traffic
49
+ Green (v2) idle, running new version
50
+
51
+ # After verification:
52
+ Blue (v1) idle (becomes standby)
53
+ Green (v2) ← traffic
54
+ ```
55
+
56
+ **Pros:** Instant rollback (switch back to blue), clean cutover
57
+ **Cons:** Requires 2x infrastructure during deployment
58
+ **Use when:** Critical services, zero-tolerance for issues
59
+
60
+ ### Canary Deployment
61
+
62
+ Route a small percentage of traffic to the new version first.
63
+
64
+ ```
65
+ v1: 95% of traffic
66
+ v2: 5% of traffic (canary)
67
+
68
+ # If metrics look good:
69
+ v1: 50% of traffic
70
+ v2: 50% of traffic
71
+
72
+ # Final:
73
+ v2: 100% of traffic
74
+ ```
75
+
76
+ **Pros:** Catches issues with real traffic before full rollout
77
+ **Cons:** Requires traffic splitting infrastructure, monitoring
78
+ **Use when:** High-traffic services, risky changes, feature flags
79
+
80
+ ## Docker
81
+
82
+ ### Multi-Stage Dockerfile (Node.js)
83
+
84
+ ```dockerfile
85
+ # Stage 1: Install dependencies
86
+ FROM node:22-alpine AS deps
87
+ WORKDIR /app
88
+ COPY package.json package-lock.json ./
89
+ RUN npm ci --production=false
90
+
91
+ # Stage 2: Build
92
+ FROM node:22-alpine AS builder
93
+ WORKDIR /app
94
+ COPY --from=deps /app/node_modules ./node_modules
95
+ COPY . .
96
+ RUN npm run build
97
+ RUN npm prune --production
98
+
99
+ # Stage 3: Production image
100
+ FROM node:22-alpine AS runner
101
+ WORKDIR /app
102
+
103
+ RUN addgroup -g 1001 -S appgroup && adduser -S appuser -u 1001
104
+ USER appuser
105
+
106
+ COPY --from=builder --chown=appuser:appgroup /app/node_modules ./node_modules
107
+ COPY --from=builder --chown=appuser:appgroup /app/dist ./dist
108
+ COPY --from=builder --chown=appuser:appgroup /app/package.json ./
109
+
110
+ ENV NODE_ENV=production
111
+ EXPOSE 3000
112
+
113
+ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
114
+ CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1
115
+
116
+ CMD ["node", "dist/server.js"]
117
+ ```
118
+
119
+ ### Multi-Stage Dockerfile (Go)
120
+
121
+ ```dockerfile
122
+ FROM golang:1.22-alpine AS builder
123
+ WORKDIR /app
124
+ COPY go.mod go.sum ./
125
+ RUN go mod download
126
+ COPY . .
127
+ RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /server ./cmd/server
128
+
129
+ FROM alpine:3.19 AS runner
130
+ RUN apk --no-cache add ca-certificates
131
+ RUN adduser -D -u 1001 appuser
132
+ USER appuser
133
+
134
+ COPY --from=builder /server /server
135
+
136
+ EXPOSE 8080
137
+ HEALTHCHECK --interval=30s --timeout=3s CMD wget -qO- http://localhost:8080/health || exit 1
138
+ CMD ["/server"]
139
+ ```
140
+
141
+ ### Multi-Stage Dockerfile (Python/Django)
142
+
143
+ ```dockerfile
144
+ FROM python:3.12-slim AS builder
145
+ WORKDIR /app
146
+ RUN pip install --no-cache-dir uv
147
+ COPY requirements.txt .
148
+ RUN uv pip install --system --no-cache -r requirements.txt
149
+
150
+ FROM python:3.12-slim AS runner
151
+ WORKDIR /app
152
+
153
+ RUN useradd -r -u 1001 appuser
154
+ USER appuser
155
+
156
+ COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
157
+ COPY --from=builder /usr/local/bin /usr/local/bin
158
+ COPY . .
159
+
160
+ ENV PYTHONUNBUFFERED=1
161
+ EXPOSE 8000
162
+
163
+ HEALTHCHECK --interval=30s --timeout=3s CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health/')" || exit 1
164
+ CMD ["gunicorn", "config.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "4"]
165
+ ```
166
+
167
+ ### Docker Best Practices
168
+
169
+ ```
170
+ # GOOD practices
171
+ - Use specific version tags (node:22-alpine, not node:latest)
172
+ - Multi-stage builds to minimize image size
173
+ - Run as non-root user
174
+ - Copy dependency files first (layer caching)
175
+ - Use .dockerignore to exclude node_modules, .git, tests
176
+ - Add HEALTHCHECK instruction
177
+ - Set resource limits in docker-compose or k8s
178
+
179
+ # BAD practices
180
+ - Running as root
181
+ - Using :latest tags
182
+ - Copying entire repo in one COPY layer
183
+ - Installing dev dependencies in production image
184
+ - Storing secrets in image (use env vars or secrets manager)
185
+ ```
186
+
187
+ ## CI/CD Pipeline
188
+
189
+ ### GitHub Actions (Standard Pipeline)
190
+
191
+ ```yaml
192
+ name: CI/CD
193
+
194
+ on:
195
+ push:
196
+ branches: [main]
197
+ pull_request:
198
+ branches: [main]
199
+
200
+ jobs:
201
+ test:
202
+ runs-on: ubuntu-latest
203
+ steps:
204
+ - uses: actions/checkout@v4
205
+ - uses: actions/setup-node@v4
206
+ with:
207
+ node-version: 22
208
+ cache: npm
209
+ - run: npm ci
210
+ - run: npm run lint
211
+ - run: npm run typecheck
212
+ - run: npm test -- --coverage
213
+ - uses: actions/upload-artifact@v4
214
+ if: always()
215
+ with:
216
+ name: coverage
217
+ path: coverage/
218
+
219
+ build:
220
+ needs: test
221
+ runs-on: ubuntu-latest
222
+ if: github.ref == 'refs/heads/main'
223
+ steps:
224
+ - uses: actions/checkout@v4
225
+ - uses: docker/setup-buildx-action@v3
226
+ - uses: docker/login-action@v3
227
+ with:
228
+ registry: ghcr.io
229
+ username: ${{ github.actor }}
230
+ password: ${{ secrets.GITHUB_TOKEN }}
231
+ - uses: docker/build-push-action@v5
232
+ with:
233
+ push: true
234
+ tags: ghcr.io/${{ github.repository }}:${{ github.sha }}
235
+ cache-from: type=gha
236
+ cache-to: type=gha,mode=max
237
+
238
+ deploy:
239
+ needs: build
240
+ runs-on: ubuntu-latest
241
+ if: github.ref == 'refs/heads/main'
242
+ environment: production
243
+ steps:
244
+ - name: Deploy to production
245
+ run: |
246
+ # Platform-specific deployment command
247
+ # Railway: railway up
248
+ # Vercel: vercel --prod
249
+ # K8s: kubectl set image deployment/app app=ghcr.io/${{ github.repository }}:${{ github.sha }}
250
+ echo "Deploying ${{ github.sha }}"
251
+ ```
252
+
253
+ ### Pipeline Stages
254
+
255
+ ```
256
+ PR opened:
257
+ lint → typecheck → unit tests → integration tests → preview deploy
258
+
259
+ Merged to main:
260
+ lint → typecheck → unit tests → integration tests → build image → deploy staging → smoke tests → deploy production
261
+ ```
262
+
263
+ ## Health Checks
264
+
265
+ ### Health Check Endpoint
266
+
267
+ ```typescript
268
+ // Simple health check
269
+ app.get("/health", (req, res) => {
270
+ res.status(200).json({ status: "ok" });
271
+ });
272
+
273
+ // Detailed health check (for internal monitoring)
274
+ app.get("/health/detailed", async (req, res) => {
275
+ const checks = {
276
+ database: await checkDatabase(),
277
+ redis: await checkRedis(),
278
+ externalApi: await checkExternalApi(),
279
+ };
280
+
281
+ const allHealthy = Object.values(checks).every(c => c.status === "ok");
282
+
283
+ res.status(allHealthy ? 200 : 503).json({
284
+ status: allHealthy ? "ok" : "degraded",
285
+ timestamp: new Date().toISOString(),
286
+ version: process.env.APP_VERSION || "unknown",
287
+ uptime: process.uptime(),
288
+ checks,
289
+ });
290
+ });
291
+
292
+ async function checkDatabase(): Promise<HealthCheck> {
293
+ try {
294
+ await db.query("SELECT 1");
295
+ return { status: "ok", latency_ms: 2 };
296
+ } catch (err) {
297
+ return { status: "error", message: "Database unreachable" };
298
+ }
299
+ }
300
+ ```
301
+
302
+ ### Kubernetes Probes
303
+
304
+ ```yaml
305
+ livenessProbe:
306
+ httpGet:
307
+ path: /health
308
+ port: 3000
309
+ initialDelaySeconds: 10
310
+ periodSeconds: 30
311
+ failureThreshold: 3
312
+
313
+ readinessProbe:
314
+ httpGet:
315
+ path: /health
316
+ port: 3000
317
+ initialDelaySeconds: 5
318
+ periodSeconds: 10
319
+ failureThreshold: 2
320
+
321
+ startupProbe:
322
+ httpGet:
323
+ path: /health
324
+ port: 3000
325
+ initialDelaySeconds: 0
326
+ periodSeconds: 5
327
+ failureThreshold: 30 # 30 * 5s = 150s max startup time
328
+ ```
329
+
330
+ ## Environment Configuration
331
+
332
+ ### Twelve-Factor App Pattern
333
+
334
+ ```bash
335
+ # All config via environment variables — never in code
336
+ DATABASE_URL=postgres://user:pass@host:5432/db
337
+ REDIS_URL=redis://host:6379/0
338
+ API_KEY=${API_KEY} # injected by secrets manager
339
+ LOG_LEVEL=info
340
+ PORT=3000
341
+
342
+ # Environment-specific behavior
343
+ NODE_ENV=production # or staging, development
344
+ APP_ENV=production # explicit app environment
345
+ ```
346
+
347
+ ### Configuration Validation
348
+
349
+ ```typescript
350
+ import { z } from "zod";
351
+
352
+ const envSchema = z.object({
353
+ NODE_ENV: z.enum(["development", "staging", "production"]),
354
+ PORT: z.coerce.number().default(3000),
355
+ DATABASE_URL: z.string().url(),
356
+ REDIS_URL: z.string().url(),
357
+ JWT_SECRET: z.string().min(32),
358
+ LOG_LEVEL: z.enum(["debug", "info", "warn", "error"]).default("info"),
359
+ });
360
+
361
+ // Validate at startup — fail fast if config is wrong
362
+ export const env = envSchema.parse(process.env);
363
+ ```
364
+
365
+ ## Rollback Strategy
366
+
367
+ ### Instant Rollback
368
+
369
+ ```bash
370
+ # Docker/Kubernetes: point to previous image
371
+ kubectl rollout undo deployment/app
372
+
373
+ # Vercel: promote previous deployment
374
+ vercel rollback
375
+
376
+ # Railway: redeploy previous commit
377
+ railway up --commit <previous-sha>
378
+
379
+ # Database: rollback migration (if reversible)
380
+ npx prisma migrate resolve --rolled-back <migration-name>
381
+ ```
382
+
383
+ ### Rollback Checklist
384
+
385
+ - [ ] Previous image/artifact is available and tagged
386
+ - [ ] Database migrations are backward-compatible (no destructive changes)
387
+ - [ ] Feature flags can disable new features without deploy
388
+ - [ ] Monitoring alerts configured for error rate spikes
389
+ - [ ] Rollback tested in staging before production release
390
+
391
+ ## Production Readiness Checklist
392
+
393
+ Before any production deployment:
394
+
395
+ ### Application
396
+ - [ ] All tests pass (unit, integration, E2E)
397
+ - [ ] No hardcoded secrets in code or config files
398
+ - [ ] Error handling covers all edge cases
399
+ - [ ] Logging is structured (JSON) and does not contain PII
400
+ - [ ] Health check endpoint returns meaningful status
401
+
402
+ ### Infrastructure
403
+ - [ ] Docker image builds reproducibly (pinned versions)
404
+ - [ ] Environment variables documented and validated at startup
405
+ - [ ] Resource limits set (CPU, memory)
406
+ - [ ] Horizontal scaling configured (min/max instances)
407
+ - [ ] SSL/TLS enabled on all endpoints
408
+
409
+ ### Monitoring
410
+ - [ ] Application metrics exported (request rate, latency, errors)
411
+ - [ ] Alerts configured for error rate > threshold
412
+ - [ ] Log aggregation set up (structured logs, searchable)
413
+ - [ ] Uptime monitoring on health endpoint
414
+
415
+ ### Security
416
+ - [ ] Dependencies scanned for CVEs
417
+ - [ ] CORS configured for allowed origins only
418
+ - [ ] Rate limiting enabled on public endpoints
419
+ - [ ] Authentication and authorization verified
420
+ - [ ] Security headers set (CSP, HSTS, X-Frame-Options)
421
+
422
+ ### Operations
423
+ - [ ] Rollback plan documented and tested
424
+ - [ ] Database migration tested against production-sized data
425
+ - [ ] Runbook for common failure scenarios
426
+ - [ ] On-call rotation and escalation path defined