# zhuinfo/django-erp architecture

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

- Interactive diagram: https://gitdiagram.com/zhuinfo/django-erp
- Repository: https://github.com/zhuinfo/django-erp

## Overview

- Web Server & Application Entry: At the center is the Django application itself with manage.py serving as the entry point, and mis/settings.py and mis/urls.py providing core configuration and URL routing.
- Common and Utility Modules: Include components like “common” (shared constants and generic functionalities), “midware” (middleware such as custom user handling), and “plugin” (extensible functionality such as workflow actions and Excel imports).
- Frontend Templates & Static Assets: Represent the “templates” directory (with admin and default templates for UI rendering) and the “static” assets (CSS, JS, and images) that support the web interface.
- Internationalization: Mark a component for localization with the “locale” directory which stores language-specific files.
- Upload & Documentation: Acknowledge the “upload” and “文档” directories as supporting resources for data import/export and user manuals.
- Installation & Setup: Optionally, mention the Install folder which includes SQL initial scripts and requirements.

##### Interactions and relationships
- That the Web Server (the Django framework) routes incoming HTTP requests to the appropriate app views (using mis/urls.py and individual app URL configurations, such as those found in invent/urls.py and selfhelp/urls.py).
- Middleware (“midware” module) as intercepting and processing requests/responses, ensuring proper user context, and potentially customizing session behavior.
- “plugin” module to the ERP modules (especially workflow) to signal how business logic like workflow actions and nodes are injected into the app.
- Static asset serving and template rendering flows: static files from the “static” directory and HTML templates from the “templates” directory feed into the presentation layer.

##### Architectural patterns and design principles
- That the project follows Django’s “MTV” (Model-Template-View) pattern. Each ERP module encapsulates its domain logic through models, presentation via views/templates, and business logic often found in views or dedicated services.
- Modularization: each ERP domain (sales, purchase, inventory, etc.) is encapsulated into separate apps, which encourages separation of concerns and easier future enhancements or isolated testing.
- Use of middleware and plugins as extension points within the application, adhering to a loosely coupled architecture.

##### Relevant technologies and frameworks
- MySQL as the chosen database backend.
- Cite additional technology components like the MySQL database driver (as mentioned in the README troubleshooting section) and potential usage of front-end assets (JavaScript and CSS in the static directory) that deliver interactivity to the UI.

## Diagram (Mermaid)

