firebase-database

A guide for using Firebase Realtime Database in Flutter apps. Firebase Realtime Database is a cloud database that synchronizes simple data changes quickly between an app and its users.

In plain words
What is it for?
Use it to add real-time synchronization, presence features such as online status, offline persistence, listeners, queries, data sharding, and database security rules to a Flutter app.
Why use it?
It helps choose this database for simple, frequently changing data and explains how to structure data, read and write it, keep it available offline, and control access. It also identifies when Cloud Firestore may be a better fit for richer queries and larger systems.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/evanca/flutter-ai-rules/firebase-database
Any agent
npx skills add evanca/flutter-ai-rules --skill firebase-database
Clone the repo
git clone --depth 1 https://github.com/evanca/flutter-ai-rules

Made for: Claude Code, Codex.

Per session 38 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,842 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00038 $0.01842
Opus 5 $0.00019 $0.00921
Sonnet 5 $0.00008 $0.00368
Haiku 4.5 $0.00004 $0.00184

Measured 2d ago against content hash 039a244fd557, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

firebase-database scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/firebase-database/SKILL.md · 293 lines

How it starts

The opening of the file, as written. The whole thing — 293 lines — stays where its author put it; the contents beside it link to each section on GitHub.

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

  1. Confirm Firebase.initializeApp() completes before accessing FirebaseDatabase.instance.
  2. Set persistence before any read/write operations.
  3. 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;

Read the full file on GitHub · 293 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 293 lines · 38 tokens per session scan A 039a244fd557

Subscribe to this mod's changes

firebase-database is a skill published in the GitHub repository evanca/flutter-ai-rules (622 stars, last pushed 4d ago), licensed MIT. It adds 38 tokens to every session and 1,842 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

base-pattern-documentation

Creates comprehensive documentation for base pattern skills following Flutter architecture conventions. Use when documenting new base classes, view patterns, state management patterns, or architectural components that serve as foundations for other code.

gurkanfikretgunak/masterfabric_core · 42 tokens

signals-migration-6-to-7

Detailed guidelines, patterns, and rules for migrating codebases from signals.dart version 6.x to version 7.x.

rodydavis/signals.dart · 33 tokens

jaspr-js-interop

Effectively integrate with Javascript when building Jaspr web applications. Use this skill when wrapping an existing JS library, accessing browser-native APIs, or bridging code safely across environments.

rodydavis/signals.dart · 40 tokens

multi-agent-handoff

Plan and document handoffs, parent lane contracts, and parallel batch contracts between specialized AI agents (foreman, workers, reviewers). Use for multi-agent workflows, subagents, original goal preservation, native gates, claim ceilings, terminal states, baton passes, or guild-style agent coordination.

Arenukvern/mcp_flutter · 62 tokens

flutter-mcp-toolkit-control

Drive a running Flutter app — tap, scroll, type, fill forms, hot-reload, navigate. Use when you need to interact with the UI.

Arenukvern/mcp_flutter · 38 tokens

harness-engineering-lifecycle

Design, implement, and integrate generalized validation harnesses across a producer-consumer boundary after a local harness contract exists. Use when refactoring custom validation CLIs/MCPs for large polyrepos, extending Steward across sibling repos, or deploying a local tool to a consumer project for dogfooding and…

Arenukvern/mcp_flutter · 88 tokens