Skip to content

Commit 7ddaa1a

Browse files
CopilotGrantBirki
andcommitted
Add comprehensive Mermaid flow diagram to README
Co-authored-by: GrantBirki <[email protected]>
1 parent aef8757 commit 7ddaa1a

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,84 @@ Hooks is a RESTful webhook server framework written in Ruby. It is designed to b
2626

2727
Hooks is designed to be very easy to setup and use. It provides a simple DSL for defining webhook endpoints and then you can use plugins to handle the incoming requests and optionally authenticate them.
2828

29+
### Architecture Flow
30+
31+
The following Mermaid diagram shows the complete request processing flow, including server bootstrap, plugin loading, and webhook request handling:
32+
33+
```mermaid
34+
flowchart TD
35+
A[Server Start] --> B[Builder.new]
36+
B --> C[Load & Validate Config]
37+
C --> D[Create Logger]
38+
D --> E[Load All Plugins]
39+
E --> F[Load Endpoints]
40+
F --> G[Create Grape API]
41+
G --> H[Server Ready]
42+
43+
H --> I[Incoming Request]
44+
I --> J[Generate Request ID]
45+
J --> K[Create Request Context]
46+
K --> L[Build Rack Environment]
47+
L --> M[Lifecycle: on_request]
48+
49+
M --> N{IP Filtering Enabled?}
50+
N -->|Yes| O[Check IP Allow/Block Lists]
51+
N -->|No| P[Enforce Request Limits]
52+
O --> Q{IP Allowed?}
53+
Q -->|No| R[Return 403 Forbidden]
54+
Q -->|Yes| P
55+
56+
P --> S[Read Request Body]
57+
S --> T{Auth Required?}
58+
T -->|Yes| U[Load Auth Plugin]
59+
T -->|No| V[Parse Payload]
60+
61+
U --> W[Validate Auth]
62+
W --> X{Auth Valid?}
63+
X -->|No| Y[Return 401/403 Error]
64+
X -->|Yes| V
65+
66+
V --> Z[Load Handler Plugin]
67+
Z --> AA[Normalize Headers]
68+
AA --> BB[Call Handler.call]
69+
BB --> CC[Lifecycle: on_response]
70+
CC --> DD[Log Success]
71+
DD --> EE[Return 200 + Response]
72+
73+
BB --> FF{Handler Error?}
74+
FF -->|Hooks::Plugins::Handlers::Error| GG[Return Handler Error Response]
75+
FF -->|StandardError| HH[Log Error]
76+
HH --> II[Lifecycle: on_error]
77+
II --> JJ[Return 500 + Error Response]
78+
79+
R --> KK[End]
80+
Y --> KK
81+
GG --> KK
82+
EE --> KK
83+
JJ --> KK
84+
85+
subgraph "Plugin Types"
86+
LL[Auth Plugins<br/>HMAC, Shared Secret, Custom]
87+
MM[Handler Plugins<br/>Process Webhook Payload]
88+
NN[Lifecycle Plugins<br/>on_request, on_response, on_error]
89+
OO[Instrument Plugins<br/>Stats, Failbot]
90+
end
91+
92+
subgraph "Configuration"
93+
PP[Global Config<br/>hooks.yml]
94+
QQ[Endpoint Configs<br/>Individual .yml files]
95+
RR[Plugin Directories<br/>Auth, Handlers, Lifecycle]
96+
end
97+
98+
style A fill:#e1f5fe
99+
style H fill:#c8e6c9
100+
style R fill:#ffcdd2
101+
style Y fill:#ffcdd2
102+
style EE fill:#c8e6c9
103+
style JJ fill:#ffcdd2
104+
style GG fill:#fff3e0
105+
```
106+
29107
Here is a very high-level overview of how Hooks works:
30108

31109
1. You define a global configuration file (e.g. `hooks.yml`) where you can specify where your webhook endpoint configs are located, and the directory where your plugins are located. Here is an example of a minimal configuration file:

0 commit comments

Comments
 (0)