dentvega/firebase-agent-skills/firebase-architecture
Claude Code and agent skill by dentvega/firebase-agent-skills
- community
Checking that the SKILL.md file is still in the repository.
Applies SOLID principles to Firebase + React Native / web apps — separating data access from UI, designing testable service layers, decoupling hooks from the Firebase SDK, and choosing the right level of abstraction. Use whenever the user asks how to structure a Firebase app, how to make Firestore calls testable, how to scale beyond a single screen of glue code, or when reviewing existing Firebase code for coupling.
Install
npx vskill@latest install dentvega/firebase-agent-skills/firebase-architectureSKILL.md
The same SKILL.md was published earlier as dentvega/firebase-agent-skills/firebase-architecture.
SOLID for Firebase Apps
The default Firebase tutorial puts every read, write, and rule check directly in a screen component. That works until your second screen needs the same query, or until you want to test a payment flow without spending real money. This skill is what to do then — applied specifically to Firebase + React Native (the web SDK story is similar).
Minimum viable example
The component uses const todos = useTodos(uid) — that's all it needs to know. Firebase is one import away from being swapped.
When SOLID earns its keep in a Firebase app
Honest evaluation before the patterns:
| Scale | Reach for SOLID? | |
|---|---|---|
| One screen, one collection, no tests | No — direct SDK calls in the component are fine | |
| 3+ screens reading the same data | Yes — extract a hook (SRP) | |
| You want to test a payment / mutation flow | Yes — wrap the SDK so tests inject a fake | |
| You're migrating from Firebase to Supabase / vice versa | Yes — the wrapper is the entire savings | |
| You're building a simple internal tool with one user | No — abstraction debt outpaces benefit |
The patterns below are progressive — apply them in order as the app grows. Don't start with a Repository pattern on day 1.
1. SRP — Single Responsibility
Bad — one component owns auth, Firestore, UI, navigation, validation:
Good — three files, each with one job:
Why it matters in Firebase apps: the SDK is stateful (snapshot listeners, auth state, persistence). Mixing state-having code with stateless UI logic makes the component hard to reason about and impossible to memoize.
2. OCP — Open/Closed
You should be able to add behavior to your Firestore writes (validation, audit logs, optimistic updates) without modifying every call site.
Bad — every screen that creates a post duplicates the same fields:
Good — a factory the service owns, screens are closed to schema changes:
When schemaVersion becomes 3, you change one file. The same pattern works for Cloud Functions middleware (auth check + app check + validation as composable wrappers).
3. LSP — Liskov Substitution
Firestore's strength here is typed converters — they let you treat a DocumentSnapshot<Post> interchangeably with any other typed snapshot.
Substitutability matters for swapping storage implementations later. If a Post always has the same shape coming out of fromFirestore regardless of where you query it from, downstream code never has to type-check.
4. ISP — Interface Segregation
Don't make hooks depend on more of the Firebase SDK than they need.
Bad:
Good:
Now hooks import useUid from lib/auth, not auth itself. The web bundle is smaller (better tree-shaking) and the dependency surface is narrower.
Same for Cloud Functions — split a giant index.ts into per-feature files re-exported from index.ts. Firebase deploys only redeploy changed functions when bundles are distinct.
5. DIP — Dependency Inversion
The big one. Hooks and components should depend on abstractions, not on Firebase directly. This is what makes tests possible without an emulator AND what lets you migrate backends.
Two levels depending on scale:
Level 1 (small app) — a service module as the seam
Hooks and components import TodosService, never firestore directly. For tests, mock the module. For backend migration, rewrite this one file.
Level 2 (real testability needed) — a Repository interface
Hooks accept the repo via context (a TodosProvider) — production wires firestoreTodos, tests wire createInMemoryTodos(). Now you can run E2E tests in milliseconds with no Firebase emulator at all.
The cost: more indirection. The benefit: tests run 100× faster, you can swap Firebase for Supabase in one file, and your domain logic stops depending on an external SDK's release cadence.
Use Level 1 by default. Promote to Level 2 when the tests-against-emulator pain exceeds the indirection pain.
Cross-cutting: Cloud Functions
The same principles apply, with one Firebase-specific twist: avoid initializing the Admin SDK in every file.
Each function file is a single responsibility (one operation, one route). The admin SDK is initialized in one place.
Common mistakes
- Premature Repository pattern. Wrapping every Firestore call in a
IUserRepositoryinterface for a 3-screen app is overhead the project can't repay. Start with direct SDK calls in a service module; promote to interfaces when you need tests. - God hooks. A
useApp()that returns user, todos, posts, notifications, and feature flags. Split per concern; let consumers choose what to subscribe to. - Service classes with state.
class TodosService { private cache = ... }is an anti-pattern — Firestore already manages cache. Use module-level functions, not classes-with-state. - Wrapping `onSnapshot` listeners in promises. They're streams, not promises. The repository abstraction returns an
Unsubscribefunction, notPromise<Todo[]>. - Exporting raw Firebase types from your service. If
TodosService.list()returns aFirebaseFirestoreTypes.CollectionReference, every consumer is coupled to Firebase. Map to your ownTodotype at the service boundary. - DIP all the way down to security rules. Rules are not application logic; they're a backend security layer. Don't try to abstract them into a generic permission system — express the security model directly in
firestore.rulesas thefirebase-firestoreskill recommends. - Class hierarchies for Firebase wrappers. A
BaseRepository<T>parent class withUsersRepository extends BaseRepository<User>is a Java reflex. In TypeScript, prefer composition with generic factory functions:function createRepository<T>(collectionName: string): Repository<T>. - Skipping SOLID for "just an MVP". Trap: the MVP becomes the codebase. Adopt SRP and ISP from day 1 (they're free). Defer OCP/LSP/DIP until they pay for themselves.
See references/testing-with-repositories.md for a complete worked example with Vitest + inMemoryTodos.
Security
- Security scanPassed, 95 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-architecture/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
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/dentvega/firebase-agent-skills/firebase-architecture)