CMPE 451 ‐ Sequence Diagrams - bounswe/bounswe2024group6 GitHub Wiki

Auth

Create Account

sequenceDiagram
  actor User
  participant RegistrationService
  participant Database
  User->> RegistrationService: createAccount(username, email, password, user_level)
  activate RegistrationService
  RegistrationService->>Database: Credentials
  activate Database
  alt success
    Database-->>RegistrationService: Success
    RegistrationService-->>User: Success
  else username/email exists
    Database-->>RegistrationService: Failure
    deactivate Database
    RegistrationService-->>User: Failure
    deactivate RegistrationService
  end
Loading

Login

sequenceDiagram
  actor User
  participant AuthService
  participant Database
  User->>AuthService: login(email, password)
  activate AuthService
  AuthService->>Database: Verify Credentials
  activate Database
  
  alt success
    Database-->>AuthService: UserData
    AuthService->>TokenService: Generate JWT (userData)
    activate TokenService
    TokenService-->>AuthService: JWT
    deactivate TokenService
    AuthService-->>User: Success<JWT>
  else failure
    Database-->>AuthService: no match
    deactivate Database
    AuthService-->>User: UnauthorizedError
  end
  
  deactivate AuthService
Loading

Logout

sequenceDiagram
  actor User
  participant AuthService
  participant Database
  User->>AuthService: logout(JWT)
  activate AuthService
  
  alt JWT is valid
    AuthService->>Database: Invalidate Token
    activate Database
    Database-->>AuthService: TokenInvalidatedMessage
    deactivate Database
    AuthService-->>User: Success
  else JWT is invalid/expired
    AuthService-->>User: UnauthorizedError
  end
  
  deactivate AuthService
Loading

Feed

Quiz Feed

sequenceDiagram
  actor User
  participant QuizFeedService
  participant Database
  User->>QuizFeedService: viewQuizFeed(userId)
  activate QuizFeedService
  
  QuizFeedService->>Database: FetchRecentQuizResults(userId)
  activate Database
  Database-->>QuizFeedService: RecentQuizResults
  deactivate Database

  QuizFeedService->>Database: FetchFollowedUsers(userId)
  activate Database
  Database-->>QuizFeedService: FollowedUsersList
  deactivate Database
  
  QuizFeedService->>Database: FetchQuizzesByLevel(userLevel)
  activate Database
  Database-->>QuizFeedService: QuizzesList
  deactivate Database

  QuizFeedService->>QuizFeedService: ProcessQuizFeed(RecentQuizResults, FollowedUsersList, QuizzesList)
  QuizFeedService-->>User: DisplayQuizFeed(customized quizzes)
  deactivate QuizFeedService

Loading

Forum Feed

sequenceDiagram
  actor User
  participant ForumFeedService
  participant Database
  User->>ForumFeedService: viewForumFeed(userId)
  activate ForumFeedService
  ForumFeedService->>Database: FetchFollowedUsersPosts(userId)
  activate Database
  Database-->>ForumFeedService: FollowedUsersPosts
  deactivate Database
  ForumFeedService->>Database: FetchGeneralPosts()
  activate Database
  Database-->>ForumFeedService: GeneralPosts
  deactivate Database
  ForumFeedService->>ForumFeedService: ApplyRankingAlgorithm(followedUsersOnTop)
  ForumFeedService-->>User: DisplayForumFeed(ranked posts)
  deactivate ForumFeedService
Loading

Post

Create Post

    sequenceDiagram
  actor User
  participant PostService
  participant Database
  
  User->>PostService: createPost(userId, postTitle, postContent)
  activate PostService
  PostService->>Database: checkUserExists(userId)
  activate Database
  
  alt user exists
    Database-->>PostService: Success
    PostService->>Database: createNewPost(userId, postTitle, postContent)
    
    alt post creation successful
      Database-->>PostService: Post Created
      PostService-->>User: Post Created
    else post creation failed
      Database-->>PostService: Error (Post Not Created)
      PostService-->>User: Post Not Created
    end
    
  else user not found
    Database-->>PostService: Error (User Not Found)
    PostService-->>User: User Not Found
  end
  deactivate Database
  deactivate PostService

Loading

Delete Post (Only Admin)

