Documentation

User Access Flow Sequence Diagrams

O2O Online Streamer Advertising Project - User Access Flow Sequence Diagrams

1. Overview

This document provides detailed descriptions of access flows for different user roles in the O2O online streamer advertising project, including sequence diagrams for various operational scenarios involving guests, players, and streamers.

2. Guest User Access Flow

2.1 Guest Browsing Streamer List Flow

sequenceDiagram
    participant U as Guest User
    participant P as Portal Frontend
    participant API as API Service
    participant DB as Database
    participant CACHE as Redis Cache

    U->>P: Visit homepage
    P->>API: GET /api/streamers?page=1
    API->>CACHE: Check cache
    alt Cache hit
        CACHE-->>API: Return cached data
    else Cache miss
        API->>DB: Query streamer list
        DB-->>API: Return streamer data
        API->>CACHE: Update cache
    end
    API-->>P: Return streamer list
    P-->>U: Display streamer card list
    
    U->>P: Click filter conditions
    P->>API: GET /api/streamers?city=Beijing&game=Honor of Kings
    API->>DB: Query by conditions
    DB-->>API: Return filtered results
    API-->>P: Return filtered data
    P-->>U: Update list display

2.2 Guest Viewing Streamer Details Flow

sequenceDiagram
    participant U as Guest User
    participant P as Portal Frontend
    participant API as API Service
    participant DB as Database
    participant ANALYTICS as Analytics Service

    U->>P: Click streamer card
    P->>API: GET /api/streamers/{id}
    API->>DB: Query streamer detailed info
    DB-->>API: Return streamer profile
    API->>ANALYTICS: Record view event
    ANALYTICS->>DB: Update view statistics
    API-->>P: Return streamer details
    P-->>U: Display streamer detail page
    
    U->>P: Click contact streamer
    P-->>U: Prompt login required
    P->>P: Redirect to login page

2.3 Guest Registration Flow

sequenceDiagram
    participant U as Guest User
    participant P as Portal Frontend
    participant API as API Service
    participant RECAPTCHA as reCAPTCHA
    participant DB as Database
    participant MAIL as Email Service

    U->>P: Click register button
    P-->>U: Display registration form
    U->>P: Fill registration info
    P->>RECAPTCHA: Verify human verification
    RECAPTCHA-->>P: Verification passed
    P->>API: POST /api/auth/register
    API->>DB: Check if email exists
    
    alt Email exists
        DB-->>API: Email already registered
        API-->>P: Return error message
        P-->>U: Display email exists
    else Email available
        API->>DB: Create user record
        DB-->>API: User created successfully
        API->>MAIL: Send verification email
        MAIL-->>API: Email sent successfully
        API-->>P: Registration successful
        P-->>U: Prompt to check verification email
    end

3. Player User Access Flow

3.1 Player Login Flow

sequenceDiagram
    participant U as Player User
    participant P as Portal Frontend
    participant API as API Service
    participant AUTH as Auth Service
    participant DB as Database
    participant CACHE as Redis Cache

    U->>P: Enter login credentials
    P->>API: POST /api/auth/login
    API->>AUTH: Verify user credentials
    AUTH->>DB: Query user info
    DB-->>AUTH: Return user data
    
    alt Login successful
        AUTH->>CACHE: Store session info
        AUTH-->>API: Generate JWT Token
        API-->>P: Return Token and user info
        P->>P: Store Token locally
        P-->>U: Redirect to user center
    else Login failed
        AUTH-->>API: Authentication failed
        API-->>P: Return error message
        P-->>U: Display login failure
    end

3.2 Player Booking Streamer Flow

sequenceDiagram
    participant U as Player User
    participant P as Portal Frontend
    participant API as API Service
    participant ORDER as Order Service
    participant PAY as Payment Service
    participant STRIPE as Stripe Payment
    participant DB as Database
    participant NOTIFY as Notification Service

    U->>P: Select streamer and time
    P->>API: POST /api/orders/create
    API->>ORDER: Create order
    ORDER->>DB: Check streamer availability
    
    alt Time conflict
        DB-->>ORDER: Time already booked
        ORDER-->>API: Return conflict info
        API-->>P: Time unavailable
        P-->>U: Prompt to select other time
    else Time available
        ORDER->>DB: Create order record
        DB-->>ORDER: Order created successfully
        ORDER-->>API: Return order info
        API-->>P: Order created successfully
        P-->>U: Redirect to payment page
        
        U->>P: Confirm payment
        P->>API: POST /api/payments/create
        API->>PAY: Create payment
        PAY->>STRIPE: Create payment intent
        STRIPE-->>PAY: Return payment info
        PAY-->>API: Payment created successfully
        API-->>P: Return payment info
        P-->>U: Display payment interface
        
        U->>STRIPE: Complete payment
        STRIPE->>API: Webhook notification
        API->>PAY: Process payment result
        PAY->>ORDER: Update order status
        ORDER->>DB: Update order to paid
        PAY->>NOTIFY: Send notification
        NOTIFY->>U: Send confirmation email
        NOTIFY->>P: Push notification to streamer
    end

