How aggregat4/delicious-bookmarks works
Project Type and Purpose
• This is a web-based bookmark storage and retrieval system built in Go. It functions similarly to legacy bookmark services like del.icio.us or Pinboard but is implemented as a statically linked binary.
• The application offers features such as storing, editing, searching bookmarks, and archiving webpages for offline reading. There is a dedicated command-line importer tool for migrating from Pinboard.
• Security is a key aspect: all pages require authentication via OpenID Connect, uses encrypted session cookies, CSRF protections, and there’s a strong emphasis on avoiding XSS and SQL injection.
Key Components from File Structure
• Command-Line Interfaces:
• Under cmd/, there are two main executables:
▪ cmd/server/main.go – the core web server.
▪ cmd/importer/main.go – which handles importing Pinboard bookmark exports into the system.
• Internal Modules:
• internal/domain: Contains core business/domain objects and logic.
• internal/repository: Contains database interaction code, including schema definition. It abstracts how data is stored in SQLite3 (tables for users and bookmarks).
• internal/server: Contains the HTTP server logic, the public resources (HTML templates under public/views, images, etc.), server tests, and initialization.
• internal/crawler: Implements the page archiver functionality for the “read later” pages.
• internal/importer: Provides additional logic for the import process beyond the CLI wrapper.
• Infrastructure & Automation:
• .github/workflows holds CI/CD configuration.
• scripts includes build and test scripts (for local and Docker builds, linting, etc.), ensuring reproducibility and consistent builds.
Architectural Patterns & Interactions
• The design follows a modular pattern. The clear separation between the domain, repository, and server layers reflects a principle similar to MVC or hexagonal architecture (though not explicitly enforced as such).
• Data Flow and Interaction:
• The Web Server:
▪ Listens on a configurable port (default 1323).
▪ After successful authentication, enforces session handling using encrypted cookies.
▪ Renders pages using Go’s template engine and provides endpoints (including the special /addbookmark page for bookmarklets).
▪ Handles security by embedding CSRF tokens and escaping data.
▪ Delivers pages with gzip compression and caching logic.
• The Database:
▪ SQLite3 is used, holding at least two tables (users and bookmarks) and employing the fts5 extension for full-text search.
• The Importer & Crawler:
▪ The importer reads JSON (from Pinboard) and populates the database using shared domain and repository logic.
▪ The crawler implements the “webpage archiver,” reducing pages to core content and storing them.
• External Dependencies:
▪ External authentication providers (OpenID Connect) and best practices for reverse proxy setup (for HTTPS and rate limiting).
Final Advice
• Be as detailed as possible while keeping each module or component clearly distinct.
• Don’t hesitate to break down the system further if needed – for example, explicitly listing UI views or security-related flows.