Skip to main content

Credit Microservice

The Credit microservice handles user credit balances, transactions, and purchase records. It defines MongoDB-based models and exposes gRPC endpoints for managing credits and transactions in an application ecosystem.

Models (credit.go)​

Purchase​

Tracks purchases made by users using credits.

FieldTypeDescription
IDObjectIDUnique identifier (MongoDB)
UserIDuint32ID of the purchasing user
AppIDuint32ID of the app where the purchase was made
ReportIDstringID of the report purchased
ReportNamestringName of the report
Creditsuint32Number of credits used
CreatedAttime.TimeTimestamp of purchase
CreatedByuint32ID of the user who recorded the purchase

CreditTransaction​

Represents a credit adjustment for a user.

FieldTypeDescription
IDObjectIDUnique identifier (MongoDB)
UserIDuint32User receiving or spending credits
AppIDuint32Application context for the transaction
Creditsuint32Amount of credits
CreatedAttime.TimeTimestamp of the transaction
CreatedByuint32ID of the actor who performed the transaction

Balance​

Tracks credit balance for a specific app.

FieldTypeDescription
AppIDuint32Application ID
Balanceuint32Available credit balance

UserCredits​

Tracks credit balances across multiple apps for a user.

FieldTypeDescription
IDObjectIDUnique identifier (MongoDB)
UserIDuint32ID of the user
Balances[]BalanceList of balances by app
CreatedAttime.TimeRecord creation timestamp
UpdatedAttime.TimeLast update timestamp
CreatedByuint32ID of creator
UpdatedByuint32ID of last updater

gRPC Service (credit.proto)​

The .proto file defines messages and RPC services for handling credit-related operations.

Messages​

  • Purchase, CreditTransaction, UserCredits, Balance: Reflect the Go model structures.
  • CreditRequest: Request to add or consume credits.
  • PurchaseRequest: Request to record a purchase.
  • UserId, AppId: Used to fetch credit details by user/app.
  • Empty: Placeholder for requests/responses that don’t require payload.

Services​

  • AddCredits(CreditRequest) returns (Empty)
  • UseCredits(PurchaseRequest) returns (Empty)
  • GetUserCredits(UserId) returns (UserCredits)
  • GetAppBalance(AppId) returns (Balance)
  • ListUserPurchases(UserId) returns (stream Purchase)
  • ListUserTransactions(UserId) returns (stream CreditTransaction)

These services allow managing credit distribution, purchases, and history tracking across users and apps.