How 50fifty/auth-scheduled-backup works
Project Type and Purpose
• This is a Firebase Extension written in TypeScript that provides a serverless, event-driven backup service.
• Its sole responsibility is to run a scheduled Cloud Function that fetches all Firebase Authentication users and writes them as a JSON backup file to a Google Cloud Storage bucket.
High-Level Architecture Overview
• Components:
• Cloud Scheduler (Cron)
• Cloud Function (the extension code)
• Firebase Authentication service (managed Google service)
• Google Cloud Storage bucket (managed Google service)
• Configuration & IAM (environment variables, service account roles)
• Flow:
1. Cloud Scheduler fires at the configured interval (daily, weekly, etc.).
2. Trigger invokes the Cloud Function entry point (extension/src/index.ts).
3. The function reads configuration (bucket name, cron schedule) from environment.
4. It calls the performBackup use case, which:
a. Uses FirebaseAuthService to list all users via Firebase Admin SDK.
b. Serializes user records into JSON.
c. Uses GoogleCloudStorageService to upload the JSON file to the target Cloud Storage bucket.
Key Architectural Patterns and Design Principles
• Dependency Injection / Interface Abstraction
• Services live behind AuthService and StorageService interfaces (in extension/src/services/interfaces).
• Enables swapping real implementations (FirebaseAuthService / GoogleCloudStorageService) with fakes for unit testing.
• Single Responsibility & Clean Layering
• src/config handles config parsing.
• src/usecases contains business logic (perform_backup.ts).
• src/services contains integration code with external services.
• Serverless, Event-Driven
• No persistent servers—everything runs on demand in response to the scheduled event.
• Testing Pyramid
• Unit tests use fake service implementations.
• Integration tests hit live Firebase Auth + GCS.
• System tests run end-to-end with emulator or real projects.
A. Cloud Scheduler
B. Cloud Function (Extension)
1. Config Module
2. Use Case Module (performBackup)
3. Service Interfaces
4. Service Implementations (FirebaseAuthService, GoogleCloudStorageService)
C. Firebase Authentication API
D. Google Cloud Storage Bucket
• Scheduler → Cloud Function (trigger).
• Cloud Function/Use Case → FirebaseAuthService → Firebase Auth API (read users).
• Cloud Function/Use Case → GoogleCloudStorageService → GCS Bucket (write JSON).
• External Dependencies:
• IAM roles (Service Account with Auth Admin & Storage Admin).
Essential Elements
• Clear component names: “Cloud Scheduler”, “Backup Function”, “FirebaseAuthService”, etc.
• Compute vs. Managed Service vs. Config.
• Call out IAM roles needed by the service account.