# asm0dey/opdsko architecture

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

- Interactive diagram: https://gitdiagram.com/asm0dey/opdsko
- Repository: https://github.com/asm0dey/opdsko

## Overview

##### Main Components

a) Core System Components:
- HTTP Server Layer (Ktor-based)
- Database Layer (SQLite with JOOQ)
- File System Scanner
- OPDS Feed Generator
- FB2 Parser Component

b) External Interfaces:
- HTTP/OPDS Client Access
- Local File System (FB2 files storage)

##### Architecture Pattern
The project follows a layered architecture with clear separation of concerns:

- Controllers Layer (`controllers` package)
- Service Layer (`service` package)
- Repository Layer (`repository` package)
- Data Access Layer (JOOQ-generated code)
- Domain Model Layer (`model` package)

**[Client Layer]**

- ▼
**[HTTP/OPDS Interface]**

- ▼
**[Application Core]**

- [Controllers]
- OPDS Controller
- API Controller
- Simple Controller

- [Services]
- InfoService

- [Repository]
- Database Access

- [File System]
- FB2 Files Scanner

##### Important Details

a) Data Flow:
- How requests flow from clients through the OPDS/HTTP endpoints
- How the FB2 parser processes files
- Database read/write operations
- Demonstrate the scanning process flow

b) Database Structure:
Main entities:
- Books
- Authors
- Genres
- Full-text search tables
- Relationships between entities

##### Technical Stack Indicators

Technology labels:
- Ktor (Web Framework)
- SQLite (Database)
- JOOQ (Database Access)
- Kotlin (Programming Language)
- Flyway (Database Migrations)

##### Interactions

Key interactions:
- Client requests for book listings
- Search operations
- File scanning processes
- Database updates
- File serving

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    Client(("OPDS/HTTP Client"))
    
    %% HTTP Layer
    subgraph HTTP["HTTP Server Layer"]
        Server["Ktor Server"]:::server
        click Server "https://github.com/asm0dey/opdsko/blob/main/src/main/kotlin/io/github/asm0dey/plugins/HTTP.kt"
    end

    %% Controllers Layer
    subgraph Controllers["Controllers Layer"]
        OPDS["OPDS Controller"]:::controller
        API["API Controller"]:::controller
        Simple["Simple Controller"]:::controller
        click OPDS "https://github.com/asm0dey/opdsko/blob/main/src/main/kotlin/io/github/asm0dey/controllers/Opds.kt"
        click API "https://github.com/asm0dey/opdsko/blob/main/src/main/kotlin/io/github/asm0dey/controllers/Api.kt"
        click Simple "https://github.com/asm0dey/opdsko/blob/main/src/main/kotlin/io/github/asm0dey/controllers/Simple.kt"
    end

    %% Service Layer
    subgraph Services["Service Layer"]
        InfoService["Info Service"]:::service
        click InfoService "https://github.com/asm0dey/opdsko/blob/main/src/main/kotlin/io/github/asm0dey/service/InfoService.kt"
    end

    %% Repository Layer
    subgraph Repository["Repository Layer"]
        DBAccess["Database Access"]:::repository
        click DBAccess "https://github.com/asm0dey/opdsko/blob/main/src/main/kotlin/io/github/asm0dey/repository/Repository.kt"
    end

    %% Database Layer
    subgraph Database["Database Layer"]
        SQLite[(SQLite DB)]:::database
        JOOQ["JOOQ Layer"]:::database
        DBModels["Database Models"]:::database
        click JOOQ "https://github.com/asm0dey/opdsko/tree/main/src/main/kotlin/io/github/asm0dey/opdsko/jooq/"
        click DBModels "https://github.com/asm0dey/opdsko/tree/main/src/main/kotlin/io/github/asm0dey/opdsko/jooq/tables/"
    end

    %% File System Layer
    subgraph FileSystem["File System Layer"]
        FB2Parser["FB2 Parser"]:::filesystem
        Scanner["INPX Scanner"]:::filesystem
        FB2Files[("FB2 Files")]:::filesystem
        click FB2Parser "https://github.com/asm0dey/opdsko/tree/main/src/main/kotlin/com/kursx/parser/fb2/"
        click Scanner "https://github.com/asm0dey/opdsko/blob/main/src/main/kotlin/io/github/asm0dey/inpx/InpxParser.kt"
    end

    %% Configuration
    subgraph Config["Configuration"]
        AppConfig["Application Config"]:::config
        FB2Config["FB2 Config"]:::config
        click AppConfig "https://github.com/asm0dey/opdsko/blob/main/src/main/resources/application.conf"
        click FB2Config "https://github.com/asm0dey/opdsko/blob/main/src/main/resources/fb2c.conf.toml"
    end

    %% Relationships
    Client --> Server
    Server --> OPDS & API & Simple
    OPDS & API & Simple --> InfoService
    InfoService --> DBAccess
    DBAccess --> JOOQ
    JOOQ --> SQLite
    JOOQ --> DBModels
    Scanner --> FB2Files
    FB2Parser --> FB2Files
    Scanner --> DBAccess
    InfoService --> FB2Parser
    AppConfig & FB2Config --> Server

    %% Styles
    classDef server fill:#1E88E5,color:white
    classDef controller fill:#43A047,color:white
    classDef service fill:#00ACC1,color:white
    classDef repository fill:#FFB300,color:white
    classDef database fill:#6D4C41,color:white
    classDef filesystem fill:#F4511E,color:white
    classDef config fill:#8E24AA,color:white

    %% Legend
    subgraph Legend
        L1["HTTP Server"]:::server
        L2["Controllers"]:::controller
        L3["Services"]:::service
        L4["Repository"]:::repository
        L5["Database"]:::database
        L6["File System"]:::filesystem
        L7["Configuration"]:::config
    end
```
