Expert guidance for working with Firebase Functions backend using Google Genkit AI framework, Vertex AI models, and TypeScript flow-based architecture.
This skill provides expert guidance for working with a Firebase Functions backend built with TypeScript and Google's Genkit AI framework. The architecture follows a flow-based pattern where AI operations are defined as reusable flows with proper authentication and validation.
When working with this codebase, use these commands:
**Development:**
**Deployment:**
**Initial Setup:**
```bash
gcloud auth login
gcloud config set project <projectID>
export GOOGLE_GENAI_API_KEY=<apikey>
cd functions && npm ci
```
1. **Entry Points:**
- `functions/index.ts` - Firebase Functions endpoints (`helloGenkit`, `GenerateImagen`)
- `functions/genkit.ts` - Genkit AI framework configuration with Vertex AI plugin
- `functions/firebaseAdmin.ts` - Authentication verification using Firebase Admin SDK
2. **AI Flow Architecture:**
- `functions/genkit-flows/` - Contains AI processing flows (helloGeminiFlow.ts, imagenFlow.ts)
- `functions/prompts/` - YAML-frontmatter prompt templates with model configuration
- Flows use `ai.defineFlow()` with Zod schemas for input/output validation
3. **Authentication Pattern:**
All endpoints require Firebase Authentication. Always verify auth as the first line:
```typescript
export const functionName = onCall(opts, async (request: CallableRequest) => {
verifyAuth(request); // Always first line
return await flowFunction(request.data);
});
```
Prompts are stored as `.prompt` files with YAML frontmatter:
```yaml
---
model: vertexai/gemini-2.0-flash-lite
config:
temperature: 1.4
maxOutputTokens: 400
---
Prompt content with {{variable}} substitution
```
Follow this pattern when adding new AI flows:
1. **Create flow file** in `genkit-flows/` directory using `ai.defineFlow()`
2. **Add prompt template** in `prompts/` directory with YAML frontmatter
3. **Export flow** and add Firebase Function in `index.ts`
4. **Include authentication** verification with `verifyAuth()` as first line
5. **Define schemas** using Zod for input/output validation
Example flow structure:
```typescript
import { ai } from '../genkit';
import { z } from 'zod';
export const myFlow = ai.defineFlow(
{
name: 'myFlow',
inputSchema: z.object({ /* ... */ }),
outputSchema: z.object({ /* ... */ })
},
async (input) => {
// Flow logic here
}
);
```
Use Firebase HTTPS errors for consistent error responses:
```typescript
throw new functions.https.HttpsError('error-code', 'message');
```
Auto-deployment via GitHub Actions:
1. Lint workflow runs on PR/push
2. Deploy workflow triggers after successful lint (main branch only)
3. Requires GitHub Secrets: `FIREBASE_TOKEN`, `FIREBASE_SERVICE_ACCOUNT_KEY_BASE64`, `GOOGLE_GENAI_API_KEY`
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/firebase-genkit-ai-backend/raw