Marketplace Architecture
The marketplace module follows the domain-based architecture pattern of the BuildAppsWith platform, providing a dedicated set of files for builder discovery, profile management, and analytics functionality.Module Structure
The marketplace module is organized as follows:Architecture Principles
1. Separation of Concerns
- Client-side vs Server-side: Clear separation between client API functions (
api.ts) and server-side data services (data/marketplace-service.ts) - Domain Boundaries: The marketplace module encapsulates all marketplace-related functionality
- Type Safety: Shared types defined in
types.tsensure consistency across the module
2. API Design
The module exposes three primary API areas:- Builder Discovery: Functions for searching, filtering, and fetching builder profiles
- Analytics: Functions for accessing and analyzing builder performance metrics
- Filter Management: Functions for retrieving marketplace filter options
3. Component Structure
The marketplace components follow a standardized structure:- One Component Per Directory: Each component has its own directory
- Consistent File Naming: Component files match their directory names
- Barrel Exports: Index files export the main component
- Specialized Supporting Files: Fallbacks, skeletons, and utilities grouped with parent components
- Implementation Design: Stateless components where possible with clear separation of concerns
- Utility Integration: Components leverage shared utilities like
cn()for class name merging
4. Error Handling
- Error Boundaries: Components are wrapped in error boundaries for isolation at the UI level
- Inline Error Handling: Components handle errors inline with fallbacks (e.g., for failed image loading)
- Graceful Degradation: Components degrade gracefully without user-facing error messages
- Type Validation: Components use type validation to prevent common errors
- Dedicated Fallback Components: Each error scenario has a dedicated fallback component
BuilderImage component implements multi-layered error handling:
5. State Management
- Stateless Design: Components are stateless where possible:
- State management moved to hooks
- Pure render functions for predictable behavior
- No complex useEffect dependencies
- Implementation avoids unnecessary re-renders
- Efficient error handling without state changes
6. Data Flow
Key Design Decisions
Design Decision: Hybrid Architecture
The marketplace module uses a hybrid architecture that combines:- Client-side API functions in
api.ts(follow REST patterns) - Server-side data services in the
data/directory (database operations)
- Clean separation between presentation and data access
- Optimized data operations on the server
- Secure access control at the API route level
Design Decision: Consolidated Type System
All marketplace types are defined in a singletypes.ts file, which serves as the source of truth for:
- Builder profile structures
- Marketplace filters
- Analytics data structures
- Domain Types (
lib/marketplace/types.ts) - Core business logic types used by services and server components - Component Types (
components/marketplace/components/types.ts) - UI-specific types that prevent circular dependencies
Design Decision: Feature Flagging
The marketplace module supports feature flagging through:- Demo account handling
- Feature-specific filters
- Environment-based configuration
Implementation Principles
Client-Side API Functions
Client-side API functions inapi.ts:
- Use fetch to call API endpoints
- Handle error states gracefully
- Return typed responses
- Support pagination and filtering
Server-Side Data Services
Server-side data services indata/marketplace-service.ts:
- Perform direct database operations
- Implement business logic
- Handle data transformations
- Manage security and access control
Evolution & Migration
The marketplace module has evolved from a simple list of builders to a comprehensive marketplace for developer services. Key migrations include:- Addition of analytics capabilities
- Enhanced filtering options
- Migration to the domain-based architecture
- Consolidation of duplicated code
api.tsanddata-service.ts(client-side operations) - withdata-service.tsnow deprecated- Multiple builder image implementations consolidated into a single component
- Type definitions consolidated into domain and component-specific files
Deprecated Components
The following components have been deprecated and will be removed in future updates:components/marketplace/builder-image.tsx→ Usecomponents/marketplace/components/builder-imagecomponents/marketplace/simplified-builder-image.tsx→ Usecomponents/marketplace/components/builder-imagecomponents/marketplace/fixed-builder-image.tsx→ Usecomponents/marketplace/components/builder-imagelib/marketplace/data-service.ts→ Uselib/marketplace/marketplace-service.ts
Future Directions
Planned enhancements to the marketplace architecture include:- Full migration to Nx libraries: Moving the marketplace module to a dedicated Nx library
- Enhanced analytics: More comprehensive builder performance metrics
- API versioning: Supporting multiple versions of the marketplace API
- GraphQL integration: Adding GraphQL support for more flexible data fetching