# aggregat4/delicious-bookmarks architecture

> Architecture diagram of the GitHub repository aggregat4/delicious-bookmarks, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aggregat4/delicious-bookmarks
- Repository: https://github.com/aggregat4/delicious-bookmarks

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    Browser["Browser Client"]:::external
    ReverseProxy["Reverse Proxy"]:::server
    OIDC["OpenID Connect"]:::external

    %% Web Server Layer
    subgraph "Web Server Layer"
        WS_Binary["Web Server Binary"]:::server
        WS_Server["HTTP Server Logic"]:::server
    end

    %% Application Core Layer
    subgraph "Application Core"
        DomainLogic["Domain Logic"]:::domain
        subgraph "Data Repository"
            DataRepo1["Repository Operations"]:::repository
            DataRepoSchema["Repository Schema"]:::repository
        end
        SQLiteDB["SQLite3 Database"]:::database
    end

    %% Auxiliary Tools
    subgraph "Auxiliary Tools"
        subgraph "Importer Tool"
            CLI_Importer_Binary["Importer Binary"]:::cli
            CLI_Importer_Logic["Importer Logic"]:::cli
        end
        Crawler["Crawler (Page Archiver)"]:::crawler
    end

    %% Public UI Views
    PublicViews["Public UI Views"]:::server

    %% DevOps & Build Scripts
    subgraph "DevOps & Build"
        CIWorkflows["CI/CD Workflows"]:::devops
        BuildScripts["Build & Test Scripts"]:::devops
    end

    %% Data Flow
    Browser -->|"HTTPRequest"| ReverseProxy
    ReverseProxy -->|"ForwardRequest"| WS_Binary
    WS_Binary -->|"Initialize"| WS_Server
    WS_Server -->|"RenderPages"| PublicViews
    WS_Server -->|"ProcessRequest"| DomainLogic
    DomainLogic -->|"Uses"| DataRepo1
    DataRepo1 -->|"DBOperations"| SQLiteDB
    WS_Server -->|"Auth"| OIDC

    %% Importer & Crawler Flow
    CLI_Importer_Binary --> CLI_Importer_Logic
    CLI_Importer_Logic -->|"MigrateData"| DomainLogic
    Crawler -->|"ArchivePages"| DataRepo1

    %% DevOps Connections
    CIWorkflows -->|"Deploy/CI"| WS_Binary
    BuildScripts -->|"Build"| CLI_Importer_Binary

    %% Click Events
    click WS_Binary "https://github.com/aggregat4/delicious-bookmarks/blob/main/cmd/server/main.go"
    click WS_Server "https://github.com/aggregat4/delicious-bookmarks/blob/main/internal/server/server.go"
    click CLI_Importer_Binary "https://github.com/aggregat4/delicious-bookmarks/blob/main/cmd/importer/main.go"
    click CLI_Importer_Logic "https://github.com/aggregat4/delicious-bookmarks/blob/main/internal/importer/import.go"
    click DomainLogic "https://github.com/aggregat4/delicious-bookmarks/blob/main/internal/domain/domain.go"
    click DataRepo1 "https://github.com/aggregat4/delicious-bookmarks/blob/main/internal/repository/repository.go"
    click DataRepoSchema "https://github.com/aggregat4/delicious-bookmarks/blob/main/internal/repository/schema.go"
    click Crawler "https://github.com/aggregat4/delicious-bookmarks/blob/main/internal/crawler/crawler.go"
    click PublicViews "https://github.com/aggregat4/delicious-bookmarks/tree/main/internal/server/public/views"
    click CIWorkflows "https://github.com/aggregat4/delicious-bookmarks/tree/main/.github/workflows"
    click BuildScripts "https://github.com/aggregat4/delicious-bookmarks/tree/main/scripts"

    %% Styles
    classDef server fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef cli fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef domain fill:#FFFF99,stroke:#000,stroke-width:1px;
    classDef repository fill:#FFDAB9,stroke:#000,stroke-width:1px;
    classDef crawler fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef external fill:#FFA07A,stroke:#000,stroke-width:1px;
    classDef devops fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef database fill:#E6E6FA,stroke:#000,stroke-width:1px;

    class Browser,OIDC external;
    class ReverseProxy,WS_Binary,WS_Server,PublicViews server;
    class CLI_Importer_Binary,CLI_Importer_Logic cli;
    class DomainLogic domain;
    class DataRepo1,DataRepoSchema repository;
    class Crawler crawler;
    class CIWorkflows,BuildScripts devops;
    class SQLiteDB database;
```
