Marketplace Service
Relevant source files
The following files were used as context for generating this wiki page:
The Marketplace Service provides the core business logic for buying and selling designs within the eefashiondesign application. It manages listings, purchases, sales, shopping carts, and user reviews. Currently, the service is a foundational implementation that uses local device storage (AsyncStorage) for data persistence.
The project roadmap indicates this feature is planned to evolve into a "Template marketplace" with cloud integration. As of now, it is disabled by default via a feature flag.
Sources: src/services/marketplaceService.js, README.md:161, src/config/constants.js:223
Architecture
The MarketplaceService is implemented as a singleton class, ensuring a single instance manages all marketplace data throughout the application's lifecycle. All data is stored in a single JSON object in AsyncStorage under the key @marketplace_data. The service includes comprehensive error handling by delegating exceptions to a centralized errorHandler.
Sources: src/services/marketplaceService.js:8,10,404, SECURITY_AND_CLEANUP_FIXES.md
The following diagram illustrates the service's dependencies and its role in data management.
Data Model
The service manages several interconnected data entities, all stored within a single JSON object. The main entities are listings, purchases, sales, cart, and favorites.
Sources: src/services/marketplaceService.js:41-47
This Entity-Relationship diagram shows the relationships between the core data structures.
Sources: src/services/marketplaceService.js
Listing Schema
A listing represents a design available for sale.
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier for the listing. |
designId | string | The ID of the associated design. |
title | string | The name of the design. |
description | string | A description of the design. |
price | number | The selling price. |
currency | string | The currency (defaults to 'USD'). |
category | string | The design category (e.g., 'general'). |
tags | string[] | An array of search tags. |
sellerId | string | The ID of the user selling the design. |
thumbnail | string | URL or data URI for the design thumbnail. |
license | string | The license type ('standard', 'extended', 'exclusive'). |
downloads | number | The number of times the design has been purchased. |
rating | number | The average user rating. |
reviews | Review[] | An array of review objects. |
status | string | The listing status ('active', 'sold', 'removed'). |
createdAt | string | ISO 8601 timestamp of creation. |
updatedAt | string | ISO 8601 timestamp of the last update. |
| Sources: src/services/marketplaceService.js:60-79 |
Purchase Schema
A purchase record is created when a user buys a design.
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier for the purchase. |
listingId | string | The ID of the purchased listing. |
designId | string | The ID of the purchased design. |
buyerId | string | The ID of the user who made the purchase. |
sellerId | string | The ID of the user who sold the design. |
price | number | The price at the time of purchase. |
paymentMethod | string | The payment method used (placeholder). |
status | string | The status of the purchase (e.g., 'completed'). |
purchasedAt | string | ISO 8601 timestamp of the purchase. |
| Sources: src/services/marketplaceService.js:304-315 |
Core Functionality
Listing Management
Sellers can list, update, and remove their designs from the marketplace.
listDesign(designData, pricing): Creates a new listing from design data and pricing information.updateListing(listingId, updates): Modifies an existing listing.removeListing(listingId, userId): Changes a listing's status toremoved, effectively delisting it. Requires theuserIdfor authorization.
Sources: src/services/marketplaceService.js:55-147
The following diagram shows the process of listing a new design.
Searching and Browsing
Users can search and filter active listings.
searchListings(query, filters): Searches active listings by a text query against title, description, and tags. It also supports filtering and sorting.getListingDetails(listingId): Retrieves the full details for a single listing.
Sources: src/services/marketplaceService.js:152-214
The searchListings function accepts the following filters:
| Filter | Type | Description |
|---|---|---|
category | string | Filters by a specific category. |
minPrice | number | Sets a minimum price for results. |
maxPrice | number | Sets a maximum price for results. |
sortBy | string | Sorts results. Options: price_asc, price_desc, popular, recent, rating. |
| Sources: src/services/marketplaceService.js:172-198 |
Shopping Cart
The service provides standard shopping cart functionality.
addToCart(listingId, userId): Adds a listing to the user's cart.removeFromCart(listingId): Removes a listing from the cart.getCart(): Retrieves all items in the cart, along with the total price.
Sources: src/services/marketplaceService.js:219-286
This sequence diagram shows the flow for adding an item to the cart.
Purchasing
The purchaseDesign function simulates a purchase transaction. In a real-world application, this would integrate with a payment gateway.
The process involves:
- Finding the listing.
- Creating a
purchaserecord for the buyer. - Incrementing the
downloadscount on the listing. - Creating a
salerecord for the seller. - Saving all changes to storage.
Sources: src/services/marketplaceService.js:291-331
User and Seller Data
The service provides methods to retrieve user-specific data:
getUserPurchases(userId): Returns all purchases made by a user.getUserSales(userId): Returns all sales made by a user and calculates total earnings.addReview(listingId, userId, rating, comment): Adds a review to a listing and recalculates its average rating.getSellerStats(userId): Compiles statistics for a seller, including total sales, revenue, downloads, and average rating across all their listings.
Sources: src/services/marketplaceService.js:336-399
Configuration
The marketplace feature is controlled by a feature flag. To enable it, the ENABLE_MARKETPLACE flag must be set to true.
// src/config/constants.js
export const FEATURES = {
ENABLE_AR: true,
ENABLE_3D: true,
ENABLE_AI_ASSISTANT: true,
ENABLE_COLLABORATION: true,
ENABLE_MARKETPLACE: false, // Coming soon
ENABLE_SOCIAL: true,
ENABLE_CLOUD_SYNC: false, // Coming soon
};
Sources: src/config/constants.js:223-231