# fangfengxiang/lua-resty-yar-grpc-bridge architecture

> Architecture diagram of the GitHub repository fangfengxiang/lua-resty-yar-grpc-bridge, 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-grpc-bridge
- Repository: https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge

## Overview

This OpenResty library bridges unary RPC calls in both directions: gRPC clients can reach YAR servers, and YAR clients can reach gRPC backends. Each direction has an independent entry point, with service/protobuf configuration and protocol conversion documented in the README. Shared concerns include deadlines, error mapping, payload limits, request IDs, and access logging. The README supports the relationships shown; no source excerpts were available to verify finer internal call ownership.

Main entry points: [`lib/resty/yar_grpc_bridge/init.lua`](https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/init.lua) (gRPC entry), [`lib/resty/yar_grpc_bridge/yar2grpc.lua`](https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/yar2grpc.lua) (YAR entry), [`lib/resty/yar_grpc_bridge/grpc2yar.lua`](https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/grpc2yar.lua) (gRPC-YAR conversion)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grpc_to_yar["gRPC to YAR"]
  node_grpc_entry["gRPC entry<br/>[init.lua]"]
  node_grpc_bridge["gRPC-YAR conversion<br/>[grpc2yar.lua]"]
end

subgraph group_yar_to_grpc["YAR to gRPC"]
  node_yar_entry["YAR entry<br/>[yar2grpc.lua]"]
  node_yar_bridge["YAR-gRPC conversion<br/>[yar2grpc.lua]"]
end

subgraph group_shared_runtime["Shared runtime"]
  node_service_config["Service mapping<br/>[init.lua]"]
  node_pb_descriptors["Precompiled descriptors"]
  node_deadline_handling["Deadline handling<br/>[grpc2yar.lua]"]
  node_error_mapping["Error mapping<br/>[grpc2yar.lua]"]
  node_host_adapter["Host adapter<br/>[host.lua]"]
  node_request_trace["Request tracing<br/>[trace.lua]"]
  node_access_log["Access logging<br/>[init.lua]"]
end

node_grpc_client(("gRPC client"))
node_yar_server(("YAR server"))
node_yar_client(("YAR client"))
node_grpc_backend(("gRPC backend"))

node_grpc_client -->|"calls"| node_grpc_entry
node_grpc_entry -->|"serves via"| node_grpc_bridge
node_grpc_bridge -->|"forwards YAR"| node_yar_server
node_yar_client -->|"calls"| node_yar_entry
node_yar_entry -->|"handles via"| node_yar_bridge
node_yar_bridge -->|"forwards gRPC"| node_grpc_backend
node_service_config -->|"configures"| node_grpc_entry
node_service_config -->|"configures"| node_yar_entry
node_pb_descriptors -->|"maps services"| node_service_config
node_grpc_entry -->|"logs phase"| node_access_log

click node_grpc_entry "https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/init.lua"
click node_grpc_bridge "https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/grpc2yar.lua"
click node_yar_entry "https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/yar2grpc.lua"
click node_yar_bridge "https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/yar2grpc.lua"
click node_service_config "https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/init.lua"
click node_deadline_handling "https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/grpc2yar.lua"
click node_error_mapping "https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/grpc2yar.lua"
click node_host_adapter "https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/host.lua"
click node_request_trace "https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/trace.lua"
click node_access_log "https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/init.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_grpc_entry,node_grpc_bridge,node_grpc_client,node_yar_client toneBlue
class node_yar_entry,node_yar_bridge toneAmber
class node_service_config,node_pb_descriptors,node_deadline_handling,node_error_mapping,node_host_adapter,node_request_trace,node_access_log,node_yar_server toneMint
class node_grpc_backend toneIndigo
```

## Components

### gRPC to YAR

- [gRPC entry](https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/init.lua): `lib/resty/yar_grpc_bridge/init.lua`
- [gRPC-YAR conversion](https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/grpc2yar.lua): `lib/resty/yar_grpc_bridge/grpc2yar.lua`

### YAR to gRPC

- [YAR entry](https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/yar2grpc.lua): `lib/resty/yar_grpc_bridge/yar2grpc.lua`
- [YAR-gRPC conversion](https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/yar2grpc.lua): `lib/resty/yar_grpc_bridge/yar2grpc.lua`

### Shared runtime

- [Service mapping](https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/init.lua): `lib/resty/yar_grpc_bridge/init.lua`
- **Precompiled descriptors**
- [Deadline handling](https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/grpc2yar.lua): `lib/resty/yar_grpc_bridge/grpc2yar.lua`
- [Error mapping](https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/grpc2yar.lua): `lib/resty/yar_grpc_bridge/grpc2yar.lua`
- [Host adapter](https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/host.lua): `lib/resty/yar_grpc_bridge/host.lua`
- [Request tracing](https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/trace.lua): `lib/resty/yar_grpc_bridge/trace.lua`
- [Access logging](https://github.com/fangfengxiang/lua-resty-yar-grpc-bridge/blob/main/lib/resty/yar_grpc_bridge/init.lua): `lib/resty/yar_grpc_bridge/init.lua`

### Other components

- **gRPC client**
- **YAR server**
- **YAR client**
- **gRPC backend**

## Connections

- gRPC client → gRPC entry: calls (evidence: `README.md`)
- gRPC entry → gRPC-YAR conversion: serves via (evidence: `README.md`)
- gRPC-YAR conversion → YAR server: forwards YAR (evidence: `README.md`)
- YAR client → YAR entry: calls (evidence: `README.md`)
- YAR entry → YAR-gRPC conversion: handles via (evidence: `README.md`)
- YAR-gRPC conversion → gRPC backend: forwards gRPC (evidence: `README.md`)
- Service mapping → gRPC entry: configures (evidence: `README.md`)
- Service mapping → YAR entry: configures (evidence: `README.md`)
- Precompiled descriptors → Service mapping: maps services (evidence: `README.md`)
- gRPC entry → Access logging: logs phase (evidence: `README.md`)
