{ "openapi": "3.0.0", "info": { "title": "Agri-Fi API", "description": "REST API for the Agri-Fi agricultural trade finance platform. Farmers list produce, traders create deals, investors fund them via Stellar escrow.", "version": "1.0.0" }, "servers": [ { "url": "http://localhost:3001", "description": "Development Server" }, { "url": "https://api.agri-fi.example.com", "description": "Production Server" } ], "components": { "securitySchemes": { "jwt": { "type": "http", "scheme": "bearer", "bearerFormat": "JWT", "description": "JWT Bearer token authentication" } } }, "security": [ { "jwt": [] } ], "tags": [ { "name": "auth", "description": "Registration, login, KYC, and wallet linking" }, { "name": "trade-deals", "description": "Create and browse agricultural trade deals" }, { "name": "investments", "description": "Fund trade deals and manage investments" }, { "name": "shipments", "description": "Record and query shipment milestones" }, { "name": "documents", "description": "Upload trade documents to IPFS" }, { "name": "users", "description": "User dashboard data" }, { "name": "health", "description": "System health status" }, { "name": "stellar", "description": "Stellar network integration" }, { "name": "admin", "description": "Admin operations" } ], "paths": { "/health": { "get": { "operationId": "HealthController_check", "summary": "Health check for database, queue, and system resources", "description": "Returns the health status of all critical services", "tags": [ "health" ], "responses": { "200": { "description": "All services healthy" }, "503": { "description": "Service unavailable" } } } }, "/auth/register": { "post": { "operationId": "AuthController_register", "summary": "Register a new user", "tags": [ "auth" ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "name": { "type": "string", "example": "Amara Diallo" }, "email": { "type": "string", "example": "amara@example.com" }, "password": { "type": "string", "minLength": 8, "example": "securePass1" }, "role": { "enum": ["farmer", "trader", "investor", "company_admin"], "example": "trader" }, "country": { "type": "string", "example": "KE" } }, "required": ["name", "email", "password", "role", "country"] } } } }, "responses": { "201": { "description": "User created successfully" }, "400": { "description": "Validation error" }, "409": { "description": "Email already in use" } } } }, "/auth/login": { "post": { "operationId": "AuthController_login", "summary": "Authenticate and receive a JWT", "tags": [ "auth" ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "email": { "type": "string", "example": "amara@example.com" }, "password": { "type": "string", "example": "securePass1" } }, "required": ["email", "password"] } } } }, "responses": { "200": { "description": "Returns access_token JWT" }, "401": { "description": "Invalid credentials" } } } }, "/trade-deals": { "get": { "operationId": "TradeDealsController_findOpen", "summary": "List open trade deals (marketplace)", "tags": [ "trade-deals" ], "parameters": [ { "name": "commodity", "in": "query", "required": false, "example": "Cocoa", "schema": { "type": "string" } }, { "name": "page", "in": "query", "required": false, "example": 1, "schema": { "type": "number" } }, { "name": "limit", "in": "query", "required": false, "example": 12, "schema": { "type": "number" } } ], "responses": { "200": { "description": "Paginated list of open deals" } } }, "post": { "operationId": "TradeDealsController_createDeal", "summary": "Create a draft trade deal (trader only, KYC required)", "tags": [ "trade-deals" ], "security": [ { "jwt": [] } ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "commodity": { "type": "string", "example": "Cocoa" }, "quantity": { "type": "number", "minimum": 1, "example": 1000 }, "quantity_unit": { "enum": ["kg", "tons"], "example": "kg" }, "total_value": { "type": "number", "minimum": 100, "example": 50000 }, "farmer_id": { "type": "string", "format": "uuid", "example": "a1b2c3d4-e5f6-7890-abcd-ef1234567890" }, "delivery_date": { "type": "string", "format": "date", "example": "2024-06-15" } }, "required": ["commodity", "quantity", "quantity_unit", "total_value", "farmer_id", "delivery_date"] } } } }, "responses": { "201": { "description": "Trade deal created" }, "400": { "description": "Validation error" }, "401": { "description": "Unauthorized" }, "403": { "description": "Role or KYC requirement not met" } } } }, "/investments/my-investments": { "get": { "operationId": "InvestmentsController_getMyInvestments", "summary": "List the authenticated investor's investments", "tags": [ "investments" ], "security": [ { "jwt": [] } ], "parameters": [ { "name": "page", "in": "query", "required": false, "example": 1, "schema": { "type": "number" } }, { "name": "limit", "in": "query", "required": false, "example": 20, "schema": { "type": "number" } } ], "responses": { "200": { "description": "List of investments" }, "401": { "description": "Unauthorized" }, "403": { "description": "Only investors can access this endpoint" } } } }, "/users/me": { "get": { "operationId": "UsersController_getCurrentUser", "summary": "Get the authenticated user's profile", "tags": [ "users" ], "security": [ { "jwt": [] } ], "responses": { "200": { "description": "Current user profile" }, "401": { "description": "Unauthorized" }, "404": { "description": "User not found" } } } }, "/stellar/submit": { "post": { "operationId": "StellarController_submitTransaction", "summary": "Submit a signed XDR transaction to Stellar", "tags": [ "stellar" ], "security": [ { "jwt": [] } ], "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "signedXdr": { "type": "string", "description": "Base64-encoded signed transaction XDR" } }, "required": ["signedXdr"] } } } }, "responses": { "200": { "description": "Transaction submitted successfully" }, "400": { "description": "Invalid XDR or transaction rejected" }, "401": { "description": "Unauthorized" }, "429": { "description": "Too Many Requests" } } } }, "/documents": { "post": { "operationId": "DocumentsController_uploadDocument", "summary": "Upload a trade document (PDF/PNG/JPEG, max 10 MB)", "tags": [ "documents" ], "security": [ { "jwt": [] } ], "requestBody": { "required": true, "content": { "multipart/form-data": { "schema": { "type": "object", "required": ["file", "doc_type", "trade_deal_id"], "properties": { "file": { "type": "string", "format": "binary", "description": "Document file (PDF, PNG, or JPEG)" }, "doc_type": { "type": "string", "example": "bill_of_lading" }, "trade_deal_id": { "type": "string", "format": "uuid", "example": "a1b2c3d4-e5f6-7890-abcd-ef1234567890" } } } } } }, "responses": { "201": { "description": "Document uploaded to IPFS and anchored on Stellar" }, "400": { "description": "Missing file, unsupported type, or file too large" }, "401": { "description": "Unauthorized" }, "404": { "description": "Trade deal not found" } } } }, "/admin/kyc/{userId}/approve": { "post": { "operationId": "AdminController_approveKyc", "summary": "Approve a user KYC submission", "tags": [ "admin" ], "security": [ { "jwt": [] } ], "parameters": [ { "name": "userId", "in": "path", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "KYC approved" }, "403": { "description": "Forbidden - Admin role required" }, "404": { "description": "User or submission not found" } } } }, "/api/v1/investments/orders/sell": { "post": { "summary": "Create secondary market sell order", "tags": ["investments"], "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "investmentId": { "type": "string" }, "dealId": { "type": "string" }, "askPrice": { "type": "number" }, "quantity": { "type": "number" }, "expiry": { "type": "string", "format": "date-time" } }, "required": ["investmentId", "dealId", "askPrice", "quantity"] } } } }, "responses": { "201": { "description": "Sell order created successfully" } } } }, "/api/v1/investments/orders/buy": { "post": { "summary": "Create secondary market buy order", "tags": ["investments"], "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "dealId": { "type": "string" }, "bidPrice": { "type": "number" }, "quantity": { "type": "number" }, "expiry": { "type": "string", "format": "date-time" } }, "required": ["dealId", "bidPrice", "quantity"] } } } }, "responses": { "201": { "description": "Buy order created successfully" } } } }, "/api/v1/investments/orders/orderbook/{dealId}": { "get": { "summary": "Get secondary market order book for a deal", "tags": ["investments"], "parameters": [ { "name": "dealId", "in": "path", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "Live bids and asks" } } } }, "/v1/admin/self-healing/status": { "get": { "operationId": "SelfHealingController_getStatus", "summary": "Get the status of the self-healing automation", "tags": ["admin/self-healing"], "security": [{ "jwt": [] }], "responses": { "200": { "description": "Automation status" } } } }, "/v1/admin/self-healing/issues": { "get": { "operationId": "SelfHealingController_getIssues", "summary": "List the detected self-healing issues", "tags": ["admin/self-healing"], "security": [{ "jwt": [] }], "parameters": [ { "name": "status", "in": "query", "required": false, "schema": { "type": "string" } }, { "name": "issueType", "in": "query", "required": false, "schema": { "type": "string" } }, { "name": "page", "in": "query", "required": false, "schema": { "type": "number" } }, { "name": "limit", "in": "query", "required": false, "schema": { "type": "number" } } ], "responses": { "200": { "description": "Detected issues" } } } }, "/v1/admin/self-healing/issues/{id}": { "get": { "operationId": "SelfHealingController_getIssue", "summary": "Get a single detected issue", "tags": ["admin/self-healing"], "security": [{ "jwt": [] }], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "Issue detail" }, "404": { "description": "Issue not found" } } } }, "/v1/admin/self-healing/issues/{id}/remediate": { "post": { "operationId": "SelfHealingController_remediateIssue", "summary": "Trigger the remediation of an issue manually", "tags": ["admin/self-healing"], "security": [{ "jwt": [] }], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "Remediation result" }, "404": { "description": "Issue not found" } } } }, "/v1/admin/self-healing/cycle": { "post": { "operationId": "SelfHealingController_runCycle", "summary": "Run a detection and remediation cycle immediately", "tags": ["admin/self-healing"], "security": [{ "jwt": [] }], "responses": { "200": { "description": "Cycle summary" } } } }, "/v1/admin/self-healing/history": { "get": { "operationId": "SelfHealingController_getHistory", "summary": "Get the remediation history (audit trail)", "tags": ["admin/self-healing"], "security": [{ "jwt": [] }], "parameters": [ { "name": "status", "in": "query", "required": false, "schema": { "type": "string" } }, { "name": "actionType", "in": "query", "required": false, "schema": { "type": "string" } }, { "name": "issueId", "in": "query", "required": false, "schema": { "type": "string" } }, { "name": "target", "in": "query", "required": false, "schema": { "type": "string" } }, { "name": "from", "in": "query", "required": false, "schema": { "type": "string" } }, { "name": "to", "in": "query", "required": false, "schema": { "type": "string" } }, { "name": "page", "in": "query", "required": false, "schema": { "type": "number" } }, { "name": "limit", "in": "query", "required": false, "schema": { "type": "number" } } ], "responses": { "200": { "description": "Remediation history" } } } }, "/v1/admin/self-healing/analytics": { "get": { "operationId": "SelfHealingController_getAnalytics", "summary": "Get the remediation analytics (success rate, time saved, false positives)", "tags": ["admin/self-healing"], "security": [{ "jwt": [] }], "parameters": [ { "name": "hours", "in": "query", "required": false, "schema": { "type": "number" } } ], "responses": { "200": { "description": "Remediation analytics" } } } }, "/v1/admin/self-healing/policies": { "get": { "operationId": "SelfHealingController_getPolicies", "summary": "List the remediation safety policies", "tags": ["admin/self-healing"], "security": [{ "jwt": [] }], "responses": { "200": { "description": "Remediation policies" } } } }, "/v1/admin/self-healing/policies/{id}": { "patch": { "operationId": "SelfHealingController_updatePolicy", "summary": "Update a remediation safety policy", "tags": ["admin/self-healing"], "security": [{ "jwt": [] }], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "Updated policy" }, "404": { "description": "Policy not found" } } } }, "/v1/admin/self-healing/scripts": { "get": { "operationId": "SelfHealingController_getScripts", "summary": "List the registered custom remediation scripts", "tags": ["admin/self-healing"], "security": [{ "jwt": [] }], "responses": { "200": { "description": "Remediation scripts" } } }, "post": { "operationId": "SelfHealingController_createScript", "summary": "Register a custom remediation script", "tags": ["admin/self-healing"], "security": [{ "jwt": [] }], "responses": { "201": { "description": "Registered script" } } } }, "/v1/admin/self-healing/scripts/{id}": { "patch": { "operationId": "SelfHealingController_updateScript", "summary": "Update a custom remediation script", "tags": ["admin/self-healing"], "security": [{ "jwt": [] }], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "Updated script" }, "404": { "description": "Script not found" } } } }, "/v1/admin/self-healing/actions/{id}": { "get": { "operationId": "SelfHealingController_getAction", "summary": "Get a single remediation action", "tags": ["admin/self-healing"], "security": [{ "jwt": [] }], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "Remediation action" } } } }, "/v1/admin/self-healing/actions/{id}/approve": { "post": { "operationId": "SelfHealingController_approveAction", "summary": "Approve a pending remediation action and execute it", "tags": ["admin/self-healing"], "security": [{ "jwt": [] }], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "Approved action" }, "404": { "description": "Action not found" } } } }, "/v1/admin/self-healing/actions/{id}/reject": { "post": { "operationId": "SelfHealingController_rejectAction", "summary": "Reject a pending remediation action", "tags": ["admin/self-healing"], "security": [{ "jwt": [] }], "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "Rejected action" }, "404": { "description": "Action not found" } } } } } }