firebase-database
Use when syncing real-time data, structuring JSON trees, reading/writing, creating listeners, enabling offline persistence, managing presence, sharding, or writing security rules.
Install / Use
npx skills add evanca/flutter-ai-rules --skill firebase-databaseInstalls into whichever agent you are using.
SKILL.md
Installable skill definition
Quality Score
Category
SecuritySupported Platforms
Our assessment of firebase-database
firebase-database scores 90/100 on our quality scale, 479th of 1,086 Security skills we index (top 45%).
Its SKILL.md is 7.8 KB long, well organised into 15 sections with 20 code examples: a thorough specification that gives an agent plenty to work with.
It has 646 GitHub stars, a meaningful sign that others use it.
Maintenance, license and trust
- The repository was last updated 19 days ago, so firebase-database is actively maintained.
- It is released under the MIT license, a permissive license that allows use, modification and commercial use with attribution.
- Its trust signals score 100/100, with no cautions. These come from repository metadata, not a code audit — read the skill file before letting an agent act on it.
firebase-database compared with similar skills
All 4 of these similar skills score higher than firebase-database; compare them before choosing.
| Skill | Score | Stars | Updated | Format |
|---|---|---|---|---|
| firebase-database (this skill)by evanca | 90 | 646 | 19d ago | SKILL.md |
| algorithmic-artby anthropics | 100 | 177.9k | 11d ago | SKILL.md |
| pptxby anthropics | 100 | 177.9k | 11d ago | SKILL.md |
| designby nextlevelbuilder | 100 | 130.2k | 12d ago | SKILL.md |
| ui-ux-pro-maxby nextlevelbuilder | 100 | 130.2k | 12d ago | SKILL.md |
Frequently asked questions
- How do I install firebase-database?
- Run
npx skills add evanca/flutter-ai-rules --skill firebase-database. The install tabs above show the steps for each supported agent. - Which AI agents does firebase-database work with?
- It is written for Universal, as a SKILL.md file. Other agents that read the same format can often use it too.
- Is firebase-database safe to use?
- It is MIT-licensed and scores 100/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
- Is firebase-database still maintained?
- The repository was last updated 19 days ago, so firebase-database is actively maintained.
Skill content
View source on GitHubname: firebase-database description: "Use when syncing real-time data, structuring JSON trees, reading/writing, creating listeners, enabling offline persistence, managing presence, sharding, or writing security rules." license: MIT
Firebase Realtime Database Skill
This skill defines how to correctly implement Firebase Realtime Database in Flutter applications, covering data modeling, queries, real-time sync, offline support, and security rules.
When to Use
Use this skill when working with Firebase Realtime Database for simple data models, low-latency sync, or presence functionality. For rich data models requiring complex queries and high scalability, use Cloud Firestore instead.
1. Database Selection
Choose Realtime Database when the app needs:
- Simple data models with simple lookups.
- Extremely low-latency synchronization (typical response times under 10ms).
- Deep queries that return an entire subtree by default.
- Access to data at any granularity, down to individual leaf-node values.
- Frequent state-syncing with built-in presence functionality.
Choose Cloud Firestore instead for rich data models requiring queryability, scalability, and high availability.
2. Setup and Configuration
flutter pub add firebase_database
import 'package:firebase_database/firebase_database.dart';
// After Firebase.initializeApp():
final DatabaseReference ref = FirebaseDatabase.instance.ref();
- Select the database location closest to users.
- Enable persistence for offline capabilities:
FirebaseDatabase.instance.setPersistenceEnabled(true);
FirebaseDatabase.instance.setPersistenceCacheSizeBytes(10000000); // 10MB
Setup Checklist
- Confirm
Firebase.initializeApp()completes before accessingFirebaseDatabase.instance. - Set persistence before any read/write operations.
- Verify connectivity by writing a test value and reading it back.
3. Data Structure
- Structure data as a flattened JSON tree — avoid deep nesting.
- Maximum nesting depth is 32 levels.
- Design the data structure to support the most common queries.
- Use push IDs for unique identifiers in list-type data:
final newPostKey = FirebaseDatabase.instance.ref().child('posts').push().key;
- Denormalize data when necessary — Realtime Database does not support joins.
- Custom keys must be UTF-8 encoded, max 768 bytes, and cannot contain
.$#[]/or ASCII control characters 0-31 or 127.
Flattened Structure Example
// Instead of nesting chat messages inside rooms:
// rooms/roomId/messages/messageId/...
// Flatten into separate top-level paths:
// rooms/roomId: { name: "General", createdBy: "uid1" }
// room-members/roomId: { uid1: true, uid2: true }
// room-messages/roomId/messageId: { text: "Hello", sender: "uid1", timestamp: ... }
This pattern allows reading room metadata without downloading all messages.
4. Indexing and Querying
- Queries can sort or filter on a property, but not both in the same query.
- Use
.indexOnin security rules to index frequently queried fields:
{
"rules": {
"dinosaurs": {
".indexOn": ["height", "length"]
}
}
}
- Queries are deep by default and return the entire subtree.
- Sort with
orderByChild(),orderByKey(), ororderByValue():
final query = FirebaseDatabase.instance.ref("dinosaurs").orderByChild("height");
- Limit results with
limitToFirst()orlimitToLast():
final query = ref.orderByChild("height").limitToFirst(10);
- Range queries using
startAt(),endAt(), andequalTo():
// Find users whose name starts with "A"
final query = ref.child("users")
.orderByChild("name")
.startAt("A")
.endAt("A\uf8ff");
5. Read and Write Operations
Read once:
final snapshot = await FirebaseDatabase.instance.ref('users/123').get();
if (snapshot.exists) {
print(snapshot.value);
}
Real-time listener:
final subscription = FirebaseDatabase.instance
.ref('users/123')
.onValue
.listen((event) {
final data = event.snapshot.value;
print(data);
});
// Cancel when no longer needed:
subscription.cancel();
A DatabaseEvent fires every time data changes at the reference, including changes to children.
Write (replace):
await ref.set({
"name": "John",
"age": 18,
"created_at": ServerValue.timestamp,
});
Update (partial):
await ref.update({"age": 19});
Atomic transaction:
final result = await FirebaseDatabase.instance
.ref('posts/123/likes')
.runTransaction((currentValue) {
return Transaction.success((currentValue as int? ?? 0) + 1);
});
print('Likes: ${result.snapshot.value}');
Multi-path atomic update:
final updates = <String, dynamic>{
'posts/$postId': postData,
'user-posts/$uid/$postId': postData,
};
await FirebaseDatabase.instance.ref().update(updates);
- Keep individual write operations under 256KB.
- Use listeners for real-time updates rather than polling.
6. Designing for Scale
- Realtime Database scales to ~200,000 concurrent connections and 1,000 writes/second per database. For higher scale, shard data across multiple database instances.
- Avoid storing large blobs — use Firebase Storage for files.
- Use server timestamps for consistent time tracking:
await FirebaseDatabase.instance.ref('posts/123/timestamp').set(ServerValue.timestamp);
- Implement fan-out patterns for data accessed from multiple paths.
- Avoid deep nesting — it leads to performance issues when retrieving data.
7. Offline Capabilities and Presence
FirebaseDatabase.instance.setPersistenceEnabled(true);
// Keep critical paths synced when offline
FirebaseDatabase.instance.ref('important-data').keepSynced(true);
Connection State and Presence
// Detect connection state
FirebaseDatabase.instance.ref('.info/connected').onValue.listen((event) {
final connected = event.snapshot.value as bool? ?? false;
if (connected) {
// Set online status and configure onDisconnect cleanup
final presenceRef = FirebaseDatabase.instance.ref('status/${uid}');
presenceRef.set({'online': true, 'last_seen': ServerValue.timestamp});
presenceRef.onDisconnect().set({
'online': false,
'last_seen': ServerValue.timestamp,
});
}
});
- Use value events (
onValue) to read data and get notified of updates — optimized for online/offline transitions. - Use
get()only when data is needed once; it probes local cache if the server is unavailable. onDisconnect()operations are executed server-side, ensuring cleanup even if the app crashes.
8. Security
{
"rules": {
"users": {
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
}
}
}
- Use
.read,.write,.validate, and.indexOnto control access and validate data. - Read and write rules cascade in Realtime Database — a parent rule granting access cannot be revoked by a child rule.
- Use the
authvariable to authenticate users in security rules.
Data Validation Example
{
"rules": {
"messages": {
"$messageId": {
".validate": "newData.hasChildren(['text', 'sender', 'timestamp'])",
"text": {
".validate": "newData.isString() && newData.val().length <= 500"
}
}
}
}
}
- Test rules thoroughly using the Firebase console's rules simulator.
- Use the Firebase Emulator Suite for local testing.
References
Related Skills
algorithmic-art
177.9kCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems.
pptx
177.9kUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an em…
design
130.2kComprehensive design skill: brand identity, design tokens, UI styling, logo generation (55 styles, Gemini, Atlas Cloud, or MuAPI AI), corporate identity program (50 deliverables, CIP mockups), HTML presentations (Chart.js), banner design (22 styles, social/ads/web/print), icon design (15 styles, SVG…
ui-ux-pro-max
130.2kUI/UX design intelligence for web, mobile, and desktop. This skill should be used when designing, building, reviewing, or fixing interfaces, including pages, components, design systems, accessibility, interaction, responsive layout, typography, color, charts, and stack-specific UI implementation.
Languages
Trust signals
From repository metadata: license, adoption, age and documentation. Not a code audit — see the Safety scan above for what the skill file itself contains.