3.3 Player Rating Streamer Flow

sequenceDiagram
    participant U as Player User
    participant P as Portal Frontend
    participant API as API Service
    participant REVIEW as Review Service
    participant ORDER as Order Service
    participant DB as Database
    participant ANALYTICS as Analytics Service

    U->>P: Enter order details page
    P->>API: GET /api/orders/{id}
    API->>ORDER: Get order info
    ORDER->>DB: Query order details
    DB-->>ORDER: Return order data
    ORDER-->>API: Order info
    API-->>P: Return order details
    P-->>U: Display order info and review button
    
    U->>P: Click review button
    P-->>U: Display review form
    U->>P: Submit review content
    P->>API: POST /api/reviews/create
    API->>REVIEW: Create review
    REVIEW->>ORDER: Verify order status
    
    alt Order incomplete or already reviewed
        ORDER-->>REVIEW: Order status invalid
        REVIEW-->>API: Return error
        API-->>P: Review failed
        P-->>U: Display error message
    else Can review
        REVIEW->>DB: Create review record
        DB-->>REVIEW: Review created successfully
        REVIEW->>ANALYTICS: Update streamer rating
        ANALYTICS->>DB: Recalculate average score
        REVIEW-->>API: Review successful
        API-->>P: Return success message
        P-->>U: Display review success
    end

4. Streamer User Access Flow

4.1 Streamer Registration and Profile Completion Flow

sequenceDiagram
    participant S as Streamer User
    participant P as Portal Frontend
    participant API as API Service
    participant USER as User Service
    participant STORAGE as Storage Service
    participant MINIO as MinIO Storage
    participant DB as Database
    participant ADMIN as Administrator

    S->>P: Register streamer account
    P->>API: POST /api/auth/register
    API->>USER: Create streamer user
    USER->>DB: Save user info
    DB-->>USER: User created successfully
    USER-->>API: Registration successful
    API-->>P: Return success message
    P-->>S: Redirect to profile completion page
    
    S->>P: Upload avatar and photos
    P->>API: POST /api/upload/images
    API->>STORAGE: Process file upload
    STORAGE->>MINIO: Store files
    MINIO-->>STORAGE: Return file URLs
    STORAGE-->>API: Upload successful
    API-->>P: Return file links
    
    S->>P: Fill detailed profile
    P->>API: PUT /api/streamers/profile
    API->>USER: Update streamer profile
    USER->>DB: Save profile info
    DB-->>USER: Update successful
    USER-->>API: Profile updated successfully
    API-->>P: Return success message
    P-->>S: Prompt awaiting approval
    
    Note over ADMIN: Administrator approval process
    ADMIN->>P: Review streamer profile
    P->>API: PUT /api/admin/streamers/{id}/approve
    API->>USER: Update approval status
    USER->>DB: Update status to approved
    USER->>S: Send approval email

4.2 Streamer Setting Available Time Flow

sequenceDiagram
    participant S as Streamer User
    participant P as Portal Frontend
    participant API as API Service
    participant SCHEDULE as Schedule Service
    participant DB as Database

    S->>P: Enter time management page
    P->>API: GET /api/streamers/schedule
    API->>SCHEDULE: Get current schedule
    SCHEDULE->>DB: Query schedule data
    DB-->>SCHEDULE: Return schedule info
    SCHEDULE-->>API: Schedule data
    API-->>P: Return schedule info
    P-->>S: Display calendar and time slots
    
    S->>P: Set available time
    P->>API: PUT /api/streamers/schedule
    API->>SCHEDULE: Update schedule
    SCHEDULE->>DB: Check time conflicts
    
    alt Time conflict
        DB-->>SCHEDULE: Conflicting orders exist
        SCHEDULE-->>API: Return conflict info
        API-->>P: Time conflict
        P-->>S: Display conflict prompt
    else Time available
        SCHEDULE->>DB: Update available time
        DB-->>SCHEDULE: Update successful
        SCHEDULE-->>API: Schedule updated successfully
        API-->>P: Return success message
        P-->>S: Display update success
    end

4.3 Streamer Purchasing Advertisement Flow

