Skip to content

How to understand a Firebase Cloud Functions codebase

Firebase projects often put their backend in a `functions/` folder. Every exported function is deployed separately and triggered by HTTP, a callable request from the app, a Firestore or Auth event, or a schedule. Security for direct database access lives separately in Firestore rules.

How to tell it's Firebase Cloud Functions

  • firebase.json and a functions/ folder with its own package.json
  • firebase-functions and firebase-admin dependencies
  • Exports such as onRequest, onCall and onDocumentCreated

Where things usually live

functions/src/index.ts
Exports every deployed function.
functions/src/<feature>/
Function implementations grouped by feature.
firebase.json
Hosting rewrites to functions, emulator config, deploy targets.
firestore.rules
Who can read and write each collection directly from clients.
src/ (app)
The client app using the Firebase SDK.

Conventions, not rules. Real projects rename and move things, so confirm against the repository.

Where to start reading

  1. functions/src/index.ts, the full list of functions
  2. firestore.rules, for what clients can do without any function

How a request moves through the code

  1. 1A trigger fires: an HTTP request, a callable from the app, a document write or a schedule.
  2. 2The function runs with Admin SDK privileges, bypassing security rules.
  3. 3It reads and writes Firestore, Storage or Auth.
  4. 4Writes can trigger other functions, which can chain.

Questions to ask about the repository

  • List every exported function and its trigger.
  • Which writes can cause another function to run?
  • What can a signed-in user do directly, according to the rules?

What trips people up

  • Admin SDK calls ignore security rules, so functions must check permissions themselves.
  • A function that writes to the document that triggered it can loop forever.
  • v1 and v2 function APIs look different (functions.https.onRequest versus onRequest).