451 ‐ Design Diagrams - bounswe/bounswe2024group9 GitHub Wiki

Class Diagram

1.1

classDiagram
    class User {
        -user_id: int
        -username: string
        -email: string
        -password: string
        -posts: Post[]
        -comments: Comment[]
        -bookmarks: Bookmark[]
        -profile: Profile

        +User(int user_id, string username, string email, string password)
        +view_post_details(int post_id): Post
        +comment(int post_id, string text, string code): Comment
        +run_snippet(string code): string
        +viewProfile(): Profile
        +editProfile(Profile): bool
        +deleteAccount(): bool
    }

    class Post {
        -post_id: int
        -post_title: string
        -post_details: string
        -post_code_snippet: string
        -labels: string[]
        -comments: Comment[]

        +Post(int post_id, string title, string details, string snippet, string[] labels)
        +run_snippet(string code): string
        +add_comment(Comment): void
    }

    class Comment {
        -comment_id: int
        -post_id: int
        -user_id: int
        -text: string
        -code_snippet: string

        +Comment(int comment_id, int post_id, int user_id, string text, string snippet)
        +editComment(string newText, string newCode): bool
    }

    class CodeExecutionApi {
        +run_snippet(string code): string
    }

    class SearchQuery {
        +queryText: string
        +filters: FilterOptions
        +executeSearch(): SearchResult[]
    }

    class FilterOptions {
        +dateRange: DateRange
        +languages: string[]
        +tags: string[]

        +FilterOptions(DateRange dateRange, string[] languages, string[] tags)
        +applyFilters(): void
    }

    class ProgrammingLanguage {
        +languageName: string
        +languageDesigner: string
        +languageFoundationDate: string
        +languageImage: Image
        +languageDescription: string

        +ProgrammingLanguage(string name, string designer, string date, Image img, string desc)
        +getSimilars(languageName: string): List[string]
    }

    class DateRange {
        +startDate: Date
        +endDate: Date

        +DateRange(Date start, Date end)
    }

    class UserController {
        +signUp(string name, string email, string password): bool
        +logIn(string email, string password): Session
        +logOut(Session): bool
        +viewProfile(User): Profile
        +editProfile(User, Profile): bool
        +deleteAccount(User): bool
        +viewQuestions(User): Post[]
        +viewComments(User): Comment[]
        +viewBookmarks(User): Bookmark[]
        +editQuestion(User, Question): bool
        +deleteQuestion(User, Question): bool
        +editComment(User, Comment): bool
        +deleteComment(User, Comment): bool
        +unbookmark(User, Post): bool
        +updateName(User, string name): bool
        +updatePassword(User, string password): bool
        +updateProfilePicture(User, Image): bool
    }

    class PrivateDatabase {
        +checkIfEmailExists(string email): bool
        +saveUser(User): bool
        +checkUser(string email, string password): bool
        +createSession(User): Session
        +invalidateSession(Session): bool
        +fetchProfileData(User): Profile
        +getQuestions(User): Post[]
        +getComments(User): Comment[]
        +getBookmarks(User): Bookmark[]
        +editQuestion(User, Question): bool
        +deleteQuestion(User, Question): bool
        +editComment(User, Comment): bool
        +deleteComment(User, Comment): bool
        +deleteBookmark(User, Post): bool
        +updateName(User, string name): bool
        +updatePassword(User, string password): bool
        +updateProfilePicture(User, Image): bool
        +deleteUser(User): bool
    }

    class Session {
        -session_id: int
        -user_id: int
        -startTime: DateTime
        -endTime: DateTime

        +Session(int session_id, int user_id, DateTime start, DateTime end)
        +isValid(): bool
    }

    class Profile {
        -profile_id: int
        -user_id: int
        -profile_picture: Image
        -bio: string
        -additional_info: string

        +Profile(int profile_id, int user_id, Image pic, string bio, string info)
        +updateProfilePicture(Image): bool
        +removeProfilePicture(): bool
        +updateBio(string bio): bool
    }

    class Bookmark {
        -bookmark_id: int
        -user_id: int
        -post_id: int

        +Bookmark(int bookmark_id, int user_id, int post_id)
        +addBookmark(Post): bool
        +removeBookmark(Post): bool
    }

    class Image {
        -image_id: int
        -url: string
        -metadata: string

        +Image(int image_id, string url, string metadata)
        +uploadImage(string path): bool
        +deleteImage(): bool
    }

    User --> Post : views/posts/comments
    User --> SearchQuery : initiates
    SearchQuery --> Post : returns
    SearchQuery --> ProgrammingLanguage : returns
    ProgrammingLanguage --> ProgrammingLanguage : related to
    Post --> CodeExecutionApi : runs snippet
    Post --> Comment : contains comments
    User --> Profile : has
    User --> Bookmark : bookmarks
    User --> Session : has
    UserController --> PrivateDatabase : interacts with
    UserController --> User : manages
    UserController --> Session : manages
    PrivateDatabase --> User : stores
    PrivateDatabase --> Post : stores
    PrivateDatabase --> Comment : stores
    PrivateDatabase --> Profile : stores
    PrivateDatabase --> Bookmark : stores
    PrivateDatabase --> Session : stores
    Profile --> Image : has
    Bookmark --> Post : references

