How paulbraganza12/cloud-firestore-triggers works
Project type and purpose
• This is an event-driven, serverless microservice built in TypeScript on Google Cloud.
• It listens for Firestore document writes (onDocumentWritten), serializes the event into a custom Protobuf/JSON envelope, and publishes it as a UsersDocumentWritten message to a Pub/Sub topic named user-written.
• Locally, it runs Firestore and Pub/Sub emulators via Docker Compose; in production, it is deployed as a 2nd-gen Cloud Function via Cloud Build.
File structure
• Top level
• Configuration files: .env-example, .gcloudignore, cloudbuild.yaml, docker-compose.yml, package.json, tsconfig.json
• firebase-docker/: Dockerfile + emulator config for Firestore and Storage rules
• protos/: Protobuf schemas, compiled JS/TS, and helper scripts (update.sh)
• src/
• index.ts: Cloud Function entrypoint that registers the Firestore trigger
• config.ts: environment and topic configuration
• pubsub/: code that constructs and sends Pub/Sub messages (user-firestore.ts)
• utils/: pure functions for serializing and parsing event data
• data.proto: your event envelope schema
• google/...: imported standard Google protobuf definitions
• __tests__/: unit tests for parsing, serialization, and end-to-end behavior
README for additional insights
• Message envelope structure (json + attributes)
• Tech stack: Docker for emulator, Vitest for testing, Node/TypeScript, Cloud Functions v2, Pub/Sub, Firestore triggers