LynxReaders Platform

Complete UML Architecture & Design Documentation

Microservices-Based Book Marketplace

Use Case Diagrams

User Use Cases

graph TB User((User)) User --> UC1[Register/Login] User --> UC2[Browse Books] User --> UC3[Search Books] User --> UC4[View Book Details] User --> UC5[Add to Cart] User --> UC6[Add to Wishlist] User --> UC7[Place Order] User --> UC8[Track Order] User --> UC9[Confirm Delivery] User --> UC10[Cancel Order] User --> UC11[Chat with Seller] User --> UC12[Write Review] User --> UC13[Request Book] User --> UC14[Manage Profile] User --> UC15[Manage Addresses] User --> UC16[Set Preferences] User --> UC17[View Notifications] User --> UC18[Listen Audio Preview] User --> UC19[View Blogs] User --> UC20[Follow Shops] UC7 --> UC7A[Select Address] UC7 --> UC7B[Cash on Delivery] UC7 --> UC7C[Confirm Order] UC13 --> UC13A[Fill Book Details] UC13 --> UC13B[Set Price Range] UC13 --> UC13C[Track Request Status]

Seller Use Cases

graph TB Seller((Seller)) Seller --> SC1[Register Shop] Seller --> SC2[Upload CIN Documents] Seller --> SC3[Manage Products] Seller --> SC4[Create Product] Seller --> SC5[Update Product] Seller --> SC6[Delete Product] Seller --> SC7[Manage Orders] Seller --> SC8[Confirm Order] Seller --> SC9[Prepare Book] Seller --> SC10[Chat with Customers] Seller --> SC11[View Analytics] Seller --> SC12[Create Discount Codes] Seller --> SC13[Publish Blogs] Seller --> SC14[Create Sponsored Books] Seller --> SC15[Manage Shop Profile] Seller --> SC16[View Earnings] Seller --> SC17[Track Trusted Badge] Seller --> SC18[Manage Notifications] Seller --> SC19[View Reviews] Seller --> SC20[Manage Multiple Addresses] SC3 --> SC3A[Upload Images to S3] SC3 --> SC3B[Set Pricing] SC3 --> SC3C[Manage Stock] SC3 --> SC3D[Add Custom Properties] SC14 --> SC14A[Use Coins] SC14 --> SC14B[Set Duration] SC14 --> SC14C[Track Performance] SC17 --> SC17A[Complete 50 Sales] SC17 --> SC17B[Get Badge]

Admin Use Cases

graph TB Admin((Admin)) Admin --> AC1[Manage Users] Admin --> AC2[Manage Sellers] Admin --> AC3[Approve Sellers] Admin --> AC4[Reject Sellers] Admin --> AC5[Manage Products] Admin --> AC6[Manage Orders] Admin --> AC7[Assign Delivery] Admin --> AC8[Track Commissions] Admin --> AC9[Collect Payments] Admin --> AC10[Manage Book Requests] Admin --> AC11[Mark Book Found] Admin --> AC12[View Analytics] Admin --> AC13[Manage Delivery Persons] Admin --> AC14[Platform Customization] Admin --> AC15[Manage Blogs] Admin --> AC16[Moderate Content] Admin --> AC17[View Logs] Admin --> AC18[Generate Reports] AC2 --> AC2A[View CIN Documents] AC2 --> AC2B[Verify Identity] AC2 --> AC2C[Suspend Seller] AC6 --> AC6A[Process Orders] AC6 --> AC6B[Handle Cancellations] AC6 --> AC6C[Resolve Disputes] AC10 --> AC10A[Review Requests] AC10 --> AC10B[Add Admin Notes] AC10 --> AC10C[Update Status]

Delivery Person Use Cases

graph TB Delivery((Delivery Person)) Delivery --> DC1[Login to App] Delivery --> DC2[View Assigned Orders] Delivery --> DC3[Accept Order] Delivery --> DC4[Collect from Seller] Delivery --> DC5[Update Status] Delivery --> DC6[Navigate to Customer] Delivery --> DC7[Deliver Order] Delivery --> DC8[Collect Payment] Delivery --> DC9[Confirm Delivery] Delivery --> DC10[View Earnings] Delivery --> DC11[View History] Delivery --> DC12[Update Profile] DC5 --> DC5A[Book Collected] DC5 --> DC5B[In Transit] DC5 --> DC5C[Delivered] DC8 --> DC8A[Cash Collection] DC8 --> DC8B[Platform Commission] DC8 --> DC8C[Seller Payment]

