# sinkaroid/matoi architecture

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

- Interactive diagram: https://gitdiagram.com/sinkaroid/matoi
- Repository: https://github.com/sinkaroid/matoi

## Overview

Matoi is a unified REST and GraphQL gateway that normalizes results from 15 booru providers into a shared post schema. The principal request path is client → Fiber routing and authentication → REST handler → provider → upstream imageboard; handlers cache results, add proxy-media URLs, and return normalized JSON. GraphQL offers parallel post and tag-completion operations. Configuration and Prometheus metrics are supporting runtime capabilities. The README and selected excerpts establish the main wiring; individual provider implementations and several handler files were not all sampled, so their internal details are not expanded.

Main entry points: [`router/router.go`](https://github.com/sinkaroid/matoi/blob/master/router/router.go) (Route registry), [`handlers`](https://github.com/sinkaroid/matoi/tree/master/handlers) (REST handlers), [`handlers/graphql.go`](https://github.com/sinkaroid/matoi/blob/master/handlers/graphql.go) (GraphQL API), [`providers`](https://github.com/sinkaroid/matoi/tree/master/providers) (Booru providers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API surface"]
  node_server["Fiber server<br/>[main.go]"]
  node_router["Route registry<br/>[router.go]"]
  node_auth["API key auth<br/>[auth.go]"]
  node_rest["REST handlers"]
  node_graphql["GraphQL API<br/>[graphql.go]"]
end

subgraph group_domain["Provider integration"]
  node_posts["Normalized posts<br/>[post.go]"]
  node_providers["Booru providers"]
end

subgraph group_runtime["Runtime services"]
  node_redis[("Redis cache<br/>[redis.go]")]
  node_config["Configuration<br/>[config.go]"]
  node_metrics["Prometheus metrics<br/>[prometheus.go]"]
end

node_client(("API client"))
node_upstream["Booru services"]

node_client -->|"sends request"| node_server
node_server -->|"sets up routes"| node_router
node_router -->|"protects API"| node_auth
node_router -->|"routes requests"| node_rest
node_router -->|"routes GraphQL"| node_graphql
node_router -->|"installs middleware"| node_metrics
node_rest -->|"fetches and completes"| node_providers
node_graphql -->|"resolves queries"| node_providers
node_providers -->|"fetches provider data"| node_upstream
node_providers -->|"normalizes results"| node_posts
node_rest -->|"reads and writes cache"| node_redis
node_graphql -->|"reads cache"| node_redis
node_rest -->|"returns JSON"| node_posts
node_graphql -->|"returns post results"| node_posts
node_server -->|"loads settings"| node_config

click node_server "https://github.com/sinkaroid/matoi/blob/master/main.go"
click node_router "https://github.com/sinkaroid/matoi/blob/master/router/router.go"
click node_auth "https://github.com/sinkaroid/matoi/blob/master/middleware/auth.go"
click node_rest "https://github.com/sinkaroid/matoi/tree/master/handlers"
click node_graphql "https://github.com/sinkaroid/matoi/blob/master/handlers/graphql.go"
click node_posts "https://github.com/sinkaroid/matoi/blob/master/models/post.go"
click node_providers "https://github.com/sinkaroid/matoi/tree/master/providers"
click node_redis "https://github.com/sinkaroid/matoi/blob/master/cache/redis.go"
click node_config "https://github.com/sinkaroid/matoi/blob/master/config/config.go"
click node_metrics "https://github.com/sinkaroid/matoi/blob/master/middleware/prometheus.go"

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_server,node_router,node_auth,node_rest,node_graphql,node_client toneBlue
class node_posts,node_providers toneAmber
class node_redis,node_config,node_metrics toneMint
class node_upstream toneIndigo
```

## Components

### API surface

- [Fiber server](https://github.com/sinkaroid/matoi/blob/master/main.go): `main.go`
- [Route registry](https://github.com/sinkaroid/matoi/blob/master/router/router.go): `router/router.go`
- [API key auth](https://github.com/sinkaroid/matoi/blob/master/middleware/auth.go): `middleware/auth.go`
- [REST handlers](https://github.com/sinkaroid/matoi/tree/master/handlers): `handlers`
- [GraphQL API](https://github.com/sinkaroid/matoi/blob/master/handlers/graphql.go): `handlers/graphql.go`

### Provider integration

- [Normalized posts](https://github.com/sinkaroid/matoi/blob/master/models/post.go): `models/post.go`
- [Booru providers](https://github.com/sinkaroid/matoi/tree/master/providers): `providers`

### Runtime services

- [Redis cache](https://github.com/sinkaroid/matoi/blob/master/cache/redis.go): `cache/redis.go`
- [Configuration](https://github.com/sinkaroid/matoi/blob/master/config/config.go): `config/config.go`
- [Prometheus metrics](https://github.com/sinkaroid/matoi/blob/master/middleware/prometheus.go): `middleware/prometheus.go`

### Other components

- **API client**
- **Booru services**

## Connections

- API client → Fiber server: sends request
- Fiber server → Route registry: sets up routes (evidence: `main.go`)
- Route registry → API key auth: protects API (evidence: `router/router.go`)
- Route registry → REST handlers: routes requests (evidence: `router/router.go`)
- Route registry → GraphQL API: routes GraphQL (evidence: `router/router.go`)
- Route registry → Prometheus metrics: installs middleware (evidence: `router/router.go`)
- REST handlers → Booru providers: fetches and completes (evidence: `handlers/rule34.go`)
- GraphQL API → Booru providers: resolves queries (evidence: `handlers/graphql.go`)
- Booru providers → Booru services: fetches provider data
- Booru providers → Normalized posts: normalizes results
- REST handlers → Redis cache: reads and writes cache (evidence: `handlers/rule34.go`)
- GraphQL API → Redis cache: reads cache (evidence: `handlers/graphql.go`)
- REST handlers → Normalized posts: returns JSON
- GraphQL API → Normalized posts: returns post results (evidence: `handlers/graphql.go`)
- Fiber server → Configuration: loads settings (evidence: `main.go`)
