node-api-builder {Backend} (v1.0)
"Firebase Functions are your backend. Design them like microservices, deploy them like magic."
Purpose
Node.js/Express API for Cloud Functions or Hostinger Node.js hosting. Middleware chain. Error handling. [EXPLICIT] When to use: Backend development within Firebase/Google ecosystem.
Core Principles
- Law of Functions: Each Cloud Function does ONE thing. Single responsibility. [EXPLICIT]
- Law of Cold Start: Minimize dependencies. Use lazy imports. Set min instances for critical functions. [EXPLICIT]
- Law of Security: Every HTTP function verifies Firebase ID tokens. No public endpoints without auth. [EXPLICIT]
Core Process
Phase 1: Design
- Map requirements to Cloud Functions triggers (HTTP, Firestore, Auth, Storage, scheduled). [EXPLICIT]
- Define input/output contracts for each function. [EXPLICIT]
- Design error handling and retry strategy. [EXPLICIT]
Phase 2: Implement
- Create function with proper trigger type. [EXPLICIT]
- Add auth middleware for HTTP functions. [EXPLICIT]
- Implement business logic with error handling. [EXPLICIT]
- Add Cloud Logging for observability. [EXPLICIT]
Phase 3: Test + Deploy
- Test with Firebase Emulator Suite. [EXPLICIT]
- Deploy with
firebase deploy --only functions. [EXPLICIT] - Verify in Firebase Console. [EXPLICIT]
3. Inputs / Outputs
| Input | Type | Required | Description |
|---|---|---|---|
| Requirements | Text/Spec | Yes | What the function does |
| Output | Type | Description | |
| -------- | ------ | ------------- | |
| Cloud Function code | TypeScript | Deployable function |
Validation Gate
- Single responsibility per function
- Auth middleware on HTTP endpoints
- Error handling with Cloud Logging
- Emulator tests pass
- No AWS/Azure services (R-002)
5. Self-Correction Triggers
[!WARNING] IF function has no auth middleware THEN add verifyIdToken check. IF function imports 10+ dependencies THEN split or lazy-load to reduce cold start.
Usage
Example invocations:
- "/node-api-builder" — Run the full node api builder workflow
- "node api builder on this project" — Apply to current context
Assumptions & Limits
- Assumes access to project artifacts (code, docs, configs) [EXPLICIT]
- Requires English-language output unless otherwise specified [EXPLICIT]
- Does not replace domain expert judgment for final decisions [EXPLICIT]
Edge Cases
| Scenario | Handling |
|---|---|
| Empty or minimal input | Request clarification before proceeding |
| Conflicting requirements | Flag conflicts explicitly, propose resolution |
| Out-of-scope request | Redirect to appropriate skill or escalate |
Source: JaviMontano/jm-adk-alfa — distributed by TomeVault.