Zurri System Flow
Complete System Architecture Flow
π― Overview
Zurri is an agents-only marketplace where creators list fully packaged AI agents, and users subscribe/purchase to chat with them via a standardized protocol.
π Complete User Journeys
1οΈβ£ Creator Journey: List an Agent
Creator Registers/Logs In
β
POST /api/auth/register or /api/auth/login
β
Receives JWT Token
β
Creates Agent Listing
POST /api/agents
{
name, description, endpoint, price,
isSubscription, subscriptionDuration,
promptTemplate, metadata, imageUrl
}
β
System Uploads Metadata to IPFS (Pinata)
- Stores: name, description, endpoint, price, creatorId, metadata
- Returns IPFS hash (CID)
β
Agent Saved to Database
- Status: PENDING
- IPFS hash stored
- Creator ID linked
β
Admin Reviews Listing
GET /api/agents/admin/pending (admin only)
β
Admin Approves/Rejects
PATCH /api/agents/:id/approve
PATCH /api/agents/:id/reject
β
Agent Status β APPROVED
β
Agent Appears in Marketplace
GET /api/agents (public)
2οΈβ£ User Journey: Discover & Subscribe
User Registers/Logs In
β
POST /api/auth/register or /api/auth/login
β
Receives JWT Token
β
Browse Marketplace
GET /api/agents
Query params: page, limit, search, sortBy
β
View Agent Details
GET /api/agents/:id
(Endpoint hidden unless creator/admin)
β
Subscribe to Agent
POST /api/subscriptions/agent/:agentId
Authorization: Bearer <token>
β
System Creates Subscription
- Checks if agent is APPROVED
- Checks for existing active subscription
- Calculates expiry date
β’ Subscription: currentDate + duration (days)
β’ One-time: 2099-12-31 (lifetime)
- Generates payment reference
β
Returns Payment Info
{
subscription: {...},
payment: {
reference: "sub_xxx_1234567890",
amount: 100.00,
currency: "NGN"
}
}
β
User Completes Payment via Paystack
(External payment flow)
β
Paystack Webhook
POST /api/subscriptions/webhook/paystack
- Verifies signature (HMAC SHA512)
- Checks event type: 'charge.success'
- Finds subscription by payment reference
β
Subscription Activated
- isPaymentVerified: true
- status: ACTIVE
β
User Can Now Chat with Agent
3οΈβ£ User Journey: Chat with Agent
User Has Active Subscription
β
Send Message to Agent
POST /api/chat/:agentId/message
Authorization: Bearer <token>
Body: {
message: "Hello!",
conversationId?: "conv_123", // Optional
metadata?: {...}
}
β
System Validates Request
- Verifies JWT token (optional auth)
- Checks agent exists and is APPROVED
- Verifies subscription access:
β’ Check active subscription
β’ Check expiry date
β’ Verify payment status
β
Chat Protocol Service Processes
- Validates message length (max 10000 chars)
- Generates conversationId if missing
- Builds payload:
{
message,
conversationId,
metadata: { agentId, timestamp, ...userMetadata },
systemPrompt: agent.promptTemplate (if exists)
}
β
Forwards to Agent Endpoint
POST <agent.endpoint>
- Uses axios with timeout (default 30s)
- Includes custom headers from agent.metadata.headers
β
Agent Processes & Responds
Returns: {
response: "Agent's reply",
conversationId: "conv_123",
metadata?: {...}
}
β
System Saves Conversation
- Saves user message to ChatMessage table
- Saves agent response to ChatMessage table
- Updates agent.usageCount++
β
Returns Response to User
{
response: "Agent's reply",
conversationId: "conv_123",
metadata: {...}
}
4οΈβ£ User Journey: View Chat History
User Requests History
GET /api/chat/:agentId/history
Authorization: Bearer <token>
Query params: conversationId?, limit=50
β
System Validates
- Verifies authentication (required)
- Checks agent exists and is APPROVED
β
Retrieves Messages
- Queries ChatMessage table
- Filters by agentId, userId
- Optionally filters by conversationId
- Orders by createdAt ASC
- Limits to 50 messages (or specified)
β
Returns Conversation History
{
messages: [
{
id, agentId, userId,
role: "user" | "assistant" | "system",
content, metadata, createdAt
},
...
]
}
π Complete Data Flow Diagrams
Agent Creation Flow
Creator Input
β
[Validation] β Required fields check
β
[IPFS Upload] β Pinata SDK
β
ββ Success β CID stored
ββ Failure β Continue without IPFS hash
β
[Database] β Agent entity created
- Status: PENDING
- IPFS hash: CID (if available)
β
Admin Moderation Queue
Subscription & Payment Flow
User Request
β
[Validation] β Agent approved? User has subscription?
β
[Database] β Create Subscription record
- Status: ACTIVE (pending verification)
- isPaymentVerified: false
β
[Payment] β Generate reference
β
Paystack Payment Flow (External)
β
[Webhook] β Paystack POST /api/subscriptions/webhook/paystack
β
[Security] β Verify HMAC signature
β
[Update] β Set isPaymentVerified: true
Chat Communication Flow
User Message
β
[Auth Check] β JWT validation (optional)
β
[Access Check] β Subscription verification
β
[Protocol Service] β Build standardized payload
β
[HTTP Request] β POST to agent.endpoint
β
[Agent Processing] β (External agent service)
β
[Response] β Agent returns structured response
β
[Persistence] β Save both messages to DB
β
[Analytics] β Update usage count
β
[Response] β Return to user
ποΈ Database Relationships
User (1) ββ< Creates >ββ (*) Agent
User (1) ββ< Subscribes >ββ (*) Agent (via Subscription)
User (1) ββ< Sends >ββ (*) ChatMessage
Agent (1) ββ< Receives >ββ (*) ChatMessage
User (1) ββ< Has >ββ (*) ApiKey
π Security Flow
Authentication
Request with Authorization header
β
Extract Bearer token
β
Verify JWT signature
β
Extract user info (id, email, isAdmin)
β
Attach to req.user
β
Continue to route handler
Authorization Checks
Public Routes: No auth required
GET /api/agents(list)GET /api/agents/:id(details, endpoint hidden)
Authenticated Routes: JWT required
POST /api/agents(create)POST /api/chat/:id/message(subscription check)GET /api/chat/:id/history(auth required)
Admin Routes: JWT + isAdmin check
PATCH /api/agents/:id/approveGET /api/agents/admin/pending
Subscription Access Control
Chat Request
β
Check subscription exists
β
Check status === ACTIVE
β
Check isPaymentVerified === true
β
Check expiresAt > now
β
Access granted β
π‘ API Endpoint Summary
Authentication
POST /api/auth/register- Register userPOST /api/auth/login- LoginGET /api/auth/me- Get current user
Agents
GET /api/agents- List approved agents (public)GET /api/agents/:id- Get agent details (public)POST /api/agents- Create agent (creator)PUT /api/agents/:id- Update agent (creator)DELETE /api/agents/:id- Delete agent (creator)GET /api/agents/my/list- Get my agents (creator)PATCH /api/agents/:id/approve- Approve (admin)PATCH /api/agents/:id/reject- Reject (admin)GET /api/agents/admin/pending- Pending list (admin)
Chat
POST /api/chat/:id/message- Send message (subscription required)GET /api/chat/:id/history- Get history (authenticated)
Subscriptions
POST /api/subscriptions/agent/:agentId- Create subscriptionGET /api/subscriptions/my- Get my subscriptionsPATCH /api/subscriptions/:id/cancel- Cancel subscriptionPOST /api/subscriptions/webhook/paystack- Payment webhook
π State Machine
Agent Status
PENDING β (admin approves) β APPROVED
PENDING β (admin rejects) β REJECTED
APPROVED β (admin suspends) β SUSPENDED
Subscription Status
ACTIVE β (expires) β EXPIRED
ACTIVE β (user cancels) β CANCELLED
πΎ IPFS Integration
Metadata Structure:
{
name: string
description: string
endpoint: string (hidden from public)
price: number
creatorId: string
metadata?: Record<string, any>
}
Upload Flow:
Creator creates agent
β
Metadata object created
β
Convert to JSON string
β
Create File object
β
Upload via Pinata SDK: upload.public.file()
β
Receive CID (IPFS hash)
β
Store CID in agent.ipfsHash
β
Retrieval: GET https://gateway.mypinata.cloud/ipfs/{CID}
π System Startup Flow
npm run dev
β
Load .env variables
β
Initialize TypeORM DataSource
β
Connect to PostgreSQL
β
Sync entities (dev mode)
β
Initialize Express app
β
Register middleware:
- Helmet (security)
- CORS
- Body parser
- Rate limiter
β
Register routes:
- /api/auth
- /api/agents
- /api/chat
- /api/subscriptions
β
Start HTTP server
β
Ready to accept requests
π Key Features
- Agent Listing: Creators submit, admins moderate
- IPFS Transparency: Metadata stored on IPFS for verification
- Subscription Model: Flexible pricing (subscription or one-time)
- Chat Protocol: Standardized agent communication
- Conversation History: Persistent message storage
- Payment Integration: Paystack webhook verification
- Access Control: Subscription-based agent access
- Security: JWT auth, rate limiting, endpoint protection
π§ Configuration Requirements
Environment Variables
DATABASE_URL=postgres://...
PINATA_JWT=your_jwt_token
GATEWAY_URL=plum-historic-starfish-867.mypinata.cloud
JWT_SECRET=your_secret
PAYSTACK_SECRET=your_paystack_secret
PORT=3000
AGENT_CHAT_TIMEOUT=30000
MAX_MESSAGE_LENGTH=10000
This flow ensures secure, scalable agent marketplace operations with proper access control, payment verification, and standardized communication protocols.