forked from zopiolabs/zopio
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
📋 Task Overview
Sprint Day: Day 1 - Morning Session
Time Slot: 12:00 - 13:00 (1 hour)
Task Type: Collaborative Service Implementation (All Team Members)
Estimated Duration: 1 hour
Dependencies: Project Structure (Issue #4)
🎯 Objectives
Implement the foundation of core services including basic EscrowService class, PaymentService skeleton, database service methods, and a basic state machine for escrow transaction management. This establishes the business logic foundation before afternoon's parallel development.
📝 Detailed Requirements
1. EscrowService Class Implementation
- Create
services/escrow/EscrowService.ts
with:- Class structure with dependency injection setup
- Methods for transaction lifecycle:
createTransaction()
- Initialize new escrowupdateStatus()
- State transitionsgetTransaction()
- Retrieve transaction detailslistTransactions()
- Query transactions with filtersvalidateTransition()
- Validate state changes
- Integration with Prisma client
- Error handling with custom error classes
- Create
services/escrow/types.ts
with:CreateEscrowInput
interfaceUpdateEscrowInput
interfaceEscrowStatus
enumTransactionResponse
type
- Implement basic validation logic
- Add activity logging for all operations
2. PaymentService Skeleton
- Create
services/payment/PaymentService.ts
with:- Jetcheckout API integration structure
- Payment method interfaces:
createPayment()
- Initialize paymentverifyPayment()
- Check payment statusprocessRefund()
- Handle refundshandleWebhook()
- Process gateway webhooks
- Hash generation utilities for security
- Mock responses for development
- Create
services/payment/types.ts
with:PaymentRequest
interfacePaymentResponse
interfaceWebhookPayload
typePaymentStatus
enum
- Set up payment gateway configuration
- Prepare webhook signature verification
3. Database Service Methods
- Create
services/database/DatabaseService.ts
with:- Prisma client singleton pattern
- Transaction management utilities
- Common query builders:
findWithPagination()
upsertRecord()
softDelete()
bulkUpdate()
- Connection health check
- Query performance logging
- Implement repository pattern for each model:
UserRepository
EscrowRepository
PaymentRepository
DocumentRepository
- Add database transaction support
- Create query optimization helpers
4. State Machine Implementation
- Create
services/escrow/StateMachine.ts
with:- State transition definitions:
DRAFT
→PENDING_PAYMENT
PENDING_PAYMENT
→PAYMENT_RECEIVED
PAYMENT_RECEIVED
→PENDING_DELIVERY
PENDING_DELIVERY
→DELIVERED
DELIVERED
→COMPLETED
- Any state →
DISPUTED
- Certain states →
CANCELLED
- Transition validation rules
- Guard conditions for each transition
- Event emission for state changes
- Rollback capabilities
- State transition definitions:
- Create state machine tests structure
- Document state transition diagram
- Implement transition history tracking
🔧 Technical Context
Service Architecture Principles
- Dependency Injection: Services should be loosely coupled
- Single Responsibility: Each service handles one domain
- Error Handling: Consistent error types and messages
- Logging: Comprehensive logging for debugging
- Testing: Services designed for easy unit testing
State Machine Design
The state machine ensures transaction integrity by:
- Enforcing valid transitions only
- Preventing race conditions with locks
- Maintaining audit trail of all changes
- Supporting rollback for failed operations
- Emitting events for external integrations
Database Patterns
- Repository Pattern: Abstraction over Prisma
- Unit of Work: Transaction management
- Query Builder: Flexible query construction
- Connection Pooling: Optimal performance
- Read Replicas: Future scalability consideration
Integration Considerations
- API Contracts: Well-defined interfaces
- Error Recovery: Graceful failure handling
- Idempotency: Safe retry mechanisms
- Monitoring: Health checks and metrics
- Documentation: Inline JSDoc comments
✅ Acceptance Criteria
- All services compile without TypeScript errors
- Basic CRUD operations work for escrow transactions
- State machine validates transitions correctly
- Payment service can mock payment creation
- Database service handles connections properly
- Services are properly exported and importable
- Basic unit test structure is in place
- Services follow SOLID principles
👥 Team Assignments
All Team Members:
- @uozopio (Umut) - Lead service architecture and state machine
- @mbyzopio (Burak) - Review service interfaces for frontend needs
- @teczopio (Enes) - Ensure services support UI requirements
This task is part of the 2-day MVP sprint for the Paylox Escrow System