# kiraaziz/mangahook-api architecture

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

- Interactive diagram: https://gitdiagram.com/kiraaziz/mangahook-api
- Repository: https://github.com/kiraaziz/mangahook-api

## Overview

##### Project type and purpose
- This is primarily an API-focused project (“Manga Hook”) that provides manga data endpoints (Express.js server under /server).
- It also includes two adjacent artifacts:
a) A documentation site built with Astro in /docs
b) A Next.js example client (“next exemple”) that demonstrates how to consume the API with React hooks.

##### File structure
- Top-level:
- /server → Express.js API with controllers, middleware, routes, and environment config
- /docs → Static documentation site (Astro) with its own config, content, assets, public folder
- /next exemple → Next.js client app showcasing ready-to-use hooks
- /types → Shared TypeScript interfaces for manga and mangaList
- The server folder follows an MVC-style pattern:
- controllers/ handle business logic per resource (manga, list, search)
- middleware/ performs request validation, API-key checking, data collection
- routes/ wire endpoints to controllers
- app.js sets up Express, middleware chain, and mounts routers
- The Next.js example app further splits into:
- /app (new App Router pages)
- /components (UI primitives and layout)
- /hooks (custom React hooks calling your API)
- /docs holds Astro’s config, MDX content, public assets, and tsconfig.

##### Key insights from README
- The core functionality is the Express API exposing endpoints under /api (GET /api/mangaList, /api/manga/:id, /api/search, /api/manga/:id/chapters, etc.)
- Features: listing manga, single manga, chapter list, chapter images, searching
- The Next.js example is there to illustrate usage via React hooks
- The documentation site is deployed separately and describes usage

