User Story #939
openEPIC #930: CS Trust Score
Feature #937: Trust Token Management
Backend User Story – Trust Token Management
0%
Description
As the ConnectSouq platform, I want to securely manage Trust Token allocation, transfer, and recording so that members can recognize genuine contributions while maintaining fairness and preventing misuse.
Business Background¶
Each active member receives a configurable monthly allocation of Trust Tokens. Tokens can only be awarded to other active members and directly increase the recipient's Community Impact score. The system must prevent self-awarding, duplicate processing, token manipulation, and any unauthorized adjustments. Governance rules identify token manipulation as a policy violation subject to penalties.
Functional Requirements¶
The system shall:
- Allocate monthly Trust Tokens automatically.
- Maintain available token balance.
- Validate recipient eligibility.
- Prevent self-awarding.
- Record every token transaction.
- Increase recipient Community Impact score.
- Trigger Trust Score recalculation.
- Generate audit records.
- Support monthly token reset.
Business Rules¶
- Every active member receives the configured monthly Trust Token allocation.
- Members cannot send tokens to themselves.
- Tokens cannot be purchased or transferred outside the platform workflow.
- Unused monthly tokens expire at the end of the cycle unless future policy changes.
- Every token awarded increases the recipient's Community Impact score by the configured value.
- Every transaction must be auditable.
- Duplicate requests must not process multiple token transfers.
Database Changes¶
Table: Trust_Token_Balance¶
| Field |
|---|
| MemberId |
| MonthlyAllocation |
| RemainingTokens |
| UsedTokens |
| CycleStartDate |
| CycleEndDate |
| LastUpdated |
Table: Trust_Token_Transaction¶
| Field |
|---|
| TransactionId |
| SenderMemberId |
| RecipientMemberId |
| TokensSent |
| Message |
| TransactionDate |
| Status |
Table: Trust_Token_Audit¶
| Field |
|---|
| AuditId |
| TransactionId |
| Action |
| PerformedBy |
| Timestamp |
API Endpoints¶
GET /api/trust-token/balance¶
Retrieve member token balance.
POST /api/trust-token/send¶
Transfer Trust Token(s).
GET /api/trust-token/history¶
Retrieve transaction history.
POST /api/trust-token/reset¶
Monthly token allocation process (scheduled job/admin).
Validation Rules¶
- Sender must be authenticated.
- Sender must be active.
- Recipient must be active.
- Sender cannot equal recipient.
- Sender must have sufficient remaining tokens.
- Duplicate requests must be ignored safely.
Error Handling¶
| Error | Response |
|---|---|
| Insufficient tokens | 400 |
| Invalid recipient | 404 |
| Self-award attempt | 400 |
| Unauthorized | 401 |
| Duplicate request | 409 |
| Internal server error | 500 |
Security¶
- JWT authentication
- Role-based authorization
- Audit logging
- Idempotent request handling
- API rate limiting
Notifications¶
Upon successful transfer:
- Notify the sender of successful token transfer.
- Notify the recipient that they have received Trust Token(s).
- Trigger Trust Score recalculation for the recipient.
Audit Logs¶
Capture:
- Sender Member ID
- Recipient Member ID
- Tokens transferred
- Previous balance
- Updated balance
- Transaction timestamp
- IP Address
- Device information
- Processing status
Acceptance Criteria¶
Scenario 1 – Successful Token Transfer¶
Given
- Sender has sufficient Trust Tokens.
- Recipient is an active member.
When
- Sender submits the token transfer.
Then
- Token balance is reduced for the sender.
- Recipient's Community Impact score is updated.
- Transaction is recorded.
- Notifications are sent.
- Audit log is created.
Scenario 2 – Self-Award Prevention¶
Given
- Sender selects their own account.
When
- Token transfer is submitted.
Then
- Transfer is rejected.
- No balance changes occur.
- Attempt is logged.
Scenario 3 – Monthly Allocation¶
Given
- A new monthly cycle begins.
When
- Monthly allocation job executes.
Then
- Active members receive the configured token allocation.
- Previous cycle is closed.
- Allocation is recorded in the audit log.
In Scope (MVP)¶
- Monthly token allocation
- Token balance management
- Token transfer
- Community Impact update
- Transaction history
- Notifications
- Audit logging
- Monthly reset job
Out of Scope¶
- Token marketplace
- Paid token purchases
- Token exchange between users
- Anonymous token sending
- Token expiry customization
- Promotional token campaigns
Definition of Done¶
- Monthly allocation process implemented.
- Token transfer APIs completed.
- Community Impact updates validated.
- Notifications integrated.
- Audit logging implemented.
- Security and validation testing passed.
- Product Owner approval received.
No data to display