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.jsonand afunctions/folder with its ownpackage.jsonfirebase-functionsandfirebase-admindependencies- Exports such as
onRequest,onCallandonDocumentCreated
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
functions/src/index.ts, the full list of functionsfirestore.rules, for what clients can do without any function
How a request moves through the code
- A trigger fires: an HTTP request, a callable from the app, a document write or a schedule.
- The function runs with Admin SDK privileges, bypassing security rules.
- It reads and writes Firestore, Storage or Auth.
- Writes 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.onRequestversusonRequest).