# sap-archive/pyrfc architecture

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

- Interactive diagram: https://gitdiagram.com/sap-archive/pyrfc
- Repository: https://github.com/sap-archive/pyrfc

## Overview

Based on your provided file tree and README, the project is a Python binding to the SAP NetWeaver RFC SDK. Its goal is to let Python code both call ABAP function modules and serve as a function provider for ABAP (client and server bindings). The repository serves as a low-level integration layer that abstracts SAP’s native RFC libraries (with some parts implemented in Cython for efficiency) so that Python applications can perform asynchronous, non-blocking RFC communications with SAP systems.

##### Main Components
- Client Module: This is the component that establishes and manages connections to SAP systems. It exposes methods (like “call”) for executing ABAP function modules. Look at examples such as ‘examples/clientIDoc.py’ and ‘examples/clientStfcStructure.py’ as they show typical client usage.
- Server Module: This module allows exposing Python functions to be called from an ABAP system. For example, you see the server components in ‘examples/server’ and server usage in the README.
- Binding/Wrapper Layer: Located in the “src/pyrfc” directory, this part includes the interfaces (including the Cython file _cyrfc.pyx and the C header definitions in csapnwrfc.pxd) that directly interact with the native SAP NW RFC SDK. Supporting modules like _exception.py and _utils.py handle error conversions and other utilities.
- Underlying Native Library Integration: The system depends on the SAP NetWeaver RFC SDK (a native dependency) – this must be clearly indicated as the foundation over which the Python layer is built.
- Build/Development Infrastructure: Configuration files (setup.py, pyproject.toml, MANIFEST.in) and tools (tox.ini for testing, Cython integration) should be indicated as auxiliary elements necessary for building, testing, and deployment.

##### Structure the Relationships and Interactions
- Next, illustrate the separation between the “Client” and “Server” components. The Client component (using “Connection” from pyrfc) issues RFC calls to SAP systems, while the Server component (using “Server” classes) exposes Python functionality to ABAP.
– From the Client component to the SAP system – indicating “ABAP function module calls”.
– From the SAP system to the Server component – indicating “function invocation by ABAP”.
- Optionally, include components for “Examples” and “Tests” to emphasize that these artifact directories validate and illustrate proper usage.

##### Architectural Patterns and Design Principles
- Layered Architecture: Clearly separate the native integration (SAP SDK), binding/wrapping (Cython interface), and higher-level Python API (client and server).
- Asynchronous, Non‑blocking Communication: Indicate that both client and server components are built to support non-blocking operations, a key architectural goal.
- Abstraction: Emphasize that the design abstracts SAP’s RFC calls into high-level API calls (e.g., Connection.call, Server.add_function).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Layer: Client API
    subgraph "Client API"
        Client["Client API"]:::client
        subgraph "Client Examples"
            c1["clientIDoc.py"]:::client
            c2["clientStfcStructure.py"]:::client
            c3["clientPrintDescription.py"]:::client
        end
    end

    %% Binding/Wrapper Layer
    subgraph "pyrfc Binding"
        Bind["pyrfc Binding"]:::binding
        subgraph "Binding Components"
            cm["_cyrfc.pyx"]:::binding
            excep["Exception Handler"]:::binding
            utils["Utils Module"]:::binding
            header["C Header"]:::binding
        end
    end

    %% Native Layer: SAP SDK
    subgraph "SAP NetWeaver RFC SDK (Native Layer)"
        SAP["SAP NetWeaver RFC SDK"]:::native
    end

    %% Application Layer: Server API
    subgraph "Server API"
        Server["Server API"]:::server
        subgraph "Server Components"
            servDir["Server Directory"]:::server
            servReadme["Server README"]:::server
            bgrfc["bgrfc_server.py"]:::server
        end
    end

    %% Build/Development Infrastructure
    subgraph "Build Infrastructure"
        build1["setup.py"]:::build
        build2["pyproject.toml"]:::build
        build3["MANIFEST.in"]:::build
        build4["tox.ini"]:::build
    end

    %% Examples and Tests
    subgraph "Examples and Tests"
        examplesNode["Examples Directory"]:::examples
        testsNode["Tests Directory"]:::examples
    end

    %% Data Flow Connections
    Client -->|"calls"| Bind
    Bind -->|"invokes"| SAP
    SAP -->|"callback"| Server
    Bind -->|"error_handling"| Client

    examplesNode ---|"usage"| Client
    examplesNode ---|"usage"| Server
    testsNode ---|"validation"| Bind

    %% Click Events for Client Module
    click c1 "https://github.com/sap-archive/pyrfc/blob/main/examples/clientIDoc.py"
    click c2 "https://github.com/sap-archive/pyrfc/blob/main/examples/clientStfcStructure.py"
    click c3 "https://github.com/sap-archive/pyrfc/blob/main/examples/clientPrintDescription.py"

    %% Click Events for Server Module
    click servDir "https://github.com/sap-archive/pyrfc/tree/main/examples/server/"
    click servReadme "https://github.com/sap-archive/pyrfc/blob/main/examples/server/README.md"
    click bgrfc "https://github.com/sap-archive/pyrfc/blob/main/examples/server/bgrfc_server.py"

    %% Click Events for Binding/Wrapper Layer
    click cm "https://github.com/sap-archive/pyrfc/blob/main/src/pyrfc/_cyrfc.pyx"
    click excep "https://github.com/sap-archive/pyrfc/blob/main/src/pyrfc/_exception.py"
    click utils "https://github.com/sap-archive/pyrfc/blob/main/src/pyrfc/_utils.py"
    click header "https://github.com/sap-archive/pyrfc/blob/main/src/pyrfc/csapnwrfc.pxd"

    %% Click Events for Build/Development Infrastructure
    click build1 "https://github.com/sap-archive/pyrfc/blob/main/setup.py"
    click build2 "https://github.com/sap-archive/pyrfc/blob/main/pyproject.toml"
    click build3 "https://github.com/sap-archive/pyrfc/blob/main/MANIFEST.in"
    click build4 "https://github.com/sap-archive/pyrfc/blob/main/tox.ini"

    %% Click Events for Examples and Tests
    click examplesNode "https://github.com/sap-archive/pyrfc/tree/main/examples/"
    click testsNode "https://github.com/sap-archive/pyrfc/tree/main/tests/"

    %% Styles
    classDef client fill:#A3E4D7,stroke:#1F618D,stroke-width:2px;
    classDef server fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef binding fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef native fill:#BB8FCE,stroke:#6C3483,stroke-width:2px;
    classDef build fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef examples fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
```