Class Diagram

Core Domain Models

classDiagram class User { +String id +String name +String email +String role +String password +String avatar +String address +String[] preferredCategories +Boolean newsletterSubscribed +DateTime createdAt +DateTime updatedAt +register() +login() +updateProfile() +updatePreferences() +subscribeNewsletter() } class Seller { +String id +String name +String email +String phone_number +String country +String password +String stripeId +String cinFrontUrl +String cinBackUrl +SellerStatus status +Boolean belongsToUs +Int coins +Int totalSales +Boolean isTrusted +DateTime trustedAt +String language +register() +uploadCIN() +getTrustedBadge() } class Shop { +String id +String name +String bio +String avatar +String coverBanner +String website +Json[] socialLinks +Float ratings +String sellerId +Boolean isDeleted +DateTime createdAt +updateProfile() +addAddress() +getAnalytics() } class Product { +String id +String title +String slug +String category +String subCategory +String short_description +String detailed_description +String video_url +String[] tags +String[] colors +String[] sizes +Int stock +Float sale_price +Float regular_price +Float ratings +Json custom_specifications +Json custom_properties +ProductStatus status +Int totalSales +String shopId +create() +update() +delete() +restore() } class Order { +String id +String userId +String shopId +Float total +Float deliveryFee +String deliveryAddress +String customerPhone +String paymentMethod +String status +DeliveryStatus deliveryStatus +Boolean sellerConfirmed +Boolean userConfirmed +Boolean isCancelled +String deliveryPersonId +placeOrder() +confirmBySeller() +confirmByUser() +cancel() +assignDelivery() } class OrderItem { +String id +String orderId +String productId +Int quantity +Float price +Json selectedOptions } class Address { +String id +String userId +AddressType label +String name +String phone +String street +String city +String governorate +String delegation +String localite +String zip +Boolean isDefault +create() +update() +delete() } class ShopAddress { +String id +String shopId +String governorate +String delegation +String localite +String cp } class Review { +String id +String userId +String productId +Float rating +String review +DateTime createdAt +create() +update() } class ShopReview { +String id +String userId +String shopsId +Float rating +String reviews +DateTime createdAt } class Message { +String id +String conversationId +String senderId +String senderType +String content +String[] attachments +String status +DateTime createdAt +send() +markAsSeen() } class ConversationGroup { +String id +Boolean isGroup +String name +String creatorId +String[] participantIds +DateTime createdAt +create() +addParticipant() } class BookRequest { +String id +String userId +String bookName +String author +String photo +Float minPrice +Float maxPrice +String phoneNumber +String fullName +String email +BookRequestStatus status +String adminNotes +Boolean isFoundByAdmin +create() +update() +delete() } class Blog { +String id +String title +String slug +String content +String excerpt +String[] tags +String[] images +String status +Int views +String shopId +DateTime createdAt +create() +update() +delete() } class SponsoredBook { +String id +String productId +String sponsorshipType +DateTime startDate +DateTime endDate +Boolean isActive +Int impressions +Int clicks +String shopId +create() +trackImpression() +trackClick() } class DeliveryOrder { +String id +String orderId +String deliveryPersonId +String pickupAddress +String deliveryAddress +DeliveryStatus status +Float totalAmount +Float platformCommission +Float sellerAmount +DateTime orderPlacedAt +DateTime deliveredAt +updateStatus() +collectPayment() } class DeliveryPerson { +String id +String name +String phone +String email +String password +String zone +DeliveryPersonStatus status +Float totalEarnings +Int totalDeliveries +login() +acceptOrder() +updateStatus() } class CommissionTransaction { +String id +String orderId +String sellerId +Float totalAmount +Float platformFee +Float sellerAmount +CommissionStatus status +DateTime processedAt +String notes +process() +collect() } class DiscountCode { +String id +String public_name +String discountType +Float discountValue +String discountCode +String sellerId +create() +apply() } class Notification { +String id +String creatorId +String receiverId +String redirect_link +String title +String message +String status +DateTime createdAt +send() +markAsRead() } class CoinTransaction { +String id +String sellerId +CoinTransactionType type +Int amount +String description +String operationType +Int balanceBefore +Int balanceAfter +DateTime createdAt } %% Relationships with proper UML notation User "1" --o "*" Order : places User "1" --o "*" Address : has User "1" --o "*" Review : writes User "1" --o "*" ShopReview : writes User "1" --o "*" BookRequest : creates User "1" --> "*" Message : sends User "1" --> "*" Notification : receives Seller "1" --* "1" Shop : owns Seller "1" --o "*" CoinTransaction : has Seller "1" --> "*" CommissionTransaction : receives Seller "1" --o "*" DiscountCode : creates Shop "1" *-- "*" Product : contains Shop "1" --o "*" Blog : publishes Shop "1" --o "*" SponsoredBook : sponsors Shop "1" --o "*" ShopAddress : has Shop "1" --> "*" Order : receives Shop "1" --> "*" ShopReview : rated by Product "1" --> "*" Review : has Product "1" --> "*" OrderItem : ordered in Product "1" <-- "1" SponsoredBook : features Order "1" *-- "*" OrderItem : contains Order "1" --> "0..1" DeliveryOrder : tracked by Order "1" --> "*" CommissionTransaction : generates Order "*" --> "1" User : placed by Order "*" --> "1" Shop : received by DeliveryPerson "1" --> "*" DeliveryOrder : delivers ConversationGroup "1" *-- "*" Message : contains OrderItem "*" --> "1" Order : belongs to OrderItem "*" --> "1" Product : references DeliveryOrder "1" --> "1" Order : tracks DeliveryOrder "*" --> "1" DeliveryPerson : assigned to CommissionTransaction "*" --> "1" Order : for CommissionTransaction "*" --> "1" Seller : paid to

