# naiymu/konnichiwa architecture

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

- Interactive diagram: https://gitdiagram.com/naiymu/konnichiwa
- Repository: https://github.com/naiymu/konnichiwa

## Overview

##### Main Components
- Client/Browser: This is the front-end seen by users (HTML, CSS, JavaScript). The assets (images, screenshots, font files, CSS) and the externally downloaded libraries (jQuery, FontAwesome, Simple HTML DOM) are part of this layer.
- Web Server & PHP Engine:
- Apache serves as the front-facing web server.
- PHP (and optionally PHP-FPM with FastCGI) runs the PHP scripts (index.php, add.php, search.php, etc.).
- A collection of PHP scripts located in various parts of the project (both in the root and in the scripts directory) act as controllers, helpers, and utilities.
- Database Layer:
- MySQL is used as the backend database.
- The SQL dump (help/create.sql) and the accompanying database schema (help/schema-details.pdf, help/schema.svg) provide schema details.
- File System & External Resources:
- The “holy directory” (which must be symlinked as “images”) stores doujinshi images—in practice, the storage for media and associated metadata.
- External libraries downloaded locally (jQuery in scripts, FontAwesome in assets) integrate into the app.

##### Out Relationships and Interactions
- Client requests are routed to the Web Server (Apache).
- Apache routes static file requests (CSS, JS, images) and dynamic requests (PHP pages).
- PHP scripts (controllers in both the root and inside the “scripts” folder) handle business logic and access:
- The MySQL database for tracking manga data, authors, tags, bookmarks, etc.
- The file system to read from (and sometimes write to) the doujinshi directories.
- Some PHP scripts (such as those inside the “scripts/modification” folder) modify the database by processing structured JSON data.
- External libraries are included via local file links (as enforced by the readme’s “no CDN” approach) and embedded into the HTML output.

##### Architectural Patterns / Design Principles
- Although not strictly following MVC, the project separates concerns between:
- Presentation layer (HTML, CSS, JavaScript in assets and scripts for client behavior);
- Application logic (PHP files like index.php, add.php, and various helper scripts);
- Data layer (MySQL along with SQL scripts for table setup).
- There is an emphasis on file-based configuration (like login.php and directory.php) that tie the server’s file system with the database and business logic.
- The project also enables manual actions (like manually using add.php or refresh_db.php) which indicates a design favoring administrative simplicity over fully automated processes.

##### Incorporate Relevant Technologies
- Apache Web Server and PHP/PHP-FPM (for processing PHP requests).
- MySQL as the relational database.
- JavaScript libraries such as jQuery and custom scripts (like add.js, download.js) to power client-side interactivity.