sequenceDiagram
    participant S as Streamer User
    participant A as Admin Backend
    participant API as API Service
    participant AD as Advertisement Service
    participant PAY as Payment Service
    participant STRIPE as Stripe Payment
    participant DB as Database

    S->>A: Login to admin backend
    A->>API: GET /api/ads/packages
    API->>AD: Get ad packages
    AD->>DB: Query package info
    DB-->>AD: Return package data
    AD-->>API: Package info
    API-->>A: Return package list
    A-->>S: Display ad packages
    
    S->>A: Select ad package
    A->>API: POST /api/ads/purchase
    API->>AD: Create ad order
    AD->>DB: Create ad record
    DB-->>AD: Ad created successfully
    AD-->>API: Return ad info
    API-->>A: Ad order created
    A-->>S: Redirect to payment page
    
    S->>A: Confirm payment
    A->>API: POST /api/payments/ads
    API->>PAY: Create ad payment
    PAY->>STRIPE: Create payment intent
    STRIPE-->>PAY: Return payment info
    PAY-->>API: Payment created successfully
    API-->>A: Return payment info
    A-->>S: Display payment interface
    
    S->>STRIPE: Complete payment
    STRIPE->>API: Webhook notification
    API->>PAY: Process payment result
    PAY->>AD: Activate advertisement
    AD->>DB: Update ad status to active
    DB-->>AD: Update successful
    AD-->>API: Ad activation successful
    API-->>A: Push activation notification
    A-->>S: Display ad is now active

5. Agency User Access Flow

5.1 Agency Registration and Sub-account Management Flow

sequenceDiagram
    participant E as Agency User
    participant A as Admin Backend
    participant API as API Service
    participant USER as User Service
    participant AGENCY as Agency Service
    participant DB as Database
    participant EXCEL as Excel Processing

    E->>A: Agency registration
    A->>API: POST /api/auth/register/agency
    API->>USER: Create agency user
    USER->>DB: Save agency info
    DB-->>USER: Agency created successfully
    USER-->>API: Registration successful
    API-->>A: Return success message
    A-->>E: Redirect to agency management page
    
    E->>A: Batch import sub-accounts
    A->>API: POST /api/agency/import-excel
    API->>EXCEL: Parse Excel file
    EXCEL-->>API: Return user data
    API->>AGENCY: Batch create sub-accounts
    
    loop Each sub-account
        AGENCY->>DB: Check if email exists
        alt Email exists
            DB-->>AGENCY: Email conflict
            AGENCY-->>API: Rollback all operations
            API-->>A: Import failed
            A-->>E: Display conflicting emails
        else Email available
            AGENCY->>DB: Create sub-account
            DB-->>AGENCY: Creation successful
        end
    end
    
    AGENCY-->>API: Batch import successful
    API-->>A: Return success message
    A-->>E: Display import results

5.2 Agency Managing Sub-account Advertisement Flow

sequenceDiagram
    participant E as Agency User
    participant A as Admin Backend
    participant API as API Service
    participant AGENCY as Agency Service
    participant AD as Advertisement Service
    participant PAY as Payment Service
    participant DB as Database

    E->>A: View sub-account list
    A->>API: GET /api/agency/sub-accounts
    API->>AGENCY: Get sub-accounts
    AGENCY->>DB: Query agency's sub-accounts
    DB-->>AGENCY: Return sub-account list
    AGENCY-->>API: Sub-account data
    API-->>A: Return sub-account info
    A-->>E: Display sub-account management page
    
    E->>A: Purchase ads for sub-account
    A->>API: POST /api/agency/ads/purchase
    API->>AGENCY: Verify agency permissions
    AGENCY->>DB: Check sub-account ownership
    
    alt Sub-account doesn't belong to agency
        DB-->>AGENCY: Insufficient permissions
        AGENCY-->>API: Return permission error
        API-->>A: Permission verification failed
        A-->>E: Display permission error
    else Permission verified
        AGENCY->>AD: Create sub-account ad
        AD->>DB: Create ad record
        DB-->>AD: Ad created successfully
        AD->>PAY: Create payment order
        PAY-->>AD: Payment order created
        AD-->>API: Ad order successful
        API-->>A: Return order info
        A-->>E: Redirect to payment page
    end
    
    E->>A: Manage sub-account ad on/off
    A->>API: PUT /api/agency/ads/{id}/toggle
    API->>AGENCY: Verify management permissions
    AGENCY->>AD: Toggle ad status
    AD->>DB: Update ad status
    DB-->>AD: Status updated successfully
    AD-->>API: Operation successful
    API-->>A: Return success message
    A-->>E: Display status update

6. Error Handling and Exception Flow

6.1 Network Exception Handling Flow

sequenceDiagram
    participant U as User
    participant P as Portal Frontend
    participant API as API Service
    participant RETRY as Retry Mechanism
    participant FALLBACK as Fallback Service

    U->>P: Initiate request
    P->>API: HTTP request
    
    alt Network timeout
        API--xP: Request timeout
        P->>RETRY: Trigger retry mechanism
        RETRY->>API: Resend request
        
        alt Retry successful
            API-->>RETRY: Return data
            RETRY-->>P: Request successful
            P-->>U: Display normal results
        else Retry failed
            API--xRETRY: Still failed
            RETRY->>FALLBACK: Enable fallback service
            FALLBACK-->>P: Return cached data
            P-->>U: Display cached content + network error prompt
        end
    else Server error
        API-->>P: Return 500 error
        P->>P: Log error
        P-->>U: Display friendly error message
    end

