Stellar Escrow Flow is a production-ready, milestone-based decentralized escrow system built on the Stellar blockchain using Soroban smart contracts. It enables secure fund management between clients and freelancers with automatic milestone approval and deadline-based fund release.
┌─────────────────────────────────────────────────────────────────┐
│ Frontend (React + Vite) │
│ - Wallet Connection (Freighter, Ledger) │
│ - Dashboard (Client & Freelancer Views) │
│ - Create Escrow with Dynamic Milestones │
│ - Real-time Status Updates │
└────────────────────┬────────────────────────────────────────────┘
│ REST API
▼
┌─────────────────────────────────────────────────────────────────┐
│ Backend (Node.js + Express + Prisma) │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ API Routes │ │
│ │ - POST /escrow/create │ │
│ │ - POST /escrow/deposit │ │
│ │ - GET /escrow/:id │ │
│ │ - POST /milestone/submit │ │
│ │ - POST /milestone/approve|reject │ │
│ │ - POST /feedback/submit │ │
│ │ - GET /user/:address/dashboard │ │
│ │ - GET /agent/status │ │
│ └──────────────────────────────────────────────────────────┘ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ Services │ │
│ │ - ContractService: Soroban interactions │ │
│ │ - PrismaClient: Database ORM │ │
│ └──────────────────────────────────────────────────────────┘ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ Automation Agents │ │
│ │ - Auto-Approval Agent (5 min cron) │ │
│ │ - Event Sync Agent (10 min cron) │ │
│ │ - Feedback Analyzer Agent (30 min cron) │ │
│ └──────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
│ │
│ Stellar SDK │ Prisma + PostgreSQL
▼ ▼
┌─────────────────┐ ┌─────────────────────┐
│ Soroban Contract│ │ PostgreSQL Database │
│ (Rust Wasm) │ │ (Hosted on Supabase)│
│ │ │ │
│ - Escrow struct │ │ - Users │
│ - Milestone data│ │ - Escrows │
│ - Fund locking │ │ - Milestones │
│ - Auto-release │ │ - Feedbacks │
│ - Events │ │ - Agent Logs │
└─────────────────┘ └─────────────────────┘
Built with Soroban SDK v21.7+ in Rust.
Key Structs:
Escrow: Main escrow agreement containing client, freelancer, milestones, deadlineMilestone: Individual milestone with amount, status, timestampsEscrowState: CREATED → FUNDED → ACTIVE → COMPLETED (or CANCELLED)MilestoneStatus: PENDING → SUBMITTED → APPROVED (or REJECTED)
Key Functions:
create_escrow(): Initialize escrow with milestone amounts and deadlinedeposit_funds(): Lock funds into contractsubmit_milestone(): Freelancer submits completed milestoneapprove_milestone(): Client approves and releases fundsreject_milestone(): Client rejects milestone for revisionauto_approve(): Auto-approve after review window expiresauto_release(): Release all pending funds when deadline passesget_escrow(): Query current escrow state
Database Schema (PostgreSQL):
User
├── walletAddress (unique)
├── role (CLIENT, FREELANCER, BOTH)
├── displayName, email
├── reputation, completedEscrows, totalTransacted
└── relations: clientEscrows, freelancerEscrows, feedbacks
Escrow
├── id, contractId (unique), escrowIdOnChain
├── clientWallet, freelancerWallet
├── totalAmount, reviewWindowDays
├── deadline (timestamp)
├── status (CREATED, FUNDED, ACTIVE, COMPLETED, CANCELLED)
├── milestone (array relation)
└── transactionLogs, feedbacks, agentLogs
Milestone
├── id, escrowId, milestoneIndex
├── description, amount
├── status (PENDING, SUBMITTED, APPROVED, REJECTED)
├── proofUrl, submittedAt, approvedAt
├── autoApproved (boolean)
└── reviewDeadline
Feedback
├── id, escrowId, userId
├── rating (1-5), comment
├── category (GENERAL, QUALITY, SPEED, PROFESSIONALISM)
└── createdAt, updatedAt
AgentLog
├── id, escrowId (optional), agentType
├── action, status, txHash
├── errorMessage, metadata
└── createdAt, updatedAt
TransactionLog
├── id, escrowId, milestoneId
├── txHash (unique), txType
├── walletAddress, amount
└── status, createdAt
IterationPlan
├── id, title, description
├── priority, feedbackCount
├── suggestions (array)
└── createdAt, updatedAt
API Endpoints:
-
Escrow Operations
POST /escrow/create- Create new escrowPOST /escrow/deposit- Deposit fundsGET /escrow/:id- Get escrow detailsGET /escrow/wallet/:address- List user escrows
-
Milestone Operations
POST /milestone/submit- Submit completed milestonePOST /milestone/approve- Approve & release fundsPOST /milestone/reject- Reject milestone
-
Feedback System
POST /feedback/submit- Submit escrow feedbackGET /feedback/escrow/:id- Get feedback on escrowGET /feedback/user/:id- Get user reputationGET /feedback/stats- Global statistics
-
User Management
GET /user/:address- Get user profileGET /user/:address/dashboard- Dashboard dataPUT /user/:address- Update profileGET /user/:address/reputation- Reputation score
-
Agent Monitoring
GET /agent/status- System statusGET /agent/logs- Agent activity logsGET /agent/pending-actions- Items awaiting processingPOST /agent/test- Health check
Pages:
Index.tsx- Landing page with features overviewCreateEscrow.tsx- Dynamic milestone creation formClientDashboard.tsx- Client view of escrows, approval interfaceFreelancerDashboard.tsx- Freelancer work submissionDashboard.tsx- Redirect to role-specific dashboardNotFound.tsx- 404 page
Key Components:
Navbar.tsx- Wallet connection, navigationWalletSelector.tsx- Multi-wallet support (Freighter, Ledger)EscrowCard.tsx- Escrow display cardEscrowStatusBadge.tsx- Status indicatorDeadlineCountdown.tsx- Countdown timer to deadlineHowItWorks.tsx- Feature explanation- UI components from shadcn/ui
- Client connects wallet
- Input freelancer address, milestones, deadline
- Frontend calls
POST /escrow/create - Backend creates transaction, calls Soroban contract
- Contract creates Escrow struct, emits event
- Backend saves to database
- Frontend shows success + explorer link
- Freelancer submits milestone with proof URL
- Backend updates milestone status to SUBMITTED, sets review deadline
- Client reviews and approves OR rejects
- If approved: Contract transfers funds, updates database
- If rejected: Milestone reverts to PENDING for resubmission
- Auto-approval triggers if review window expires
- Agent runs every 5 minutes
- Checks escrows past global deadline
- Auto-approves any submitted-but-unapproved milestones
- Releases remaining funds to freelancer
- Marks escrow as COMPLETED
-
Contract Security
- All funds locked in contract until approval
- No reentrancy issues (token transfer at end)
- Auth checks ensure only authorized parties act
- Prevent double-spending with status checks
-
Backend Security
- Input validation on all endpoints
- Stellar address format verification
- Wallet address confirmation for operations
- Transaction hash verification
- Rate limiting recommended but not implemented
-
Frontend Security
- Wallet signing for all transactions
- No private keys stored locally
- HTTPS required in production
- localStorage only for non-sensitive data
-
Database Security
- Use Supabase with RLS (Row Level Security)
- Encrypt sensitive fields
- Backup and recovery procedures
-
Database
- Use PostgreSQL (Supabase) for reliability
- Indexing on commonly queried fields
- Connection pooling with Prisma
-
Backend
- Stateless design for horizontal scaling
- Agent jobs can run in separate containers
- Cache frequently accessed data (Redis optional)
-
Frontend
- React Query for data caching
- Lazy loading for large lists
- Code splitting with Vite
-
Contract
- One contract per escrow is more flexible than single global contract
- Consider contract pooling for cost optimization
See DEPLOYMENT_GUIDE.md for detailed instructions.
- Contract deployed to Stellar testnet/mainnet
- Backend running on Render, Railway, or similar
- PostgreSQL database on Supabase
- Frontend deployed to Vercel, Netlify, or similar
- Environment variables configured correctly
- Agents running continuously
- Monitoring and alerting set up
- SSL/TLS enabled
- Rate limiting configured
- Database backups automated