Sequence Diagrams

User Registration & Login Flow

sequenceDiagram participant U as User participant UI as User-UI participant AG as API Gateway participant AS as Auth Service participant DB as MongoDB participant Redis as Redis Cache U->>UI: Enter registration details UI->>AG: POST /api/user-registration AG->>AS: Forward request AS->>DB: Check if email exists DB-->>AS: Email available AS->>AS: Hash password AS->>DB: Create user record AS->>AS: Generate activation code AS->>Redis: Store activation code (5min TTL) AS->>AS: Send activation email AS-->>UI: Registration successful UI-->>U: Show activation prompt U->>UI: Enter activation code UI->>AG: POST /api/verify-user AG->>AS: Forward verification AS->>Redis: Validate code Redis-->>AS: Code valid AS->>DB: Activate user account AS->>AS: Generate JWT tokens AS-->>UI: Return tokens + user data UI->>UI: Store tokens in cookies UI-->>U: Redirect to dashboard

Product Browsing & Search

sequenceDiagram participant U as User participant UI as User-UI participant AG as API Gateway participant PS as Product Service participant DB as MongoDB participant Redis as Redis Cache U->>UI: Browse products page UI->>AG: GET /product/api/get-all-products?page=1 AG->>PS: Forward request PS->>Redis: Check cache alt Cache hit Redis-->>PS: Return cached products else Cache miss PS->>DB: Query products DB-->>PS: Return products PS->>Redis: Cache results (2min) end PS-->>UI: Return products list UI-->>U: Display products U->>UI: Search "Harry Potter" UI->>AG: GET /product/api/search-products?q=Harry Potter AG->>PS: Forward search PS->>DB: Full-text search DB-->>PS: Matching products PS-->>UI: Search results UI-->>U: Display results

Add to Cart & Checkout Flow

sequenceDiagram participant U as User participant UI as User-UI participant Store as Zustand Store participant AG as API Gateway participant OS as Order Service participant PS as Product Service participant DB as MongoDB U->>UI: Click "Add to Cart" UI->>Store: addToCart(product) Store->>Store: Update cart state Store->>Store: Save to localStorage Store-->>UI: Cart updated UI-->>U: Show cart badge U->>UI: Go to checkout UI->>AG: GET /user/api/shipping-addresses AG->>AG: Verify JWT token AG-->>UI: Return addresses UI-->>U: Show checkout form U->>UI: Select address & confirm UI->>AG: POST /order/api/place AG->>OS: Create order OS->>DB: Begin transaction OS->>PS: Check stock availability PS->>DB: Lock products DB-->>PS: Stock available PS-->>OS: Stock confirmed OS->>DB: Create order record OS->>DB: Create order items OS->>DB: Update product stock OS->>DB: Create delivery order OS->>DB: Commit transaction OS->>OS: Send notification to seller OS-->>UI: Order created successfully UI->>Store: clearCart() UI-->>U: Redirect to orders page

Real-time Chat Communication

