# cmtdrt/mirage architecture

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

- Interactive diagram: https://gitdiagram.com/cmtdrt/mirage
- Repository: https://github.com/cmtdrt/mirage

## Overview

Mirage is a CLI tool that reads JSON endpoint definitions and serves them as a mock HTTP API. The main workflow is operator → CLI parsing → configuration loading → route registration → HTTP requests and JSON responses. Routes also provide health and per-port logs; responses support status codes, delays, and path-variable substitution. The README additionally documents example-file creation and guide generation. Edges reflect shown calls or documented behavior; some unsampled documentation and example internals are represented only at their supported directory paths.

Main entry points: [`main.go`](https://github.com/cmtdrt/mirage/blob/main/main.go) (Command entry), [`src/server/route.go`](https://github.com/cmtdrt/mirage/blob/main/src/server/route.go) (Route handlers), [`src/server/server.go`](https://github.com/cmtdrt/mirage/blob/main/src/server/server.go) (HTTP servers), [`src/config/config.go`](https://github.com/cmtdrt/mirage/blob/main/src/config/config.go) (Config loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_startup["CLI and startup"]
  node_entry["Command entry<br/>[main.go]"]
  node_flags["CLI flags<br/>[flags.go]"]
  node_config["Config loader<br/>[config.go]"]
  node_input["Config input<br/>[input.go]"]
end

subgraph group_api["Mock API runtime"]
  node_endpoint["Endpoint model<br/>[endpoint.go]"]
  node_routes["Route handlers<br/>[route.go]"]
  node_response["Response writer<br/>[response.go]"]
  node_httpserver["HTTP servers<br/>[server.go]"]
end

subgraph group_observability["Request logging"]
  node_logging[("Per-port logs<br/>[logging.go]")]
end

subgraph group_extras["Examples and guides"]
  node_example["Example creator"]
  node_guides["Guide generator"]
  node_docs["Usage descriptions"]
end

node_operator(("Operator"))
node_apiuser(("API caller"))

node_operator -->|"runs"| node_entry
node_entry -->|"parses flags"| node_flags
node_entry -->|"initializes"| node_logging
node_entry -->|"creates example"| node_example
node_entry -->|"loads config"| node_config
node_entry -->|"registers routes"| node_routes
node_entry -->|"starts servers"| node_httpserver
node_entry -->|"generates guide"| node_guides
node_config -->|"decodes JSON"| node_input
node_routes -->|"uses definitions"| node_endpoint
node_routes -->|"writes response"| node_response
node_routes -->|"records requests"| node_logging
node_routes -->|"prints descriptions"| node_docs
node_httpserver -->|"serves registered routes"| node_routes
node_apiuser -->|"sends HTTP requests"| node_httpserver
node_response -->|"returns JSON"| node_apiuser

click node_entry "https://github.com/cmtdrt/mirage/blob/main/main.go"
click node_flags "https://github.com/cmtdrt/mirage/blob/main/src/cli/flags.go"
click node_config "https://github.com/cmtdrt/mirage/blob/main/src/config/config.go"
click node_input "https://github.com/cmtdrt/mirage/blob/main/src/models/input.go"
click node_endpoint "https://github.com/cmtdrt/mirage/blob/main/src/models/endpoint.go"
click node_routes "https://github.com/cmtdrt/mirage/blob/main/src/server/route.go"
click node_response "https://github.com/cmtdrt/mirage/blob/main/src/server/response.go"
click node_httpserver "https://github.com/cmtdrt/mirage/blob/main/src/server/server.go"
click node_logging "https://github.com/cmtdrt/mirage/blob/main/src/logging/logging.go"
click node_example "https://github.com/cmtdrt/mirage/tree/main/src/example"
click node_guides "https://github.com/cmtdrt/mirage/tree/main/src/doc"
click node_docs "https://github.com/cmtdrt/mirage/tree/main/src/doc"

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_entry,node_flags,node_config,node_input toneBlue
class node_endpoint,node_routes,node_response,node_httpserver toneAmber
class node_logging,node_apiuser toneMint
class node_example,node_guides,node_docs toneRose
class node_operator toneIndigo
```

## Components

### CLI and startup

- [Command entry](https://github.com/cmtdrt/mirage/blob/main/main.go): `main.go`
- [CLI flags](https://github.com/cmtdrt/mirage/blob/main/src/cli/flags.go): `src/cli/flags.go`
- [Config loader](https://github.com/cmtdrt/mirage/blob/main/src/config/config.go): `src/config/config.go`
- [Config input](https://github.com/cmtdrt/mirage/blob/main/src/models/input.go): `src/models/input.go`

### Mock API runtime

- [Endpoint model](https://github.com/cmtdrt/mirage/blob/main/src/models/endpoint.go): `src/models/endpoint.go`
- [Route handlers](https://github.com/cmtdrt/mirage/blob/main/src/server/route.go): `src/server/route.go`
- [Response writer](https://github.com/cmtdrt/mirage/blob/main/src/server/response.go): `src/server/response.go`
- [HTTP servers](https://github.com/cmtdrt/mirage/blob/main/src/server/server.go): `src/server/server.go`

### Request logging

- [Per-port logs](https://github.com/cmtdrt/mirage/blob/main/src/logging/logging.go): `src/logging/logging.go`

### Examples and guides

- [Example creator](https://github.com/cmtdrt/mirage/tree/main/src/example): `src/example`
- [Guide generator](https://github.com/cmtdrt/mirage/tree/main/src/doc): `src/doc`
- [Usage descriptions](https://github.com/cmtdrt/mirage/tree/main/src/doc): `src/doc`

### Other components

- **Operator**
- **API caller**

## Connections

- Operator → Command entry: runs (evidence: `README.md`)
- Command entry → CLI flags: parses flags (evidence: `main.go`)
- Command entry → Per-port logs: initializes (evidence: `main.go`)
- Command entry → Example creator: creates example (evidence: `main.go`)
- Command entry → Config loader: loads config (evidence: `main.go`)
- Command entry → Route handlers: registers routes (evidence: `main.go`)
- Command entry → HTTP servers: starts servers (evidence: `main.go`)
- Command entry → Guide generator: generates guide (evidence: `main.go`)
- Config loader → Config input: decodes JSON (evidence: `src/config/config.go`)
- Route handlers → Endpoint model: uses definitions (evidence: `src/server/route.go`)
- Route handlers → Response writer: writes response (evidence: `src/server/route.go`)
- Route handlers → Per-port logs: records requests (evidence: `src/server/route.go`)
- Route handlers → Usage descriptions: prints descriptions (evidence: `src/server/route.go`)
- HTTP servers → Route handlers: serves registered routes (evidence: `README.md`)
- API caller → HTTP servers: sends HTTP requests (evidence: `README.md`)
- Response writer → API caller: returns JSON (evidence: `README.md`)
