# gzmilgar/sap_n8n architecture

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

- Interactive diagram: https://gitdiagram.com/gzmilgar/sap_n8n
- Repository: https://github.com/gzmilgar/sap_n8n

## Overview

This repository is a local SAP CAP + n8n order-approval demo. Its main loop creates an order through CAP, sends a post-commit webhook to n8n, applies an automatic or human approval decision, and writes the result back through CAP; the Fiori list displays the updated status. A second workflow uses an AI agent to look up products and customers and create orders, which re-enters the same approval loop. The workflow files and UI are documented, but their source was not sampled, so those relationships rely on the README.

Main entry points: [`order-demo/srv/order-service.js`](https://github.com/gzmilgar/sap_n8n/blob/main/order-demo/srv/order-service.js) (Order Handlers), [`n8n-workflows/01-order-approval.json`](https://github.com/gzmilgar/sap_n8n/blob/main/n8n-workflows/01-order-approval.json) (Approval Workflow), [`order-demo/srv/order-service.cds`](https://github.com/gzmilgar/sap_n8n/blob/main/order-demo/srv/order-service.cds) (Order OData API), [`n8n-workflows/02-order-agent.json`](https://github.com/gzmilgar/sap_n8n/blob/main/n8n-workflows/02-order-agent.json) (Lookup and Create Tools)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cap["CAP Order Service"]
  node_cap_api["Order OData API<br/>[order-service.cds]"]
  node_order_logic["Order Handlers<br/>[order-service.js]"]
  node_approval_actions["Decision Actions<br/>[order-service.js]"]
end

subgraph group_interfaces["Order Interfaces"]
  node_order_form["Order Form<br/>[index.html]"]
  node_agent_chat["Agent Chat<br/>[chat.html]"]
  node_fiori["Fiori Order List"]
end

subgraph group_workflows["n8n Workflows"]
  node_approval_flow["Approval Workflow"]
  node_agent_flow["Order Agent"]
  node_agent_tools["Lookup and Create Tools"]
  node_error_flow["Error Notifications"]
  node_offline_flow["Offline Approval Form"]
end

subgraph group_data["Order Data"]
  node_order_store[("SQLite Order Data<br/>[schema.cds]")]
  node_catalog_data[("Product and Customer Data")]
end

node_user(("Order User"))
node_telegram(("Telegram"))

node_user -->|"enters order"| node_order_form
node_order_form -->|"submits order"| node_cap_api
node_user -->|"chats with"| node_agent_chat
node_agent_chat -->|"starts chat"| node_agent_flow
node_agent_flow -->|"invokes tools"| node_agent_tools
node_agent_tools -->|"queries and creates"| node_cap_api
node_cap_api -->|"dispatches handlers"| node_order_logic
node_order_logic -->|"reads product price"| node_catalog_data
node_order_logic -->|"creates order"| node_order_store
node_order_logic -->|"posts after commit"| node_approval_flow
node_approval_flow -->|"requests approval"| node_telegram
node_approval_flow -->|"posts decision"| node_approval_actions
node_offline_flow -->|"posts decision"| node_approval_actions
node_approval_actions -->|"reads and updates"| node_order_store
node_fiori -->|"shows order status"| node_cap_api
node_error_flow -->|"sends error notice"| node_telegram
node_agent_tools -->|"created order triggers"| node_approval_flow

click node_order_form "https://github.com/gzmilgar/sap_n8n/blob/main/order-demo/app/index.html"
click node_agent_chat "https://github.com/gzmilgar/sap_n8n/blob/main/order-demo/app/chat.html"
click node_cap_api "https://github.com/gzmilgar/sap_n8n/blob/main/order-demo/srv/order-service.cds"
click node_order_logic "https://github.com/gzmilgar/sap_n8n/blob/main/order-demo/srv/order-service.js"
click node_approval_actions "https://github.com/gzmilgar/sap_n8n/blob/main/order-demo/srv/order-service.js"
click node_fiori "https://github.com/gzmilgar/sap_n8n/blob/main/order-demo/app/fiori-annotations.cds"
click node_order_store "https://github.com/gzmilgar/sap_n8n/blob/main/order-demo/db/schema.cds"
click node_catalog_data "https://github.com/gzmilgar/sap_n8n/tree/main/order-demo/db/data"
click node_approval_flow "https://github.com/gzmilgar/sap_n8n/blob/main/n8n-workflows/01-order-approval.json"
click node_agent_flow "https://github.com/gzmilgar/sap_n8n/blob/main/n8n-workflows/02-order-agent.json"
click node_agent_tools "https://github.com/gzmilgar/sap_n8n/blob/main/n8n-workflows/02-order-agent.json"
click node_error_flow "https://github.com/gzmilgar/sap_n8n/blob/main/n8n-workflows/03-error-handler.json"
click node_offline_flow "https://github.com/gzmilgar/sap_n8n/blob/main/n8n-workflows/04-order-approval-OFFLINE.json"

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_cap_api,node_order_logic,node_approval_actions,node_user toneBlue
class node_order_form,node_agent_chat,node_fiori toneAmber
class node_approval_flow,node_agent_flow,node_agent_tools,node_error_flow,node_offline_flow toneMint
class node_order_store,node_catalog_data toneRose
class node_telegram toneIndigo
```

## Components

### CAP Order Service

- [Order OData API](https://github.com/gzmilgar/sap_n8n/blob/main/order-demo/srv/order-service.cds): `order-demo/srv/order-service.cds`
- [Order Handlers](https://github.com/gzmilgar/sap_n8n/blob/main/order-demo/srv/order-service.js): `order-demo/srv/order-service.js`
- [Decision Actions](https://github.com/gzmilgar/sap_n8n/blob/main/order-demo/srv/order-service.js): `order-demo/srv/order-service.js`

### Order Interfaces

- [Order Form](https://github.com/gzmilgar/sap_n8n/blob/main/order-demo/app/index.html): `order-demo/app/index.html`
- [Agent Chat](https://github.com/gzmilgar/sap_n8n/blob/main/order-demo/app/chat.html): `order-demo/app/chat.html`
- [Fiori Order List](https://github.com/gzmilgar/sap_n8n/blob/main/order-demo/app/fiori-annotations.cds): `order-demo/app/fiori-annotations.cds`

### n8n Workflows

- [Approval Workflow](https://github.com/gzmilgar/sap_n8n/blob/main/n8n-workflows/01-order-approval.json): `n8n-workflows/01-order-approval.json`
- [Order Agent](https://github.com/gzmilgar/sap_n8n/blob/main/n8n-workflows/02-order-agent.json): `n8n-workflows/02-order-agent.json`
- [Lookup and Create Tools](https://github.com/gzmilgar/sap_n8n/blob/main/n8n-workflows/02-order-agent.json): `n8n-workflows/02-order-agent.json`
- [Error Notifications](https://github.com/gzmilgar/sap_n8n/blob/main/n8n-workflows/03-error-handler.json): `n8n-workflows/03-error-handler.json`
- [Offline Approval Form](https://github.com/gzmilgar/sap_n8n/blob/main/n8n-workflows/04-order-approval-OFFLINE.json): `n8n-workflows/04-order-approval-OFFLINE.json`

### Order Data

- [SQLite Order Data](https://github.com/gzmilgar/sap_n8n/blob/main/order-demo/db/schema.cds): `order-demo/db/schema.cds`
- [Product and Customer Data](https://github.com/gzmilgar/sap_n8n/tree/main/order-demo/db/data): `order-demo/db/data`

### Other components

- **Order User**
- **Telegram**

## Connections

- Order User → Order Form: enters order (evidence: `README.md`)
- Order Form → Order OData API: submits order (evidence: `README.md`)
- Order User → Agent Chat: chats with (evidence: `README.md`)
- Agent Chat → Order Agent: starts chat (evidence: `README.md`)
- Order Agent → Lookup and Create Tools: invokes tools (evidence: `README.md`)
- Lookup and Create Tools → Order OData API: queries and creates (evidence: `README.md`)
- Order OData API → Order Handlers: dispatches handlers (evidence: `README.md`)
- Order Handlers → Product and Customer Data: reads product price (evidence: `order-demo/srv/order-service.js`)
- Order Handlers → SQLite Order Data: creates order (evidence: `README.md`)
- Order Handlers → Approval Workflow: posts after commit (evidence: `order-demo/srv/order-service.js`)
- Approval Workflow → Telegram: requests approval (evidence: `README.md`)
- Approval Workflow → Decision Actions: posts decision (evidence: `README.md`)
- Offline Approval Form → Decision Actions: posts decision (evidence: `README.md`)
- Decision Actions → SQLite Order Data: reads and updates (evidence: `order-demo/srv/order-service.js`)
- Fiori Order List → Order OData API: shows order status (evidence: `README.md`)
- Error Notifications → Telegram: sends error notice (evidence: `README.md`)
- Lookup and Create Tools → Approval Workflow: created order triggers (evidence: `README.md`)