sequenceDiagram participant U as User participant UI as User-UI participant AG as API Gateway participant CS as Chatting Service participant WS as WebSocket Server participant DB as MongoDB participant S as Seller participant SUI as Seller-UI U->>UI: Click "Chat with Seller" UI->>AG: POST /chatting/api/create-user-conversationGroup AG->>CS: Create conversation CS->>DB: Check existing conversation alt Conversation exists DB-->>CS: Return conversation else New conversation CS->>DB: Create conversation CS->>DB: Add participants DB-->>CS: Conversation created end CS-->>UI: Return conversation ID UI->>WS: Connect WebSocket WS->>WS: Authenticate user WS-->>UI: Connection established U->>UI: Type message UI->>WS: Send message payload WS->>DB: Save message WS->>WS: Broadcast to seller WS-->>SUI: New message event SUI-->>S: Show notification WS-->>UI: Message sent confirmation UI-->>U: Display message S->>SUI: Reply to message SUI->>WS: Send reply WS->>DB: Save reply WS->>WS: Broadcast to user WS-->>UI: New message event UI-->>U: Display reply

Order Delivery Workflow

sequenceDiagram participant U as User participant A as Admin participant AUI as Admin-UI participant S as Seller participant SUI as Seller-UI participant D as Delivery Person participant DUI as Delivery-UI participant OS as Order Service participant DB as MongoDB participant WS as WebSocket Note over U,DB: Order Placed U->>OS: Place order OS->>DB: Create order (status: OrderPlaced) OS->>WS: Notify seller WS-->>SUI: New order notification Note over A,DB: Admin Processing A->>AUI: View pending orders AUI->>OS: GET /admin/api/orders OS-->>AUI: Return orders A->>AUI: Assign delivery person AUI->>OS: POST /admin/api/assign-delivery OS->>DB: Update order (status: DeliveryAssigned) OS->>WS: Notify delivery person WS-->>DUI: New delivery assignment Note over S,DB: Seller Preparation S->>SUI: Confirm order SUI->>OS: POST /order/api/seller-confirm OS->>DB: Update (status: BookPrepared) OS->>WS: Notify delivery person Note over D,DB: Delivery Collection D->>DUI: Collect from seller DUI->>OS: POST /order/api/update-status OS->>DB: Update (status: BookCollectedFromSeller) OS->>WS: Notify user WS-->>U: Order in transit Note over D,U: Delivery D->>DUI: Mark as delivered DUI->>OS: POST /order/api/deliver OS->>DB: Update (status: AwaitingUserConfirmation) OS->>WS: Notify user Note over U,DB: User Confirmation U->>OS: Confirm receipt OS->>DB: Update (status: Delivered) OS->>DB: Create commission transaction OS->>WS: Notify all parties Note over D,DB: Payment Collection D->>DUI: Collect payment DUI->>OS: POST /order/api/collect-payment OS->>DB: Update (status: PaymentCollected) OS->>DB: Update commission (status: Collected) OS->>DB: Unlock chat for user-seller OS-->>DUI: Payment recorded

Seller Product Management

sequenceDiagram participant S as Seller participant SUI as Seller-UI participant AG as API Gateway participant PS as Product Service participant S3 as AWS S3 participant DB as MongoDB participant Redis as Redis Cache S->>SUI: Create new product SUI->>SUI: Fill product form S->>SUI: Upload images SUI->>AG: POST /product/api/upload-product-image-s3 AG->>PS: Forward upload PS->>S3: Upload images S3-->>PS: Return image URLs PS-->>SUI: Image URLs S->>SUI: Submit product SUI->>AG: POST /product/api/create-product AG->>PS: Create product PS->>PS: Validate data PS->>PS: Generate slug PS->>DB: Insert product PS->>Redis: Invalidate cache PS-->>SUI: Product created SUI-->>S: Show success message S->>SUI: Update product SUI->>AG: PUT /product/api/update-product/:id AG->>PS: Update product PS->>DB: Update record PS->>Redis: Invalidate cache PS-->>SUI: Product updated S->>SUI: Delete product SUI->>AG: DELETE /product/api/delete-product/:id AG->>PS: Soft delete PS->>DB: Set isDeleted=true PS->>Redis: Invalidate cache PS-->>SUI: Product deleted

AI Book Recommendation System

