# senapati484/iopress architecture

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

- Interactive diagram: https://gitdiagram.com/senapati484/iopress
- Repository: https://github.com/senapati484/iopress

## Overview

1. **What this repo is**
   - `@iopress/core` is a Node.js native addon that implements a high-performance HTTP server.
   - The architecture is split between a small JavaScript API layer and a larger C/C++ runtime that handles network I/O, parsing, and routing.

2. **Public entry points**
   - The package surface is centered on `index.js`, `js/index.js`, and `index.d.ts`.
   - JavaScript consumers create an app, register middleware/routes, configure body limits/buffering, and start/stop the server through this layer.

3. **Native addon boundary**
   - `binding.gyp`, `src/binding.c`, and `src/main.cpp` define the Node addon boundary.
   - This is the bridge from V8/Node into the native server implementation, and it is the main seam where JS hands off work to C/C++.

4. **Request lifecycle**
   - Incoming connections enter the native server, are parsed into HTTP requests, then routed to either native fast-path handlers or JS middleware/route handlers.
   - Responses flow back through the native layer to the socket backend, with the JS API exposing helpers like `json`, `send`, `status`, and `end`.

5. **Core HTTP stack**
   - `src/parser.c`, `src/router.c`, `src/server.c`, and `src/error_handling.c` form the protocol and dispatch core.
   - `src/common/server.cpp` and `src/common/util.cpp` hold shared logic used across platform backends.

6. **Fast routing optimization**
   - `src/fast_router.c` and `src/fast_router.h` implement a native fast path for static routes.
   - The README indicates that simple routes can be handled entirely in C, avoiding a JavaScript hop for the highest-throughput endpoints.

7. **Platform-specific async I/O**
   - The repo has separate backend implementations for Linux, macOS, and Windows: `src/platform/linux/io_uring.cpp`, `src/platform/linux/epoll_fallback.cpp`, `src/platform/macos/kqueue.cpp`, and `src/platform/windows/iocp.cpp`.
   - Additional backend-specific server files (`src/server_uring.c`, `src/server_kevent.c`, `src/server_iocp.c`, `src/server_libuv.c`) show that backend choice is a first-class architectural decision.
   - The runtime auto-selects the best backend and falls back to libuv when needed.

8. **Cross-platform support boundary**
   - The architecture is explicitly layered around OS capabilities: io_uring on modern Linux, kqueue on macOS, IOCP on Windows, and libuv as compatibility fallback.
   - This means performance characteristics and deployment requirements vary by host OS/kernel, which is central to the system design.

9. **Body handling and API behavior**
   - The README’s options (`initialBufferSize`, `maxBodySize`, `streamBody`) imply a native buffering/streaming pipeline with configurable memory tradeoffs.
   - That affects the diagram because request body processing is not delegated to external middleware libraries; it is built into the server runtime.

10. **Distribution, builds, and prebuilt binaries**
   - `npm` scripts, `scripts/test-prebuilds.js`, and docs under `docs/deployment/PREBUILT_BINARIES.md` indicate the project is shipped as a compiled native package with CI-assisted prebuild validation.
   - `node-gyp`/native compilation is part of the normal lifecycle, not an optional plugin.

11. **Testing and verification**
   - The `test/` directory covers integration, streaming, large bodies, memory, and deprecation behavior.
   - Benchmarks live in `benchmark/` and `benchmarks/`, including regression scripts and sample server code, so performance is a first-class acceptance criterion.

12. **Supporting repo structure**
   - `examples/` demonstrates typical application shapes: basic routes, middleware, uploads, REST APIs, and stress tests.
   - `docs/` contains the architecture, compatibility, deployment, and performance narratives that reinforce the same layered model used by the codebase.

13. **Operational boundaries**
   - GitHub Actions workflows for CI, release, security, and prebuild testing show that validation spans compilation, runtime tests, and platform-specific packaging.
   - This repo is therefore best diagrammed as: JavaScript API layer → native addon boundary → core HTTP/routing engine → OS-specific async I/O backend.

