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]
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