Skip to main content

Bookmark and Collection Lifecycle State Machine

The state architecture diagram illustrates the lifecycle of the two primary entities in the system: Bookmark and Collection.

Bookmark Lifecycle

Bookmarks follow a visibility-based state machine defined by the BookmarkStatus enum.

  • Active: The initial state upon creation via create_bookmark.
  • Archived: A state for bookmarks that are no longer active but preserved. Transitions occur via archive_bookmark.
  • Trashed: A soft-deleted state. Bookmarks are moved here via delete_bookmark.
  • Restoration: Bookmarks in either the Archived or Trashed states can be returned to the Active state using restore_bookmark.
  • Cross-Transitions: The system allows moving bookmarks directly between Archived and Trashed states.

Collection Lifecycle

Collections are categorized by their CollectionType and their pinning status.

  • Types: Collections are either Manual (user-added bookmarks) or Smart (filter-based auto-population). This type is immutable after creation.
  • Pinning: Both manual and smart collections can inhabit Pinned or Unpinned states, toggled via the pin() and unpin() methods. This affects their display priority in the UI.

The diagram captures these transitions as implemented in the Bookmark and Collection models and orchestrated by the BookmarkService.

Key Architectural Findings:

  • Bookmarks use a 'BookmarkStatus' enum with ACTIVE, ARCHIVED, and TRASHED states.
  • The 'delete_bookmark' service method performs a soft delete by transitioning the bookmark to the TRASHED state.
  • The 'restore_bookmark' method can transition a bookmark from either ARCHIVED or TRASHED back to ACTIVE.
  • Collections have a fixed 'CollectionType' (MANUAL or SMART) set at creation.
  • Collections track a 'is_pinned' boolean state, modified by 'pin()' and 'unpin()' methods.
  • The 'BookmarkService' acts as the state transition coordinator, ensuring repository updates and cache invalidation.
Loading diagram...