sequenceDiagram participant U as User participant UI as User-UI participant AG as API Gateway participant AI as AI Service participant US as User Service participant PS as Product Service participant DB as MongoDB participant WS as WebSocket Note over U,DB: User Sets Preferences U->>UI: Select preferred categories UI->>AG: PATCH /user/api/update-preferences AG->>US: Update preferences US->>DB: Save preferences US->>AI: Trigger recommendation update AI->>DB: Fetch user preferences AI->>DB: Fetch user history AI->>AI: Train recommendation model AI-->>US: Model updated Note over AI,DB: New Book Added PS->>DB: New product created PS->>AI: Notify new book AI->>DB: Fetch book details AI->>AI: Match with user preferences AI->>DB: Find matching users loop For each matching user AI->>WS: Send book match notification WS-->>UI: new-book-match event UI->>UI: Save to chatbot messages UI->>UI: Show notification UI-->>U: Display recommendation end Note over U,AI: User Browses U->>UI: View product UI->>AG: Track view event AG->>AI: Record interaction AI->>DB: Update user analytics AI->>AI: Refine recommendations

Book Request Workflow

sequenceDiagram participant U as User participant UI as User-UI participant AG as API Gateway participant US as User Service participant A as Admin participant AUI as Admin-UI participant AS as Admin Service participant DB as MongoDB participant Email as Email Service U->>UI: Submit book request UI->>AG: POST /user/api/book-requests AG->>US: Create request US->>DB: Save request (status: Pending) US->>Email: Notify admin US-->>UI: Request created UI-->>U: Show confirmation A->>AUI: View book requests AUI->>AG: GET /admin/api/book-requests AG->>AS: Fetch requests AS->>DB: Query requests DB-->>AS: Return requests AS-->>AUI: Display requests A->>AUI: Update request status AUI->>AG: PUT /admin/api/book-requests/:id AG->>AS: Update request AS->>DB: Update (status: InProgress) AS->>DB: Add admin notes AS->>Email: Notify user AS-->>AUI: Request updated A->>AUI: Mark as found AUI->>AG: PUT /admin/api/book-requests/:id AG->>AS: Mark found AS->>DB: Update (status: Found, isFoundByAdmin: true) AS->>Email: Send details to user AS-->>AUI: Request completed

Trusted Badge Achievement

sequenceDiagram participant S as Seller participant SUI as Seller-UI participant AG as API Gateway participant SS as Seller Service participant OS as Order Service participant DB as MongoDB participant Email as Email Service Note over S,DB: Seller completes orders loop Each order completion OS->>DB: Update order (status: Completed) OS->>SS: Increment seller totalSales SS->>DB: Update seller.totalSales alt totalSales >= 50 AND not trusted SS->>DB: Update seller (isTrusted: true, trustedAt: now) SS->>Email: Send congratulations email SS->>SS: Create notification SS-->>SUI: Badge achieved notification SUI-->>S: Show badge celebration end end S->>SUI: View dashboard SUI->>AG: GET /seller/api/trusted-badge/status AG->>SS: Get badge status SS->>DB: Query seller DB-->>SS: Return seller data SS->>SS: Calculate progress SS-->>SUI: Return status & progress SUI-->>S: Display badge & progress bar

System Architecture

Microservices Architecture Overview

graph TB subgraph "Client Layer" UserUI[User UI
Next.js] SellerUI[Seller UI
Next.js] AdminUI[Admin UI
Next.js] DeliveryUI[Delivery UI
Ionic/React] end subgraph "API Gateway Layer" Gateway[API Gateway
Port 3000
Rate Limiting, Routing] end subgraph "Microservices Layer" Auth[Auth Service
Port 3001
JWT, OAuth] User[User Service
Port 3002
Profiles, Addresses] Product[Product Service
Port 3003
Books, Reviews] Seller[Seller Service
Port 3005
Shops, Analytics] Admin[Admin Service
Port 3006
Management] Chat[Chatting Service
Port 3007
WebSocket] Order[Order Service
Port 3008
Orders, Delivery] AI[AI Service
Port 3014
Recommendations, Chatbot] end subgraph "Data Layer" MongoDB[(MongoDB
Primary Database)] Redis[(Redis
Cache & Sessions)] S3[(AWS S3
File Storage)] end subgraph "External Services" Stripe[Stripe
Payments] Email[SMTP
Email Service] ImageKit[ImageKit
Image CDN] end UserUI --> Gateway SellerUI --> Gateway AdminUI --> Gateway DeliveryUI --> Gateway Gateway --> Auth Gateway --> User Gateway --> Product Gateway --> Seller Gateway --> Admin Gateway --> Chat Gateway --> Order Gateway --> AI Auth --> MongoDB Auth --> Redis User --> MongoDB User --> Redis Product --> MongoDB Product --> Redis Product --> S3 Seller --> MongoDB Seller --> Stripe Admin --> MongoDB Chat --> MongoDB Order --> MongoDB AI --> MongoDB Auth --> Email Product --> ImageKit