sequenceDiagram
  actor User
  participant PostService
  participant Database

  User->>PostService: deletePost(userId, postId)
  activate PostService
  PostService->>Database: verifyAdmin(userId)
  activate Database
  
  alt user is an admin
    Database-->>PostService: Admin Verified
    PostService->>Database: deletePost(postId)
    alt deletion successful
      Database-->>PostService: Post Deleted
      PostService-->>User: Post Deleted
    else deletion failed
      Database-->>PostService: Error (Post Not Deleted)
      PostService-->>User: Post Not Deleted
    end
  else user is not an admin
    Database-->>PostService: Error (Not Authorized)
    PostService-->>User: Not Authorized
  end
  
  deactivate Database
  deactivate PostService

Loading

Add Tags To Post

  sequenceDiagram
  actor User
  participant PostService
  participant Database
  
  User->>PostService: addTagsToPost(userId, postId, tags)
  activate PostService
  PostService->>Database: checkPostOwnership(userId, postId)
  activate Database
  
  alt post belongs to user
    Database-->>PostService: Success
    PostService->>Database: addTags(postId, tags)
    
    alt tags added successfully
      Database-->>PostService: Tags Added
      PostService-->>User: Tags Added Successfully
    else tags addition failed
      Database-->>PostService: Error (Tags Not Added)
      PostService-->>User: Tags Not Added
    end
    
  else post does not belong to user
    Database-->>PostService: Error (Unauthorized)
    PostService-->>User: Unauthorized
  end
  deactivate Database
  deactivate PostService
Loading

Remove Tags From Post

  sequenceDiagram
  actor User
  participant PostService
  participant Database
  
  User->>PostService: removeTagsFromPost(userId, postId, tags)
  activate PostService
  PostService->>Database: checkPostOwnership(userId, postId)
  activate Database
  
  alt post belongs to user
    Database-->>PostService: Success
    PostService->>Database: removeTags(postId, tags)
    
    alt tags removed successfully
      Database-->>PostService: Tags Removed
      PostService-->>User: Tags Removed Successfully
    else tags removal failed
      Database-->>PostService: Error (Tags Not Removed)
      PostService-->>User: Tags Not Removed
    end
    
  else post does not belong to user
    Database-->>PostService: Error (Unauthorized)
    PostService-->>User: Unauthorized
  end
  deactivate Database
  deactivate PostService
Loading

Like/Unlike Post

  sequenceDiagram
  actor User
  participant PostService
  participant Database
  
  User->>PostService: votePost(userId, postId, voteType)
  activate PostService
  PostService->>Database: checkPostExists(postId)
  activate Database
  
  alt post exists
    Database-->>PostService: Success
    PostService->>Database: applyVote(userId, postId, voteType)
    
    alt vote applied successfully
      Database-->>PostService: Vote Applied
      PostService-->>User: Vote Recorded
    else vote failed
      Database-->>PostService: Error (Vote Failed)
      PostService-->>User: Vote Failed
    end
    
  else post does not exist
    Database-->>PostService: Error (Post Not Found)
    PostService-->>User: Post Not Found
  end
  deactivate Database
  deactivate PostService
Loading

Comment

Create Comment

sequenceDiagram
  actor User
  participant CommentService
  participant Database
  User->> CommentService: createComment(content, userId, postId)
  activate CommentService
  CommentService->>Database: StoreComment(content, userId, postId)
  activate Database
  alt success
    Database-->>CommentService: Success(commentId)
    CommentService-->>User: CommentCreatedSuccess(commentId)
  else failure (e.g., database error)
    Database-->>CommentService: Failure
    deactivate Database
    CommentService-->>User: CommentCreationFailure
    deactivate CommentService
  end


Loading

Delete Comment

sequenceDiagram
  actor User
  participant CommentService
  participant Database
  User->> CommentService: deleteComment(commentId, userId)
  activate CommentService
  CommentService->>Database: MarkAsDeleted(commentId, userId)
  activate Database
  alt success
    Database-->>CommentService: Success
    CommentService-->>User: CommentDeletedSuccess
  else failure (e.g., post not found or unauthorized)
    Database-->>CommentService: Failure
    deactivate Database
    CommentService-->>User: CommentDeletionFailure
    deactivate CommentService
  end
Loading

Like/Unlike Comment

sequenceDiagram
  actor User
  participant VoteService
  participant Database
  User->>VoteService: voteComment(commentId, userId, vote)
  activate VoteService
  VoteService->>Database: CheckVotePermissions(commentId, userId)
  activate Database
  alt authorized
    Database-->>VoteService: Authorized
    VoteService->>Database: RecordVote(commentId, userId, vote)
    alt success
      Database-->>VoteService: VoteRecordedSuccess
      VoteService-->>User: VoteSuccess
    else failure (e.g., database error)
      Database-->>VoteService: VoteRecordFailure
      VoteService-->>User: VoteFailure
    end
  else unauthorized
    Database-->>VoteService: Unauthorized
    VoteService-->>User: UnauthorizedError
  end
  deactivate Database
  deactivate VoteService