##### Final advice
- Be detailed: break the API server into its three main layers
- Endpoints grouped under the manga resource
- Separate static documentation from interactive client
- How the shared TypeScript types tie client and server together

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Documentation Site
    subgraph "Astro Docs Site" 
        direction TB
        DocsMain["Astro Docs Site"]:::docs
        DocsConfig["Config (astro.config.mjs, package.json)"]:::docs
        DocsContent["MDX Content"]:::docs
        DocsPublic["Public Assets"]:::docs
    end

    %% Next.js Example Client
    subgraph "Next.js Client (Example)" 
        direction TB
        NextJSMain["Next.js Client"]:::client
        NextAppRouter["App Router Pages"]:::client
        NextComponents["UI Components"]:::client
        NextHooks["Custom Hooks"]:::client
        NextConfigFile["next.config.js"]:::client
        NextTailwind["tailwind.config.js"]:::client
        NextStyles["Styles"]:::client
    end

    %% Express API Server
    subgraph "Express API Server" 
        direction TB
        App["Express App"]:::server

        subgraph "Routes Layer"
            direction TB
            MLRouter["Manga List Routes"]:::server
            MRouter["Manga & Chapters Routes"]:::server
            SearchRouter["Search Routes"]:::server
        end

        subgraph "Middleware Layer"
            direction TB
            APIKey["API Key Validation"]:::middleware
            MangaExist["Manga Existence Checks"]:::middleware
            ChapterExist["Chapter Existence Checks"]:::middleware
            MangaListMiddlewares["MangaList Middlewares"]:::middleware
            SearchValidation["Search Page Validation"]:::middleware
        end

        subgraph "Controllers Layer"
            direction TB
            ListController["ListMangaController"]:::controller
            MangaController["MangaController"]:::controller
            ChapterController["ChapterController"]:::controller
            SearchController["SearchMangaController"]:::controller
        end

        External["External Manga Source"]:::external
    end

    %% Shared Types
    Types["Shared Type Definitions"]:::types

    %% Connections
    DocsMain --> DocsConfig
    DocsMain --> DocsContent
    DocsMain --> DocsPublic

    NextJSMain --> NextAppRouter
    NextJSMain --> NextComponents
    NextJSMain --> NextHooks
    NextJSMain --> NextConfigFile
    NextJSMain --> NextTailwind
    NextJSMain --> NextStyles

    NextJSMain -->|HTTP/JSON| App
    NextHooks -->|calls API| App

    App --> MLRouter
    App --> MRouter
    App --> SearchRouter

    MLRouter -->|uses| MangaListMiddlewares
    MRouter -->|uses| APIKey
    MRouter -->|uses| MangaExist
    MRouter -->|uses| ChapterExist
    SearchRouter -->|uses| SearchValidation

    MangaListMiddlewares --> ListController
    APIKey --> ListController
    APIKey --> MangaController
    MangaExist --> MangaController
    MangaExist --> ChapterController
    ChapterExist --> ChapterController
    SearchValidation --> SearchController

    ListController --> External
    MangaController --> External
    ChapterController --> External
    SearchController --> External

    Types --> NextJSMain
    Types --> App

    %% Click Events
    click App "https://github.com/kiraaziz/mangahook-api/blob/main/server/app.js"
    click ListController "https://github.com/kiraaziz/mangahook-api/blob/main/server/controllers/ListMangaController.js"
    click MangaController "https://github.com/kiraaziz/mangahook-api/blob/main/server/controllers/mangaController.js"
    click ChapterController "https://github.com/kiraaziz/mangahook-api/blob/main/server/controllers/chapterController.js"
    click SearchController "https://github.com/kiraaziz/mangahook-api/blob/main/server/controllers/searchMangaController.js"
    click APIKey "https://github.com/kiraaziz/mangahook-api/blob/main/server/middleware/apiKeyMiddleware.js"
    click MangaExist "https://github.com/kiraaziz/mangahook-api/blob/main/server/middleware/manga/mangaExistMiddleware.js"
    click ChapterExist "https://github.com/kiraaziz/mangahook-api/blob/main/server/middleware/manga/chapterExistMiddleware.js"
    click MangaListMiddlewares "https://github.com/kiraaziz/mangahook-api/tree/main/server/middleware/mangaList/"
    click SearchValidation "https://github.com/kiraaziz/mangahook-api/blob/main/server/middleware/search/searchPageValidationMiddleware.js"
    click MLRouter "https://github.com/kiraaziz/mangahook-api/blob/main/server/routes/mangaListRouter.js"
    click MRouter "https://github.com/kiraaziz/mangahook-api/blob/main/server/routes/mangaRouter.js"
    click SearchRouter "https://github.com/kiraaziz/mangahook-api/blob/main/server/routes/mangaSearch.js"
    click DocsConfig "https://github.com/kiraaziz/mangahook-api/blob/main/docs/astro.config.mjs"
    click DocsContent "https://github.com/kiraaziz/mangahook-api/tree/main/docs/src/content/docs/"
    click DocsPublic "https://github.com/kiraaziz/mangahook-api/tree/main/docs/public/"
    click NextJSMain "https://github.com/kiraaziz/mangahook-api/tree/main/next exemple/app/"
    click NextComponents "https://github.com/kiraaziz/mangahook-api/tree/main/next exemple/components/"
    click NextHooks "https://github.com/kiraaziz/mangahook-api/tree/main/next exemple/hooks/"
    click NextConfigFile "https://github.com/kiraaziz/mangahook-api/blob/main/next exemple/next.config.js"
    click NextTailwind "https://github.com/kiraaziz/mangahook-api/blob/main/next exemple/tailwind.config.js"
    click NextStyles "https://github.com/kiraaziz/mangahook-api/tree/main/next exemple/styles/"
    click Types "https://github.com/kiraaziz/mangahook-api/blob/main/types/manga.ts"

    %% Styles
    classDef client fill:#cce5ff,stroke:#004085,color:#004085
    classDef server fill:#d4edda,stroke:#155724,color:#155724
    classDef middleware fill:#fff3cd,stroke:#856404,color:#856404
    classDef controller fill:#f8d7da,stroke:#721c24,color:#721c24
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d
    classDef docs fill:#ffe5b4,stroke:#cc8400,color:#cc8400
    classDef types fill:#e3e4fa,stroke:#6f42c1,color:#6f42c1
```
