Services
Service Layer
Section titled “Service Layer”Shared services in src/lib/services/ encapsulate Firebase operations that are used across multiple modules.
UserService
Section titled “UserService”File: user.service.ts
User profile and account operations:
class UserService { updateRole(userId, role); updateInfo(userId, info); updateWorkHours(userId, hours); updateMetadata(userId, metadata); deleteUser(userId); getUserByUserName(userName); // Check username existence}EmailService
Section titled “EmailService”File: email.service.ts (Singleton)
Email queue system using Firestore mail collection:
class EmailService { sendEmail(to, subject, html); sendDisputeNotificationEmail(disputeData); sendDisputeResolutionEmails(resolutionData);}Emails are queued in the mail Firestore collection and processed by a Firebase extension/function.
StorageUserService
Section titled “StorageUserService”File: storage-user.service.ts
Tracks file uploads and storage usage per user:
class StorageUserService { findFileByPath(path); initializeStorage(userId); createStorage(fileData); updateStorage(fileId, updates); deleteStorage(fileId); updateStorageSpace(userId, delta);}Firestore path: storageUser/{userId}/files/{fileId}
UserRegistryService
Section titled “UserRegistryService”File: user-registry-service.ts
Manages the user registration system configuration (for private beta):
class UserRegistryService { initializeConfig(); updateConfig(updates); setUserLimit(limit); toggleEnabled(enabled);}Firestore path: config/userRegistry
CheckoutService
Section titled “CheckoutService”File: checkout.service.ts
Stripe checkout session management with platform fee calculation:
class CheckoutService { // Platform fee constant static PLATFORM_FEE_PERCENT = 0.05; // 5%
createCheckoutSession(price, metadata, options); createMarketplaceCheckout({ priceId, sellerStripeAccountId, amountInCents, metadata }); createCheckoutSessionCustom(price, options, metadata); getCheckoutSession(sessionId); watchCheckoutSession(sessionId, callback);}Marketplace checkout flow:
- Creates a checkout session on the seller’s Stripe Connect account
- Calculates 5% platform fee as
application_fee_amount - Stores session in Firestore:
users/{buyerId}/checkout_sessions/{sessionId} - Returns Stripe checkout URL for redirect
StripeConnectService (Server)
Section titled “StripeConnectService (Server)”File: src/lib/server/stripe-connect.service.ts
Server-side Stripe Connect account management:
class StripeConnectService { createExpressAccount(userId, userData); // Creates Express account with card_payments and transfers // Returns { accountId, accountLink }
getAccountStatus(accountId); // Returns { chargesEnabled, payoutsEnabled }}