# anime-kun32/hianime-mapper architecture

> Architecture diagram of the GitHub repository anime-kun32/hianime-mapper, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/anime-kun32/hianime-mapper
- Repository: https://github.com/anime-kun32/hianime-mapper

## Overview

1. **What this repo is**
   - `Hianime-mapper` is a small TypeScript/Node.js API that translates an AniList anime ID into Hianime-related data: anime details, episode/server mappings, and playable streaming sources.

2. **Top-level architecture**
   - The project is organized as a thin HTTP layer plus a set of scraping/decryption helpers.
   - The API surface is defined in `src/server.ts`.
   - The heavy lifting is split into `src/extractors/` and `src/utils/`.

3. **HTTP entrypoint and routing**
   - `src/server.ts` is the main application bootstrap and route registry.
   - It is built on **Hono.js**, so the server is lightweight and likely deployed as a serverless-compatible app.
   - The public routes documented in the README are:
     - `/anime/info/:anilistId`
     - `/anime/servers/:episodeId`
     - `/anime/sources?serverId=...&episodeId=...`

4. **Request-to-response flow**
   - A request enters the Hono app in `server.ts`.
   - The route handler calls into utility/extractor code to fetch remote Hianime data.
   - The result is normalized into a consistent JSON shape and returned as `data: ...`.
   - This means the API is primarily an orchestration layer over external content sources, not a database-backed service.

5. **AniList-to-Hianime mapping boundary**
   - The `/anime/info/:anilistId` endpoint is the main mapping layer.
   - It enriches an AniList ID into a full anime payload plus `episodesList`, which is the key bridge from metadata to Hianime episode IDs.
   - This is the core domain boundary of the repo: AniList identity on one side, Hianime episode/source discovery on the other.

6. **Episode server discovery**
   - `/anime/servers/:episodeId` exposes the next boundary down the pipeline.
   - Given a Hianime episode ID, it returns available **sub** and **dub** server lists.
   - This is a discovery step before actual video URL extraction.

7. **Streaming source extraction**
   - `/anime/sources` is the final fetch step in the data flow.
   - It accepts `serverId` and `episodeId` and returns streaming metadata:
     - intro/outro timings
     - source URLs and formats
     - subtitle tracks
     - server identifier
   - This endpoint is where playback-ready M3U8-style URLs are surfaced.

8. **Extractor subsystem**
   - `src/extractors/megacloud.ts` is the only named extractor in the tree, so the repo likely uses a provider-specific implementation for Hianime playback hosts.
   - This file is the boundary between the API and the actual host-specific extraction logic.
   - The architecture suggests provider swapping is possible, even if only one extractor is currently present.

9. **Utility layer responsibilities**
   - `src/utils/client.ts` likely centralizes outbound HTTP requests and request headers/session behavior.
   - `src/utils/decrypt.ts` indicates the source URLs or tokens require decryption or signature handling before they can be used.
   - `src/utils/methods.ts` and `src/utils/constant.ts` likely hold shared parsing logic, string helpers, and fixed values used across routes/extractors.
   - This utility layer keeps the route handlers thin and isolates fragile scraping logic.

10. **Type and contract surface**
   - `src/index.d.ts` suggests the repo defines custom TypeScript types for request/response shapes or extracted payloads.
   - That matters architecturally because the API is contract-driven: the response structures in the README are part of the public interface.

11. **Deployment/runtime boundary**
   - `vercel.json` shows the service is intended for **Vercel** deployment.
   - That implies serverless/edge-style constraints may influence how requests are made, how state is handled, and why the code stays stateless.

12. **Cross-origin access**
   - The README notes CORS is configured in `server.ts` via an allowlist of frontend origins.
   - This indicates the API is meant to be consumed by external web clients, not just server-to-server calls.

13. **External dependencies and assumptions**
   - The API depends on remote services rather than internal storage:
     - AniList for anime identity/metadata
     - Hianime for episodes/servers/sources
     - a Megacloud-like streaming host for media URLs
   - There is no evidence of a database, queue, or persistent cache in the repo tree, so the architecture is stateless and fetch-driven.

