# timschofield/weberp architecture

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

- Interactive diagram: https://gitdiagram.com/timschofield/weberp
- Repository: https://github.com/timschofield/weberp

## Overview

##### Project Type & Purpose
- webERP is a monolithic, web-based ERP application written in PHP that serves as a full‐feature business administration and accounting system. It serves end users through a browser and offers modules that cover areas such as general ledger, accounts receivable, inventory, purchasing, manufacturing (MRP), reporting, and more.
- The README confirms that it is intended for multi-user business administration and accounting tasks, and the file tree shows there are many PHP files spread across modules (like BankAccounts, Inventory, Sales, etc.), a dedicated “api” folder for integration endpoints, “includes” for shared logic and libraries, “install” for setup scripts, “companies” for company-specific settings and data, and several directories for documentation, CSS, JavaScript, and third-party libraries.

##### Key Components from the File Structure
a. Presentation Layer:
- The front-end is served via many PHP files (e.g., index.php, login pages, dashboard scripts) and associated assets in the “css”, “javascripts”, and “locale” directories.
- The “dashboard” and “reportwriter” folders signal specialized user interfaces for dashboards and reports.
b. Business Logic / Application Layer:
- This layer is implemented in the bulk of PHP scripts and the “includes” folder, which houses class definitions, functions for connecting to databases (e.g., ConnectDB.inc, ConnectDB_mysql.inc, etc.), utility functions (e.g., DateFunctions.inc, MiscFunctions.php), EDI, PDF processing (using tcpdf and phplot libraries), and other business rules.
- Modules for different ERP functions (such as BankAccounts.php, Customers.php, SalesReport.php, MRP*.php, etc.) clearly show that many components are tightly integrated into a monolithic PHP application.
c. Data Access / Persistence Layer:
- All SQL scripts and upgrade/installation files in the “install” and “sql” directories indicate that the system uses a MySQL (or MariaDB) relational database.
- Database connection logic is provided via PHP include files allowing dynamic connections according to the configuration in “config.distrib.php” (and your custom config.php file).
d. API/Integration Layer:
- The “api” directory includes endpoints for operations like branches, customers, GL accounts, stock, etc. This acts as an integration layer for external systems or services.
e. Supporting & Ancillary Modules:
- The “companies” directory holds company-specific configuration and possibly company data files.
- Localization is clearly supported through the “locale” directory.
- Additional libraries (such as tcpdf, phplot, and xmlrpc) in the “includes” and “vendor” areas support reporting, barcode generation, PDF generation, and XML RPC communications.
- The “install” folder contains the scripts needed for both new installations and upgrades.

##### How the Components Interact
- Users interact with the system via a web browser and HTML5 front-end. Their input is handled by PHP scripts which reside in root level files (like index.php) and in dedicated dashboards.
- The web server (Apache, NGINX, etc.) executes the PHP code, which in turn invokes functions and classes from the “includes” directory, and modules across the application.
- The PHP code accesses the relational database (MySQL/MariaDB) to retrieve and update enterprise data (customers, orders, inventory, financial transactions, etc.). SQL scripts and upgrade routines in the “sql” and “install” folders help to manage and upgrade the database schema.
- API endpoints (inside the “api” folder) allow external systems (or even the frontend) to interact with ERP functionalities using HTTP/JSON or XML-RPC.
- Report modules in “reportwriter” and PDF-generating libraries (TCPDF) allow the creation and formatting of financial reports, invoices, picking lists, and other documentation.
- The use of multiple CSS themes and localized content (via “locale”) ensures that the user interface can be customized and localized.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI1["Index Page"]:::presentation
        UI2["Dashboard (Template)"]:::presentation
        UI3["CSS Assets"]:::presentation
        UI4["JavaScript Assets"]:::presentation
        UI5["Locale Resources"]:::presentation
    end

    %% Application/Business Logic
    subgraph "Application/Business Logic"
        BL1["Customers Module"]:::biz
        BL2["BankAccounts Module"]:::biz
        BL3["SalesReport Module"]:::biz
        BL4["MRP Module"]:::biz
        BL5["Shared Includes"]:::biz
        BL6["API Endpoints"]:::biz
        BL7["Reporting Modules"]:::biz
        BL8["Company Config"]:::biz
        BL9["External Libraries"]:::biz
    end

    %% Data Access / Persistence
    subgraph "Data Access / Persistence"
        DA1["MySQL Database"]:::persistence
        DA2["Install Scripts"]:::persistence
        DA3["SQL Scripts"]:::persistence
        DA4["Configuration File"]:::persistence
    end

    %% Flow from Presentation Layer to Business Logic
    UI1 -->|"request"| BL1
    UI2 -->|"request"| BL1
    UI4 -->|"request"| BL1
    UI5 -->|"request"| BL1
    UI3 --- BL5

    %% Business Logic internal interactions
    BL1 ---|"uses"| BL5
    BL2 ---|"uses"| BL5
    BL3 ---|"uses"| BL5
    BL4 ---|"uses"| BL5

    BL5 -->|"config"| DA4

    BL1 -->|"query"| DA1
    BL2 -->|"query"| DA1
    BL3 -->|"query"| DA1
    BL4 -->|"query"| DA1

    BL7 -->|"calls"| BL9
    BL7 -->|"fetches"| DA1

    BL8 -->|"references"| DA4

    %% API Endpoints can be accessed directly by external systems and also serve internal modules
    BL6 -->|"integrates"| BL1
    UI2 -->|"API call"| BL6

    %% Data Access connections from installation components
    DA2 -->|"setup"| DA1
    DA3 -->|"upgrade"| DA1

    %% Styles for layers
    classDef presentation fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef biz fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef persistence fill:#FFB6C1,stroke:#000,stroke-width:2px;

    %% Click Events for Presentation Layer
    click UI1 "https://github.com/timschofield/weberp/blob/master/index.php"
    click UI2 "https://github.com/timschofield/weberp/blob/master/dashboard/template.php"
    click UI3 "https://github.com/timschofield/weberp/tree/master/css/"
    click UI4 "https://github.com/timschofield/weberp/blob/master/javascripts/Login.js"
    click UI5 "https://github.com/timschofield/weberp/tree/master/locale/"

    %% Click Events for Business Logic Layer
    click BL1 "https://github.com/timschofield/weberp/blob/master/Customers.php"
    click BL2 "https://github.com/timschofield/weberp/blob/master/BankAccounts.php"
    click BL3 "https://github.com/timschofield/weberp/blob/master/SalesReport.php"
    click BL4 "https://github.com/timschofield/weberp/blob/master/MRP.php"
    click BL5 "https://github.com/timschofield/weberp/tree/master/includes/"
    click BL6 "https://github.com/timschofield/weberp/tree/master/api/"
    click BL7 "https://github.com/timschofield/weberp/tree/master/reportwriter/"
    click BL8 "https://github.com/timschofield/weberp/tree/master/companies/"
    click BL9 "https://github.com/timschofield/weberp/tree/master/vendor/"

    %% Click Events for Data Access / Persistence Layer
    click DA2 "https://github.com/timschofield/weberp/tree/master/install/"
    click DA3 "https://github.com/timschofield/weberp/tree/master/sql/"
    click DA4 "https://github.com/timschofield/weberp/blob/master/config.distrib.php"
```
