openapi: 3.1.0 info: # Do not change the title, if the title changes, the import paths will be broken title: Api version: 0.1.0 description: Wareef agricultural platform API servers: - url: /api description: Base API path tags: - name: health description: Health operations - name: auth description: Authentication - name: users description: User profiles - name: categories description: Product categories - name: listings description: Marketplace produce listings - name: buy-requests description: Buy requests from buyers - name: orders description: Orders - name: dashboard description: Dashboard aggregates - name: search description: Search paths: /healthz: get: operationId: healthCheck tags: [health] summary: Health check responses: "200": description: Healthy content: application/json: schema: $ref: "#/components/schemas/HealthStatus" # ── Auth ──────────────────────────────────────────────────────── /auth/register: post: operationId: register tags: [auth] summary: Register a new user requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/RegisterInput" responses: "201": description: Registered content: application/json: schema: $ref: "#/components/schemas/AuthResponse" "400": description: Validation error content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" /auth/login: post: operationId: login tags: [auth] summary: Login requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/LoginInput" responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/AuthResponse" "401": description: Invalid credentials content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" /auth/logout: post: operationId: logout tags: [auth] summary: Logout responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" # ── Users ─────────────────────────────────────────────────────── /users/me: get: operationId: getMe tags: [users] summary: Get current user profile responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/User" "401": description: Unauthorized content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" patch: operationId: updateMe tags: [users] summary: Update current user profile requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/UserUpdate" responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/User" /users/{userId}: get: operationId: getUser tags: [users] summary: Get public user profile parameters: - name: userId in: path required: true schema: type: integer responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/UserPublic" "404": description: Not found content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" # ── Categories ────────────────────────────────────────────────── /categories: get: operationId: getCategories tags: [categories] summary: List all categories parameters: - name: type in: query schema: type: string enum: [produce, supply, equipment, service, all] responses: "200": description: OK content: application/json: schema: type: array items: $ref: "#/components/schemas/Category" # ── Listings ──────────────────────────────────────────────────── /listings: get: operationId: getListings tags: [listings] summary: List marketplace produce listings parameters: - name: search in: query schema: type: string - name: category_id in: query schema: type: integer - name: price_min in: query schema: type: number - name: price_max in: query schema: type: number - name: is_organic in: query schema: type: boolean - name: region in: query schema: type: string - name: sort in: query schema: type: string enum: [newest, price_asc, price_desc, popular] - name: page in: query schema: type: integer default: 1 - name: limit in: query schema: type: integer default: 20 responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/ListingsPage" post: operationId: createListing tags: [listings] summary: Create a new listing requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/ListingInput" responses: "201": description: Created content: application/json: schema: $ref: "#/components/schemas/Listing" /listings/featured: get: operationId: getFeaturedListings tags: [listings] summary: Get featured listings for homepage responses: "200": description: OK content: application/json: schema: type: array items: $ref: "#/components/schemas/Listing" /listings/my: get: operationId: getMyListings tags: [listings] summary: Get current farmer's own listings parameters: - name: status in: query schema: type: string enum: [active, draft, sold, expired, all] - name: page in: query schema: type: integer default: 1 responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/ListingsPage" /listings/{listingId}: get: operationId: getListing tags: [listings] summary: Get listing detail parameters: - name: listingId in: path required: true schema: type: integer responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/ListingDetail" "404": description: Not found content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" patch: operationId: updateListing tags: [listings] summary: Update a listing parameters: - name: listingId in: path required: true schema: type: integer requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/ListingUpdate" responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/Listing" delete: operationId: deleteListing tags: [listings] summary: Delete a listing parameters: - name: listingId in: path required: true schema: type: integer responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/SuccessResponse" /listings/{listingId}/orders: post: operationId: createOrder tags: [orders] summary: Place an order on a listing parameters: - name: listingId in: path required: true schema: type: integer requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/OrderInput" responses: "201": description: Created content: application/json: schema: $ref: "#/components/schemas/Order" # ── Buy Requests ───────────────────────────────────────────────── /buy-requests: get: operationId: getBuyRequests tags: [buy-requests] summary: List buy requests parameters: - name: search in: query schema: type: string - name: category_id in: query schema: type: integer - name: status in: query schema: type: string enum: [open, fulfilled, closed, all] - name: region in: query schema: type: string - name: sort in: query schema: type: string enum: [newest, deadline, budget_high, budget_low] - name: page in: query schema: type: integer default: 1 - name: limit in: query schema: type: integer default: 20 responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/BuyRequestsPage" post: operationId: createBuyRequest tags: [buy-requests] summary: Post a buy request requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/BuyRequestInput" responses: "201": description: Created content: application/json: schema: $ref: "#/components/schemas/BuyRequest" /buy-requests/my: get: operationId: getMyBuyRequests tags: [buy-requests] summary: Get current buyer's buy requests parameters: - name: status in: query schema: type: string enum: [open, fulfilled, closed, all] responses: "200": description: OK content: application/json: schema: type: array items: $ref: "#/components/schemas/BuyRequest" /buy-requests/{requestId}: get: operationId: getBuyRequest tags: [buy-requests] summary: Get buy request detail parameters: - name: requestId in: path required: true schema: type: integer responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/BuyRequestDetail" "404": description: Not found content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" patch: operationId: updateBuyRequest tags: [buy-requests] summary: Update a buy request parameters: - name: requestId in: path required: true schema: type: integer requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/BuyRequestUpdate" responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/BuyRequest" /buy-requests/{requestId}/offers: get: operationId: getBuyRequestOffers tags: [buy-requests] summary: Get offers on a buy request parameters: - name: requestId in: path required: true schema: type: integer responses: "200": description: OK content: application/json: schema: type: array items: $ref: "#/components/schemas/Offer" post: operationId: createOffer tags: [buy-requests] summary: Submit offer on a buy request parameters: - name: requestId in: path required: true schema: type: integer requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/OfferInput" responses: "201": description: Created content: application/json: schema: $ref: "#/components/schemas/Offer" /buy-requests/{requestId}/offers/{offerId}/accept: post: operationId: acceptOffer tags: [buy-requests] summary: Accept an offer parameters: - name: requestId in: path required: true schema: type: integer - name: offerId in: path required: true schema: type: integer responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/Offer" # ── Orders ─────────────────────────────────────────────────────── /orders: get: operationId: getOrders tags: [orders] summary: Get orders (as buyer or seller) parameters: - name: role in: query schema: type: string enum: [buyer, seller] - name: status in: query schema: type: string enum: [pending, confirmed, completed, cancelled, all] - name: page in: query schema: type: integer default: 1 responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/OrdersPage" /orders/{orderId}: get: operationId: getOrder tags: [orders] summary: Get order detail parameters: - name: orderId in: path required: true schema: type: integer responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/OrderDetail" patch: operationId: updateOrder tags: [orders] summary: Update order status parameters: - name: orderId in: path required: true schema: type: integer requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/OrderUpdate" responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/Order" # ── Dashboard ───────────────────────────────────────────────────── /dashboard/farmer: get: operationId: getFarmerDashboard tags: [dashboard] summary: Farmer dashboard aggregates responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/FarmerDashboard" /dashboard/buyer: get: operationId: getBuyerDashboard tags: [dashboard] summary: Buyer dashboard aggregates responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/BuyerDashboard" # ── Search ──────────────────────────────────────────────────────── /search: get: operationId: search tags: [search] summary: Search listings and buy requests parameters: - name: q in: query required: true schema: type: string - name: type in: query schema: type: string enum: [listings, buy_requests, all] - name: page in: query schema: type: integer default: 1 - name: limit in: query schema: type: integer default: 20 responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/SearchResults" # ── Schemas ─────────────────────────────────────────────────────────────────── components: schemas: HealthStatus: type: object properties: status: type: string required: [status] ErrorResponse: type: object properties: error: type: string required: [error] SuccessResponse: type: object properties: success: type: boolean required: [success] # ── Auth ───────────────────────────────────────────────────────── RegisterInput: type: object required: [email, password, fullNameAr, role] properties: email: type: string password: type: string minLength: 8 fullNameAr: type: string fullNameEn: type: ["string", "null"] phone: type: ["string", "null"] role: type: string enum: [farmer, buyer] LoginInput: type: object required: [email, password] properties: email: type: string password: type: string AuthResponse: type: object required: [token, user] properties: token: type: string user: $ref: "#/components/schemas/User" # ── Users ───────────────────────────────────────────────────────── User: type: object required: [id, email, fullNameAr, role, createdAt] properties: id: type: integer email: type: string fullNameAr: type: string fullNameEn: type: ["string", "null"] phone: type: ["string", "null"] avatarUrl: type: ["string", "null"] bioAr: type: ["string", "null"] role: type: string enum: [farmer, buyer, admin] region: type: ["string", "null"] isVerified: type: boolean createdAt: type: string format: date-time UserPublic: type: object required: [id, fullNameAr, role, createdAt] properties: id: type: integer fullNameAr: type: string fullNameEn: type: ["string", "null"] avatarUrl: type: ["string", "null"] bioAr: type: ["string", "null"] role: type: string region: type: ["string", "null"] isVerified: type: boolean createdAt: type: string format: date-time UserUpdate: type: object properties: fullNameAr: type: string fullNameEn: type: ["string", "null"] phone: type: ["string", "null"] avatarUrl: type: ["string", "null"] bioAr: type: ["string", "null"] region: type: ["string", "null"] # ── Categories ──────────────────────────────────────────────────── Category: type: object required: [id, nameAr, nameEn, slug, type] properties: id: type: integer nameAr: type: string nameEn: type: string slug: type: string type: type: string icon: type: ["string", "null"] listingCount: type: integer # ── Listings ────────────────────────────────────────────────────── Listing: type: object required: [id, sellerId, categoryId, titleAr, price, priceUnit, status, createdAt] properties: id: type: integer sellerId: type: integer categoryId: type: integer titleAr: type: string titleEn: type: ["string", "null"] descriptionAr: type: ["string", "null"] price: type: number priceUnit: type: string quantity: type: ["number", "null"] quantityUnit: type: ["string", "null"] region: type: ["string", "null"] isOrganic: type: boolean isFeatured: type: boolean status: type: string enum: [active, draft, sold, expired] imageUrl: type: ["string", "null"] viewCount: type: integer sellerName: type: ["string", "null"] sellerRegion: type: ["string", "null"] categoryNameAr: type: ["string", "null"] harvestDate: type: ["string", "null"] createdAt: type: string format: date-time ListingDetail: type: object required: [id, sellerId, categoryId, titleAr, price, priceUnit, status, createdAt] properties: id: type: integer sellerId: type: integer categoryId: type: integer titleAr: type: string titleEn: type: ["string", "null"] descriptionAr: type: ["string", "null"] descriptionEn: type: ["string", "null"] price: type: number priceUnit: type: string quantity: type: ["number", "null"] quantityUnit: type: ["string", "null"] region: type: ["string", "null"] isOrganic: type: boolean isFeatured: type: boolean status: type: string imageUrl: type: ["string", "null"] viewCount: type: integer harvestDate: type: ["string", "null"] seller: $ref: "#/components/schemas/UserPublic" category: $ref: "#/components/schemas/Category" relatedListings: type: array items: $ref: "#/components/schemas/Listing" createdAt: type: string format: date-time ListingInput: type: object required: [categoryId, titleAr, price, priceUnit] properties: categoryId: type: integer titleAr: type: string titleEn: type: ["string", "null"] descriptionAr: type: ["string", "null"] descriptionEn: type: ["string", "null"] price: type: number priceUnit: type: string quantity: type: ["number", "null"] quantityUnit: type: ["string", "null"] region: type: ["string", "null"] isOrganic: type: boolean imageUrl: type: ["string", "null"] harvestDate: type: ["string", "null"] status: type: string enum: [active, draft] ListingUpdate: type: object properties: titleAr: type: string titleEn: type: ["string", "null"] descriptionAr: type: ["string", "null"] price: type: number priceUnit: type: string quantity: type: ["number", "null"] quantityUnit: type: ["string", "null"] region: type: ["string", "null"] isOrganic: type: boolean imageUrl: type: ["string", "null"] harvestDate: type: ["string", "null"] status: type: string enum: [active, draft, sold, expired] ListingsPage: type: object required: [data, total, page, limit] properties: data: type: array items: $ref: "#/components/schemas/Listing" total: type: integer page: type: integer limit: type: integer # ── Buy Requests ────────────────────────────────────────────────── BuyRequest: type: object required: [id, buyerId, categoryId, titleAr, status, createdAt] properties: id: type: integer buyerId: type: integer categoryId: type: integer titleAr: type: string titleEn: type: ["string", "null"] descriptionAr: type: ["string", "null"] quantity: type: ["number", "null"] quantityUnit: type: ["string", "null"] budgetMin: type: ["number", "null"] budgetMax: type: ["number", "null"] region: type: ["string", "null"] deliveryRequired: type: boolean status: type: string enum: [open, fulfilled, closed] offerCount: type: integer buyerName: type: ["string", "null"] categoryNameAr: type: ["string", "null"] expiresAt: type: ["string", "null"] createdAt: type: string format: date-time BuyRequestDetail: type: object required: [id, buyerId, categoryId, titleAr, status, createdAt] properties: id: type: integer buyerId: type: integer categoryId: type: integer titleAr: type: string titleEn: type: ["string", "null"] descriptionAr: type: ["string", "null"] quantity: type: ["number", "null"] quantityUnit: type: ["string", "null"] budgetMin: type: ["number", "null"] budgetMax: type: ["number", "null"] region: type: ["string", "null"] deliveryRequired: type: boolean status: type: string offerCount: type: integer expiresAt: type: ["string", "null"] buyer: $ref: "#/components/schemas/UserPublic" category: $ref: "#/components/schemas/Category" offers: type: array items: $ref: "#/components/schemas/Offer" createdAt: type: string format: date-time BuyRequestInput: type: object required: [categoryId, titleAr] properties: categoryId: type: integer titleAr: type: string titleEn: type: ["string", "null"] descriptionAr: type: ["string", "null"] quantity: type: ["number", "null"] quantityUnit: type: ["string", "null"] budgetMin: type: ["number", "null"] budgetMax: type: ["number", "null"] region: type: ["string", "null"] deliveryRequired: type: boolean expiresAt: type: ["string", "null"] BuyRequestUpdate: type: object properties: titleAr: type: string descriptionAr: type: ["string", "null"] quantity: type: ["number", "null"] budgetMin: type: ["number", "null"] budgetMax: type: ["number", "null"] status: type: string enum: [open, fulfilled, closed] BuyRequestsPage: type: object required: [data, total, page, limit] properties: data: type: array items: $ref: "#/components/schemas/BuyRequest" total: type: integer page: type: integer limit: type: integer Offer: type: object required: [id, requestId, sellerId, price, status, createdAt] properties: id: type: integer requestId: type: integer sellerId: type: integer price: type: number quantity: type: ["number", "null"] notesAr: type: ["string", "null"] status: type: string enum: [pending, accepted, rejected, withdrawn] sellerName: type: ["string", "null"] sellerRegion: type: ["string", "null"] sellerIsVerified: type: boolean createdAt: type: string format: date-time OfferInput: type: object required: [price] properties: price: type: number quantity: type: ["number", "null"] notesAr: type: ["string", "null"] # ── Orders ──────────────────────────────────────────────────────── Order: type: object required: [id, buyerId, sellerId, listingId, quantity, totalPrice, status, createdAt] properties: id: type: integer orderNumber: type: string buyerId: type: integer sellerId: type: integer listingId: type: integer listingTitleAr: type: ["string", "null"] quantity: type: number unitPrice: type: number totalPrice: type: number status: type: string enum: [pending, confirmed, preparing, shipped, delivered, completed, cancelled] paymentStatus: type: string enum: [pending, paid, refunded] buyerName: type: ["string", "null"] sellerName: type: ["string", "null"] createdAt: type: string format: date-time OrderDetail: type: object required: [id, buyerId, sellerId, listingId, quantity, totalPrice, status, createdAt] properties: id: type: integer orderNumber: type: string buyerId: type: integer sellerId: type: integer quantity: type: number unitPrice: type: number totalPrice: type: number status: type: string paymentStatus: type: string notes: type: ["string", "null"] listing: $ref: "#/components/schemas/Listing" buyer: $ref: "#/components/schemas/UserPublic" seller: $ref: "#/components/schemas/UserPublic" createdAt: type: string format: date-time OrderInput: type: object required: [quantity] properties: quantity: type: number notes: type: ["string", "null"] OrderUpdate: type: object properties: status: type: string enum: [confirmed, preparing, shipped, delivered, completed, cancelled] OrdersPage: type: object required: [data, total, page, limit] properties: data: type: array items: $ref: "#/components/schemas/Order" total: type: integer page: type: integer limit: type: integer # ── Dashboard ───────────────────────────────────────────────────── FarmerDashboard: type: object required: [totalListings, activeListings, totalOrders, totalRevenue, pendingOrders, recentOrders, recentListings] properties: totalListings: type: integer activeListings: type: integer totalOrders: type: integer totalRevenue: type: number pendingOrders: type: integer recentOrders: type: array items: $ref: "#/components/schemas/Order" recentListings: type: array items: $ref: "#/components/schemas/Listing" openBuyRequests: type: integer monthlyRevenue: type: number BuyerDashboard: type: object required: [totalOrders, totalSpent, openBuyRequests, activeOrders, recentOrders, recentBuyRequests] properties: totalOrders: type: integer totalSpent: type: number openBuyRequests: type: integer activeOrders: type: integer recentOrders: type: array items: $ref: "#/components/schemas/Order" recentBuyRequests: type: array items: $ref: "#/components/schemas/BuyRequest" totalOffersReceived: type: integer # ── Search ──────────────────────────────────────────────────────── SearchResults: type: object required: [listings, buyRequests, total, page, limit] properties: listings: type: array items: $ref: "#/components/schemas/Listing" buyRequests: type: array items: $ref: "#/components/schemas/BuyRequest" total: type: integer page: type: integer limit: type: integer