Main entry points: [`src/server.c`](https://github.com/senapati484/iopress/blob/main/src/server.c) (Server Core), [`js/index.js`](https://github.com/senapati484/iopress/blob/main/js/index.js) (JS Facade), [`binding.gyp`](https://github.com/senapati484/iopress/blob/main/binding.gyp) (Addon Build), [`src/server_uring.c`](https://github.com/senapati484/iopress/blob/main/src/server_uring.c) (Uring Server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_js["JavaScript API"]
  node_n_index_js["Entry API<br/>js entry<br/>[index.js]"]
  node_n_js_index["JS Facade<br/>js wrapper<br/>[index.js]"]
  node_n_js_deprecation["Deprecations<br/>js compat<br/>[deprecation.js]"]
  node_n_types["Types<br/>d.ts surface<br/>[index.d.ts]"]
end

subgraph group_grp_native["Native Core"]
  node_n_binding_gyp["Addon Build<br/>gyp config<br/>[binding.gyp]"]
  node_n_binding_c["Node Binding<br/>addon bridge<br/>[binding.c]"]
  node_n_main_cpp["Addon Main<br/>addon init<br/>[main.cpp]"]
  node_n_server_c["Server Core<br/>http runtime<br/>[server.c]"]
  node_n_parser["Parser<br/>[parser.c]"]
  node_n_router["Router<br/>dispatch<br/>[router.c]"]
  node_n_fast_router["Fast Router<br/>native fast-path<br/>[fast_router.c]"]
  node_n_error["Errors<br/>error handling<br/>[error_handling.c]"]
  node_n_common_server["Shared Server<br/>shared core<br/>[server.cpp]"]
  node_n_common_util["Shared Utils<br/>[util.cpp]"]
end

subgraph group_grp_platform["Platform Backends"]
  node_n_linux_io_uring["io_uring<br/>linux io<br/>[io_uring.cpp]"]
  node_n_linux_epoll["epoll fallback<br/>linux fallback<br/>[epoll_fallback.cpp]"]
  node_n_macos_kqueue["kqueue<br/>macos io<br/>[kqueue.cpp]"]
  node_n_windows_iocp["IOCP<br/>windows io<br/>[iocp.cpp]"]
  node_n_server_uring["Uring Server<br/>backend server<br/>[server_uring.c]"]
  node_n_server_kevent["Kevent Server<br/>backend server<br/>[server_kevent.c]"]
  node_n_server_iocp["IOCP Server<br/>backend server<br/>[server_iocp.c]"]
  node_n_server_libuv["Libuv Server<br/>compat backend<br/>[server_libuv.c]"]
end

subgraph group_grp_tooling["Build & Validation"]
  node_n_examples["Examples<br/>sample apps"]
  node_n_benchmarks["Benchmarks<br/>perf harness"]
  node_n_prebuild_test["Prebuild Check<br/>release test<br/>[test-prebuilds.js]"]
end

node_n_index_js -->|"exports"| node_n_js_index
node_n_js_index -->|"warns"| node_n_js_deprecation
node_n_js_index -.->|"describes"| node_n_types
node_n_js_index -->|"loads"| node_n_binding_c
node_n_binding_gyp -->|"builds"| node_n_binding_c
node_n_binding_gyp -->|"builds"| node_n_main_cpp
node_n_binding_c -->|"initializes"| node_n_main_cpp
node_n_main_cpp -->|"starts"| node_n_server_c
node_n_server_c -->|"parses"| node_n_parser
node_n_server_c -->|"dispatches"| node_n_router
node_n_router -->|"accelerates"| node_n_fast_router
node_n_server_c -->|"handles"| node_n_error
node_n_server_c -->|"shares"| node_n_common_server
node_n_common_server -->|"uses"| node_n_common_util
node_n_server_c -.->|"selects"| node_n_server_uring
node_n_server_c -.->|"selects"| node_n_server_kevent
node_n_server_c -.->|"selects"| node_n_server_iocp
node_n_server_c -.->|"falls back"| node_n_server_libuv
node_n_server_uring -->|"uses"| node_n_linux_io_uring
node_n_server_uring -->|"falls back"| node_n_linux_epoll
node_n_server_kevent -->|"uses"| node_n_macos_kqueue
node_n_server_iocp -->|"uses"| node_n_windows_iocp
node_n_js_index -.->|"showcases"| node_n_examples
node_n_server_c -.->|"measured by"| node_n_benchmarks
node_n_binding_gyp -.->|"validates"| node_n_prebuild_test

click node_n_index_js "https://github.com/senapati484/iopress/blob/main/index.js"
click node_n_js_index "https://github.com/senapati484/iopress/blob/main/js/index.js"
click node_n_js_deprecation "https://github.com/senapati484/iopress/blob/main/js/deprecation.js"
click node_n_types "https://github.com/senapati484/iopress/blob/main/index.d.ts"
click node_n_binding_gyp "https://github.com/senapati484/iopress/blob/main/binding.gyp"
click node_n_binding_c "https://github.com/senapati484/iopress/blob/main/src/binding.c"
click node_n_main_cpp "https://github.com/senapati484/iopress/blob/main/src/main.cpp"
click node_n_server_c "https://github.com/senapati484/iopress/blob/main/src/server.c"
click node_n_parser "https://github.com/senapati484/iopress/blob/main/src/parser.c"
click node_n_router "https://github.com/senapati484/iopress/blob/main/src/router.c"
click node_n_fast_router "https://github.com/senapati484/iopress/blob/main/src/fast_router.c"
click node_n_error "https://github.com/senapati484/iopress/blob/main/src/error_handling.c"
click node_n_common_server "https://github.com/senapati484/iopress/blob/main/src/common/server.cpp"
click node_n_common_util "https://github.com/senapati484/iopress/blob/main/src/common/util.cpp"
click node_n_linux_io_uring "https://github.com/senapati484/iopress/blob/main/src/platform/linux/io_uring.cpp"
click node_n_linux_epoll "https://github.com/senapati484/iopress/blob/main/src/platform/linux/epoll_fallback.cpp"
click node_n_macos_kqueue "https://github.com/senapati484/iopress/blob/main/src/platform/macos/kqueue.cpp"
click node_n_windows_iocp "https://github.com/senapati484/iopress/blob/main/src/platform/windows/iocp.cpp"
click node_n_server_uring "https://github.com/senapati484/iopress/blob/main/src/server_uring.c"
click node_n_server_kevent "https://github.com/senapati484/iopress/blob/main/src/server_kevent.c"
click node_n_server_iocp "https://github.com/senapati484/iopress/blob/main/src/server_iocp.c"
click node_n_server_libuv "https://github.com/senapati484/iopress/blob/main/src/server_libuv.c"
click node_n_examples "https://github.com/senapati484/iopress/tree/main/examples"
click node_n_benchmarks "https://github.com/senapati484/iopress/tree/main/benchmarks"
click node_n_prebuild_test "https://github.com/senapati484/iopress/blob/main/scripts/test-prebuilds.js"

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_index_js,node_n_js_index,node_n_js_deprecation,node_n_types toneBlue
class node_n_binding_gyp,node_n_binding_c,node_n_main_cpp,node_n_server_c,node_n_parser,node_n_router,node_n_fast_router,node_n_error,node_n_common_server,node_n_common_util toneAmber
class node_n_linux_io_uring,node_n_linux_epoll,node_n_macos_kqueue,node_n_windows_iocp,node_n_server_uring,node_n_server_kevent,node_n_server_iocp,node_n_server_libuv toneMint
class node_n_examples,node_n_benchmarks,node_n_prebuild_test toneRose
```

## Components

### JavaScript API

Public package surface and JS-side request helpers

- [Entry API](https://github.com/senapati484/iopress/blob/main/index.js): js entry · Package entry that exposes the server API to consumers · `index.js`
- [JS Facade](https://github.com/senapati484/iopress/blob/main/js/index.js): js wrapper · Main JavaScript API layer for app creation, middleware, routes, and response helpers · `js/index.js`
- [Deprecations](https://github.com/senapati484/iopress/blob/main/js/deprecation.js): js compat · Compatibility warnings and deprecated API behavior · `js/deprecation.js`
- [Types](https://github.com/senapati484/iopress/blob/main/index.d.ts): d.ts surface · TypeScript declarations for the public API · `index.d.ts`

### Native Core

Addon boundary plus HTTP parsing, routing, and server runtime

- [Addon Build](https://github.com/senapati484/iopress/blob/main/binding.gyp): gyp config · Native addon build configuration and compilation boundary · `binding.gyp`
- [Node Binding](https://github.com/senapati484/iopress/blob/main/src/binding.c): addon bridge · C addon entry point that connects Node/V8 to the native runtime · `src/binding.c`
- [Addon Main](https://github.com/senapati484/iopress/blob/main/src/main.cpp): addon init · Native module initialization and startup wiring · `src/main.cpp`
- [Server Core](https://github.com/senapati484/iopress/blob/main/src/server.c): http runtime · Core server lifecycle, connection handling, and request dispatch · `src/server.c`
- [Parser](https://github.com/senapati484/iopress/blob/main/src/parser.c): http parser · HTTP request parsing and input framing · `src/parser.c`
- [Router](https://github.com/senapati484/iopress/blob/main/src/router.c): dispatch · Route matching and handler dispatch logic · `src/router.c`
- [Fast Router](https://github.com/senapati484/iopress/blob/main/src/fast_router.c): native fast-path · Optimized native route path for simple static handlers · `src/fast_router.c`
- [Errors](https://github.com/senapati484/iopress/blob/main/src/error_handling.c): error handling · Native error translation and server-side failure handling · `src/error_handling.c`
- [Shared Server](https://github.com/senapati484/iopress/blob/main/src/common/server.cpp): shared core · Cross-backend server logic shared by platform implementations · `src/common/server.cpp`
- [Shared Utils](https://github.com/senapati484/iopress/blob/main/src/common/util.cpp): shared util · Common native utilities used across the runtime · `src/common/util.cpp`

### Platform Backends

OS-specific async I/O implementations and fallback server variants

- [io_uring](https://github.com/senapati484/iopress/blob/main/src/platform/linux/io_uring.cpp): linux io · High-performance Linux async I/O backend · `src/platform/linux/io_uring.cpp`
- [epoll fallback](https://github.com/senapati484/iopress/blob/main/src/platform/linux/epoll_fallback.cpp): linux fallback · Linux fallback backend when io_uring is unavailable · `src/platform/linux/epoll_fallback.cpp`
- [kqueue](https://github.com/senapati484/iopress/blob/main/src/platform/macos/kqueue.cpp): macos io · macOS evented I/O backend · `src/platform/macos/kqueue.cpp`
- [IOCP](https://github.com/senapati484/iopress/blob/main/src/platform/windows/iocp.cpp): windows io · Windows asynchronous I/O backend · `src/platform/windows/iocp.cpp`
- [Uring Server](https://github.com/senapati484/iopress/blob/main/src/server_uring.c): backend server · Server variant wired to io_uring · `src/server_uring.c`
- [Kevent Server](https://github.com/senapati484/iopress/blob/main/src/server_kevent.c): backend server · Server variant wired to kqueue/kevent · `src/server_kevent.c`
- [IOCP Server](https://github.com/senapati484/iopress/blob/main/src/server_iocp.c): backend server · Server variant wired to IOCP · `src/server_iocp.c`
- [Libuv Server](https://github.com/senapati484/iopress/blob/main/src/server_libuv.c): compat backend · Compatibility server path used as fallback · `src/server_libuv.c`

### Build & Validation

Compilation, prebuild, benchmarking, and example usage

- [Examples](https://github.com/senapati484/iopress/tree/main/examples): sample apps · Representative application shapes and usage patterns · `examples`
- [Benchmarks](https://github.com/senapati484/iopress/tree/main/benchmarks): perf harness · Benchmark runners and sample server workloads · `benchmarks`
- [Prebuild Check](https://github.com/senapati484/iopress/blob/main/scripts/test-prebuilds.js): release test · Validation script for shipped native prebuilds · `scripts/test-prebuilds.js`

## Connections

- Entry API → JS Facade: exports · Package entry delegates to the main JS facade
- JS Facade → Deprecations: warns · JS API surfaces compatibility and deprecation behavior
- JS Facade → Types: describes · Public API is mirrored by TypeScript declarations
- JS Facade → Node Binding: loads · JS layer loads the native addon through the binding
- Addon Build → Node Binding: builds · gyp config compiles the addon bridge
- Addon Build → Addon Main: builds · gyp config compiles addon initialization code
- Node Binding → Addon Main: initializes · Native binding hands off module setup to main initialization
- Addon Main → Server Core: starts · Addon initialization enters the server runtime
- Server Core → Parser: parses · Incoming data is parsed into HTTP requests
- Server Core → Router: dispatches · Parsed requests are routed to handlers
- Router → Fast Router: accelerates · Simple static routes can take the native fast path
- Server Core → Errors: handles · Runtime errors are translated and surfaced
- Server Core → Shared Server: shares · Server behavior is factored into common native logic
- Shared Server → Shared Utils: uses · Shared server code depends on utility helpers
- Server Core → Uring Server: selects · Native server can be specialized for io_uring
- Server Core → Kevent Server: selects · Native server can be specialized for kqueue/kevent
- Server Core → IOCP Server: selects · Native server can be specialized for IOCP
- Server Core → Libuv Server: falls back · Compatibility path is used when native backends are unavailable
- Uring Server → io_uring: uses · Linux high-performance backend powers the server variant
- Uring Server → epoll fallback: falls back · Linux backend falls back to epoll when needed
- Kevent Server → kqueue: uses · macOS event loop backend powers the server variant
- IOCP Server → IOCP: uses · Windows async backend powers the server variant
- JS Facade → Examples: showcases · Examples demonstrate the consumer-facing API
- Server Core → Benchmarks: measured by · Benchmarks exercise runtime throughput and regression behavior
- Addon Build → Prebuild Check: validates · Prebuild validation checks packaged native binaries