##### Summary
- Clients (Web Browsers) → HTTP Requests
- Apache (and optional PHP-FPM) → Processes requests; serves PHP pages, static assets.
- PHP Scripts: Core business logic (located in the main directory and scripts folder) that perform functions such as adding, editing, listing, and searching manga/doujinshi entries.
- MySQL Database: Stores metadata (information about pages, authors, tags, bookmarks, etc.) configured using provided SQL schema.
- File System: The repository for doujinshi images, linked via the “images” symlink to the actual “holy directory.”
- External Libraries/Assets: jQuery, FontAwesome, Simple HTML DOM, along with other assets like CSS and images.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        Browser("Browser/Client"):::client
        Assets("Assets & Screenshots"):::client
        Styles("Site CSS"):::client
        JSAdd("add.js"):::client
        JSDownload("download.js"):::client
        JSRead("read.js"):::client
        JSTagCheck("tag_check.js"):::client
        External("External Libraries"):::external
    end

    %% Application Layer
    subgraph "Application Layer"
        Apache("Apache Web Server"):::server
        subgraph "PHP Application"
            subgraph "PHP Controllers"
                Index("index.php"):::php
                Add("add.php"):::php
                Search("search.php"):::php
                Authors("authors.php"):::php
                Bookmarks("bookmarks.php"):::php
                ByAuthor("byauthor.php"):::php
                ByTag("bytag.php"):::php
                EditAuthors("editauthors.php"):::php
                EditDir("editdir.php"):::php
                EditTags("edittags.php"):::php
                Favourites("favourites.php"):::php
                Get("get.php"):::php
                Info("info.php"):::php
                List("list.php"):::php
                New("new.php"):::php
                Read("read.php"):::php
                Tags("tags.php"):::php
            end
            subgraph "PHP Utilities"
                AddUtil("scripts/add.php"):::php
                Bookmark("scripts/bookmark.php"):::php
                DownloadUtil("scripts/download.php"):::php
                ErrorUtil("scripts/error.php"):::php
                HeaderUtil("scripts/header.php"):::php
                HTMLFuncs("scripts/html_funcs.php"):::php
                Navbar("scripts/navbar.php"):::php
                Preview("scripts/preview.php"):::php
                Progress("scripts/progress.php"):::php
                Start("scripts/start.php"):::php
            end
            Modification("scripts/modification/refresh_db.php"):::php
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        MySQL("MySQL Database"):::database
        SQLCreate("help/create.sql"):::database
        SchemaPDF("help/schema-details.pdf"):::database
        Doujinshi("Doujinshi Image Repository"):::filesystem
    end

    %% Connections - Presentation to Application
    Browser -->|"HTTP_Request"| Apache
    Apache -->|"Process_PHP"| Index

    %% Connections - Application to Data
    Index -->|"DB_Query/Update"| MySQL
    Modification -->|"DB_Modify"| MySQL
    Read -->|"File_Access"| Doujinshi

    %% Connections within Presentation Layer
    Browser -->|"Load"| Assets
    Browser -->|"Load"| Styles
    Browser -->|"Load"| JSAdd
    Browser -->|"Load"| JSDownload
    Browser -->|"Load"| JSRead
    Browser -->|"Load"| JSTagCheck
    Browser -->|"Uses"| External

    %% Click Events - Presentation
    click Assets "https://github.com/naiymu/konnichiwa/tree/master/assets"
    click Styles "https://github.com/naiymu/konnichiwa/blob/master/styles/site.css"
    click JSAdd "https://github.com/naiymu/konnichiwa/blob/master/scripts/add.js"
    click JSDownload "https://github.com/naiymu/konnichiwa/blob/master/scripts/download.js"
    click JSRead "https://github.com/naiymu/konnichiwa/blob/master/scripts/read.js"
    click JSTagCheck "https://github.com/naiymu/konnichiwa/blob/master/scripts/tag_check.js"

    %% Click Events - PHP Controllers
    click Index "https://github.com/naiymu/konnichiwa/blob/master/index.php"
    click Add "https://github.com/naiymu/konnichiwa/blob/master/add.php"
    click Search "https://github.com/naiymu/konnichiwa/blob/master/search.php"
    click Authors "https://github.com/naiymu/konnichiwa/blob/master/authors.php"
    click Bookmarks "https://github.com/naiymu/konnichiwa/blob/master/bookmarks.php"
    click ByAuthor "https://github.com/naiymu/konnichiwa/blob/master/byauthor.php"
    click ByTag "https://github.com/naiymu/konnichiwa/blob/master/bytag.php"
    click EditAuthors "https://github.com/naiymu/konnichiwa/blob/master/editauthors.php"
    click EditDir "https://github.com/naiymu/konnichiwa/blob/master/editdir.php"
    click EditTags "https://github.com/naiymu/konnichiwa/blob/master/edittags.php"
    click Favourites "https://github.com/naiymu/konnichiwa/blob/master/favourites.php"
    click Get "https://github.com/naiymu/konnichiwa/blob/master/get.php"
    click Info "https://github.com/naiymu/konnichiwa/blob/master/info.php"
    click List "https://github.com/naiymu/konnichiwa/blob/master/list.php"
    click New "https://github.com/naiymu/konnichiwa/blob/master/new.php"
    click Read "https://github.com/naiymu/konnichiwa/blob/master/read.php"
    click Tags "https://github.com/naiymu/konnichiwa/blob/master/tags.php"

    %% Click Events - PHP Utilities
    click AddUtil "https://github.com/naiymu/konnichiwa/blob/master/scripts/add.php"
    click Bookmark "https://github.com/naiymu/konnichiwa/blob/master/scripts/bookmark.php"
    click DownloadUtil "https://github.com/naiymu/konnichiwa/blob/master/scripts/download.php"
    click ErrorUtil "https://github.com/naiymu/konnichiwa/blob/master/scripts/error.php"
    click HeaderUtil "https://github.com/naiymu/konnichiwa/blob/master/scripts/header.php"
    click HTMLFuncs "https://github.com/naiymu/konnichiwa/blob/master/scripts/html_funcs.php"
    click Navbar "https://github.com/naiymu/konnichiwa/blob/master/scripts/navbar.php"
    click Preview "https://github.com/naiymu/konnichiwa/blob/master/scripts/preview.php"
    click Progress "https://github.com/naiymu/konnichiwa/blob/master/scripts/progress.php"
    click Start "https://github.com/naiymu/konnichiwa/blob/master/scripts/start.php"

    %% Click Event - Database Modification Script
    click Modification "https://github.com/naiymu/konnichiwa/blob/master/scripts/modification/refresh_db.php"

    %% Click Events - Database Setup
    click SQLCreate "https://github.com/naiymu/konnichiwa/blob/master/help/create.sql"
    click SchemaPDF "https://github.com/naiymu/konnichiwa/blob/master/help/schema-details.pdf"

    %% Styles
    classDef client fill:#a0d8f1,stroke:#333,stroke-width:2px;
    classDef server fill:#b7e4c7,stroke:#333,stroke-width:2px;
    classDef php fill:#f4a261,stroke:#333,stroke-width:2px;
    classDef database fill:#ffe066,stroke:#333,stroke-width:2px;
    classDef filesystem fill:#f7c59f,stroke:#333,stroke-width:2px;
    classDef external fill:#d0a9f5,stroke:#333,stroke-width:2px;
```
