Bookmark Lifecycle States
The state diagram illustrates the lifecycle of a Bookmark entity within the Etchblok API.
Key States:
- Active: The initial state of a bookmark upon creation. It is visible in the main list and searchable.
- Archived: A state for bookmarks that are no longer active but preserved for reference. They can be filtered out of the main view.
- Trashed: A soft-deleted state. Bookmarks in this state are typically hidden from the user but can be restored or permanently archived.
Transitions and Triggers:
- Creation: A bookmark starts in the
Activestate when created via thecreate_bookmarkservice method (triggered byPOST /api/bookmarks/). - Archival: Moving a bookmark to the
Archivedstate is triggered by thearchive_bookmarkmethod (POST /api/bookmarks/<id>/archive). This can be done from either theActiveorTrashedstates. - Soft Deletion: Moving a bookmark to the
Trashedstate is triggered by thedelete_bookmarkmethod (DELETE /api/bookmarks/<id>). This can be done from either theActiveorArchivedstates. - Restoration: A bookmark in the
ArchivedorTrashedstate can be returned to theActivestate using therestore_bookmarkmethod (POST /api/bookmarks/<id>/restore).
The diagram reflects the actual implementation in app/models/bookmark.py and app/services/bookmark_service.py, where status changes are handled by explicit methods that update the BookmarkStatus enum. Notably, while the repository layer supports hard deletion, the service layer currently only implements soft deletion via the Trashed state.
Key Architectural Findings:
- The Bookmark entity uses a BookmarkStatus enum with three values: ACTIVE, ARCHIVED, and TRASHED.
- New bookmarks are initialized with the ACTIVE status by default in the Bookmark dataclass.
- The delete_bookmark service method performs a soft delete by transitioning the bookmark to the TRASHED state.
- The restore_bookmark service method transitions a bookmark from either ARCHIVED or TRASHED back to the ACTIVE state.
- Transitions between ARCHIVED and TRASHED are possible through their respective service methods without intermediate steps.
- The repository layer contains a hard-delete method (delete_bookmark) that is currently unused by the service layer.