# ryoutajs/anime-search architecture

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

- Interactive diagram: https://gitdiagram.com/ryoutajs/anime-search
- Repository: https://github.com/ryoutajs/anime-search

## Overview

Based on your project’s file structure and the README, this is a Next.js–based web application for searching anime by season and title. It uses TypeScript, Chakra UI for the UI layer, Apollo Client along with GraphQL to fetch data from the external Annict API, and is hosted on Vercel.

##### Main Components
- GraphQL Client Layer: Located in src/graphqlClient (apollo.ts) and aided by hooks (in src/hooks such as useFetchAnimeData.ts and useSeasonData.ts) that orchestrate data fetching.
- External API (Annict API): The source of anime data, which is fetched using GraphQL queries (defined in src/queries/fetchAnimeData.ts).
- Styling & UI Library: The integration of Chakra UI is important for rendering consistent themes (see src/styles/theme.ts).
- Deployment Environment: Vercel, indicating that the entire application is hosted using Vercel’s platform.

##### Relationships and Interactions
- The Next.js pages (for example, the home page in src/pages/index.tsx) serve the UI.
- These pages use React components (from src/components) to build the visual layout.
- UI interactions (clicking buttons, entering text in the SearchBar) trigger hooks (e.g., useFetchAnimeData, useSeasonData) that call functions from the GraphQL client.
- The Apollo Client in src/graphqlClient/apollo.ts takes care of executing GraphQL queries defined in src/queries and fetches the required anime data from the Annict API.
- Fetched data flows back into the components and is rendered appropriately, with the LoadingIndicator component used for user feedback during these operations.
- The overall UI leverages Chakra UI for styling and theming.

##### Architectural Patterns & Design Principles
- Component-based architecture: The project is separated into modular UI components (such as AnimeCard, Header, SearchBar).
- Separation of concerns: Pages handle routing and high-level view logic, while hooks and GraphQL client manage data operations.
- Declarative Data Fetching: Use of Apollo Client to manage GraphQL queries and caching.
- The design clearly separates concerns for styling (theme file) and data access (GraphQL client and related queries).

##### Relevant Technologies
- Next.js (version 14.2.5) for the React framework.
- TypeScript for type safety.
- Chakra UI for front-end styling.
- Apollo Client and GraphQL for data fetching.
- Annict API as the external source of anime information.
- Vercel for hosting/deployment.

##### Elements
- From user interactions to UI components.
- From components to custom hooks.
- From hooks to the Apollo Client.
- From Apollo Client to the Annict API.
- And the reverse flow for rendering fetched data.
- Frontend/UI components (e.g., rectangles),
- Third-party/external systems such as Annict API.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User and Browser
    User["User Interaction"]:::user
    Browser["Browser (Client)"]:::client

    %% Next.js Server Layer
    subgraph "Next.js Server"
        Pages["Next.js Pages (_app.tsx, index.tsx)"]:::pages
        Components["UI Components"]:::components
    end

    %% UI Components Group
    subgraph "UI Components"
        Header["Header"]:::component
        AnimeCard["AnimeCard"]:::component
        AnimeCardBody["AnimeCardBody"]:::component
        SearchBar["SearchBar"]:::component
        LoadingIndicator["LoadingIndicator"]:::component
    end

    %% Data Fetching & GraphQL Layer
    subgraph "Data Layer"
        Hooks["Data Fetching Hooks (useFetchAnimeData, useSeasonData)"]:::hooks
        Apollo["Apollo Client"]:::apollo
        GraphQLQuery["GraphQL Query (fetchAnimeData)"]:::query
        AnnictAPI["Annict API"]:::external
    end

    %% Styling and Deployment
    Theme["Chakra UI Theme"]:::theme
    Vercel["Vercel (Hosting)"]:::vercel

    %% Connections
    User -->|"interacts"| Browser
    Browser -->|"loads"| Pages
    Pages -->|"renders"| Components

    Components -->|"includes"| Header
    Components -->|"includes"| AnimeCard
    AnimeCard -->|"contains"| AnimeCardBody
    Components -->|"includes"| SearchBar
    Components -->|"includes"| LoadingIndicator

    SearchBar -->|"triggers"| Hooks
    Header -->|"may trigger"| Hooks

    Hooks -->|"calls"| Apollo
    Apollo -->|"executes"| GraphQLQuery
    GraphQLQuery -->|"fetches data from"| AnnictAPI
    AnnictAPI -->|"returns data to"| GraphQLQuery
    GraphQLQuery -->|"sends data to"| Apollo
    Apollo -->|"provides data to"| Hooks
    Hooks -->|"updates"| Components

    Pages -->|"styled by"| Theme
    Pages -->|"deployed on"| Vercel

    %% Click Events
    click Pages "https://github.com/ryoutajs/anime-search/tree/main/src/pages"
    click Header "https://github.com/ryoutajs/anime-search/blob/main/src/components/Header/Header.tsx"
    click AnimeCard "https://github.com/ryoutajs/anime-search/blob/main/src/components/AnimeCard/AnimeCard.tsx"
    click AnimeCardBody "https://github.com/ryoutajs/anime-search/blob/main/src/components/AnimeCardBody/AnimeCardBody.tsx"
    click SearchBar "https://github.com/ryoutajs/anime-search/blob/main/src/components/SearchBar/SearchBar.tsx"
    click LoadingIndicator "https://github.com/ryoutajs/anime-search/blob/main/src/components/LoadingIndicator/LoadingIndicator.tsx"
    click Apollo "https://github.com/ryoutajs/anime-search/blob/main/src/graphqlClient/apollo.ts"
    click Hooks "https://github.com/ryoutajs/anime-search/tree/main/src/hooks"
    click GraphQLQuery "https://github.com/ryoutajs/anime-search/blob/main/src/queries/fetchAnimeData.ts"
    click Theme "https://github.com/ryoutajs/anime-search/blob/main/src/styles/theme.ts"

    %% Styles
    classDef client fill:#e1f5fe,stroke:#0277bd,stroke-width:2px;
    classDef user fill:#fce4ec,stroke:#c2185b,stroke-width:2px;
    classDef pages fill:#e8f5e9,stroke:#388e3c,stroke-width:2px;
    classDef components fill:#fff3e0,stroke:#f57c00,stroke-width:2px;
    classDef component fill:#ffe0b2,stroke:#ef6c00,stroke-width:2px;
    classDef hooks fill:#e3f2fd,stroke:#1976d2,stroke-width:2px;
    classDef apollo fill:#ede7f6,stroke:#5e35b1,stroke-width:2px;
    classDef query fill:#f3e5f5,stroke:#8e24aa,stroke-width:2px;
    classDef external fill:#ffebee,stroke:#c62828,stroke-width:2px;
    classDef theme fill:#e0f7fa,stroke:#00838f,stroke-width:2px;
    classDef vercel fill:#e8eaf6,stroke:#3949ab,stroke-width:2px;
```
