firebase-development

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Firebase Development

Firebase开发

Overview

概述

This skill system guides Firebase development using proven patterns from production projects. It routes to specialized sub-skills based on detected intent.
Sub-skills:
  • firebase-development:project-setup
    - Initialize new Firebase projects
  • firebase-development:add-feature
    - Add functions/collections/endpoints
  • firebase-development:debug
    - Troubleshoot emulator and runtime issues
  • firebase-development:validate
    - Review Firebase code for security/patterns
该技能系统借助生产项目中验证有效的模式,指导Firebase开发工作。它会根据检测到的意图,将任务路由到对应的专业子技能。
子技能:
  • firebase-development:project-setup
    - 初始化新的Firebase项目
  • firebase-development:add-feature
    - 添加函数/集合/端点
  • firebase-development:debug
    - 排查模拟器和运行时问题
  • firebase-development:validate
    - 审核Firebase代码的安全性与模式规范

When This Skill Applies

适用场景

  • Starting new Firebase projects
  • Adding Cloud Functions or Firestore collections
  • Debugging emulator issues or rule violations
  • Reviewing Firebase code for security and patterns
  • Setting up multi-hosting configurations
  • Implementing authentication (API keys or Firebase Auth)
  • 启动新的Firebase项目
  • 添加Cloud Functions或Firestore集合
  • 调试模拟器问题或规则违规情况
  • 审核Firebase代码的安全性与模式规范
  • 配置多托管环境
  • 实现认证功能(API密钥或Firebase Auth)

Routing Logic

路由逻辑

Keywords by Sub-Skill

各子技能对应的关键词

project-setup:
  • "new firebase project", "initialize firebase", "firebase init"
  • "set up firebase", "create firebase app", "start firebase project"
add-feature:
  • "add function", "create endpoint", "new tool", "add api"
  • "new collection", "add feature", "build", "implement"
debug:
  • "error", "not working", "debug", "emulator issue"
  • "rules failing", "permission denied", "troubleshoot", "deployment failed"
validate:
  • "review firebase", "check firebase", "validate", "audit firebase"
  • "look at firebase code", "security review"
project-setup:
  • "new firebase project", "initialize firebase", "firebase init"
  • "set up firebase", "create firebase app", "start firebase project"
add-feature:
  • "add function", "create endpoint", "new tool", "add api"
  • "new collection", "add feature", "build", "implement"
debug:
  • "error", "not working", "debug", "emulator issue"
  • "rules failing", "permission denied", "troubleshoot", "deployment failed"
validate:
  • "review firebase", "check firebase", "validate", "audit firebase"
  • "look at firebase code", "security review"

Routing Process

路由流程

  1. Analyze Request: Check for routing keywords
  2. Match Sub-Skill: Identify best match based on keyword density
  3. Announce: "I'm using the firebase-development:[sub-skill] skill to [action]"
  4. Route: Load and execute the sub-skill
  5. Fallback: If ambiguous, use AskUserQuestion with 4 options
  1. 分析请求:检查是否包含路由关键词
  2. 匹配子技能:根据关键词密度确定最佳匹配项
  3. 告知用户:"我将使用firebase-development:[子技能]技能来执行[操作]"
  4. 路由任务:加载并执行对应的子技能
  5. 回退机制:若意图不明确,使用AskUserQuestion功能提供4个选项

Fallback Example

回退示例

If intent is unclear, ask:
Question: "What Firebase task are you working on?"
Options:
  - "Project Setup" (Initialize new Firebase project)
  - "Add Feature" (Add functions, collections, endpoints)
  - "Debug Issue" (Troubleshoot errors or problems)
  - "Validate Code" (Review against patterns)
当意图不清晰时,询问:
问题:"你正在处理哪项Firebase任务?"
选项:
  - "项目搭建"(初始化新的Firebase项目)
  - "添加功能"(添加函数、集合、端点)
  - "调试问题"(排查错误或故障)
  - "代码验证"(对照模式规范进行审核)

Reference Projects

参考项目

Patterns are extracted from three production Firebase projects:
ProjectPathKey Patterns
oneonone
/Users/dylanr/work/2389/oneonone
Express API, custom API keys, server-write-only
bot-socialmedia
/Users/dylanr/work/2389/bot-socialmedia-server
Domain-grouped functions, Firebase Auth + roles
meme-rodeo
/Users/dylanr/work/2389/meme-rodeo
Individual function files, entitlements
所有模式均提取自三个生产环境中的Firebase项目:
项目路径核心模式
oneonone
/Users/dylanr/work/2389/oneonone
Express API、自定义API密钥、仅服务器可写入
bot-socialmedia
/Users/dylanr/work/2389/bot-socialmedia-server
按领域分组的函数、Firebase Auth + 角色权限
meme-rodeo
/Users/dylanr/work/2389/meme-rodeo
独立函数文件、权限管理

Pattern Summaries

模式总结

Multi-Hosting Setup

多托管配置

Three options based on needs:
OptionWhen to UseKey Feature
site:
based
Multiple independent URLsSimple, no build coordination
target:
based
Need predeploy hooksBuild scripts run automatically
Single + rewritesSmaller projectsAll under one domain
Details: See
docs/examples/multi-hosting-setup.md
根据需求提供三种选项:
选项适用场景核心特性
基于
site:
多个独立URL配置简单,无需构建协调
基于
target:
需要预部署钩子构建脚本自动运行
单域名+重写小型项目所有内容统一在一个域名下
详情: 参见
docs/examples/multi-hosting-setup.md