Use Case Diagrams

2.1 Post Details & Code Execution

by Kristina, Serhan

flowchart 
  User --> ViewPost;
  ViewPost-->ExecuteCodeSnippet;
  ViewPost-->Comment;
  ViewPost-->Report
  Comment-->AddCommentDescription;
  Comment-->AddCodeSnippet;
  ViewPost-->UpvoteDownvote
  

2.2 Post Creation

_by Damla

flowchart 
 User --> CreatePost;
 CreatePost-->AddTitle;
 CreatePost-->AddBody;
 CreatePost-->SpecifyLanguage;
 CreatePost-->SpecifyLabel;
 CreatePost-->Comment
 AddBody-->AddCodeSnippet

2.3 Browsing Programming Languages

by Eray

flowchart
    User --> SearchLanguages
    User --> FilterLanguages
    User --> ViewQuestionsAboutLanguage

    SearchLanguages --> Browser
    Browser --> GetWordsFromAPI
    Browser --> GetLanguageDetails

    GetWordsFromAPI --> WikidataAPI
    GetLanguageDetails --> WikidataAPI

    ViewQuestionsAboutLanguage --> LanguageController
    LanguageController --> ShowLanguageDetails
    LanguageController --> ShowRelatedPosts

    ShowLanguageDetails --> WikidataAPI
    ShowRelatedPosts --> WikidataAPI

    FilterLanguages --> LanguageController
    FilterLanguages --> ViewQuestionsAboutLanguage

    LanguageController --> FilteredPosts

2.4 Profile

by Emin

flowchart
    User --> SeeProfilePicture
    User --> ListQuestions
    User --> ListComments
    User --> ListBookmarks
    User --> EditProfileInfo
    User --> DeleteAccount
    ListQuestions --> EditQuestions
    ListQuestions --> DeleteQuestions
    ListComments --> EditComments
    ListComments --> DeleteComments
    ListBookmarks --> Unbookmark
    EditProfileInfo --> EditName
    EditProfileInfo --> EditPassword
    EditProfileInfo --> EditProfilePicture
    EditProfilePicture --> RemovePicture

2.5 Signup, Login, Logout

by Emin

flowchart
    User["Guest User"] --> SignUp["Sign Up"]
    SignUp --> CheckEmail["Is Email Registered?"]
    CheckEmail --> SignUpFailed["Sign-Up Failed: Email already registered"]
    CheckEmail --> SaveUser["Save User"]
    SaveUser --> SignUpSuccess["Sign-Up Successful"]

    User --> Login["Log In"]
    Login --> CheckCredentials["Are Credentials Valid?"]
    CheckCredentials --> LoginFailed["Login Failed: Invalid email or password"]
    CheckCredentials --> CreateSession["Create Session"]
    CreateSession --> LoginSuccess["Login Successful"]

    RegisteredUser --> Logout["Log Out"]
    Logout --> InvalidateSession["Invalidate Session"]
    InvalidateSession --> LoggedOut["User Logged Out"]

2.6 Feed

by Halil, Ceylin

