# gizmo-ds/misstodon architecture

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

- Interactive diagram: https://gitdiagram.com/gizmo-ds/misstodon
- Repository: https://github.com/gizmo-ds/misstodon

## Overview

##### Project type and purpose
- This is an open-source API proxy service (“misstodon”) written in Go.
- It exposes Mastodon-compatible HTTP endpoints and internally translates them into Misskey API calls.
- Its primary goal is to let Mastodon clients work against a Misskey server by providing compatibility layers for OAuth, REST, nodeinfo, streaming, etc.

##### File structure
- Top-level:
- cmd/misstodon: CLI entrypoint (`main.go`), subcommand wiring, logging setup.
- internal/api: HTTP server implementation (router, middleware, versioned handlers).
- internal/database: local caching via BuntDB.
- internal/global: configuration and build info.
- pkg/httpclient: reusable HTTP client abstraction.
- pkg/misstodon/provider/misskey: the core translation logic that maps Mastodon API calls to Misskey endpoints using the HTTP client.
- Config/deployment:
- config_example.toml / environment variables
- Dockerfile, docker-compose.yml, Makefile for containerization and local development.

##### README for additional insights
- It details supported endpoints (/.well-known, /nodeinfo, /api/v1, streaming, media, timelines, etc.).
- Points out self-hosting via Docker Compose, and a fallback_server configuration to point to any Misskey instance.

## Diagram (Mermaid)

```mermaid
flowchart TB
    Client["Client (Mastodon)"]:::external

    subgraph "misstodon HTTP Server"
        subgraph "CLI Startup"
            Main["main.go"]:::request
            Commands["start.go"]:::request
            LoggerCLI["logger.go"]:::request
        end

        subgraph "Global Config"
            Config["config.go"]:::request
            BuildInfo["buildinfo.go"]:::request
            GlobalDBConf["database.go"]:::request
        end

        Router["router.go"]:::request
        ErrorHandler["error.go"]:::request

        subgraph "Middleware Stack"
            ContextMW["context.go"]:::request
            CORSMW["cors.go"]:::request
            LoggerMW["logger.go"]:::request
            RecoverMW["recover.go"]:::request
        end

        subgraph "Controllers"
            WellKnown["wellknown.go"]:::request
            OAuth["oauth.go"]:::request
            NodeInfo["nodeinfo.go"]:::request
            V1["v1 (accounts, application, instance, media, notifications, staticfile, statuses, streaming, timelines, trends)"]:::request
            V2["media.go (v2)"]:::request
        end
    end

    subgraph "Translation Layer"
        Provider["Misskey Provider"]:::library
        subgraph "HTTP Client"
            HTTPClientCore["httpclient.go"]:::library
            HTTPClientResty["resty.go"]:::library
        end
        subgraph "Models & Utils"
            Models["models/*.go"]:::library
            UtilsHTTP["http.go"]:::library
            UtilsMap["map.go"]:::library
            UtilsGen["utils.go"]:::library
        end
    end

    Cache["BuntDB Cache (db.go)"]:::datastore

    Misskey["Misskey Instance"]:::external

    %% Connections
    Client -->|HTTP Request| Router
    Router -->|routes to| ErrorHandler
    ErrorHandler -->|passes to| ContextMW
    ContextMW --> CORSMW --> LoggerMW --> RecoverMW --> WellKnown
    RecoverMW --> OAuth
    RecoverMW --> NodeInfo
    RecoverMW --> V1
    RecoverMW --> V2

    WellKnown -->|translates via| Provider
    OAuth --> Provider
    NodeInfo --> Provider
    V1 --> Provider
    V2 --> Provider

    WellKnown <--> Cache
    OAuth <--> Cache
    NodeInfo <--> Cache
    V1 <--> Cache
    V2 <--> Cache

    Provider --> HTTPClientCore
    Provider --> HTTPClientResty
    HTTPClientCore --> Misskey
    HTTPClientResty --> Misskey

    %% Click Events
    click Main "https://github.com/gizmo-ds/misstodon/blob/main/cmd/misstodon/main.go"
    click Commands "https://github.com/gizmo-ds/misstodon/blob/main/cmd/misstodon/commands/start.go"
    click LoggerCLI "https://github.com/gizmo-ds/misstodon/blob/main/cmd/misstodon/logger/logger.go"
    click Config "https://github.com/gizmo-ds/misstodon/blob/main/internal/global/config.go"
    click BuildInfo "https://github.com/gizmo-ds/misstodon/blob/main/internal/global/buildinfo.go"
    click GlobalDBConf "https://github.com/gizmo-ds/misstodon/blob/main/internal/global/database.go"
    click Router "https://github.com/gizmo-ds/misstodon/blob/main/internal/api/router.go"
    click ErrorHandler "https://github.com/gizmo-ds/misstodon/blob/main/internal/api/httperror/error.go"
    click ContextMW "https://github.com/gizmo-ds/misstodon/blob/main/internal/api/middleware/context.go"
    click CORSMW "https://github.com/gizmo-ds/misstodon/blob/main/internal/api/middleware/cors.go"
    click LoggerMW "https://github.com/gizmo-ds/misstodon/blob/main/internal/api/middleware/logger.go"
    click RecoverMW "https://github.com/gizmo-ds/misstodon/blob/main/internal/api/middleware/recover.go"
    click WellKnown "https://github.com/gizmo-ds/misstodon/blob/main/internal/api/wellknown/wellknown.go"
    click OAuth "https://github.com/gizmo-ds/misstodon/blob/main/internal/api/oauth/oauth.go"
    click NodeInfo "https://github.com/gizmo-ds/misstodon/blob/main/internal/api/nodeinfo/nodeinfo.go"
    click V1 "https://github.com/gizmo-ds/misstodon/blob/main/internal/api/v1/accounts.go"
    click V2 "https://github.com/gizmo-ds/misstodon/blob/main/internal/api/v2/media.go"
    click Cache "https://github.com/gizmo-ds/misstodon/blob/main/internal/database/buntdb/db.go"
    click HTTPClientCore "https://github.com/gizmo-ds/misstodon/blob/main/pkg/httpclient/httpclient.go"
    click HTTPClientResty "https://github.com/gizmo-ds/misstodon/blob/main/pkg/httpclient/resty.go"
    click Provider "https://github.com/gizmo-ds/misstodon/blob/main/pkg/misstodon/provider/misskey/accounts.go"

    %% Styles
    classDef request fill:#DDA0DD,stroke:#333,stroke-width:1px
    classDef external fill:#90EE90,stroke:#333,stroke-width:1px
    classDef datastore fill:#FFA500,stroke:#333,stroke-width:1px
    classDef library fill:#ADD8E6,stroke:#333,stroke-width:1px
```
