# jinseyd/erpnext_wxwork architecture

> Architecture diagram of the GitHub repository jinseyd/erpnext_wxwork, 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/jinseyd/erpnext_wxwork
- Repository: https://github.com/jinseyd/erpnext_wxwork

## Overview

##### Project Type and Purpose
- This is an ERPNext/Frappe application that integrates Enterprise WeChat (企业微信) functionality into an existing ERPNext system.
- Its main goals include enabling password-less login via the Enterprise WeChat client and sending notifications (via “Wxwork Notification Logs”) to Enterprise WeChat.
- The README also covers manual configuration steps (setting up the app, configuring settings for wxwork, and binding ERPNext users to wxwork users), indicating tight integration between ERPNext and Enterprise WeChat.

##### High-Level File Structure & Architectural Implications
- The top-level files such as setup.py, MANIFEST.in, requirements.txt, and .gitignore indicate a packaged Python module.
- The erpnext_wxwork directory has a typical Frappe/ERPNext app structure:
- The “config” directory holds configuration files like desktop.py and docs.py.
- The “doctype” subdirectories (for wxwork_notification_logs, wxwork_setting, and wxwork_user) encapsulate business objects along with their tests, JS for client-side behavior, JSON metadata, and Python logic.
- The “wxwork” directory contains core business logic (e.g., authentication, console commands, notification logging, and specific Enterprise WeChat API integrations via wechat_client.py and wechat_user.py).
- The “public” and “templates” directories suggest web assets and static resources for the plug-in’s user interface.
- The presence of “hooks.py”, “oauth.py”, and “uninstall.py” implies integration hooks with ERPNext’s lifecycle (installation, event triggers, and OAuth routing).

##### Key Components
a. ERPNext/Frappe Core System:
- Represents the host ERP system into which this app is installed.
- Details like:
– The integration point via Frappe hooks (from hooks.py).
– The database, where doctype records (wxwork_notification_logs, wxwork_setting, wxwork_user) are stored.
b. Erpnext Wxwork Module:
- Contains the integration logic split into subcomponents:
– Configuration Component: Managed by configuration files in erpnext_wxwork/config (desktop.py, docs.py).
– Doctype Components: Each doctype (wxwork_notification_logs, wxwork_setting, wxwork_user) defines specific business logic and UI for interacting with Enterprise WeChat data.
– OAuth & Authentication: Handled in oauth.py and related methods in the wxwork directory.
– Business Logic: Core integration logic under erpnext_wxwork/wxwork includes API clients (wechat_client.py), user management (wechat_user.py, wxwork_user.py), authentication (auth.py), and logging (notification_log.py).
c. Enterprise WeChat External System:
- Enterprise WeChat service, which the app interacts with for:
– Sending notifications when a new WX notification log is created.
– Handling password-less login and OAuth redirection.
– Displaying information via the Enterprise WeChat client.
d. Client/User Interface:
- Web assets and templates (“public”, “templates”) that render configuration screens (e.g., wxwork_setting.png and wxwork_user.png) and support user interactions.

##### Relationships and Data Flows
– How user actions or database events (e.g., insertion in wxwork_notification_logs) trigger business logic flows in the “wxwork” subsystem.
– The OAuth component interacting both with incoming HTTP requests (from ERPNext’s API layer) and the Enterprise WeChat platform.
- A feedback loop for error handling or notification logs can also be noted.

##### Architectural Patterns and Technologies
- Modular design using the Frappe/ERPNext app structure — each doctype acts like a mini MVC unit.
- Use of hooks implies event-driven programming where ERPNext events trigger the Wxwork logic.
- Separation of concerns: configuration, business logic, and UI layers are clearly delineated.
- Technologies include Python, Frappe Framework, ERPNext modules, and the wechatpy library (as noted in the installation instructions).

## Diagram (Mermaid)

