firebase-firestore
Skill0 starsChanged 5 months agoMITView on GitHub
Provisions and uses Cloud Firestore — creating databases, designing collections and documents, writing security rules, defining composite indexes, and writing client SDK reads/writes. Use whenever the user needs persistent structured storage that syncs in real time across clients.
- Reads credentials
5 other projects use a version of this.
Adopted by
Most recently taken up by
- renansouza12/mixtape-their own version, first seen Oct 13, 2026
- conjure-3301/skillstheir own version, first seen Aug 17, 2026
- baliadventours/Tripbone-SaaS-Productiontheir own version, first seen Aug 5, 2026
- VolantTyler/Cognitive-Bridge-Antigravitytheir own version, first seen Jun 5, 2026
- firebase/agent-skillstheir own version, first seen Jun 5, 2026
Other versions5 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 5
- firebase/agent-skills★ 506same name
- VolantTyler/Cognitive-Bridge-Antigravity★ 1same name
- baliadventours/Tripbone-SaaS-Production★ 0same name
- conjure-3301/skills★ 0same name
- renansouza12/mixtape-★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository15 other files it gives its agents.
- firebase-ai-logicSkill
- firebase-analyticsSkill
- firebase-app-checkSkill
- firebase-architectureSkill
- firebase-authSkill
- firebase-cloud-functionsSkill
- firebase-cost-optimizationSkill
- firebase-crashlyticsSkill
- firebase-emulatorsSkill
- firebase-expoSkill
- firebase-hostingSkill
- firebase-messagingSkill
- firebase-realtime-databaseSkill
- firebase-remote-configSkill
- firebase-storageSkill
The file
We split this skill into the rules it gives an agent
7 rules. 0 are common, 3 are distinctive, and 4 are very specific to this project.
0
Common
Most of the 5 edited versions we read keep these.
3
Distinctive
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 43
If none exists, create one.
- Distinctive: line 59
Read what you display: If you list 50 todos, store enough on each todo to render the list without N+1 fetches.
- Distinctive: line 61
Top-level collections for cross-cutting queries: If you ever need "all posts site-wide, newest first", use a top-level collection.
- Very specific: line 69
Default to deny everything, then open up the minimum needed.
- Very specific: line 109
CRITICAL: never write a rule like allow read, write: if request.auth != null.
- Very specific: line 155
Polling with
getDocsfor UI that should react to changes: Use onSnapshot and return its unsubscribe from useEffect. - Very specific: line 156
Trusting client timestamps: Use serverTimestamp() on write and request.time in rules — never Date.now().
“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Cloud Firestore
Minimum viable example
import firestore from "@react-native-firebase/firestore";
// Write
await firestore().collection("posts").add({
title: "hi",
authorId: uid,
createdAt: firestore.FieldValue.serverTimestamp(),
});
// Real-time read
const unsub = firestore()
.collection("posts")
.where("authorId", "==", uid)
.orderBy("createdAt", "desc")
.onSnapshot((snap) => setPosts(snap.docs.map((d) => ({ id: d.id, ...d.data() }))));That's the canonical pattern. serverTimestamp() instead of client time, onSnapshot instead of polling, return the unsubscribe.
1. Identify or create the database
List existing databases:
npx -y firebase-tools@latest firestore:databases:listIf none exists, create one. Default to Enterprise (native mode) unless the user has a specific reason to use Standard edition:
npx -y firebase-tools@latest firestore:locations
npx -y firebase-tools@latest firestore:databases:create "(default)" \
--edition="enterprise" --location="<region>"Pick the same region as the rest of the user's Firebase resources (Functions, Storage) to avoid cross-region latency and egress charges.
2. Data modeling
Firestore is document-oriented with collections of documents. Documents can hold subcollections. The right shape depends on access patterns, not on what feels normalized.
Rules of thumb
- Read what you display. If you list 50 todos, store enough on each todo to render the list without N+1 fetches. Denormalize liberally.
- Subcollections for ownership.
users/{uid}/posts/{postId}is better than a top-levelpostsfiltered byownerIdif posts are only ever shown in that user's context — rules become trivial. - Top-level collections for cross-cutting queries. If you ever need "all posts site-wide, newest first", use a top-level collection.
- Avoid documents that grow unboundedly. A document max is 1 MiB. A chat with 100k messages must be a subcollection, not an array.
- Use auto-generated IDs unless you have a strong external key (e.g. an order number).
See references/data-modeling.md for full patterns.
3. Security rules
Default to deny everything, then open up the minimum needed. Edit firestore.rules:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read, update, delete: if request.auth != null && request.auth.uid == userId;
allow create: if request.auth != null && request.auth.uid == userId;
match /posts/{postId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
}
match /publicPosts/{postId} {
allow read: if true;
allow create: if request.auth != null
&& request.resource.data.authorId == request.auth.uid;
allow update, delete: if request.auth != null
&& resource.data.authorId == request.auth.uid;
}
}
}For a default-deny starter that follows this pattern, invoke the scaffold:
node node_modules/firebase-agent-skills/scripts/scaffold/firestore-rules.mjs \
--out firestore.rules --collection todosDeploy:
npx -y firebase-tools@latest deploy --only firestore:rulesCRITICAL: never write a rule like allow read, write: if request.auth != null; and ship it. It lets any signed-in user read or overwrite any document. Anchor every rule to ownership or membership.
See references/security-rules.md for advanced patterns: role-based access via custom claims, member-of-group checks, write validation, rate limiting.
4. Indexes
Single-field indexes are automatic. Composite indexes (more than one where + orderBy) must be declared in firestore.indexes.json:
{
"indexes": [
{
"collectionGroup": "posts",
"queryScope": "COLLECTION",
"fields": [
{ "fieldPath": "authorId", "order": "ASCENDING" },
{ "fieldPath": "createdAt", "order": "DESCENDING" }
]
}
]
}Deploy:
npx -y firebase-tools@latest deploy --only firestore:indexesThe first time a query needs a missing composite index, Firestore throws an error with a console link that creates it for you. In dev, click the link; in CI / prod, commit the entry to firestore.indexes.json.
5. Client SDK usage
- Web → references/web-sdk.md
- Expo / React Native → references/react-native.md (use
@react-native-firebase/firestorefor native; the web SDK also works for managed Expo apps with reduced features)
Always-true patterns
- Use
onSnapshotfor any UI that should react to changes. Polling withgetDocsis almost always wrong. - Cleanup snapshot listeners in
useEffectcleanup, otherwise they leak and the SDK keeps the document hydrated forever. - Batch writes ≤ 500 ops. For more, chunk and run them sequentially or in parallel batches.
- Never put secrets in documents. Rules can be probed; if a field shouldn't be readable, don't store it client-side at all.
6. Common mistakes
allow read, write: if request.auth != null;— leaks every doc to every signed-in user. Always anchor rules to ownership (request.auth.uid == resource.data.ownerId) or membership.- Polling with
getDocsfor UI that should react to changes. UseonSnapshotand return its unsubscribe fromuseEffect. Otherwise listeners leak. - Trusting client timestamps. Use
serverTimestamp()on write andrequest.timein rules — neverDate.now(). - Unbounded documents. 1 MiB hard cap. A chat with 100k messages must be a subcollection, not an
array. - Querying object properties inside arrays. Firestore can only
array-containswhole values. Restructure to a subcollection if you need to filter by inner fields. - Forgetting composite indexes in production. Dev gets a console link to create them; CI hits the missing-index error. Commit
firestore.indexes.json. - Calling
setDoc(ref, data, { merge: true })and expectingcreaterules to fire. Merged writes evaluateupdaterules — write both.
7. Local emulator
For development, run the emulator suite so you don't burn quota and can iterate on rules safely:
npx -y firebase-tools@latest init emulators
npx -y firebase-tools@latest emulators:start --only firestoreConnect from the client:
import { connectFirestoreEmulator, getFirestore } from "firebase/firestore";
const db = getFirestore();
if (process.env.NODE_ENV === "development") {
connectFirestoreEmulator(db, "127.0.0.1", 8080);
}Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