Authentication

认证模式

PatternWhen to UseExample
Custom API keysMCP tools, server-to-serveroneonone
Firebase Auth + rolesUser-facing appsbot-socialmedia
HybridBoth patterns neededWeb UI + API access
Details: See
docs/examples/api-key-authentication.md
模式适用场景示例项目
自定义API密钥MCP工具、服务器到服务器通信oneonone
Firebase Auth + 角色权限面向用户的应用bot-socialmedia
混合模式同时需要上述两种模式Web UI + API访问
详情: 参见
docs/examples/api-key-authentication.md

Cloud Functions Architecture

Cloud Functions架构

PatternWhen to UseStructure
Express appAPI with middleware, routing
app.post('/mcp', handler)
Domain-groupedFeature-rich apps
posts.ts
,
journal.ts
Individual filesMaximum modularityOne function per file
Details: See
docs/examples/express-function-architecture.md
模式适用场景结构
Express应用带中间件、路由的API
app.post('/mcp', handler)
按领域分组功能丰富的应用
posts.ts
,
journal.ts
独立文件模式最大化模块化每个函数对应一个文件
详情: 参见
docs/examples/express-function-architecture.md

Security Model

安全模型

ModelWhen to UseComplexity
Server-write-onlyLight-write apps, high securitySimple rules
Client-write + validationHigh-volume writes, real-timeComplex rules
Strongly prefer server-write-only for light-write applications.
Details: See
docs/examples/firestore-rules-patterns.md
模型适用场景复杂度
仅服务器可写入低写入量应用、高安全性需求规则简单
客户端可写入+验证高写入量应用、实时需求规则复杂
强烈推荐在低写入量应用中使用仅服务器可写入模型。
详情: 参见
docs/examples/firestore-rules-patterns.md

Emulator-First Development

优先使用模拟器开发

Always develop locally with emulators:
bash
firebase emulators:start
始终在本地使用模拟器进行开发:
bash
firebase emulators:start

访问UI界面:http://127.0.0.1:4000


**Key settings in firebase.json:**
- `singleProjectMode: true` - Essential for emulators to work together
- `ui.enabled: true` - Access debug UI

**Details:** See `docs/examples/emulator-workflow.md`

**firebase.json中的关键设置:**
- `singleProjectMode: true` - 模拟器协同工作的必要配置
- `ui.enabled: true` - 启用调试UI界面

**详情:** 参见`docs/examples/emulator-workflow.md`

Modern Tooling Standards

现代工具标准

All Firebase projects follow these standards:
ToolPurposeConfig File
TypeScriptType safety
tsconfig.json
vitestTesting
vitest.config.ts
biomeLinting + formatting
biome.json
所有Firebase项目均遵循以下标准:
工具用途配置文件
TypeScript类型安全
tsconfig.json
vitest测试
vitest.config.ts
biome代码检查+格式化
biome.json

ABOUTME Comment Pattern

ABOUTME注释规范

Every TypeScript file starts with 2-line ABOUTME comment:
typescript
// ABOUTME: Brief description of what this file does
// ABOUTME: Second line with additional context
每个TypeScript文件开头必须包含两行ABOUTME注释:
typescript
// ABOUTME: 简要描述该文件的功能
// ABOUTME: 第二行补充额外上下文信息

Testing Requirements

测试要求

  • Unit tests: Test handlers/utilities in isolation
  • Integration tests: Test with emulators running
  • Both required for every feature
  • 单元测试:独立测试处理器/工具函数
  • 集成测试:在模拟器运行的环境下进行测试
  • 所有功能都必须同时满足上述两种测试要求

Common Gotchas

常见问题与解决方案

IssueSolution
Emulator ports in use
lsof -i :5001
, kill process
Admin SDK vs Client SDKAdmin bypasses rules, client respects rules
Cold start delaysFirst call takes 5-10s, normal
Data persistenceUse Ctrl+C (not kill) to export data
CORS in functions
app.use(cors({ origin: true }))
问题解决方案
模拟器端口被占用执行
lsof -i :5001
,终止占用进程
Admin SDK与Client SDK的区别Admin SDK绕过规则限制,Client SDK遵循规则
冷启动延迟首次调用耗时5-10秒,属于正常现象
数据持久化使用Ctrl+C(而非kill命令)导出数据
函数中的CORS问题添加
app.use(cors({ origin: true }))

Summary

总结

This orchestrator routes to specialized sub-skills:
  1. Detects intent via keywords
  2. Routes to appropriate sub-skill
  3. Sub-skills use TodoWrite checklists
  4. All reference shared patterns in
    docs/examples/
Sub-Skills:
  • firebase-development:project-setup
    - Initialize new projects
  • firebase-development:add-feature
    - Add functions/collections
  • firebase-development:debug
    - Troubleshoot issues
  • firebase-development:validate
    - Review code
该协调器会将任务路由到对应的专业子技能:
  1. 通过关键词检测用户意图
  2. 路由到合适的子技能
  3. 子技能使用TodoWrite检查清单
  4. 所有内容均参考
    docs/examples/
    中的共享模式
子技能:
  • firebase-development:project-setup
    - 初始化新项目
  • firebase-development:add-feature
    - 添加函数/集合
  • firebase-development:debug
    - 排查问题
  • firebase-development:validate
    - 审核代码