14. **Diagramming takeaway**
   - The cleanest architecture diagram would show:
     - client/front-end callers
     - Hono API (`server.ts`)
     - route-specific handlers
     - utility/decryption layer
     - extractor/provider layer
     - external services: AniList, Hianime, and the streaming host
   - The key flow is metadata lookup first, then episode/server discovery, then source URL extraction.

Main entry points: [`src/server.ts`](https://github.com/anime-kun32/hianime-mapper/blob/main/src/server.ts) (Anime info), [`src/extractors/megacloud.ts`](https://github.com/anime-kun32/hianime-mapper/blob/main/src/extractors/megacloud.ts) (Megacloud), [`src/utils/client.ts`](https://github.com/anime-kun32/hianime-mapper/blob/main/src/utils/client.ts) (HTTP client), [`src/utils/decrypt.ts`](https://github.com/anime-kun32/hianime-mapper/blob/main/src/utils/decrypt.ts) (Decrypt layer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_api["HTTP API"]
  node_n_server["Server<br/>hono app<br/>[server.ts]"]
  node_n_info["Anime info<br/>route<br/>[server.ts]"]
  node_n_servers["Episode servers<br/>route<br/>[server.ts]"]
  node_n_sources["Streaming sources<br/>route<br/>[server.ts]"]
end

subgraph group_g_core["Core pipeline"]
  node_n_http["HTTP client<br/>fetch util<br/>[client.ts]"]
  node_n_crypto["Decrypt layer<br/>crypto util<br/>[decrypt.ts]"]
  node_n_shared["Shared helpers<br/>parse utils<br/>[methods.ts]"]
  node_n_extractor["Megacloud<br/>provider extractor<br/>[megacloud.ts]"]
  node_n_types["Contracts<br/>ts types<br/>[index.d.ts]"]
end

subgraph group_g_external["External systems"]
  node_n_client(("Clients<br/>callers"))
  node_n_anilist(("AniList<br/>metadata API"))
  node_n_hianime(("Hianime<br/>content site"))
  node_n_stream(("Stream host<br/>media host"))
  node_n_vercel["Vercel<br/>deployment<br/>[vercel.json]"]
end

node_n_client -->|"HTTP request"| node_n_server
node_n_server -->|"registers"| node_n_info
node_n_server -->|"registers"| node_n_servers
node_n_server -->|"registers"| node_n_sources
node_n_info -->|"lookup"| node_n_anilist
node_n_info -->|"map"| node_n_hianime
node_n_info -->|"fetch"| node_n_http
node_n_info -->|"normalize"| node_n_shared
node_n_info -->|"contracts"| node_n_types
node_n_servers -->|"discover"| node_n_hianime
node_n_servers -->|"fetch"| node_n_http
node_n_servers -->|"parse"| node_n_shared
node_n_sources -->|"resolve"| node_n_hianime
node_n_sources -->|"extract"| node_n_extractor
node_n_sources -->|"decrypt"| node_n_crypto
node_n_extractor -->|"load"| node_n_stream
node_n_extractor -->|"fetch"| node_n_http
node_n_extractor -->|"decrypt"| node_n_crypto
node_n_server -->|"deploys on"| node_n_vercel

click node_n_server "https://github.com/anime-kun32/hianime-mapper/blob/main/src/server.ts"
click node_n_info "https://github.com/anime-kun32/hianime-mapper/blob/main/src/server.ts"
click node_n_servers "https://github.com/anime-kun32/hianime-mapper/blob/main/src/server.ts"
click node_n_sources "https://github.com/anime-kun32/hianime-mapper/blob/main/src/server.ts"
click node_n_http "https://github.com/anime-kun32/hianime-mapper/blob/main/src/utils/client.ts"
click node_n_crypto "https://github.com/anime-kun32/hianime-mapper/blob/main/src/utils/decrypt.ts"
click node_n_shared "https://github.com/anime-kun32/hianime-mapper/blob/main/src/utils/methods.ts"
click node_n_extractor "https://github.com/anime-kun32/hianime-mapper/blob/main/src/extractors/megacloud.ts"
click node_n_types "https://github.com/anime-kun32/hianime-mapper/blob/main/src/index.d.ts"
click node_n_vercel "https://github.com/anime-kun32/hianime-mapper/blob/main/vercel.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_server,node_n_info,node_n_servers,node_n_sources toneBlue
class node_n_http,node_n_crypto,node_n_shared,node_n_extractor,node_n_types toneAmber
class node_n_client,node_n_anilist,node_n_hianime,node_n_stream,node_n_vercel toneMint
```

## Components

### HTTP API

Public request surface and route handlers

- [Server](https://github.com/anime-kun32/hianime-mapper/blob/main/src/server.ts): hono app · HTTP bootstrap and route registry · `src/server.ts`
- [Anime info](https://github.com/anime-kun32/hianime-mapper/blob/main/src/server.ts): route · AniList ID to anime payload and episode list · `src/server.ts`
- [Episode servers](https://github.com/anime-kun32/hianime-mapper/blob/main/src/server.ts): route · Episode ID to sub and dub server lists · `src/server.ts`
- [Streaming sources](https://github.com/anime-kun32/hianime-mapper/blob/main/src/server.ts): route · Server and episode ID to playback-ready source data · `src/server.ts`

### Core pipeline

Shared utilities, extraction logic, and contracts

- [HTTP client](https://github.com/anime-kun32/hianime-mapper/blob/main/src/utils/client.ts): fetch util · Outbound requests and request/session behavior · `src/utils/client.ts`
- [Decrypt layer](https://github.com/anime-kun32/hianime-mapper/blob/main/src/utils/decrypt.ts): crypto util · Token or source decryption and signature handling · `src/utils/decrypt.ts`
- [Shared helpers](https://github.com/anime-kun32/hianime-mapper/blob/main/src/utils/methods.ts): parse utils · Common methods and constants used across routes · `src/utils/methods.ts`
- [Megacloud](https://github.com/anime-kun32/hianime-mapper/blob/main/src/extractors/megacloud.ts): provider extractor · Host-specific source extraction implementation · `src/extractors/megacloud.ts`
- [Contracts](https://github.com/anime-kun32/hianime-mapper/blob/main/src/index.d.ts): ts types · Custom response and payload type definitions · `src/index.d.ts`

### External systems

Remote services and deployment target

- **Clients**: callers · Frontend or API consumers invoking the service
- **AniList**: metadata API · Anime identity and metadata source
- **Hianime**: content site · Episode, server, and source discovery target
- **Stream host**: media host · Playback host behind extracted source URLs
- [Vercel](https://github.com/anime-kun32/hianime-mapper/blob/main/vercel.json): deployment · Serverless deployment target · `vercel.json`

## Connections

- Clients → Server: HTTP request · Consumers call the public API
- Server → Anime info: registers · Route registry exposes AniList mapping endpoint
- Server → Episode servers: registers · Route registry exposes server discovery endpoint
- Server → Streaming sources: registers · Route registry exposes streaming source endpoint
- Anime info → AniList: lookup · Resolves AniList identity and metadata
- Anime info → Hianime: map · Translates metadata into Hianime episode listings
- Anime info → HTTP client: fetch · Uses shared outbound client for remote requests
- Anime info → Shared helpers: normalize · Applies shared parsing and shaping logic
- Anime info → Contracts: contracts · Returns typed API payloads
- Episode servers → Hianime: discover · Fetches episode server lists from Hianime
- Episode servers → HTTP client: fetch · Uses shared outbound client for remote requests
- Episode servers → Shared helpers: parse · Reuses shared parsing and constants
- Streaming sources → Hianime: resolve · Uses episode and server IDs to reach source data
- Streaming sources → Megacloud: extract · Delegates host-specific playback extraction
- Streaming sources → Decrypt layer: decrypt · Decodes signed or protected source data
- Megacloud → Stream host: load · Pulls playable media URLs from the host
- Megacloud → HTTP client: fetch · Uses shared outbound client for remote requests
- Megacloud → Decrypt layer: decrypt · Handles provider-specific protected payloads
- Server → Vercel: deploys on · Configured for Vercel runtime