flowchart TD
    %% Loading the feed
    User([User]) --> LoadFeed[Load Feed]
    LoadFeed --> FetchPosts[Fetch Posts from Database]
    FetchPosts --> DecisionSuccess{Posts Loaded Successfully?}
    DecisionSuccess -->|Yes| DisplayPosts[Display Posts in Feed]
    DecisionSuccess -->|No| ShowError[Show Error Message]

    %% Display and filter logic
    DisplayPosts --> DecisionFilter{Apply Filters/Sorting?}
    DecisionFilter -->|Yes| GetFilters[Get Filter/Sort Criteria]
    GetFilters --> ApplyFilter[Apply Filters/Sorting]
    ApplyFilter --> FetchPosts
    
    DecisionFilter -->|No| WaitForAction[Wait for User Action]

    %% Handling post click or interactions
    WaitForAction --> DecisionPostClick{User Clicks a Post?}
    DecisionPostClick -->|Yes| ShowPost[Show Post Details]
    DecisionPostClick -->|No| DecisionInteraction{Upvote, Downvote?}
    
    %% Handling other interactions like like/comment/share
    DecisionInteraction -->|Yes| PerformAction[Perform Upvote, Downvote]
    PerformAction --> WaitForAction
    DecisionInteraction -->|No| WaitForAction

    %% Post details and returning to main feed
    ShowPost --> WaitForAction

Sequence Diagrams

3.1 Code Execution

by Kristina

sequenceDiagram
   participant User
   participant Post
   participant CodeExecutionApi
   
   User->>Post: runCodeSnippet()
   Post->>CodeExecutionApi: run_snippet(string code)
   CodeExecutionApi-->>Post: string output
   Post-->>User: displayOutput(output)

3.2 Commenting

by Damla, Serhan

sequenceDiagram
   participant User
   participant PostDetailsPage
   participant CommentDatabase
   
alt Add Comment
    User ->> PostDetailsPage: writeComment()
    PostDetailsPage ->> CommentDatabase: storeComment()
    CommentDatabase -->> PostDetailsPage: commentStored()
    PostDetailsPage -->> User: displayComment()
end

alt Edit Comment
    User ->> PostDetailsPage: editComment()
    PostDetailsPage ->> CommentDatabase: updateCommentInDB()
    CommentDatabase -->> PostDetailsPage: commentUpdated()
    PostDetailsPage -->> User: displayUpdatedComment()
end

alt Delete Comment
    User ->> PostDetailsPage: deleteComment()
    PostDetailsPage ->> CommentDatabase: deleteCommentFromDB()
    CommentDatabase -->> PostDetailsPage: commentDeleted()
    PostDetailsPage -->> User: confirmCommentDeletion()
end

3.3 Browsing Programming Languages

by Mutti

sequenceDiagram
    User ->> ProgrammingLanguage: ViewDetails
    ProgrammingLanguage-->>User: Show Language
    ProgrammingLanguage->>WikidataAPI: Get Details
    WikidataAPI-->>ProgrammingLanguage: Metadata 

3.4 Profile Page

by Emin

