Feature: Add Note to Budget Command#176
Open
CarolGitonga wants to merge 5 commits intoitalanta:mainfrom
Open
Conversation
Author
|
"Latest changes pushed — refactored handler placement to follow the libs/functions/finance/budgeting pattern consistent with the rest of the codebase." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Kujali backend follows a CQRS (Command Query Responsibility Segregation) pattern built on top of Firebase Cloud Functions. Each business operation is expressed as a Command and a Handler.
Design Choices
AddNoteToBudgetCommand (add-note.command.ts)
A plain class with readonly fields: orgId, budgetId, content, createdBy, createdAt
orgId is included because all Firestore data in this project is multi-tenant, scoped under orgs/{orgId}/.... Without it, the handler cannot construct the correct Firestore path.
createdAt defaults to Date.now() so callers don't have to provide it explicitly.
BudgetNote (budget-note.interface.ts)
Extends IObject, which provides the auto-generated id field.
Keeps the model in the model/budgetting library, consistent with how all other domain interfaces are structured in the monorepo.
AddNoteToBudgetHandler (add-note.handler.ts)
Extends FunctionHandler<AddNoteToBudgetCommand, AddNoteToBudgetResult>
add-budget-note.function.ts
Uses RestRegistrar, the same registrar used by promoteBudget and other command functions. This makes the function callable from the Angular frontend using AngularFire's httpsCallable.
Registered under the name addNoteToBudget and exported from main.ts so Firebase picks it up at deploy time.
Serverless Deployment & Scaling
What is Serverless?
Serverless means the infrastructure (servers, OS, runtime) is fully managed by the cloud provider. You deploy code (a function), define a trigger, and the platform handles provisioning, scaling, and availability. Firebase Cloud Functions run on Google Cloud Functions, which is a fully serverless compute platform.
Trade-offs to be aware of
Cold starts can affect UX if the function is rarely called. Mitigation: Cloud Scheduler keep-alive pings, or migrating to Cloud Run (which supports min-instances).
No long-running processes — serverless functions have a max timeout (9 minutes on Gen 1). addNoteToBudget is a fast write operation so this is not a concern here.
The screenshot below shows addNoteToBudget on the emulator