Loading

Bookmark Comment

sequenceDiagram
  actor User
  participant CommentService
  participant Database
  
  User->>CommentService: bookmarkComment(userId, commentId)
  CommentService->>Database: checkIfCommentExists(commentId)
  
  alt comment exists
    Database-->>CommentService: Comment Found
    CommentService->>Database: bookmarkComment(userId, commentId)
    Database-->>CommentService: Comment Added to Bookmarks
    CommentService-->>User: Comment Added to Bookmarks Successfully
    
  else comment does not exist
    Database-->>CommentService: Comment Not Found
    CommentService-->>User: Comment Not Found
  end
Loading

Quizzes

Create Quiz

sequenceDiagram
  actor User
  participant QuizService
  participant Database
  participant LexvoService
  
  User->>QuizService: createQuiz(userId, quizTitle, questionType)
  QuizService->>Database: checkUserPermissions(userId)
  
  alt user has permissions
    Database-->>QuizService: Success
    
    loop Add Questions
      QuizService->>LexvoService: fetchAnswerOptions(questionType, question)
      LexvoService-->>QuizService: answerOptions
      QuizService->>Database: addQuestionToQuiz(userId, quizTitle, answerOptions)
      Database-->>QuizService: Question Added
    end
    
    QuizService-->>User: Quiz Created Successfully
    
  else user lacks permissions
    Database-->>QuizService: Permission Denied
    QuizService-->>User: Permission Denied
  end

Loading

Solve Quiz

sequenceDiagram
  actor User
  participant QuizService
  participant Database
  
  User->>QuizService: solveQuiz(userId, quizId)
  QuizService->>Database: getQuiz(quizId)
  
  alt quiz exists
    Database-->>QuizService: quizData

    loop Answer Questions
      User->>QuizService: submitAnswer(questionId, answer)

      alt user cancels quiz
        QuizService-->>User: Quiz Aborted
        note right of QuizService: End of quiz session
      else continue answering
        QuizService->>QuizService: collectAnswers(answer)
      end
    end

    QuizService->>QuizService: calculateResult(collectedAnswers)
    QuizService->>Database: saveQuizResult(userId, quizId, result)
    Database-->>QuizService: Result Saved
    QuizService-->>User: Quiz Completed with Result
  end
  
  alt quiz does not exist
    Database-->>QuizService: Quiz Not Found
    QuizService-->>User: Quiz Not Found
  end


Loading

Delete Quiz (Only Admin)

sequenceDiagram
  actor Admin
  participant QuizService
  participant Database
  
  Admin->>QuizService: deleteQuiz(adminId, quizId)
  QuizService->>Database: checkAdminPermissions(adminId)
  
  alt admin has permissions
    Database-->>QuizService: Success
    QuizService->>Database: deleteQuiz(quizId)
    Database-->>QuizService: Quiz Deleted
    QuizService-->>Admin: Quiz Deleted Successfully
    
  else admin lacks permissions
    Database-->>QuizService: Permission Denied
    QuizService-->>Admin: Permission Denied
  end
Loading

Bookmark Quiz

sequenceDiagram
  actor User
  participant QuizService
  participant Database
  
  User->>QuizService: bookmarkQuiz(userId, quizId)
  QuizService->>Database: checkIfQuizExists(quizId)
  
  alt quiz exists
    Database-->>QuizService: Quiz Found
    QuizService->>Database: bookmarkQuiz(userId, quizId)
    Database-->>QuizService: Quiz Added to Bookmarks
    QuizService-->>User: Quiz Added to Bookmarks Successfully
    
  else quiz does not exist
    Database-->>QuizService: Quiz Not Found
    QuizService-->>User: Quiz Not Found
  end
Loading

Remove Quiz from Bookmarks

sequenceDiagram
  actor User
  participant QuizService
  participant Database
  
  User->>QuizService: removeQuizFromBookmarks(userId, quizId)
  QuizService->>Database: checkIfBookmarkExists(userId, quizId)
  
  alt quiz is in bookmarks
    Database-->>QuizService: Quiz Found in Bookmarks
    QuizService->>Database: removeQuizFromBookmarks(userId, quizId)
    Database-->>QuizService: Quiz Removed from Bookmarks
    QuizService-->>User: Quiz Removed from Bookmarks Successfully
    
  else quiz is not in bookmarks
    Database-->>QuizService: Quiz Not Found in Bookmarks
    QuizService-->>User: Quiz Not in Bookmarks
  end

