# bitsbytoader/tsuki architecture

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

- Interactive diagram: https://gitdiagram.com/bitsbytoader/tsuki
- Repository: https://github.com/bitsbytoader/tsuki

## Overview

##### Main Components Identification

The system should be represented with these key components:

a. Client Applications
- iOS/iPadOS App
- macOS App
- Widget Extensions

b. Core Components
- Data Models Layer
- Persistence Layer
- UI Components
- External Services (MangaDex API)

##### Specific Implementation Details

- Data flow between MangaDex API and local storage
- Widget data updates
- Authentication flow
- Chapter download/caching mechanism

##### Key Architectural Patterns to Highlight

- Shared code architecture (note the "Shared" folder structure)
- MVVM pattern for view management
- CoreData integration for persistence
- Widget extension architecture

**┌─────────────────── Client Layer ───────────────────┐**
- ┌─────────┐    ┌──────────┐    ┌──────────────┐  │
- iOS App │    │macOS App │    │    Widgets   │  │
- ┘    └──────────┘    └──────────────┘  │
- ┬──────────────────────────┘
- ┌──────────▼───────────┐
- Shared Module     │
- ┬───────────┘
**┌──────────────────────────────────────────────────┐**
- ┌─────────────┐  ┌────────────┐  ┌────────────┐ │
- AppState   │  │View Models │  │  Helpers   │ │
- ┘  └────────────┘  └────────────┘ │
- ┬──────────────────────────┘
**┌──────────────────────▼──────────────────────────┐**
- ┌─────────────┐  ┌────────────┐  ┌────────────┐ │
- Data Models │  │  CoreData  │  │   Cache    │ │
- ┘  └────────────┘  └────────────┘ │
- ┬──────────────────────────┘
- ┌──────────▼───────────┐
- MangaDex API      │
- ┘

##### Important Notes

- A note about the offline functionality
- Authentication flow with MangaDex
- Widget data update mechanism
- Localization support (en.lproj, ro.lproj)
- Future integration points for planned features

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        iOS["iOS App"]
        macOS["macOS App"]
        Widgets["Widget Extensions"]
    end

    subgraph "Shared Module"
        AppEntry["TsukiApp"]
        ContentView["ContentView"]
        
        subgraph "View Layer"
            AccountViews["Account Views"]
            LibraryViews["Library Views"]
            ReaderViews["Reader Views"]
            SearchViews["Search Views"]
            Onboarding["Onboarding Experience"]
            
            subgraph "Reader Types"
                SwipeReader["Swipe Reader"]
                ScrollReader["Scroll Reader"]
            end
        end
        
        subgraph "Business Logic"
            AppState["App State"]
            Helpers["Helpers"]
        end
        
        subgraph "Data Layer"
            DataModels["Data Models"]
            CoreData["CoreData Schema"]
            PersistentStore["Persistent Store"]
            
            subgraph "Entity Models"
                DownloadedManga["Downloaded Manga"]
                DownloadedChapter["Downloaded Chapter"]
            end
        end
    end

    subgraph "Widget Implementation"
        WidgetViews["Widget Views"]
        WidgetLogic["Widget Logic"]
    end

    subgraph "Localization"
        EnglishLoc["English"]
        RomanianLoc["Romanian"]
    end

    MangaDexAPI["MangaDex API"]:::external

    %% Connections
    iOS --> AppEntry
    macOS --> AppEntry
    Widgets --> WidgetLogic
    
    AppEntry --> ContentView
    ContentView --> AppState
    
    AppState --> DataModels
    DataModels --> CoreData
    CoreData --> PersistentStore
    
    ReaderViews --> SwipeReader
    ReaderViews --> ScrollReader
    
    WidgetLogic --> WidgetViews
    WidgetLogic --> PersistentStore
    
    PersistentStore --> MangaDexAPI

    %% Styling
    classDef client fill:#a8dadc
    classDef view fill:#457b9d
    classDef logic fill:#1d3557
    classDef data fill:#e63946
    classDef external fill:#f4a261
    
    class iOS,macOS,Widgets client
    class AccountViews,LibraryViews,ReaderViews,SearchViews,Onboarding,SwipeReader,ScrollReader,WidgetViews view
    class AppState,Helpers,WidgetLogic logic
    class DataModels,CoreData,PersistentStore,DownloadedManga,DownloadedChapter data
    class MangaDexAPI external

    %% Click Events
    click iOS "https://github.com/BitsByToader/Tsuki/tree/main/iOS"
    click macOS "https://github.com/BitsByToader/Tsuki/tree/main/macOS"
    click Widgets "https://github.com/BitsByToader/Tsuki/tree/main/LatestUpdatesWidget"
    click DataModels "https://github.com/BitsByToader/Tsuki/tree/main/Shared/Data models"
    click DownloadedManga "https://github.com/BitsByToader/Tsuki/blob/main/Shared/CoreData/DownloadedManga+CoreDataClass.swift"
    click DownloadedChapter "https://github.com/BitsByToader/Tsuki/blob/main/Shared/CoreData/DownloadedChapter+CoreDataClass.swift"
    click CoreData "https://github.com/BitsByToader/Tsuki/blob/main/Shared/CoreData/Tsuki.xcdatamodeld"
    click PersistentStore "https://github.com/BitsByToader/Tsuki/blob/main/PersistentStore.swift"
    click AccountViews "https://github.com/BitsByToader/Tsuki/tree/main/Shared/Views/Account Views"
    click LibraryViews "https://github.com/BitsByToader/Tsuki/tree/main/Shared/Views/Library Views"
    click ReaderViews "https://github.com/BitsByToader/Tsuki/tree/main/Shared/Views/Reader Views"
    click SearchViews "https://github.com/BitsByToader/Tsuki/tree/main/Shared/Views/Search Views"
    click Onboarding "https://github.com/BitsByToader/Tsuki/tree/main/Shared/Views/Onboarding Experience"
    click AppState "https://github.com/BitsByToader/Tsuki/blob/main/Shared/AppState.swift"
    click Helpers "https://github.com/BitsByToader/Tsuki/tree/main/Shared/Helpers"
    click WidgetViews "https://github.com/BitsByToader/Tsuki/tree/main/LatestUpdatesWidget/Widgets"
    click WidgetLogic "https://github.com/BitsByToader/Tsuki/blob/main/LatestUpdatesWidget/LatestUpdatesWidget.swift"
    click EnglishLoc "https://github.com/BitsByToader/Tsuki/blob/main/en.lproj/Localizable.strings"
    click RomanianLoc "https://github.com/BitsByToader/Tsuki/blob/main/ro.lproj/Localizable.strings"
    click SwipeReader "https://github.com/BitsByToader/Tsuki/blob/main/Shared/Views/Reader Views/SwipeReader.swift"
    click ScrollReader "https://github.com/BitsByToader/Tsuki/blob/main/Shared/Views/Reader Views/ScrollReader.swift"
    click AppEntry "https://github.com/BitsByToader/Tsuki/blob/main/Shared/TsukiApp.swift"
    click ContentView "https://github.com/BitsByToader/Tsuki/blob/main/Shared/Views/ContentView.swift"
```
