@namch/agent-assistant 1.0.0 → 1.0.1

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 (168) hide show
  1. package/README.md +83 -539
  2. package/agents/backend-engineer.md +0 -8
  3. package/agents/brainstormer.md +0 -6
  4. package/agents/business-analyst.md +0 -5
  5. package/agents/database-architect.md +0 -6
  6. package/agents/debugger.md +0 -6
  7. package/agents/designer.md +0 -5
  8. package/agents/devops-engineer.md +0 -7
  9. package/agents/docs-manager.md +0 -6
  10. package/agents/frontend-engineer.md +0 -7
  11. package/agents/game-engineer.md +0 -7
  12. package/agents/mobile-engineer.md +0 -7
  13. package/agents/performance-engineer.md +0 -7
  14. package/agents/planner.md +0 -6
  15. package/agents/project-manager.md +0 -6
  16. package/agents/researcher.md +0 -5
  17. package/agents/reviewer.md +0 -6
  18. package/agents/scouter.md +0 -6
  19. package/agents/security-engineer.md +0 -7
  20. package/agents/tech-lead.md +0 -7
  21. package/agents/tester.md +0 -5
  22. package/cli/README.md +19 -10
  23. package/documents/business/business-features.md +1 -1
  24. package/documents/business/business-prd.md +4 -4
  25. package/documents/knowledge-architecture.md +1 -1
  26. package/documents/knowledge-domain.md +1 -1
  27. package/documents/knowledge-overview.md +14 -29
  28. package/documents/knowledge-source-base.md +14 -14
  29. package/package.json +1 -1
  30. package/rules/QUICK-REFERENCE.md +4 -1
  31. package/rules/SKILL-DISCOVERY.md +37 -14
  32. package/skills/active-directory-attacks/SKILL.md +383 -0
  33. package/skills/active-directory-attacks/references/advanced-attacks.md +382 -0
  34. package/skills/agent-evaluation/SKILL.md +64 -0
  35. package/skills/agent-memory-mcp/SKILL.md +82 -0
  36. package/skills/agent-memory-systems/SKILL.md +67 -0
  37. package/skills/agent-tool-builder/SKILL.md +53 -0
  38. package/skills/ai-agents-architect/SKILL.md +90 -0
  39. package/skills/ai-product/SKILL.md +54 -0
  40. package/skills/ai-wrapper-product/SKILL.md +273 -0
  41. package/skills/api-documentation-generator/SKILL.md +484 -0
  42. package/skills/api-fuzzing-bug-bounty/SKILL.md +433 -0
  43. package/skills/api-security-best-practices/SKILL.md +907 -0
  44. package/skills/autonomous-agent-patterns/SKILL.md +761 -0
  45. package/skills/autonomous-agents/SKILL.md +68 -0
  46. package/skills/aws-penetration-testing/SKILL.md +405 -0
  47. package/skills/aws-penetration-testing/references/advanced-aws-pentesting.md +469 -0
  48. package/skills/azure-functions/SKILL.md +42 -0
  49. package/skills/backend-dev-guidelines/SKILL.md +342 -0
  50. package/skills/backend-dev-guidelines/resources/architecture-overview.md +451 -0
  51. package/skills/backend-dev-guidelines/resources/async-and-errors.md +307 -0
  52. package/skills/backend-dev-guidelines/resources/complete-examples.md +638 -0
  53. package/skills/backend-dev-guidelines/resources/configuration.md +275 -0
  54. package/skills/backend-dev-guidelines/resources/database-patterns.md +224 -0
  55. package/skills/backend-dev-guidelines/resources/middleware-guide.md +213 -0
  56. package/skills/backend-dev-guidelines/resources/routing-and-controllers.md +756 -0
  57. package/skills/backend-dev-guidelines/resources/sentry-and-monitoring.md +336 -0
  58. package/skills/backend-dev-guidelines/resources/services-and-repositories.md +789 -0
  59. package/skills/backend-dev-guidelines/resources/testing-guide.md +235 -0
  60. package/skills/backend-dev-guidelines/resources/validation-patterns.md +754 -0
  61. package/skills/broken-authentication/SKILL.md +476 -0
  62. package/skills/bullmq-specialist/SKILL.md +57 -0
  63. package/skills/bun-development/SKILL.md +691 -0
  64. package/skills/burp-suite-testing/SKILL.md +380 -0
  65. package/skills/cloud-penetration-testing/SKILL.md +501 -0
  66. package/skills/cloud-penetration-testing/references/advanced-cloud-scripts.md +318 -0
  67. package/skills/computer-use-agents/SKILL.md +315 -0
  68. package/skills/content-creator/SKILL.md +248 -0
  69. package/skills/content-creator/assets/content_calendar_template.md +99 -0
  70. package/skills/content-creator/references/brand_guidelines.md +199 -0
  71. package/skills/content-creator/references/content_frameworks.md +534 -0
  72. package/skills/content-creator/references/social_media_optimization.md +317 -0
  73. package/skills/content-creator/scripts/brand_voice_analyzer.py +185 -0
  74. package/skills/content-creator/scripts/seo_optimizer.py +419 -0
  75. package/skills/context-window-management/SKILL.md +53 -0
  76. package/skills/conversation-memory/SKILL.md +61 -0
  77. package/skills/copy-editing/SKILL.md +439 -0
  78. package/skills/copywriting/SKILL.md +225 -0
  79. package/skills/crewai/SKILL.md +243 -0
  80. package/skills/discord-bot-architect/SKILL.md +277 -0
  81. package/skills/dispatching-parallel-agents/SKILL.md +180 -0
  82. package/skills/email-sequence/SKILL.md +925 -0
  83. package/skills/email-systems/SKILL.md +54 -0
  84. package/skills/ethical-hacking-methodology/SKILL.md +466 -0
  85. package/skills/executing-plans/SKILL.md +76 -0
  86. package/skills/file-path-traversal/SKILL.md +486 -0
  87. package/skills/finishing-a-development-branch/SKILL.md +200 -0
  88. package/skills/frontend-dev-guidelines/SKILL.md +359 -0
  89. package/skills/frontend-dev-guidelines/resources/common-patterns.md +331 -0
  90. package/skills/frontend-dev-guidelines/resources/complete-examples.md +872 -0
  91. package/skills/frontend-dev-guidelines/resources/component-patterns.md +502 -0
  92. package/skills/frontend-dev-guidelines/resources/data-fetching.md +767 -0
  93. package/skills/frontend-dev-guidelines/resources/file-organization.md +502 -0
  94. package/skills/frontend-dev-guidelines/resources/loading-and-error-states.md +501 -0
  95. package/skills/frontend-dev-guidelines/resources/performance.md +406 -0
  96. package/skills/frontend-dev-guidelines/resources/routing-guide.md +364 -0
  97. package/skills/frontend-dev-guidelines/resources/styling-guide.md +428 -0
  98. package/skills/frontend-dev-guidelines/resources/typescript-standards.md +418 -0
  99. package/skills/gcp-cloud-run/SKILL.md +288 -0
  100. package/skills/git-pushing/SKILL.md +33 -0
  101. package/skills/git-pushing/scripts/smart_commit.sh +19 -0
  102. package/skills/github-workflow-automation/SKILL.md +846 -0
  103. package/skills/html-injection-testing/SKILL.md +498 -0
  104. package/skills/idor-testing/SKILL.md +442 -0
  105. package/skills/inngest/SKILL.md +55 -0
  106. package/skills/javascript-mastery/SKILL.md +645 -0
  107. package/skills/kaizen/SKILL.md +730 -0
  108. package/skills/langfuse/SKILL.md +238 -0
  109. package/skills/langgraph/SKILL.md +287 -0
  110. package/skills/linux-privilege-escalation/SKILL.md +504 -0
  111. package/skills/llm-app-patterns/SKILL.md +760 -0
  112. package/skills/metasploit-framework/SKILL.md +478 -0
  113. package/skills/multi-agent-brainstorming/SKILL.md +256 -0
  114. package/skills/neon-postgres/SKILL.md +56 -0
  115. package/skills/nextjs-supabase-auth/SKILL.md +56 -0
  116. package/skills/nosql-expert/SKILL.md +111 -0
  117. package/skills/pentest-checklist/SKILL.md +334 -0
  118. package/skills/pentest-commands/SKILL.md +438 -0
  119. package/skills/plaid-fintech/SKILL.md +50 -0
  120. package/skills/planning-with-files/SKILL.md +211 -0
  121. package/skills/planning-with-files/examples.md +202 -0
  122. package/skills/planning-with-files/reference.md +218 -0
  123. package/skills/planning-with-files/scripts/check-complete.sh +44 -0
  124. package/skills/planning-with-files/scripts/init-session.sh +120 -0
  125. package/skills/planning-with-files/templates/findings.md +95 -0
  126. package/skills/planning-with-files/templates/progress.md +114 -0
  127. package/skills/planning-with-files/templates/task_plan.md +132 -0
  128. package/skills/privilege-escalation-methods/SKILL.md +333 -0
  129. package/skills/production-code-audit/SKILL.md +540 -0
  130. package/skills/prompt-caching/SKILL.md +61 -0
  131. package/skills/prompt-engineering/SKILL.md +171 -0
  132. package/skills/prompt-library/SKILL.md +322 -0
  133. package/skills/rag-engineer/SKILL.md +90 -0
  134. package/skills/rag-implementation/SKILL.md +63 -0
  135. package/skills/react-ui-patterns/SKILL.md +289 -0
  136. package/skills/red-team-tools/SKILL.md +310 -0
  137. package/skills/scanning-tools/SKILL.md +589 -0
  138. package/skills/shodan-reconnaissance/SKILL.md +503 -0
  139. package/skills/slack-bot-builder/SKILL.md +264 -0
  140. package/skills/smtp-penetration-testing/SKILL.md +500 -0
  141. package/skills/social-content/SKILL.md +807 -0
  142. package/skills/software-architecture/SKILL.md +75 -0
  143. package/skills/sql-injection-testing/SKILL.md +448 -0
  144. package/skills/sqlmap-database-pentesting/SKILL.md +400 -0
  145. package/skills/ssh-penetration-testing/SKILL.md +488 -0
  146. package/skills/stripe-integration/SKILL.md +69 -0
  147. package/skills/subagent-driven-development/SKILL.md +240 -0
  148. package/skills/subagent-driven-development/code-quality-reviewer-prompt.md +20 -0
  149. package/skills/subagent-driven-development/implementer-prompt.md +78 -0
  150. package/skills/subagent-driven-development/spec-reviewer-prompt.md +61 -0
  151. package/skills/tavily-web/SKILL.md +36 -0
  152. package/skills/telegram-bot-builder/SKILL.md +254 -0
  153. package/skills/test-driven-development/SKILL.md +371 -0
  154. package/skills/test-driven-development/testing-anti-patterns.md +299 -0
  155. package/skills/test-fixing/SKILL.md +119 -0
  156. package/skills/top-web-vulnerabilities/SKILL.md +543 -0
  157. package/skills/trigger-dev/SKILL.md +67 -0
  158. package/skills/twilio-communications/SKILL.md +295 -0
  159. package/skills/upstash-qstash/SKILL.md +68 -0
  160. package/skills/verification-before-completion/SKILL.md +139 -0
  161. package/skills/voice-agents/SKILL.md +68 -0
  162. package/skills/voice-ai-development/SKILL.md +302 -0
  163. package/skills/windows-privilege-escalation/SKILL.md +496 -0
  164. package/skills/wireshark-analysis/SKILL.md +497 -0
  165. package/skills/wordpress-penetration-testing/SKILL.md +485 -0
  166. package/skills/workflow-automation/SKILL.md +68 -0
  167. package/skills/xss-html-injection/SKILL.md +499 -0
  168. package/skills/zapier-make-patterns/SKILL.md +67 -0