```mermaid
flowchart TD
    ERP["ERPNext Core System"]:::ERPCore

    subgraph "Erpnext Wxwork Module"
        H["Hooks"]:::internal
        subgraph "Configuration Component"
            DConfig["Desktop Config"]:::internal
            DocsConfig["Docs Config"]:::internal
        end
        subgraph "Doctype Components"
            DLog["wxwork_notification_logs"]:::internal
            DSet["wxwork_setting"]:::internal
            DUser["wxwork_user"]:::internal
        end
        OAuth["OAuth & Authentication"]:::internal
        subgraph "Business Logic"
            API["API Client"]:::internal
            UMan["User Management"]:::internal
            NLog["Notification Logging"]:::internal
            Console["Console Commands"]:::internal
        end
        subgraph "User Interface & Web Assets"
            Public["Public Assets"]:::internal
            Templates["Templates"]:::internal
        end
    end

    subgraph "Enterprise WeChat"
        WECHAT["Enterprise WeChat"]:::external
    end

    ERP -->|"triggers"| H
    H -->|"loads settings"| DConfig
    H -->|"activates"| DLog
    H -->|"activates"| DSet
    H -->|"activates"| DUser
    H -->|"initiates"| OAuth
    DConfig -->|"provides config"| OAuth
    DLog -->|"triggers log"| NLog
    DUser -->|"fires user binding"| UMan
    OAuth -->|"OAuthFlow"| WECHAT
    API -->|"sends notify"| WECHAT
    DocsConfig -->|"serves UI"| Templates
    DConfig -->|"serves UI"| Public
    Console -->|"manages logs"| NLog

    click H "https://github.com/jinseyd/erpnext_wxwork/blob/master/erpnext_wxwork/hooks.py"
    click DConfig "https://github.com/jinseyd/erpnext_wxwork/blob/master/erpnext_wxwork/config/desktop.py"
    click DocsConfig "https://github.com/jinseyd/erpnext_wxwork/blob/master/erpnext_wxwork/config/docs.py"
    click DLog "https://github.com/jinseyd/erpnext_wxwork/tree/master/erpnext_wxwork/erpnext_wxwork/doctype/wxwork_notification_logs/"
    click DSet "https://github.com/jinseyd/erpnext_wxwork/tree/master/erpnext_wxwork/erpnext_wxwork/doctype/wxwork_setting/"
    click DUser "https://github.com/jinseyd/erpnext_wxwork/tree/master/erpnext_wxwork/erpnext_wxwork/doctype/wxwork_user/"
    click OAuth "https://github.com/jinseyd/erpnext_wxwork/blob/master/erpnext_wxwork/oauth.py"
    click OAuth "https://github.com/jinseyd/erpnext_wxwork/blob/master/erpnext_wxwork/wxwork/auth.py"
    click API "https://github.com/jinseyd/erpnext_wxwork/blob/master/erpnext_wxwork/wxwork/wechat_client.py"
    click UMan "https://github.com/jinseyd/erpnext_wxwork/blob/master/erpnext_wxwork/wxwork/wechat_user.py"
    click UMan "https://github.com/jinseyd/erpnext_wxwork/blob/master/erpnext_wxwork/wxwork/wxwork_user.py"
    click NLog "https://github.com/jinseyd/erpnext_wxwork/blob/master/erpnext_wxwork/wxwork/notification_log.py"
    click Console "https://github.com/jinseyd/erpnext_wxwork/blob/master/erpnext_wxwork/wxwork/console.py"
    click Public "https://github.com/jinseyd/erpnext_wxwork/tree/master/erpnext_wxwork/public/"
    click Templates "https://github.com/jinseyd/erpnext_wxwork/tree/master/erpnext_wxwork/templates/"

    classDef ERPCore fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef internal fill:#98FB98,stroke:#333,stroke-width:2px;
    classDef external fill:#FFB6C1,stroke:#333,stroke-dasharray:5,5;
```