sequenceDiagram
    participant User
    participant UserController
    participant PrivateDatabase
    
    alt DisplayProfile
        User ->> UserController: viewProfile()
        UserController ->> PrivateDatabase: fetchProfileData(User)
        PrivateDatabase -->> UserController: ProfileData
        UserController -->> User: ProfileData
    end
    
    alt GetQuestions
        User ->> UserController: viewQuestions()
        UserController ->> PrivateDatabase: getQuestions(User)
        PrivateDatabase -->> UserController: Questions
        UserController -->> User: Questions
    end
    
    alt GetComments
        User ->> UserController: viewComments()
        UserController ->> PrivateDatabase: getComments(User)
        PrivateDatabase -->> UserController: Comments
        UserController -->> User: Comments
    end
    
    alt GetBookmarks
        User ->> UserController: viewBookmarks()
        UserController ->> PrivateDatabase: getBookmarks(User)
        PrivateDatabase -->> UserController: Bookmarks
        UserController -->> User: Bookmarks
    end

    alt EditQuestion
        User ->> UserController: editQuestion(Question)
        alt Question is empty
            UserController ->> UserController: deleteQuestion()
            UserController ->> PrivateDatabase: deleteQuestion(User)
            PrivateDatabase -->> UserController: delete status
            UserController -->> User: delete status
        else Question is not empty
            UserController ->> PrivateDatabase: editQuestion(User, Question)
            PrivateDatabase -->> UserController: edit status
            UserController -->> User: edit status
        end
    end

    alt EditComment
        User ->> UserController: editComment(Comment)
        alt Comment is empty
            UserController ->> UserController: deleteComment()
            UserController ->> PrivateDatabase: deleteComment(User)
            PrivateDatabase -->> UserController: delete status
            UserController -->> User: delete status
        else Comment is not empty
            UserController ->> PrivateDatabase: editComment(User, Comment)
            PrivateDatabase -->> UserController: edit status
            UserController -->> User: edit status
        end
    end

    alt Unbookmark
        User ->> UserController: unbookmark(Post)
        UserController ->> PrivateDatabase: deleteBookmark(User, Post)
        PrivateDatabase -->> UserController: status
        UserController -->> User: "Bookmark removed successfully"
    end
    
    alt EditName
        User ->> UserController: updateName(Name)
        UserController ->> PrivateDatabase: updateName(User, Name)
        PrivateDatabase -->> UserController: status
        UserController -->> User: status
    end
    
    alt EditPassword
        User ->> UserController: updatePassword(Password)
        UserController ->> PrivateDatabase: updatePassword(User, Password)
        PrivateDatabase -->> UserController: status
        UserController -->> User: status
    end
    
    alt EditProfilePicture
        User ->> UserController: updateProfile(Image)
        UserController ->> PrivateDatabase: updateProfilePicture(User, Image)
        PrivateDatabase -->> UserController: status
        UserController -->> User: status
    end

3.5 SignUp, Login, Logout

by Emin

sequenceDiagram
    participant User
    participant UserController
    participant PrivateDatabase

    alt SignUp
        User ->> UserController: signUp(Name, Email, Password)
        UserController ->> PrivateDatabase: checkIfEmailExists(Email)
        PrivateDatabase -->> UserController: emailExists?
        alt Email exists
            UserController -->> User: "Email already registered"
        else Email does not exist
            UserController ->> PrivateDatabase: saveUser(Name, Email, Password)
            PrivateDatabase -->> UserController: signUpStatus
            UserController -->> User: "Sign-up successful"
        end
    end

    alt Login
        User ->> UserController: logIn(Email, Password)
        UserController ->> PrivateDatabase: checkUser(Email, Password)
        PrivateDatabase -->> UserController: userFound?
        alt User found
            UserController ->> PrivateDatabase: createSession(User)
            PrivateDatabase -->> UserController: sessionInfo
            UserController -->> User: "Login successful", sessionInfo
        else User not found
            UserController -->> User: "Invalid email or password"
        end
    end

    alt LogOut
        User ->> UserController: logOut()
        UserController ->> PrivateDatabase: invalidateSession(User)
        PrivateDatabase -->> UserController: logoutStatus
        UserController -->> User: "Logout successful"
    end

3.6 Feed

by Halil, Ceylin

sequenceDiagram
    participant User
    participant Feed
    participant SearchQuery
    participant PostController

    alt Browse Feed
        User ->> Feed: openFeed()
        Feed->> SearchQuery: executeSearch(filters)
        SearchQuery ->> PostController: fetchPosts(filters)
        PostController -->> SearchQuery: posts[]
        SearchQuery -->> Feed: searchResults[]
        Feed-->> User: displayPosts(searchResults)
    end

    alt Filter/Sort Posts
        User ->> Feed: applyFilter(filterOptions)
        Feed->> SearchQuery: executeSearch(filterOptions)
        SearchQuery ->> PostController: fetchPosts(filterOptions)
        PostController -->> SearchQuery: filteredPosts[]
        SearchQuery -->> Feed: filteredResults[]
        Feed-->> User: displayFilteredPosts(filteredResults)
    end

    alt View Post Details
        User ->> Feed: selectPost(postId)
        Feed->> PostController: fetchPostDetails(postId)
        PostController -->> Feed: postDetails
        Feed-->> User: displayPostDetails(postDetails)
    end