# shyambandla/samlang_uws architecture

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

- Interactive diagram: https://gitdiagram.com/shyambandla/samlang_uws
- Repository: https://github.com/shyambandla/samlang_uws

## Overview

samlang_uws is a small samlang binding for uWebSockets. A samlang application supplies event callbacks and starts the server; the native shim dispatches HTTP and WebSocket events, exposes the current request or message to samlang, and accepts response or socket operations back. The README documents the samlang API, while the sampled C++ shows the native event loop and callbacks. The samlang implementation was not sampled, so its internal wrapper calls are not expanded.

Main entry points: [`server.sam`](https://github.com/shyambandla/samlang_uws/blob/main/server.sam) (Server API), [`uws_shim.cpp`](https://github.com/shyambandla/samlang_uws/blob/main/uws_shim.cpp) (WebSocket dispatch)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Samlang API"]
  node_server_api["Server API<br/>[server.sam]"]
end

subgraph group_native["Native shim"]
  node_event_loop["Event loop<br/>[uws_shim.cpp]"]
  node_http_dispatch["HTTP dispatch<br/>[uws_shim.cpp]"]
  node_request_context["Request context<br/>[uws_shim.cpp]"]
  node_request_access["Request accessors<br/>[uws_shim.cpp]"]
  node_http_response["HTTP response<br/>[uws_shim.cpp]"]
  node_header_buffer["Pending headers<br/>[uws_shim.cpp]"]
  node_ws_dispatch["WebSocket dispatch<br/>[uws_shim.cpp]"]
  node_socket_registry[("Socket registry<br/>[uws_shim.cpp]")]
  node_ws_operations["Socket operations<br/>[uws_shim.cpp]"]
end

subgraph group_external["External clients"]
  node_http_client(("HTTP client"))
  node_ws_client(("WebSocket client"))
end

node_app(("Samlang application"))

node_app -->|"uses"| node_server_api
node_server_api -->|"starts"| node_event_loop
node_event_loop -->|"dispatches"| node_http_dispatch
node_http_dispatch -->|"sets"| node_request_context
node_http_dispatch -->|"calls request"| node_app
node_server_api -->|"reads context"| node_request_access
node_request_access -->|"reads"| node_request_context
node_app -->|"answers via"| node_server_api
node_server_api -->|"responds"| node_http_response
node_server_api -->|"sets headers"| node_header_buffer
node_http_response -->|"writes"| node_header_buffer
node_event_loop -->|"dispatches"| node_ws_dispatch
node_ws_dispatch -->|"sets message"| node_request_context
node_ws_dispatch -->|"registers sockets"| node_socket_registry
node_ws_dispatch -->|"calls callbacks"| node_app
node_server_api -->|"sends or closes"| node_ws_operations
node_ws_operations -->|"looks up socket"| node_socket_registry
node_http_client -.->|"sends requests"| node_http_dispatch
node_ws_client -.->|"exchanges frames"| node_ws_dispatch

click node_server_api "https://github.com/shyambandla/samlang_uws/blob/main/server.sam"
click node_event_loop "https://github.com/shyambandla/samlang_uws/blob/main/uws_shim.cpp"
click node_http_dispatch "https://github.com/shyambandla/samlang_uws/blob/main/uws_shim.cpp"
click node_request_context "https://github.com/shyambandla/samlang_uws/blob/main/uws_shim.cpp"
click node_request_access "https://github.com/shyambandla/samlang_uws/blob/main/uws_shim.cpp"
click node_http_response "https://github.com/shyambandla/samlang_uws/blob/main/uws_shim.cpp"
click node_header_buffer "https://github.com/shyambandla/samlang_uws/blob/main/uws_shim.cpp"
click node_ws_dispatch "https://github.com/shyambandla/samlang_uws/blob/main/uws_shim.cpp"
click node_socket_registry "https://github.com/shyambandla/samlang_uws/blob/main/uws_shim.cpp"
click node_ws_operations "https://github.com/shyambandla/samlang_uws/blob/main/uws_shim.cpp"

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_api toneBlue
class node_event_loop,node_http_dispatch,node_request_context,node_request_access,node_http_response,node_header_buffer,node_ws_dispatch,node_socket_registry,node_ws_operations toneAmber
class node_http_client,node_ws_client toneMint
class node_app toneIndigo
```

## Components

### Samlang API

- [Server API](https://github.com/shyambandla/samlang_uws/blob/main/server.sam): `server.sam`

### Native shim

- [Event loop](https://github.com/shyambandla/samlang_uws/blob/main/uws_shim.cpp): `uws_shim.cpp`
- [HTTP dispatch](https://github.com/shyambandla/samlang_uws/blob/main/uws_shim.cpp): `uws_shim.cpp`
- [Request context](https://github.com/shyambandla/samlang_uws/blob/main/uws_shim.cpp): `uws_shim.cpp`
- [Request accessors](https://github.com/shyambandla/samlang_uws/blob/main/uws_shim.cpp): `uws_shim.cpp`
- [HTTP response](https://github.com/shyambandla/samlang_uws/blob/main/uws_shim.cpp): `uws_shim.cpp`
- [Pending headers](https://github.com/shyambandla/samlang_uws/blob/main/uws_shim.cpp): `uws_shim.cpp`
- [WebSocket dispatch](https://github.com/shyambandla/samlang_uws/blob/main/uws_shim.cpp): `uws_shim.cpp`
- [Socket registry](https://github.com/shyambandla/samlang_uws/blob/main/uws_shim.cpp): `uws_shim.cpp`
- [Socket operations](https://github.com/shyambandla/samlang_uws/blob/main/uws_shim.cpp): `uws_shim.cpp`

### External clients

- **HTTP client**
- **WebSocket client**

### Other components

- **Samlang application**

## Connections

- Samlang application → Server API: uses (evidence: `README.md`)
- Server API → Event loop: starts (evidence: `README.md`)
- Event loop → HTTP dispatch: dispatches (evidence: `uws_shim.cpp`)
- HTTP dispatch → Request context: sets (evidence: `uws_shim.cpp`)
- HTTP dispatch → Samlang application: calls request (evidence: `uws_shim.cpp`)
- Server API → Request accessors: reads context (evidence: `README.md`)
- Request accessors → Request context: reads (evidence: `uws_shim.cpp`)
- Samlang application → Server API: answers via (evidence: `README.md`)
- Server API → HTTP response: responds (evidence: `README.md`)
- Server API → Pending headers: sets headers (evidence: `README.md`)
- HTTP response → Pending headers: writes (evidence: `uws_shim.cpp`)
- Event loop → WebSocket dispatch: dispatches (evidence: `uws_shim.cpp`)
- WebSocket dispatch → Request context: sets message (evidence: `uws_shim.cpp`)
- WebSocket dispatch → Socket registry: registers sockets (evidence: `uws_shim.cpp`)
- WebSocket dispatch → Samlang application: calls callbacks (evidence: `uws_shim.cpp`)
- Server API → Socket operations: sends or closes (evidence: `README.md`)
- Socket operations → Socket registry: looks up socket (evidence: `uws_shim.cpp`)
- HTTP client → HTTP dispatch: sends requests (evidence: `README.md`)
- WebSocket client → WebSocket dispatch: exchanges frames (evidence: `README.md`)
