evanca/flutter-ai-rules/firebase-cloud-firestore
Claude Code and agent skill by evanca/flutter-ai-rules
- community
Checking that the SKILL.md file is still in the repository.
Use when setting up Firestore, designing schemas, doing CRUD, creating listeners, paginating queries, configuring indexes, enabling offline persistence, or writing security rules.
Install
npx vskill@latest install evanca/flutter-ai-rules/firebase-cloud-firestoreSKILL.md
Firebase Cloud Firestore Skill
This skill defines how to correctly implement Cloud Firestore in Flutter applications, covering data modeling, queries, real-time updates, security rules, and scale optimization.
When to Use
Use this skill when:
- Setting up and configuring Cloud Firestore in a Flutter project.
- Designing document and collection structure or planning subcollections.
- Performing read, write, batch, or transaction operations.
- Implementing real-time listeners or paginated queries.
- Optimizing for scale and avoiding write hotspots.
- Writing or debugging Firestore security rules.
1. Database Selection
Choose Cloud Firestore when the app needs:
- Rich, hierarchical data models with subcollections.
- Complex queries: chaining filters, combining filtering and sorting on a property.
- Transactions that atomically read and write data from any part of the database.
- High availability (typical uptime 99.999%) or critical-level reliability.
- Automatic scaling to millions of concurrent users.
Use Realtime Database instead for simple data models requiring simple lookups and extremely low-latency synchronization (typical response times under 10ms).
2. Setup and Configuration
Security (eMudhra CA fix): Use Dart ≥ 3.13.7 and Flutter ≥ 3.47.8(advisory GHSA-frr6-h895-5pxp).For Apple or Windows targets using Firestore, also upgradecloud_firestoreto ≥ 7.1.0 (FlutterFire BoM ≥ 5.1.0) and runflutter pub upgrade, then rebuild and redeploy.
Location:
- Select the database location closest to users and compute resources.
- Use multi-region locations for critical apps (maximum availability and durability).
- Use regional locations for lower costs and lower write latency.
iOS/macOS: Consider pre-compiled frameworks to improve build times:
Offline persistence is enabled by default on mobile. Configure cache size:
3. Document Structure
- Avoid document IDs
.and..(special meaning in Firestore paths). - Avoid forward slashes (
/) in document IDs (path separators). - Do not use monotonically increasing document IDs (e.g.,
Customer1,Customer2) — causes write hotspots. - Use Firestore's automatic document IDs when possible:
- Avoid these characters in field names (require extra escaping):
.[]*``` - Use subcollections within documents to organize complex, hierarchical data rather than deeply nested objects.
4. Indexing
- Firestore queries are indexed by default; query performance is proportional to the result set size, not the dataset size.
- Set collection-level index exemptions to reduce write latency and storage costs.
- Disable Descending and Array indexing for fields that do not need them.
- Exempt string fields with long values that are not used for querying.
- Exempt fields with sequential values (e.g., timestamps) from indexing if not used in queries — avoids the 500 writes/second index limit.
- Add single-field exemptions for TTL fields.
- Exempt large array or map fields not used in queries — avoids the 40,000 index entries per document limit.
5. Read and Write Operations
Read All Documents in a Collection
Query with Filters
Cursor-Based Pagination
- Do not use offsets for pagination — use cursors to avoid retrieving and being billed for skipped documents.
Write with Server Timestamp
Batch Write (Atomic, Up to 500 Operations)
Transaction
- Execute independent operations (e.g., a document lookup and a query) in parallel, not sequentially.
- Be aware of write rate limits: ~1 write per second per document.
- For writing a large number of documents, use a bulk writer instead of the atomic batch writer.
6. Designing for Scale
- Avoid high read or write rates to lexicographically close documents (hotspotting).
- Avoid creating new documents with monotonically increasing fields (like timestamps) at a very high rate.
- Avoid deleting documents in a collection at a high rate.
- Gradually increase traffic when writing to the database at a high rate — ramp up over 5 minutes.
- Avoid queries that skip over recently deleted data — use
start_atto find the correct start point. - Distribute writes across different document paths to avoid contention.
- Firestore scales automatically to ~1 million concurrent connections and 10,000 writes/second.
7. Real-time Updates
- Limit the number of simultaneous real-time listeners.
- Detach listeners when they are no longer needed to avoid memory leaks and unnecessary reads.
- Use compound queries to filter data server-side rather than filtering on the client.
- For large collections, use queries to limit the data being listened to — never listen to an entire large collection.
8. Security
- Always use Firebase Security Rules to protect Firestore data.
- Security rules do not cascade unless a wildcard is used.
- If a query's results might contain data the user does not have access to, the entire query fails.
Example rules for user-owned documents:
- Validate user input before submitting to Firestore to prevent injection attacks.
- Use transactions for operations that require atomic updates to multiple documents.
- Implement proper error handling for all Firestore operations.
- Never store sensitive information in Firestore without proper access controls.
References
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/firebase-cloud-firestore/SKILL.md
Popularity
- Repository stars
- 492
- Repository forks
- 50
- 7-day trend score
- 31
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 21 Mar 2026, 8 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/evanca/flutter-ai-rules/firebase-cloud-firestore)