# zennomi/truyendex architecture

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

- Interactive diagram: https://gitdiagram.com/zennomi/truyendex
- Repository: https://github.com/zennomi/truyendex

## Overview

##### Main Components

a) Frontend Layer:
- Next.js Application (Client-side)
- Main routes (/app directory structure)
- Authentication flows
- Manga reading interface
- User interface components
- Progressive Web App (PWA) features
- Service Worker (src/app/sw.ts)
- Offline functionality

b) API Layer:
- Internal API Routes (/api)
- External API Integration
- MangaDex API client
- Authentication services

c) Core Services:
- User Management
- Reading History
- Following System
- Comment System
- Sync System

d) Data Storage:
- Browser Storage (LocalStorage/IndexedDB for offline support)
- External Data Sources (MangaDex)

##### Relationship Flows to Highlight

- User authentication flow
- Manga data retrieval from MangaDex
- Comment system interactions
- Reading history synchronization
- Following/subscription flows

##### Specific Implementation Details

a) Frontend Architecture:
**Client Layer**
- Main Layout ((main) route group)
- Auth Layout ((auth) route group)
- Manga Reader Layout (nettrom route group)
- Components
- Core Components
- Manga Related Components
- UI Components (shadcn)

b) API Integration:
**API Layer**
- MangaDex API Client
- Authentication
- Manga Data
- Chapter Data
- User Data
- Internal API
- Sync
- Comments
- User Management

##### Technical Stack Indicators

- Next.js
- TypeScript
- TailwindCSS
- MangaDex API
- PWA features

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        MainRoutes["Main Routes"]:::frontend
        AuthUI["Authentication UI"]:::frontend
        Reader["Manga Reader"]:::frontend
        UIComp["UI Components"]:::frontend
        CoreUI["Core UI Components"]:::frontend
        Settings["Settings Management"]:::frontend
        Search["Search Interface"]:::frontend
        Offline["Offline Features"]:::frontend
    end

    subgraph PWA
        SW["Service Worker"]:::pwa
        Manifest["PWA Manifest"]:::pwa
    end

    subgraph "API Layer"
        MDClient["MangaDex Client"]:::api
        AuthService["Auth Service"]:::api
        UserMgmt["User Management"]:::api
        CommentSys["Comment System"]:::api
        FollowSys["Following System"]:::api
        ChapterMgmt["Chapter Management"]:::api
        MangaData["Manga Data Service"]:::api
        CoreAPI["Core API Services"]:::api
    end

    subgraph "Core Services"
        ReadHistory["Reading History"]:::service
        SyncSystem["Sync System"]:::service
    end

    subgraph "Storage"
        Browser[("Browser Storage")]:::storage
        MangaDex[("MangaDex API")]:::external
    end

    MainRoutes --> UIComp
    MainRoutes --> CoreUI
    MainRoutes --> AuthUI
    MainRoutes --> Reader
    Reader --> ChapterMgmt
    UIComp --> Search
    CoreUI --> Offline
    CoreUI --> Settings

    AuthUI --> AuthService
    AuthService --> MangaDex
    
    MDClient --> MangaDex
    MDClient --> ChapterMgmt
    MDClient --> MangaData
    
    Reader --> ReadHistory
    ReadHistory --> Browser
    
    SyncSystem --> Browser
    SyncSystem --> MangaDex
    
    CommentSys --> CoreAPI
    FollowSys --> MangaDex
    UserMgmt --> CoreAPI
    
    SW --> Offline
    Manifest --> SW

    %% Click Events
    click MainRoutes "https://github.com/zennomi/truyendex/tree/develop/src/app/(main)"
    click AuthUI "https://github.com/zennomi/truyendex/tree/develop/src/app/(main)/(auth)"
    click Reader "https://github.com/zennomi/truyendex/tree/develop/src/app/(nettrom)"
    click UIComp "https://github.com/zennomi/truyendex/tree/develop/src/components/nettrom"
    click CoreUI "https://github.com/zennomi/truyendex/tree/develop/src/components/core"
    click MDClient "https://github.com/zennomi/truyendex/tree/develop/src/api/mangadex"
    click AuthService "https://github.com/zennomi/truyendex/blob/develop/src/api/mangadex/authentication.ts"
    click UserMgmt "https://github.com/zennomi/truyendex/blob/develop/src/api/core/user.ts"
    click CommentSys "https://github.com/zennomi/truyendex/blob/develop/src/api/core/comment.ts"
    click FollowSys "https://github.com/zennomi/truyendex/blob/develop/src/api/mangadex/follows.ts"
    click ReadHistory "https://github.com/zennomi/truyendex/blob/develop/src/hooks/useReadingHistory.tsx"
    click SyncSystem "https://github.com/zennomi/truyendex/tree/develop/public/js/sync"
    click SW "https://github.com/zennomi/truyendex/blob/develop/src/app/sw.ts"
    click Manifest "https://github.com/zennomi/truyendex/blob/develop/src/app/manifest.ts"
    click ChapterMgmt "https://github.com/zennomi/truyendex/blob/develop/src/api/mangadex/chapter.ts"
    click MangaData "https://github.com/zennomi/truyendex/blob/develop/src/api/mangadex/manga.ts"
    click CoreAPI "https://github.com/zennomi/truyendex/tree/develop/src/api/core"
    click Settings "https://github.com/zennomi/truyendex/blob/develop/src/contexts/settings.tsx"
    click Offline "https://github.com/zennomi/truyendex/blob/develop/src/components/core/offline.tsx"
    click Search "https://github.com/zennomi/truyendex/tree/develop/src/components/nettrom/tim-kiem"

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef service fill:#e74c3c,stroke:#c0392b,color:white
    classDef storage fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#e67e22,stroke:#d35400,color:white
    classDef pwa fill:#f1c40f,stroke:#f39c12,color:white
```
