# andyongh/api-server architecture

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

- Interactive diagram: https://gitdiagram.com/andyongh/api-server
- Repository: https://github.com/andyongh/api-server

## Overview

This is a C JSON-RPC API server. A client POST is parsed and authenticated by the HTTP handler, dispatched to a registered method, and returned synchronously or accepted as a background task. Task-management methods let users inspect and control those tasks. The README documents polling, cancellation, refresh, and listing; the sampled implementation confirms these stages. The task store is in-memory. Edges are limited to calls and startup wiring visible in excerpts or explicitly documented; unsampled integrations are omitted.

Main entry points: [`src/server.c`](https://github.com/andyongh/api-server/blob/main/src/server.c) (HTTP server), [`src/methods.c`](https://github.com/andyongh/api-server/blob/main/src/methods.c) (Method registry), [`src/main.c`](https://github.com/andyongh/api-server/blob/main/src/main.c) (Runtime startup), [`src/task_manager.c`](https://github.com/andyongh/api-server/blob/main/src/task_manager.c) (Task lifecycle)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_request["Request handling"]
  node_http["HTTP server<br/>[server.c]"]
  node_rpc["JSON-RPC codec<br/>[jsonrpc.c]"]
  node_auth["Authentication<br/>[auth.c]"]
end

subgraph group_methods["Methods and tasks"]
  node_registry["Method registry<br/>[methods.c]"]
  node_sync["Sync methods<br/>[methods.c]"]
  node_async["Async compute<br/>[methods.c]"]
  node_task_methods["Task operations<br/>[methods.c]"]
  node_task_store[("Task lifecycle<br/>[task_manager.c]")]
end

subgraph group_runtime["Concurrency runtime"]
  node_workers["Worker pool<br/>[worker_pool.c]"]
  node_startup["Runtime startup<br/>[main.c]"]
end

subgraph group_support["Shared support"]
  node_uuid["UUID generation<br/>[uuid.c]"]
  node_logging["Thread-safe logging<br/>[log.h]"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_http
node_http -->|"parses and formats"| node_rpc
node_http -->|"verifies session"| node_auth
node_http -->|"looks up methods"| node_registry
node_http -->|"submits work"| node_workers
node_http -->|"creates tasks"| node_task_store
node_registry -->|"registers handlers"| node_sync
node_registry -->|"registers handlers"| node_async
node_registry -->|"registers handlers"| node_task_methods
node_task_methods -->|"queries and updates"| node_task_store
node_task_store -->|"generates task IDs"| node_uuid
node_startup -->|"initializes and destroys"| node_task_store
node_startup -->|"initializes"| node_registry
node_startup -->|"creates and destroys"| node_workers
node_startup -->|"starts and stops"| node_http

click node_http "https://github.com/andyongh/api-server/blob/main/src/server.c"
click node_rpc "https://github.com/andyongh/api-server/blob/main/src/jsonrpc.c"
click node_auth "https://github.com/andyongh/api-server/blob/main/src/auth.c"
click node_registry "https://github.com/andyongh/api-server/blob/main/src/methods.c"
click node_sync "https://github.com/andyongh/api-server/blob/main/src/methods.c"
click node_async "https://github.com/andyongh/api-server/blob/main/src/methods.c"
click node_task_methods "https://github.com/andyongh/api-server/blob/main/src/methods.c"
click node_task_store "https://github.com/andyongh/api-server/blob/main/src/task_manager.c"
click node_workers "https://github.com/andyongh/api-server/blob/main/src/worker_pool.c"
click node_startup "https://github.com/andyongh/api-server/blob/main/src/main.c"
click node_uuid "https://github.com/andyongh/api-server/blob/main/src/uuid.c"
click node_logging "https://github.com/andyongh/api-server/blob/main/src/log.h"

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_http,node_rpc,node_auth,node_client toneBlue
class node_registry,node_sync,node_async,node_task_methods,node_task_store toneAmber
class node_workers,node_startup toneMint
class node_uuid,node_logging toneRose
```

## Components

### Request handling

- [HTTP server](https://github.com/andyongh/api-server/blob/main/src/server.c): `src/server.c`
- [JSON-RPC codec](https://github.com/andyongh/api-server/blob/main/src/jsonrpc.c): `src/jsonrpc.c`
- [Authentication](https://github.com/andyongh/api-server/blob/main/src/auth.c): `src/auth.c`

### Methods and tasks

- [Method registry](https://github.com/andyongh/api-server/blob/main/src/methods.c): `src/methods.c`
- [Sync methods](https://github.com/andyongh/api-server/blob/main/src/methods.c): `src/methods.c`
- [Async compute](https://github.com/andyongh/api-server/blob/main/src/methods.c): `src/methods.c`
- [Task operations](https://github.com/andyongh/api-server/blob/main/src/methods.c): `src/methods.c`
- [Task lifecycle](https://github.com/andyongh/api-server/blob/main/src/task_manager.c): `src/task_manager.c`

### Concurrency runtime

- [Worker pool](https://github.com/andyongh/api-server/blob/main/src/worker_pool.c): `src/worker_pool.c`
- [Runtime startup](https://github.com/andyongh/api-server/blob/main/src/main.c): `src/main.c`

### Shared support

- [UUID generation](https://github.com/andyongh/api-server/blob/main/src/uuid.c): `src/uuid.c`
- [Thread-safe logging](https://github.com/andyongh/api-server/blob/main/src/log.h): `src/log.h`

### Other components

- **API client**

## Connections

- API client → HTTP server: sends requests (evidence: `README.md`)
- HTTP server → JSON-RPC codec: parses and formats (evidence: `src/server.c`)
- HTTP server → Authentication: verifies session (evidence: `src/server.c`)
- HTTP server → Method registry: looks up methods (evidence: `src/server.c`)
- HTTP server → Worker pool: submits work (evidence: `src/server.c`)
- HTTP server → Task lifecycle: creates tasks (evidence: `src/server.c`)
- Method registry → Sync methods: registers handlers (evidence: `src/methods.c`)
- Method registry → Async compute: registers handlers (evidence: `src/methods.c`)
- Method registry → Task operations: registers handlers (evidence: `src/methods.c`)
- Task operations → Task lifecycle: queries and updates (evidence: `src/methods.c`)
- Task lifecycle → UUID generation: generates task IDs (evidence: `src/task_manager.c`)
- Runtime startup → Task lifecycle: initializes and destroys (evidence: `src/main.c`)
- Runtime startup → Method registry: initializes (evidence: `src/main.c`)
- Runtime startup → Worker pool: creates and destroys (evidence: `src/main.c`)
- Runtime startup → HTTP server: starts and stops (evidence: `src/main.c`)
