# go-shiori/shiori architecture

> Architecture diagram of the GitHub repository go-shiori/shiori, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/go-shiori/shiori
- Repository: https://github.com/go-shiori/shiori

## Overview

##### Main Components

a. Client Layer:
- Web Interface (internal/view)
- CLI Interface (internal/cmd)
- Web Extension (external component)

b. Server Layer:
- HTTP Server (internal/http)
- API Routes (internal/http/routes/api/v1)
- Authentication Middleware (internal/http/middleware)

c. Core Business Layer:
- Bookmark Management (internal/domains)
- Account Management (internal/domains)
- Archive Management (internal/domains)

d. Data Layer:
- Database Abstraction (internal/database)
- Multiple Database Support:
- SQLite
- PostgreSQL
- MySQL

e. External Services:
- Pocket API Integration
- Web Page Archival System

**[Client Layer] → [Server Layer] → [Core Business Layer] → [Data Layer]**
- ↘ [External Services]

##### Key Relationships to Highlight

a. Client-Server Interaction:
- How the web UI, CLI, and web extension connect to the server
- API routes (v1) as the main entry point

b. Authentication Flow:
- Auth middleware's position in the request pipeline
- Connection to account management

c. Data Flow:
- Demonstrate how bookmarks flow from user input through the system
- Archival process for webpage content
- Database abstraction layer with multiple database support

##### Technical Details

- Go-specific components (internal packages)
- Database migrations system
- Template rendering system
- Static asset handling
- API versioning (v1)

##### Implementation Notes

- Authentication flow
- Bookmark CRUD operations
- Archive creation process
- Database interaction layer

Remember to highlight the portable nature of the application and its ability to run as both a web service and CLI tool from a single binary.

This system design should help developers understand how Shiori's components work together to provide bookmark management, webpage archival, and multi-user support across different deployment scenarios.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style definitions
    classDef client fill:#3498db,stroke:#2980b9,color:white
    classDef server fill:#2ecc71,stroke:#27ae60,color:white
    classDef core fill:#f1c40f,stroke:#f39c12,color:black
    classDef data fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#e67e22,stroke:#d35400,color:white

    subgraph "Client Layer"
        WUI["Web Interface"]:::client
        CLI["CLI Interface"]:::client
        WEX["Web Extension"]:::client
    end

    subgraph "Server Layer"
        HTTP["HTTP Server"]:::server
        API["API Routes"]:::server
        AUTH["Authentication Middleware"]:::server
        WS["Web Server"]:::server
    end

    subgraph "Core Business Layer"
        BM["Bookmark Management"]:::core
        AM["Account Management"]:::core
        ARC["Archive Management"]:::core
        CONF["Configuration"]:::core
        MOD["Models/Entities"]:::core
    end

    subgraph "Data Layer"
        DBA["Database Abstraction"]:::data
        subgraph "Database Implementations"
            SQLITE["SQLite"]:::data
            PG["PostgreSQL"]:::data
            MYSQL["MySQL"]:::data
            MIGR["Migrations"]:::data
        end
    end

    subgraph "External Services"
        POCKET["Pocket API"]:::external
        ARCH["Web Page Archival"]:::external
    end

    %% Relationships
    WUI --> HTTP
    CLI --> HTTP
    WEX --> HTTP
    
    HTTP --> API
    HTTP --> AUTH
    HTTP --> WS
    
    API --> BM
    API --> AM
    API --> ARC
    
    AUTH --> AM
    
    BM --> DBA
    AM --> DBA
    ARC --> DBA
    
    DBA --> SQLITE
    DBA --> PG
    DBA --> MYSQL
    DBA --> MIGR
    
    BM --> POCKET
    ARC --> ARCH

    %% Click events
    click WUI "https://github.com/go-shiori/shiori/tree/master/internal/view"
    click CLI "https://github.com/go-shiori/shiori/tree/master/internal/cmd"
    click HTTP "https://github.com/go-shiori/shiori/tree/master/internal/http"
    click API "https://github.com/go-shiori/shiori/tree/master/internal/http/routes/api/v1"
    click AUTH "https://github.com/go-shiori/shiori/tree/master/internal/http/middleware"
    click BM "https://github.com/go-shiori/shiori/blob/master/internal/domains/bookmarks.go"
    click AM "https://github.com/go-shiori/shiori/blob/master/internal/domains/accounts.go"
    click ARC "https://github.com/go-shiori/shiori/blob/master/internal/domains/archiver.go"
    click DBA "https://github.com/go-shiori/shiori/blob/master/internal/database/database.go"
    click SQLITE "https://github.com/go-shiori/shiori/blob/master/internal/database/sqlite.go"
    click PG "https://github.com/go-shiori/shiori/blob/master/internal/database/pg.go"
    click MYSQL "https://github.com/go-shiori/shiori/blob/master/internal/database/mysql.go"
    click MOD "https://github.com/go-shiori/shiori/tree/master/internal/model"
    click CONF "https://github.com/go-shiori/shiori/tree/master/internal/config"
    click WS "https://github.com/go-shiori/shiori/tree/master/internal/webserver"
    click MIGR "https://github.com/go-shiori/shiori/tree/master/internal/database/migrations"

    %% Legend
    classDef legend fill:#f5f5f5,stroke:#cccccc,color:black
    subgraph Legend
        L1["Client Components"]:::client
        L2["Server Components"]:::server
        L3["Core Components"]:::core
        L4["Data Components"]:::data
        L5["External Services"]:::external
    end
```
