Bookmark API Internal Component Structure
The Bookmark API follows a layered architecture designed for maintainability and separation of concerns.
At the top, the API Layer consists of Flask Blueprints that handle HTTP requests and delegate business logic to the service layer.
The Service Layer is centered around the [BookmarkService](/api_ref/app/services/bookmark/service/bookmarkservice), which acts as a facade and orchestrator. It is implemented as a singleton to ensure consistent state across the application. It coordinates between the Persistence Layer, the Search Index, and an internal LRU Cache.
The Persistence Layer uses the [BookmarkRepository](/api_ref/app/db/repository/bookmarkrepository) to abstract data access. While currently implemented in-memory, the repository pattern allows for future migration to a persistent database without affecting the service layer.
The Domain Models ([Bookmark](/api_ref/app/models/bookmark/bookmark), Tag, Collection) are shared across all layers and encapsulate both state and entity-specific logic.
Finally, the Configuration module provides environment-specific settings that drive the application's behavior, such as page sizes and secret keys.
Key Architectural Findings:
- The application uses a layered architecture: API -> Service -> Repository -> Models.
- BookmarkService is a singleton facade that orchestrates business logic, caching, and search indexing.
- SearchIndex provides an inverted index for full-text search, rebuilt from the repository and updated incrementally.
- LRUCache is an internal utility used by the service layer to optimize frequent bookmark lookups.
- BookmarkRepository implements the repository pattern, currently providing in-memory storage for all domain entities.
- Domain models (Bookmark, Tag, Collection) are rich objects that handle their own state transitions (e.g., archiving, trashing).