# logedosoft/erpnext-turkish-delight architecture

> Architecture diagram of the GitHub repository logedosoft/erpnext-turkish-delight, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/logedosoft/erpnext-turkish-delight
- Repository: https://github.com/logedosoft/erpnext-turkish-delight

## Overview

##### Project Type & Purpose
- This is an ERPNext (Frappe framework) app/plugin providing Turkish-specific customizations:
– e-Fatura/e-İrsaliye web-service integration
– Custom DocTypes and UI buttons (manual reorder, production plan)
– Fixtures and overrides for core ERPNext behavior
- It extends the ERPNext backend (Python) and frontend (client-side JS) and integrates with an external SOAP/REST e-invoice service.

##### High-Level Architecture Components
a. User Interface Layer
– Browser (end user)
– Frappe Desk / Web Pages (erpnextturkish/www/orderinfo.html + .py)
– Client scripts in erpnextturkish/public/js and doctype/*.js
b. Application Server Layer
– Frappe Framework + ERPNext Core
– Custom app module: erpnextturkish/
- Hooks & configuration (hooks.py, modules.txt, patches.txt)
- Python packages:
– eirsaliye/api (XML templates, utils, delivery_note.js wrapper)
– doctype controllers (e_irsaliye_ayarlar.py, efatura_ayarlar.py, etc.)
– td_utils.py, selling/api/selling_utils.py
- Fixtures loader (fixtures/*.json)
- Public assets (XML templates, build.json, SS_AUTOREORDER_BTN.mp4)
c. Persistence Layer
– MariaDB (or compatible RDBMS) storing both core ERPNext and custom DocType schemas + fixture records
d. External Services
– Turkish Government e-İrsaliye / e-Fatura SOAP or REST endpoints
– Authentication, XML payload exchange, validation responses

##### Relationships & Data Flow
1. User clicks a custom button in ERPNext Desk (client JS triggers) →
2. A Frappe RPC call / Server method is invoked (Python doctype controller) →
3. The controller reads/writes to Database (ORM) →
4. If e-Fatura/e-İrsaliye operation, server builds XML via api/*.xml templates and calls external SOAP endpoint →
5. Response is processed (api/utils.py), records statuses in DocType (e.g., e_irsaliye_ayarlar) →
6. Result is returned to client JS and rendered in UI.

##### Architectural Patterns & Principles
- MVC pattern via Frappe:
– Models: DocType definitions (.json) + Python controllers (.py)
– Views: Desk forms, HTML templates, custom web pages
– Controllers: server methods exposed to client
- Separation of concerns:
– UI scripts (public/js & doctype/*.js)
– Business logic (td_utils.py, selling/api)
– Integration logic (eirsaliye/api)
- Configuration-driven: fixtures, hooks, modules.txt register components into Frappe

##### Essential Elements
– Clear component labels (UI, Server modules, DB, e-Fatura Service)
– Annotations for major directories:
- erpnextturkish/public/js
- erpnextturkish/erpnext_turkish/doctype
- erpnextturkish/eirsaliye/api
- hooks.py / modules.txt

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "User Interface Layer"
        Browser["Browser"]:::frontend
        OrderInfo["Order Info WebPage"]:::frontend
        ClientScripts["Client-side Scripts"]:::frontend
    end

    %% Server Layer
    subgraph "Application Server Layer"
        Frappe["Frappe Framework + ERPNext Core"]:::backend
        subgraph "Custom App Module (erpnextturkish)"
            HooksConfig["hooks.py / modules.txt / patches.txt"]:::backend
            EirsaliyeAPI["e-İrsaliye Integration API"]:::backend
            EirsaliyeDoctype["e-İrsaliye DocType Controllers & Schemas"]:::backend
            EFaturaDoctype["e-Fatura DocType Controllers & Schemas"]:::backend
            Utils["td_utils.py"]:::backend
            SellingUtils["selling_utils.py"]:::backend
            Fixtures["Fixtures Loader"]:::backend
            PublicAssets["Public Assets"]:::backend
            Overrides["Overrides into ERPNext Core"]:::backend
            Config["Custom Desktop Configuration"]:::backend
        end
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        DB["MariaDB"]:::db
    end

    %% External Services
    subgraph "External Services"
        External["Turkish e-Fatura / e-İrsaliye Web Service"]:::external
    end

    %% Connections
    Browser -->|"loads"| OrderInfo
    Browser -->|"executes"| ClientScripts
    OrderInfo -->|"HTTP/RPC"| Frappe
    ClientScripts -->|"RPC calls"| Frappe
    Frappe -->|"manages"| HooksConfig
    Frappe -->|"invokes"| EirsaliyeAPI
    Frappe -->|"uses models"| EirsaliyeDoctype
    Frappe -->|"uses models"| EFaturaDoctype
    Frappe -->|"calls utils"| Utils
    Frappe -->|"calls utils"| SellingUtils
    Frappe -->|"loads fixtures"| Fixtures
    Frappe -->|"serves assets"| PublicAssets
    Frappe -->|"applies overrides"| Overrides
    Frappe -->|"loads config"| Config
    Frappe -->|"queries"| DB
    EirsaliyeAPI -->|"SOAP/REST over HTTPS"| External
    External -->|"response"| EirsaliyeAPI
    Frappe -->|"response"| Browser

    %% Click Events
    click OrderInfo "https://github.com/logedosoft/erpnext-turkish-delight/blob/master/erpnextturkish/www/orderinfo.html"
    click ClientScripts "https://github.com/logedosoft/erpnext-turkish-delight/tree/master/erpnextturkish/public/js"
    click HooksConfig "https://github.com/logedosoft/erpnext-turkish-delight/blob/master/erpnextturkish/hooks.py"
    click EirsaliyeAPI "https://github.com/logedosoft/erpnext-turkish-delight/tree/master/erpnextturkish/eirsaliye/api"
    click EirsaliyeDoctype "https://github.com/logedosoft/erpnext-turkish-delight/tree/master/erpnextturkish/eirsaliye/doctype/e_irsaliye_ayarlar"
    click EFaturaDoctype "https://github.com/logedosoft/erpnext-turkish-delight/tree/master/erpnextturkish/erpnext_turkish/doctype/efatura_ayarlar"
    click Utils "https://github.com/logedosoft/erpnext-turkish-delight/blob/master/erpnextturkish/td_utils.py"
    click SellingUtils "https://github.com/logedosoft/erpnext-turkish-delight/blob/master/erpnextturkish/selling/api/selling_utils.py"
    click Fixtures "https://github.com/logedosoft/erpnext-turkish-delight/tree/master/erpnextturkish/fixtures"
    click PublicAssets "https://github.com/logedosoft/erpnext-turkish-delight/blob/master/erpnextturkish/public/SS_AUTOREORDER_BTN.mp4"
    click Overrides "https://github.com/logedosoft/erpnext-turkish-delight/blob/master/erpnextturkish/overrides/production_plan.py"
    click Config "https://github.com/logedosoft/erpnext-turkish-delight/blob/master/erpnextturkish/config/desktop.py"

    %% Styles
    classDef frontend fill:#CFE2F3,stroke:#0366d6,color:#0366d6;
    classDef backend fill:#D9EAD3,stroke:#228B22,color:#228B22;
    classDef db fill:#F9CB9C,stroke:#E69138,color:#E69138;
    classDef external fill:#D9D2E9,stroke:#6A0DAD,color:#6A0DAD;
```