Loading

Search

Search Quizzes and Posts

sequenceDiagram
  actor User
  participant SearchService
  participant Database
  participant LexvoService
  
  User->>SearchService: searchContent(userId, searchCriteria)
  SearchService->>Database: checkUserExists(userId)
  
  alt user exists
    Database-->>SearchService: User Found
    
    SearchService->>LexvoService: fetchLexvoData(searchCriteria)
    
    alt Lexvo responses received
      LexvoService-->>SearchService: lexvoData
      
      par searchPosts
        SearchService->>Database: queryPosts(lexvoData)
        alt posts found
          Database-->>SearchService: relevantPosts
        else no posts found
          Database-->>SearchService: No relevant posts
        end
      and searchQuizzes
        SearchService->>Database: fetchQuizzes(lexvoData)
        alt quizzes found
          Database-->>SearchService: quizList
        else no quizzes found
          Database-->>SearchService: No quizzes found
        end
      end
      
      alt posts or quizzes found
        SearchService-->>User: Display relevantPosts and quizList
      else no content found
        SearchService-->>User: No relevant content found
      end
    
    else error in semantic search
      SearchService-->>User: Error in semantic search
    end
    
  else user not found
    Database-->>SearchService: User Not Found
    SearchService-->>User: User Not Found
  end
Loading

Profile

View Profile

sequenceDiagram
  actor User
  participant ProfileService
  participant Database
  User->>ProfileService: viewProfile(profileId, viewerId)
  activate ProfileService
  ProfileService->>Database: FetchProfileData(profileId)
  activate Database
  alt profile found
    Database-->>ProfileService: ProfileData(profileId + visibility settings)
    ProfileService->>ProfileService: CheckProfileVisibility(profileId, viewerId)
    alt authorized to view
      ProfileService-->>User: DisplayProfile(profile data)
    else unauthorized to view
      ProfileService-->>User: UnauthorizedError
    end
  else profile not found
    Database-->>ProfileService: ProfileNotFound
    deactivate Database
    ProfileService-->>User: ProfileNotFoundError
  end
  deactivate ProfileService
Loading

Update Profile

sequenceDiagram
  actor User
  participant ProfileService
  participant Database
  User->>ProfileService: updateProfile(profileId, newProfileData, userId)
  activate ProfileService
  ProfileService->>Database: CheckUpdatePermissions(profileId, userId)
  activate Database
  alt authorized to update
    Database-->>ProfileService: Authorized
    ProfileService->>Database: UpdateProfileData(profileId, newProfileData)
    alt update success
      Database-->>ProfileService: UpdateSuccess
      ProfileService-->>User: ProfileUpdateSuccess
    else update failure (e.g., database error)
      Database-->>ProfileService: UpdateFailure
      ProfileService-->>User: ProfileUpdateFailure
    end
  else unauthorized
    Database-->>ProfileService: UnauthorizedError
    deactivate Database
    ProfileService-->>User: UnauthorizedError
  end
  deactivate ProfileService
Loading

Follow Other Users

sequenceDiagram
  actor User
  participant FollowService
  participant Database
  User->>FollowService: followUser(followerId, followeeId)
  activate FollowService
  FollowService->>Database: RecordFollow(followerId, followeeId)
  activate Database
  alt follow success
    Database-->>FollowService: FollowSuccess
    FollowService-->>User: FollowSuccess
  else follow failure (e.g., database error)
    Database-->>FollowService: FollowFailure
    FollowService-->>User: FollowFailure
  end
  deactivate Database
  deactivate FollowService
Loading

Unfollow Other Users

sequenceDiagram
  actor User
  participant FollowService
  participant Database
  User->>FollowService: unfollowUser(followerId, followeeId)
  activate FollowService
  FollowService->>Database: RemoveFollow(followerId, followeeId)
  activate Database
  alt unfollow success
    Database-->>FollowService: UnfollowSuccess
    FollowService-->>User: UnfollowSuccess
  else unfollow failure (e.g., database error)
    Database-->>FollowService: UnfollowFailure
    FollowService-->>User: UnfollowFailure
  end
  deactivate Database
  deactivate FollowService
Loading
⚠️ **GitHub.com Fallback** ⚠️