@@ -0,0 +1,418 @@
1
+ # TypeScript Standards
2
+
3
+ TypeScript best practices for type safety and maintainability in React frontend code.
4
+
5
+ ---
6
+
7
+ ## Strict Mode
8
+
9
+ ### Configuration
10
+
11
+ TypeScript strict mode is **enabled** in the project:
12
+
13
+ ```json
14
+ // tsconfig.json
15
+ {
16
+ "compilerOptions": {
17
+ "strict": true,
18
+ "noImplicitAny": true,
19
+ "strictNullChecks": true
20
+ }
21
+ }
22
+ ```
23
+
24
+ **This means:**
25
+ - No implicit `any` types
26
+ - Null/undefined must be handled explicitly
27
+ - Type safety enforced
28
+
29
+ ---
30
+
31
+ ## No `any` Type
32
+
33
+ ### The Rule
34
+
35
+ ```typescript
36
+ // ❌ NEVER use any
37
+ function handleData(data: any) {
38
+ return data.something;
39
+ }
40
+
41
+ // ✅ Use specific types
42
+ interface MyData {
43
+ something: string;
44
+ }
45
+
46
+ function handleData(data: MyData) {
47
+ return data.something;
48
+ }
49
+
50
+ // ✅ Or use unknown for truly unknown data
51
+ function handleUnknown(data: unknown) {
52
+ if (typeof data === 'object' && data !== null && 'something' in data) {
53
+ return (data as MyData).something;
54
+ }
55
+ }
56
+ ```
57
+
58
+ **If you truly don't know the type:**
59
+ - Use `unknown` (forces type checking)
60
+ - Use type guards to narrow
61
+ - Document why type is unknown
62
+
63
+ ---
64
+
65
+ ## Explicit Return Types
66
+
67
+ ### Function Return Types
68
+
69
+ ```typescript
70
+ // ✅ CORRECT - Explicit return type
71
+ function getUser(id: number): Promise<User> {
72
+ return apiClient.get(`/users/${id}`);
73
+ }
74
+
75
+ function calculateTotal(items: Item[]): number {
76
+ return items.reduce((sum, item) => sum + item.price, 0);
77
+ }
78
+
79
+ // ❌ AVOID - Implicit return type (less clear)
80
+ function getUser(id: number) {
81
+ return apiClient.get(`/users/${id}`);
82
+ }
83
+ ```
84
+
85
+ ### Component Return Types
86
+
87
+ ```typescript
88
+ // React.FC already provides return type (ReactElement)
89
+ export const MyComponent: React.FC<Props> = ({ prop }) => {
90
+ return <div>{prop}</div>;
91
+ };
92
+
93
+ // For custom hooks
94
+ function useMyData(id: number): { data: Data; isLoading: boolean } {
95
+ const [data, setData] = useState<Data | null>(null);
96
+ const [isLoading, setIsLoading] = useState(true);
97
+
98
+ return { data: data!, isLoading };
99
+ }
100
+ ```
101
+
102
+ ---
103
+
104
+ ## Type Imports
105
+
106
+ ### Use 'type' Keyword
107
+
108
+ ```typescript
109
+ // ✅ CORRECT - Explicitly mark as type import
110
+ import type { User } from '~types/user';
111
+ import type { Post } from '~types/post';
112
+ import type { SxProps, Theme } from '@mui/material';
113
+
114
+ // ❌ AVOID - Mixed value and type imports
115
+ import { User } from '~types/user'; // Unclear if type or value
116
+ ```
117
+
118
+ **Benefits:**
119
+ - Clearly separates types from values
120
+ - Better tree-shaking
121
+ - Prevents circular dependencies
122
+ - TypeScript compiler optimization
123
+
124
+ ---
125
+
126
+ ## Component Prop Interfaces
127
+
128
+ ### Interface Pattern
129
+
130
+ ```typescript
131
+ /**
132
+ * Props for MyComponent
133
+ */
134
+ interface MyComponentProps {
135
+ /** The user ID to display */
136
+ userId: number;
137
+
138
+ /** Optional callback when action completes */
139
+ onComplete?: () => void;
140
+
141
+ /** Display mode for the component */
142
+ mode?: 'view' | 'edit';
143
+
144
+ /** Additional CSS classes */
145
+ className?: string;
146
+ }
147
+
148
+ export const MyComponent: React.FC<MyComponentProps> = ({
149
+ userId,
150
+ onComplete,
151
+ mode = 'view', // Default value
152
+ className,
153
+ }) => {
154
+ return <div>...</div>;
155
+ };
156
+ ```
157
+
158
+ **Key Points:**
159
+ - Separate interface for props
160
+ - JSDoc comments for each prop
161
+ - Optional props use `?`
162
+ - Provide defaults in destructuring
163
+
164
+ ### Props with Children
165
+
166
+ ```typescript
167
+ interface ContainerProps {
168
+ children: React.ReactNode;
169
+ title: string;
170
+ }
171
+
172
+ // React.FC automatically includes children type, but be explicit
173
+ export const Container: React.FC<ContainerProps> = ({ children, title }) => {
174
+ return (
175
+ <div>
176
+ <h2>{title}</h2>
177
+ {children}
178
+ </div>
179
+ );
180
+ };
181
+ ```
182
+
183
+ ---
184
+
185
+ ## Utility Types
186
+
187
+ ### Partial<T>
188
+
189
+ ```typescript
190
+ // Make all properties optional
191
+ type UserUpdate = Partial<User>;
192
+
193
+ function updateUser(id: number, updates: Partial<User>) {
194
+ // updates can have any subset of User properties
195
+ }
196
+ ```
197
+
198
+ ### Pick<T, K>
199
+
200
+ ```typescript
201
+ // Select specific properties
202
+ type UserPreview = Pick<User, 'id' | 'name' | 'email'>;
203
+
204
+ const preview: UserPreview = {
205
+ id: 1,
206
+ name: 'John',
207
+ email: 'john@example.com',
208
+ // Other User properties not allowed
209
+ };
210
+ ```
211
+
212
+ ### Omit<T, K>
213
+
214
+ ```typescript
215
+ // Exclude specific properties
216
+ type UserWithoutPassword = Omit<User, 'password' | 'passwordHash'>;
217
+
218
+ const publicUser: UserWithoutPassword = {
219
+ id: 1,
220
+ name: 'John',
221
+ email: 'john@example.com',
222
+ // password and passwordHash not allowed
223
+ };
224
+ ```
225
+
226
+ ### Required<T>
227
+
228
+ ```typescript
229
+ // Make all properties required
230
+ type RequiredConfig = Required<Config>; // All optional props become required
231
+ ```
232
+
233
+ ### Record<K, V>
234
+
235
+ ```typescript
236
+ // Type-safe object/map
237
+ const userMap: Record<string, User> = {
238
+ 'user1': { id: 1, name: 'John' },
239
+ 'user2': { id: 2, name: 'Jane' },
240
+ };
241
+
242
+ // For styles
243
+ import type { SxProps, Theme } from '@mui/material';
244
+
245
+ const styles: Record<string, SxProps<Theme>> = {
246
+ container: { p: 2 },
247
+ header: { mb: 1 },
248
+ };
249
+ ```
250
+
251
+ ---
252
+
253
+ ## Type Guards
254
+
255
+ ### Basic Type Guards
256
+
257
+ ```typescript
258
+ function isUser(data: unknown): data is User {
259
+ return (
260
+ typeof data === 'object' &&
261
+ data !== null &&
262
+ 'id' in data &&
263
+ 'name' in data
264
+ );
265
+ }
266
+
267
+ // Usage
268
+ if (isUser(response)) {
269
+ console.log(response.name); // TypeScript knows it's User
270
+ }
271
+ ```
272
+
273
+ ### Discriminated Unions
274
+
275
+ ```typescript
276
+ type LoadingState =
277
+ | { status: 'idle' }
278
+ | { status: 'loading' }
279
+ | { status: 'success'; data: Data }
280
+ | { status: 'error'; error: Error };
281
+
282
+ function Component({ state }: { state: LoadingState }) {
283
+ // TypeScript narrows type based on status
284
+ if (state.status === 'success') {
285
+ return <Display data={state.data} />; // data available here
286
+ }
287
+
288
+ if (state.status === 'error') {
289
+ return <Error error={state.error} />; // error available here
290
+ }
291
+
292
+ return <Loading />;
293
+ }
294
+ ```
295
+
296
+ ---
297
+
298
+ ## Generic Types
299
+
300
+ ### Generic Functions
301
+
302
+ ```typescript
303
+ function getById<T>(items: T[], id: number): T | undefined {
304
+ return items.find(item => (item as any).id === id);
305
+ }
306
+
307
+ // Usage with type inference
308
+ const users: User[] = [...];
309
+ const user = getById(users, 123); // Type: User | undefined
310
+ ```
311
+
312
+ ### Generic Components
313
+
314
+ ```typescript
315
+ interface ListProps<T> {
316
+ items: T[];
317
+ renderItem: (item: T) => React.ReactNode;
318
+ }
319
+
320
+ export function List<T>({ items, renderItem }: ListProps<T>): React.ReactElement {
321
+ return (
322
+ <div>
323
+ {items.map((item, index) => (
324
+ <div key={index}>{renderItem(item)}</div>
325
+ ))}
326
+ </div>
327
+ );
328
+ }
329
+
330
+ // Usage
331
+ <List<User>
332
+ items={users}
333
+ renderItem={(user) => <UserCard user={user} />}
334
+ />
335
+ ```
336
+
337
+ ---
338
+
339
+ ## Type Assertions (Use Sparingly)
340
+
341
+ ### When to Use
342
+
343
+ ```typescript
344
+ // ✅ OK - When you know more than TypeScript
345
+ const element = document.getElementById('my-element') as HTMLInputElement;
346
+ const value = element.value;
347
+
348
+ // ✅ OK - API response that you've validated
349
+ const response = await api.getData();
350
+ const user = response.data as User; // You know the shape
351
+ ```
352
+
353
+ ### When NOT to Use
354
+
355
+ ```typescript
356
+ // ❌ AVOID - Circumventing type safety
357
+ const data = getData() as any; // WRONG - defeats TypeScript
358
+
359
+ // ❌ AVOID - Unsafe assertion
360
+ const value = unknownValue as string; // Might not actually be string
361
+ ```
362
+
363
+ ---
364
+
365
+ ## Null/Undefined Handling
366
+
367
+ ### Optional Chaining
368
+
369
+ ```typescript
370
+ // ✅ CORRECT
371
+ const name = user?.profile?.name;
372
+
373
+ // Equivalent to:
374
+ const name = user && user.profile && user.profile.name;
375
+ ```
376
+
377
+ ### Nullish Coalescing
378
+
379
+ ```typescript
380
+ // ✅ CORRECT
381
+ const displayName = user?.name ?? 'Anonymous';
382
+
383
+ // Only uses default if null or undefined
384
+ // (Different from || which triggers on '', 0, false)
385
+ ```
386
+
387
+ ### Non-Null Assertion (Use Carefully)
388
+
389
+ ```typescript
390
+ // ✅ OK - When you're certain value exists
391
+ const data = queryClient.getQueryData<Data>(['data'])!;
392
+
393
+ // ⚠️ CAREFUL - Only use when you KNOW it's not null
394
+ // Better to check explicitly:
395
+ const data = queryClient.getQueryData<Data>(['data']);
396
+ if (data) {
397
+ // Use data
398
+ }
399
+ ```
400
+
401
+ ---
402
+
403
+ ## Summary
404
+
405
+ **TypeScript Checklist:**
406
+ - ✅ Strict mode enabled
407
+ - ✅ No `any` type (use `unknown` if needed)
408
+ - ✅ Explicit return types on functions
409
+ - ✅ Use `import type` for type imports
410
+ - ✅ JSDoc comments on prop interfaces
411
+ - ✅ Utility types (Partial, Pick, Omit, Required, Record)
412
+ - ✅ Type guards for narrowing
413
+ - ✅ Optional chaining and nullish coalescing
414
+ - ❌ Avoid type assertions unless necessary
415
+
416
+ **See Also:**
417
+ - [component-patterns.md](component-patterns.md) - Component typing
418
+ - [data-fetching.md](data-fetching.md) - API typing
@@ -0,0 +1,288 @@
1
+ ---
2
+ name: gcp-cloud-run
3
+ description: "Specialized skill for building production-ready serverless applications on GCP. Covers Cloud Run services (containerized), Cloud Run Functions (event-driven), cold start optimization, and event-driven architecture with Pub/Sub."
4
+ source: vibeship-spawner-skills (Apache 2.0)
5
+ ---
6
+
7
+ # GCP Cloud Run
8
+
9
+ ## Patterns
10
+
11
+ ### Cloud Run Service Pattern
12
+
13
+ Containerized web service on Cloud Run
14
+
15
+ **When to use**: ['Web applications and APIs', 'Need any runtime or library', 'Complex services with multiple endpoints', 'Stateless containerized workloads']
16
+
17
+ ```javascript
18
+ ```dockerfile
19
+ # Dockerfile - Multi-stage build for smaller image
20
+ FROM node:20-slim AS builder
21
+ WORKDIR /app
22
+ COPY package*.json ./
23
+ RUN npm ci --only=production
24
+
25
+ FROM node:20-slim
26
+ WORKDIR /app
27
+
28
+ # Copy only production dependencies
29
+ COPY --from=builder /app/node_modules ./node_modules
30
+ COPY src ./src
31
+ COPY package.json ./
32
+
33
+ # Cloud Run uses PORT env variable
34
+ ENV PORT=8080
35
+ EXPOSE 8080
36
+
37
+ # Run as non-root user
38
+ USER node
39
+
40
+ CMD ["node", "src/index.js"]
41
+ ```
42
+
43
+ ```javascript
44
+ // src/index.js
45
+ const express = require('express');
46
+ const app = express();
47
+
48
+ app.use(express.json());
49
+
50
+ // Health check endpoint
51
+ app.get('/health', (req, res) => {
52
+ res.status(200).send('OK');
53
+ });
54
+
55
+ // API routes
56
+ app.get('/api/items/:id', async (req, res) => {
57
+ try {
58
+ const item = await getItem(req.params.id);
59
+ res.json(item);
60
+ } catch (error) {
61
+ console.error('Error:', error);
62
+ res.status(500).json({ error: 'Internal server error' });
63
+ }
64
+ });
65
+
66
+ // Graceful shutdown
67
+ process.on('SIGTERM', () => {
68
+ console.log('SIGTERM received, shutting down gracefully');
69
+ server.close(() => {
70
+ console.log('Server closed');
71
+ process.exit(0);
72
+ });
73
+ });
74
+
75
+ const PORT = process.env.PORT || 8080;
76
+ const server = app.listen(PORT, () => {
77
+ console.log(`Server listening on port ${PORT}`);
78
+ });
79
+ ```
80
+
81
+ ```yaml
82
+ # cloudbuild.yaml
83
+ steps:
84
+ # Build the container image
85
+ - name: 'gcr.io/cloud-builders/docker'
86
+ args: ['build', '-t', 'gcr.io/$PROJECT_ID/my-service:$COMMIT_SHA', '.']
87
+
88
+ # Push the container image
89
+ - name: 'gcr.io/cloud-builders/docker'
90
+ args: ['push', 'gcr.io/$PROJECT_ID/my-service:$COMMIT_SHA']
91
+
92
+ # Deploy to Cloud Run
93
+ - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
94
+ entrypoint: gcloud
95
+ args:
96
+ - 'run'
97
+ - 'deploy'
98
+ - 'my-service'
99
+ - '--image=gcr.io/$PROJECT_ID/my-service:$COMMIT_SHA'
100
+ - '--region=us-central1'
101
+ - '--platform=managed'
102
+ - '--allow-unauthenticated'
103
+ - '--memory=512Mi'
104
+ - '--cpu=1'
105
+ - '--min-instances=1'
106
+ - '--max-instances=100'
107
+
108
+ ```
109
+
110
+ ### Cloud Run Functions Pattern
111
+
112
+ Event-driven functions (formerly Cloud Functions)
113
+
114
+ **When to use**: ['Simple event handlers', 'Pub/Sub message processing', 'Cloud Storage triggers', 'HTTP webhooks']
115
+
116
+ ```javascript
117
+ ```javascript
118
+ // HTTP Function
119
+ // index.js
120
+ const functions = require('@google-cloud/functions-framework');
121
+
122
+ functions.http('helloHttp', (req, res) => {
123
+ const name = req.query.name || req.body.name || 'World';
124
+ res.send(`Hello, ${name}!`);
125
+ });
126
+ ```
127
+
128
+ ```javascript
129
+ // Pub/Sub Function
130
+ const functions = require('@google-cloud/functions-framework');
131
+
132
+ functions.cloudEvent('processPubSub', (cloudEvent) => {
133
+ // Decode Pub/Sub message
134
+ const message = cloudEvent.data.message;
135
+ const data = message.data
136
+ ? JSON.parse(Buffer.from(message.data, 'base64').toString())
137
+ : {};
138
+
139
+ console.log('Received message:', data);
140
+
141
+ // Process message
142
+ processMessage(data);
143
+ });
144
+ ```
145
+
146
+ ```javascript
147
+ // Cloud Storage Function
148
+ const functions = require('@google-cloud/functions-framework');
149
+
150
+ functions.cloudEvent('processStorageEvent', async (cloudEvent) => {
151
+ const file = cloudEvent.data;
152
+
153
+ console.log(`Event: ${cloudEvent.type}`);
154
+ console.log(`Bucket: ${file.bucket}`);
155
+ console.log(`File: ${file.name}`);
156
+
157
+ if (cloudEvent.type === 'google.cloud.storage.object.v1.finalized') {
158
+ await processUploadedFile(file.bucket, file.name);
159
+ }
160
+ });
161
+ ```
162
+
163
+ ```bash
164
+ # Deploy HTTP function
165
+ gcloud functions deploy hello-http \
166
+ --gen2 \
167
+ --runtime nodejs20 \
168
+ --trigger-http \
169
+ --allow-unauthenticated \
170
+ --region us-central1
171
+
172
+ # Deploy Pub/Sub function
173
+ gcloud functions deploy process-messages \
174
+ --gen2 \
175
+ --runtime nodejs20 \
176
+ --trigger-topic my-topic \
177
+ --region us-central1
178
+
179
+ # Deploy Cloud Storage function
180
+ gcloud functions deploy process-uploads \
181
+ --gen2 \
182
+ --runtime nodejs20 \
183
+ --trigger-event-filters="type=google.cloud.storage.object.v1.finalized" \
184
+ --trigger-event-filters="bucket=my-bucket" \
185
+ --region us-central1
186
+ ```
187
+ ```
188
+
189
+ ### Cold Start Optimization Pattern
190
+
191
+ Minimize cold start latency for Cloud Run
192
+
193
+ **When to use**: ['Latency-sensitive applications', 'User-facing APIs', 'High-traffic services']
194
+
195
+ ```javascript
196
+ ## 1. Enable Startup CPU Boost
197
+
198
+ ```bash
199
+ gcloud run deploy my-service \
200
+ --cpu-boost \
201
+ --region us-central1
202
+ ```
203
+
204
+ ## 2. Set Minimum Instances
205
+
206
+ ```bash
207
+ gcloud run deploy my-service \
208
+ --min-instances 1 \
209
+ --region us-central1
210
+ ```
211
+
212
+ ## 3. Optimize Container Image
213
+
214
+ ```dockerfile
215
+ # Use distroless for minimal image
216
+ FROM node:20-slim AS builder
217
+ WORKDIR /app
218
+ COPY package*.json ./
219
+ RUN npm ci --only=production
220
+
221
+ FROM gcr.io/distroless/nodejs20-debian12
222
+ WORKDIR /app
223
+ COPY --from=builder /app/node_modules ./node_modules
224
+ COPY src ./src
225
+ CMD ["src/index.js"]
226
+ ```
227
+
228
+ ## 4. Lazy Initialize Heavy Dependencies
229
+
230
+ ```javascript
231
+ // Lazy load heavy libraries
232
+ let bigQueryClient = null;
233
+
234
+ function getBigQueryClient() {
235
+ if (!bigQueryClient) {
236
+ const { BigQuery } = require('@google-cloud/bigquery');
237
+ bigQueryClient = new BigQuery();
238
+ }
239
+ return bigQueryClient;
240
+ }
241
+
242
+ // Only initialize when needed
243
+ app.get('/api/analytics', async (req, res) => {
244
+ const client = getBigQueryClient();
245
+ const results = await client.query({...});
246
+ res.json(results);
247
+ });
248
+ ```
249
+
250
+ ## 5. Increase Memory (More CPU)
251
+
252
+ ```bash
253
+ # Higher memory = more CPU during startup
254
+ gcloud run deploy my-service \
255
+ --memory 1Gi \
256
+ --cpu 2 \
257
+ --region us-central1
258
+ ```
259
+ ```
260
+
261
+ ## Anti-Patterns
262
+
263
+ ### ❌ CPU-Intensive Work Without Concurrency=1
264
+
265
+ **Why bad**: CPU is shared across concurrent requests. CPU-bound work
266
+ will starve other requests, causing timeouts.
267
+
268
+ ### ❌ Writing Large Files to /tmp
269
+
270
+ **Why bad**: /tmp is an in-memory filesystem. Large files consume
271
+ your memory allocation and can cause OOM errors.
272
+
273
+ ### ❌ Long-Running Background Tasks
274
+
275
+ **Why bad**: Cloud Run throttles CPU to near-zero when not handling
276
+ requests. Background tasks will be extremely slow or stall.
277
+
278
+ ## ⚠️ Sharp Edges
279
+
280
+ | Issue | Severity | Solution |
281
+ |-------|----------|----------|
282
+ | Issue | high | ## Calculate memory including /tmp usage |
283
+ | Issue | high | ## Set appropriate concurrency |
284
+ | Issue | high | ## Enable CPU always allocated |
285
+ | Issue | medium | ## Configure connection pool with keep-alive |
286
+ | Issue | high | ## Enable startup CPU boost |
287
+ | Issue | medium | ## Explicitly set execution environment |
288
+ | Issue | medium | ## Set consistent timeouts |