```mermaid
graph TD
    Browser["Browser"]:::frontend
    Browser -->|"HTTP_request"| Django["Django Framework"]:::entry

    subgraph "Core Application"
        Manage["manage.py"]:::entry
        Settings["mis/settings.py"]:::entry
        URLs["mis/urls.py"]:::entry
        Views["mis/views.py"]:::entry
    end
    Django --> Manage
    Django --> Settings
    Django --> URLs
    Django --> Views

    subgraph "ERP Modules"
        Basedata["ERP Module: Basedata"]:::module
        HR["ERP Module: HR"]:::module
        Invent["ERP Module: Inventory"]:::module
        Organ["ERP Module: Organization"]:::module
        Purchase["ERP Module: Purchase"]:::module
        Sale["ERP Module: Sales"]:::module
        Selfhelp["ERP Module: Self-help"]:::module
        Syscfg["ERP Module: System Configuration"]:::module
        Workflow["ERP Module: Workflow"]:::module
    end
    Django -->|"routes"| Basedata
    Django -->|"routes"| HR
    Django -->|"routes"| Invent
    Django -->|"routes"| Organ
    Django -->|"routes"| Purchase
    Django -->|"routes"| Sale
    Django -->|"routes"| Selfhelp
    Django -->|"routes"| Syscfg
    Django -->|"routes"| Workflow

    subgraph "Common & Utility"
        Const["Common: const.py"]:::utility
        Generic["Common: generic.py"]:::utility
        Middleware["Middleware: cuser.py"]:::utility
    end
    Django -->|"utilizes"| Const
    Django -->|"utilizes"| Generic
    Django -->|"middleware"| Middleware

    subgraph "Plugin System"
        WFActions["Plugin: WF Actions"]:::plugin
        WFNodes["Plugin: WF Nodes"]:::plugin
        WFUsers["Plugin: WF Users"]:::plugin
        Excel["Plugin: Excel Import"]:::plugin
    end
    Workflow -->|"integrates"| WFActions
    Workflow -->|"integrates"| WFNodes
    Workflow -->|"integrates"| WFUsers
    Workflow -->|"integrates"| Excel

    subgraph "Frontend Assets"
        Templates["Templates"]:::frontend
        Static["Static Assets"]:::frontend
    end
    Django -->|"renders"| Templates
    Django -->|"serves"| Static

    Internationalization["Internationalization: locale files"]:::frontend
    Django -->|"i18n"| Internationalization

    subgraph "Upload & Documentation"
        Upload["Upload Resources"]:::utility
        Docs["Documentation"]:::utility
    end
    Django -->|"handles"| Upload
    Django -->|"provides"| Docs

    Installation["Installation & Setup"]:::utility
    Django --> Installation

    Database["MySQL Database"]:::database
    Django -->|"DB_Connection"| Database

    classDef entry fill:#ADD8E6,stroke:#000,stroke-width:2px
    classDef module fill:#90EE90,stroke:#000,stroke-width:2px
    classDef utility fill:#FFD700,stroke:#000,stroke-width:2px
    classDef frontend fill:#FFB6C1,stroke:#000,stroke-width:2px
    classDef database fill:#FFA07A,stroke:#000,stroke-width:2px
    classDef plugin fill:#DDA0DD,stroke:#000,stroke-width:2px

    click Manage "https://github.com/zhuinfo/django-erp/blob/master/manage.py"
    click Settings "https://github.com/zhuinfo/django-erp/blob/master/mis/settings.py"
    click URLs "https://github.com/zhuinfo/django-erp/blob/master/mis/urls.py"
    click Views "https://github.com/zhuinfo/django-erp/blob/master/mis/views.py"

    click Basedata "https://github.com/zhuinfo/django-erp/tree/master/basedata/"
    click HR "https://github.com/zhuinfo/django-erp/tree/master/hr/"
    click Invent "https://github.com/zhuinfo/django-erp/tree/master/invent/"
    click Organ "https://github.com/zhuinfo/django-erp/tree/master/organ/"
    click Purchase "https://github.com/zhuinfo/django-erp/tree/master/purchase/"
    click Sale "https://github.com/zhuinfo/django-erp/tree/master/sale/"
    click Selfhelp "https://github.com/zhuinfo/django-erp/tree/master/selfhelp/"
    click Syscfg "https://github.com/zhuinfo/django-erp/tree/master/syscfg/"
    click Workflow "https://github.com/zhuinfo/django-erp/tree/master/workflow/"

    click Const "https://github.com/zhuinfo/django-erp/blob/master/common/const.py"
    click Generic "https://github.com/zhuinfo/django-erp/blob/master/common/generic.py"
    click Middleware "https://github.com/zhuinfo/django-erp/blob/master/midware/cuser.py"

    click WFActions "https://github.com/zhuinfo/django-erp/blob/master/plugin/wfactions.py"
    click WFNodes "https://github.com/zhuinfo/django-erp/blob/master/plugin/wfnodes.py"
    click WFUsers "https://github.com/zhuinfo/django-erp/blob/master/plugin/wfusers.py"
    click Excel "https://github.com/zhuinfo/django-erp/blob/master/plugin/xls.py"

    click Templates "https://github.com/zhuinfo/django-erp/tree/master/templates/"
    click Static "https://github.com/zhuinfo/django-erp/tree/master/static/"
    click Internationalization "https://github.com/zhuinfo/django-erp/tree/master/locale/zh_CN/LC_MESSAGES"

    click Upload "https://github.com/zhuinfo/django-erp/tree/master/upload/"
    click Docs "https://github.com/zhuinfo/django-erp/tree/master/文档/"
    click Installation "https://github.com/zhuinfo/django-erp/blob/master/Install/requirements.txt"
```