6.2 Payment Exception Handling Flow

sequenceDiagram
    participant U as User
    participant P as Portal Frontend
    participant API as API Service
    participant PAY as Payment Service
    participant STRIPE as Stripe Payment
    participant DB as Database
    participant NOTIFY as Notification Service

    U->>P: Initiate payment
    P->>API: Create payment order
    API->>PAY: Process payment request
    PAY->>STRIPE: Call Stripe API
    
    alt Stripe service exception
        STRIPE--xPAY: Service unavailable
        PAY->>DB: Record payment failure
        PAY-->>API: Payment service exception
        API-->>P: Return payment failure
        P-->>U: Display payment failed, suggest retry later
    else Payment declined
        STRIPE-->>PAY: Payment declined
        PAY->>DB: Record decline reason
        PAY-->>API: Payment declined
        API-->>P: Return decline info
        P-->>U: Display decline reason and solution suggestions
    else Payment timeout
        STRIPE--xPAY: Payment timeout
        PAY->>DB: Record timeout status
        PAY->>NOTIFY: Send async query task
        PAY-->>API: Payment status unknown
        API-->>P: Return processing status
        P-->>U: Display payment processing, check results later
        
        Note over NOTIFY: Async query payment result
        NOTIFY->>STRIPE: Query payment status
        STRIPE-->>NOTIFY: Return final status
        NOTIFY->>PAY: Update payment status
        PAY->>DB: Update order status
        NOTIFY->>U: Send payment result notification
    end

7. Security Verification Flow

7.1 reCAPTCHA Verification Flow

sequenceDiagram
    participant U as User
    participant P as Portal Frontend
    participant RECAPTCHA as reCAPTCHA Service
    participant API as API Service
    participant SECURITY as Security Service

    U->>P: Submit form (register/login/contact)
    P->>RECAPTCHA: Request human verification
    RECAPTCHA-->>P: Return verification challenge
    P-->>U: Display verification interface
    
    U->>RECAPTCHA: Complete verification challenge
    RECAPTCHA-->>P: Return verification token
    P->>API: Submit form + verification token
    API->>SECURITY: Verify reCAPTCHA token
    SECURITY->>RECAPTCHA: Server-side token verification
    
    alt Verification passed
        RECAPTCHA-->>SECURITY: Verification successful
        SECURITY-->>API: Human verification passed
        API->>API: Continue business logic processing
        API-->>P: Return processing result
        P-->>U: Display operation success
    else Verification failed
        RECAPTCHA-->>SECURITY: Verification failed
        SECURITY-->>API: Human verification failed
        API-->>P: Return verification failure
        P-->>U: Request re-verification
    end

8. Session Management Flow

8.1 JWT Token Refresh Flow

sequenceDiagram
    participant U as User
    participant P as Portal Frontend
    participant API as API Service
    participant AUTH as Auth Service
    participant CACHE as Redis Cache

    U->>P: Initiate API request
    P->>API: Carry JWT Token
    API->>AUTH: Verify Token
    
    alt Token valid
        AUTH-->>API: Token verification passed
        API->>API: Process business request
        API-->>P: Return business data
        P-->>U: Display request results
    else Token about to expire
        AUTH-->>API: Token about to expire
        API->>AUTH: Auto refresh Token
        AUTH->>CACHE: Check refresh Token
        CACHE-->>AUTH: Return refresh Token
        AUTH->>AUTH: Generate new access Token
        AUTH->>CACHE: Update Token cache
        AUTH-->>API: Return new Token
        API-->>P: Return data + new Token
        P->>P: Update local Token
        P-->>U: Display request results
    else Token expired
        AUTH-->>API: Token expired
        API-->>P: Return 401 unauthorized
        P->>P: Clear local Token
        P-->>U: Redirect to login page
    end

9. Flow Optimization Recommendations

9.1 Performance Optimization

  • Implement request caching strategies to reduce duplicate API calls

  • Use CDN to accelerate static resource loading

  • Implement lazy loading for on-demand content loading

  • Optimize database queries using indexes and query optimization

9.2 User Experience Optimization

  • Add loading status indicators

  • Implement offline caching functionality

  • Provide friendly error messages

  • Optimize mobile responsive design

9.3 Security Enhancement

  • Implement API access rate limiting

  • Strengthen input validation and SQL injection protection

  • Regularly update security certificates

  • Monitor abnormal access patterns