Cloud Functions
The functions module integrates Firebase Cloud Functions in your project. It provides a serverless framework to run backend code in response to events triggered by HTTPS requests, background events, or scheduled jobs.
Directoryfunctions/src/
Directoryaccount/ // Account management
- …
Directorypayment/ // Payment processing
- …
Directorychat/ // Chat functionality
- …
Directorygenkit/ // AI features (optional)
- …
- index.ts // Function exports
- main.ts // Express app setup
- store.ts // Firestore helpers
Setup
From within the functions
folder:
-
Install dependencies:
-
Create a
.env
file in thefunctions
folder: -
Modify and adapt for your needs
-
Deploy the functions:
Express Engine
ShipFlutter uses Express.js to handle HTTP functions. The setup is defined in main.ts
and it means all HTTP endpoints:
- Are prefixed with
/v1
for versioning - Accept JSON payloads automatically
- Follow the pattern:
https://REGION-PROJECT_ID.cloudfunctions.net/api/v1/PATH
Function Types
ShipFlutter uses several types of Cloud Functions:
Used for webhooks and external integrations. For example:
Called from the app using the Firebase SDK:
Testing Functions
Test your functions locally using the Firebase Emulator:
Available Modules
ShipFlutter includes several function modules:
-
Account Management (
/account
)- User data synchronization
- Account deletion
- Social auth
-
Payment Processing (
/payment
)- RevenueCat webhooks
- LemonSqueezy webhooks
- Product syncing
-
Chat Features (
/chat
)- Message handling
- Chat history
- Real-time updates
-
GenKit (
/genkit
)- AI-powered features
- Vertex AI and Gemini integration
- Custom flows
Using Functions in Flutter
The AppFunctions
class provides a type-safe way to call Cloud Functions: