# rr-/szurubooru architecture

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

- Interactive diagram: https://gitdiagram.com/rr-/szurubooru
- Repository: https://github.com/rr-/szurubooru

## Overview

##### Main Components

a. Client-Side (Frontend):
- Single Page Application (SPA) built with JavaScript
- MVC architecture with:
- Controllers (client/js/controllers/)
- Models (client/js/models/)
- Views (client/js/views/)
- Static assets (CSS, HTML templates, images)

b. Server-Side (Backend):
- REST API (server/szurubooru/api/)
- Database layer (server/szurubooru/model/)
- Search system (server/szurubooru/search/)
- File storage system
- Authentication system

c. External Services:
- yt-dlp integration for web video content
- Email service (for password reset)

- Client Layer |     |  Server Layer  |     | Storage Layer |

##### Component Relationships

- Client → Server: REST API calls
- Server → Database: Data persistence
- Server → File Storage: Media storage
- Server → External Services: Video fetching, email

##### Detailed Components

Client Layer:

- Client Layer       |

- Views     |    |

- Controllers  |    |

- Models     |    |

- Router     |    |

Server Layer:

- Server Layer       |

- REST API    |    |

- Authentication|    |

- Search System  |    |

- Business Logic |    |

##### Important Features to Highlight

Create subsections showing:
- Post management system
- Tag system with implications and aliases
- Pool management
- User privilege system
- Search functionality
- Media processing pipeline

##### Additional Elements

Include:
- Version information
- Database schema overview
- API endpoints summary
- Security boundaries

##### Technical Details to Note

- Nginx serving static files
- SQLAlchemy ORM
- Alembic migrations
- Docker containerization
- Token-based authentication
- REST API architecture

Remember to maintain a balance between detail and clarity, focusing on the architectural decisions that make szurubooru unique, such as its tag system, search capabilities, and media handling features.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        FE_Views["Views"]:::frontend
        FE_Controllers["Controllers"]:::frontend
        FE_Models["Models"]:::frontend
        FE_Router["Router"]:::frontend
        FE_Templates["Templates"]:::frontend
        FE_CSS["Stylesheets"]:::frontend
        FE_Images["Images"]:::frontend
        FE_Config["Client Config"]:::config
    end

    subgraph Server
        API["REST API"]:::backend
        Auth["Authentication"]:::security
        Search["Search System"]:::backend
        BL["Business Logic"]:::backend

        subgraph BusinessLogic
            FileManager["File Management"]:::backend
            ImageProc["Image Processing"]:::backend
            EmailService["Email Service"]:::backend
            UserManager["User Management"]:::backend
            PostManager["Post Management"]:::backend
        end
    end

    subgraph Storage
        DB[(Database)]:::database
        FileStorage[("File Storage")]:::storage
        Migrations["DB Migrations"]:::database
    end

    subgraph External
        YT["yt-dlp"]:::external
        SMTP["SMTP Server"]:::external
    end

    %% Client Layer Relationships
    FE_Views --> FE_Controllers
    FE_Controllers --> FE_Models
    FE_Models --> API
    FE_Router --> FE_Controllers

    %% Server Layer Relationships
    API --> Auth
    API --> Search
    API --> BL
    Search --> DB
    Auth --> DB

    %% Business Logic Relationships
    FileManager --> FileStorage
    ImageProc --> FileStorage
    EmailService --> SMTP
    UserManager --> DB
    PostManager --> DB
    PostManager --> YT

    %% Storage Relationships
    DB --> Migrations

    %% Click Events
    click FE_Controllers "https://github.com/rr-/szurubooru/tree/master/client/js/controllers/"
    click FE_Models "https://github.com/rr-/szurubooru/tree/master/client/js/models/"
    click FE_Views "https://github.com/rr-/szurubooru/tree/master/client/js/views/"
    click FE_Templates "https://github.com/rr-/szurubooru/tree/master/client/html/"
    click FE_CSS "https://github.com/rr-/szurubooru/tree/master/client/css/"
    click FE_Images "https://github.com/rr-/szurubooru/tree/master/client/img/"
    click API "https://github.com/rr-/szurubooru/tree/master/server/szurubooru/api/"
    click Search "https://github.com/rr-/szurubooru/tree/master/server/szurubooru/search/"
    click Auth "https://github.com/rr-/szurubooru/blob/master/server/szurubooru/middleware/authenticator.py"
    click FileManager "https://github.com/rr-/szurubooru/blob/master/server/szurubooru/func/files.py"
    click ImageProc "https://github.com/rr-/szurubooru/blob/master/server/szurubooru/func/images.py"
    click EmailService "https://github.com/rr-/szurubooru/blob/master/server/szurubooru/func/mailer.py"
    click UserManager "https://github.com/rr-/szurubooru/blob/master/server/szurubooru/func/users.py"
    click PostManager "https://github.com/rr-/szurubooru/blob/master/server/szurubooru/func/posts.py"
    click Migrations "https://github.com/rr-/szurubooru/tree/master/server/szurubooru/migrations/versions/"
    click FE_Config "https://github.com/rr-/szurubooru/blob/master/client/js/config.js"

    classDef frontend fill:#2196F3,stroke:#1565C0,color:white
    classDef backend fill:#4CAF50,stroke:#2E7D32,color:white
    classDef database fill:#FFC107,stroke:#FFA000,color:black
    classDef storage fill:#90A4AE,stroke:#546E7A,color:white
    classDef security fill:#F44336,stroke:#C62828,color:white
    classDef external fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef config fill:#FF9800,stroke:#F57C00,color:white
```
