# fangfengxiang/lua-resty-yar architecture

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

- Interactive diagram: https://gitdiagram.com/fangfengxiang/lua-resty-yar
- Repository: https://github.com/fangfengxiang/lua-resty-yar

## Overview

lua-resty-yar is an OpenResty framework around lua-yar, adding server and client runtime support plus configuration, extensions, and observability. The principal workflow configures a shared server facade, accepts HTTP or TCP RPC requests, and lets client code make RPC calls over cosockets. Edges are based on README statements; source excerpts were unavailable, so implementation details beyond those statements are not inferred.

Main entry points: [`lib/resty/yar/init.lua`](https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/init.lua) (Setup Facade), [`lib/resty/yar/server/init.lua`](https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/server/init.lua) (Server Facade), [`lib/resty/yar/client.lua`](https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/client.lua) (Cosocket Client), [`lib/resty/yar/observability.lua`](https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/observability.lua) (Observability Suite)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["RPC Runtime"]
  node_server["Server Facade<br/>[init.lua]"]
  node_http["HTTP Server<br/>[http.lua]"]
  node_tcp["TCP Server<br/>[tcp.lua]"]
  node_client["Cosocket Client<br/>[client.lua]"]
end

subgraph group_setup["Setup And Extensions"]
  node_setup["Setup Facade<br/>[init.lua]"]
  node_config["Config Schema<br/>[config.lua]"]
  node_registry["Plugin Registry<br/>[registry.lua]"]
  node_hooks["Lifecycle Hooks<br/>[hooks.lua]"]
end

subgraph group_observe["Observability"]
  node_observability["Observability Suite<br/>[observability.lua]"]
end

node_app(("Application"))
node_yar["lua-yar"]
node_httpactor(("HTTP Caller"))
node_tcpactor(("TCP Caller"))
node_clientactor(("Client Code"))
node_ngx["OpenResty Runtime"]
node_caccel["C Codec Extensions"]
node_restyhttp["lua-resty-http"]

node_app -->|"configures"| node_setup
node_setup -->|"merges config"| node_config
node_setup -->|"creates facade"| node_server
node_setup -->|"adapts hooks"| node_hooks
node_app -->|"registers plugins"| node_registry
node_httpactor -->|"serves RPC"| node_server
node_tcpactor -->|"serves RPC"| node_server
node_server -->|"dispatches HTTP"| node_http
node_server -->|"dispatches TCP"| node_tcp
node_clientactor -->|"calls methods"| node_client
node_client -->|"uses protocol"| node_yar
node_client -->|"uses cosockets"| node_ngx
node_setup -->|"injects hooks"| node_observability
node_observability -->|"uses timers"| node_ngx
node_setup -.->|"registers codecs"| node_caccel
node_setup -.->|"injects transport"| node_restyhttp

click node_setup "https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/init.lua"
click node_config "https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/config.lua"
click node_registry "https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/registry.lua"
click node_hooks "https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/hooks.lua"
click node_server "https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/server/init.lua"
click node_http "https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/server/http.lua"
click node_tcp "https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/server/tcp.lua"
click node_client "https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/client.lua"
click node_observability "https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/observability.lua"

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,node_http,node_tcp,node_client,node_clientactor toneBlue
class node_setup,node_config,node_registry,node_hooks toneAmber
class node_observability toneMint
class node_app,node_yar,node_httpactor,node_tcpactor,node_ngx,node_caccel,node_restyhttp toneIndigo
```

## Components

### RPC Runtime

- [Server Facade](https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/server/init.lua): `lib/resty/yar/server/init.lua`
- [HTTP Server](https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/server/http.lua): `lib/resty/yar/server/http.lua`
- [TCP Server](https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/server/tcp.lua): `lib/resty/yar/server/tcp.lua`
- [Cosocket Client](https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/client.lua): `lib/resty/yar/client.lua`

### Setup And Extensions

- [Setup Facade](https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/init.lua): `lib/resty/yar/init.lua`
- [Config Schema](https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/config.lua): `lib/resty/yar/config.lua`
- [Plugin Registry](https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/registry.lua): `lib/resty/yar/registry.lua`
- [Lifecycle Hooks](https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/hooks.lua): `lib/resty/yar/hooks.lua`

### Observability

- [Observability Suite](https://github.com/fangfengxiang/lua-resty-yar/blob/main/lib/resty/yar/observability.lua): `lib/resty/yar/observability.lua`

### Other components

- **Application**
- **lua-yar**
- **HTTP Caller**
- **TCP Caller**
- **Client Code**
- **OpenResty Runtime**
- **C Codec Extensions**
- **lua-resty-http**

## Connections

- Application → Setup Facade: configures (evidence: `README.md`)
- Setup Facade → Config Schema: merges config (evidence: `README.md`)
- Setup Facade → Server Facade: creates facade (evidence: `README.md`)
- Setup Facade → Lifecycle Hooks: adapts hooks (evidence: `README.md`)
- Application → Plugin Registry: registers plugins (evidence: `README.md`)
- HTTP Caller → Server Facade: serves RPC (evidence: `README.md`)
- TCP Caller → Server Facade: serves RPC (evidence: `README.md`)
- Server Facade → HTTP Server: dispatches HTTP (evidence: `README.md`)
- Server Facade → TCP Server: dispatches TCP (evidence: `README.md`)
- Client Code → Cosocket Client: calls methods (evidence: `README.md`)
- Cosocket Client → lua-yar: uses protocol (evidence: `README.md`)
- Cosocket Client → OpenResty Runtime: uses cosockets (evidence: `README.md`)
- Setup Facade → Observability Suite: injects hooks (evidence: `README.md`)
- Observability Suite → OpenResty Runtime: uses timers (evidence: `README.md`)
- Setup Facade → C Codec Extensions: registers codecs (evidence: `README.md`)
- Setup Facade → lua-resty-http: injects transport (evidence: `README.md`)
