# digitalpalidictionary/dpd-db architecture

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

- Interactive diagram: https://gitdiagram.com/digitalpalidictionary/dpd-db
- Repository: https://github.com/digitalpalidictionary/dpd-db

## Overview

##### Main Components
- Data Ingestion & Processing Modules:
– There are many “deconstructor” modules (both in the archive/ folders and in go_modules/deconstructor) that ingest raw Pāḷi texts, apply sandhi rules, split words, and deconstruct compounds.
– Frequency calculators (go_modules/frequency, db/frequency scripts, and related tools) process and generate statistics.
– Various “families”, “inflections”, “lookup”, and “variants” submodules (under db, exporter, and tools) indicate that the project processes core dictionary data and metadata.
- Data Storage & Database:
– The “db” folder and its subdirectories house source files, helper functions, and a variety of TSV backups.
– Tools for converting, backing up, and rebuilding the database (scripts/backup, tools/[...]) form the persistent storage layer.
- Export & Integration Modules:
– Under “exporter” you see modules for outputting different dictionary formats (GoldenDict, Kindle, Kobo, etc.) and a rich set of templates.
– There is also the “go_modules/dpdDb” which likely holds the models and DB access code.
- API/Service Layer (Web Apps and External Interfaces):
– The “exporter/webapp” directory and the various API integrations in the README (e.g., GoldenDict, DictTango) indicate that there is a REST/web service layer providing dictionary lookup.
– GUIs in folders “gui” and “gui2” are desktop client interfaces (using PySimpleGUI and similar libraries).
- Build, Deployment, and Auxiliary Tools:
– Numerous scripts in “scripts”, “tools”, “misc” and the GitHub workflows (.github/workflows) show continuous integration and build scripts.
– “go_modules” additionally includes test suites and tool components for configuration and database setup.

##### Relationships and Data Flow
- Raw Data (resources/ other text files) and source TSV/Excel files (e.g., under misc, shared_data, resources) feed into data ingestion modules.
- Processing modules (e.g., the deconstructor in Go and Python, frequency analysis scripts, sandhi splitters) take the raw inputs and produce structured DB files.
- The resulting database (stored in TSV, sometimes rebuilt with scripts or Go modules) is used by various export processes to generate dictionary lookup files for different platforms.
- Exporters and webapp modules (both in “exporter” and “go_modules”) then expose the functionality as APIs or GUIs for end users.
- Finally, integration points with external services (as documented in the readme’s integration section) receive or utilize the exported dictionary data.

##### Architectural Patterns and Design Principles
- Modular Design and Separation of Concerns:
– Notice how deconstruction, frequency analysis, export, GUI frontends, and tools are kept in self-contained modules.
– This facilitates an MVC-like separation: the “model” (database, TSV files, processed data) is maintained by backend scripts; the “view” (GUIs, webapp, exported formats) is independent; and the “controller” logic is distributed across processing scripts and API/network layers.
- Polyglot Implementation:
- High Extensibility & Integration:
– The presence of multiple exporters, API modules, and integration folders (“integrations” in the docs) shows the system is built to feed external applications.

##### Relevant Technologies & Frameworks
- That the system uses Git (with GitHub workflows), Go for core processing and frequency analysis, and Python for many utility scripts and GUI development.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Data Source Layer
    subgraph "Data Source Layer"
        DS["Raw Data (resources, misc, shared_data)"]:::sources
    end

    %% Data Processing Layer
    subgraph "Data Processing Layer"
        DArchive["Deconstructor (Archive-based)"]:::processing
        DGo["Deconstructor (Go-based)"]:::processing
        FreqPy["Frequency Analysis (Python)"]:::processing
        FreqGo["Frequency Analysis (Go)"]:::processing
        DictProc["Dictionary Processing (Families,Inflections,Lookup,Variants)"]:::processing
    end

    %% Persistent Storage Layer
    subgraph "Persistent Storage Layer"
        DB["DPD Database & Backups"]:::storage
        DBTools["DB Conversion Tools"]:::storage
    end

    %% Export & Integration Layer
    subgraph "Export & Integration Layer"
        Exp["Exporters (GoldenDict,Kindle,Kobo,PDF,etc.)"]:::export
        DPDdb["Go-based DPD DB Access"]:::export
    end

    %% Service & API Layer
    subgraph "Service & API Layer"
        API["Web App API"]:::service
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        GUI1["Desktop GUI (PySimpleGUI - gui)"]:::presentation
        GUI2["Desktop GUI (PySimpleGUI - gui2)"]:::presentation
    end

    %% Build, Deployment & Auxiliary Tools
    subgraph "Build, Deployment & Auxiliary Tools"
        CI["CI/CD & Build Scripts"]:::tools
        Aux["Auxiliary Tools"]:::tools
    end

    %% Data Flow Connections
    DS --> DArchive
    DS --> DGo
    DS --> FreqPy
    DS --> FreqGo
    DS --> DictProc

    DArchive --> DB
    DGo --> DB
    FreqPy --> DB
    FreqGo --> DB
    DictProc --> DB

    DB --> Exp
    DB --> DPDdb
    DB --> GUI1
    DB --> GUI2

    Exp --> API
    DPDdb --> API

    CI --> DB
    CI --> Exp
    Aux --> DArchive
    Aux --> DGo
    Aux --> FreqPy
    Aux --> FreqGo
    Aux --> DictProc

    %% Styles
    classDef sources fill:#F5F5A4,stroke:#333,stroke-width:2px;
    classDef processing fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef storage fill:#A9DFBF,stroke:#333,stroke-width:2px;
    classDef export fill:#F9D7E1,stroke:#333,stroke-width:2px;
    classDef service fill:#FDEBD0,stroke:#333,stroke-width:2px;
    classDef presentation fill:#D2F4EA,stroke:#333,stroke-width:2px;
    classDef tools fill:#E2E2E2,stroke:#333,stroke-width:2px;

    %% Click Events
    click DArchive "https://github.com/digitalpalidictionary/dpd-db/tree/main/archive/db/deconstructor/"
    click DGo "https://github.com/digitalpalidictionary/dpd-db/tree/main/go_modules/deconstructor/"
    click FreqPy "https://github.com/digitalpalidictionary/dpd-db/tree/main/archive/db/frequency/"
    click FreqGo "https://github.com/digitalpalidictionary/dpd-db/tree/main/go_modules/frequency/"
    click DictProc "https://github.com/digitalpalidictionary/dpd-db/tree/main/db/"
    click DB "https://github.com/digitalpalidictionary/dpd-db/tree/main/db/"
    click DBTools "https://github.com/digitalpalidictionary/dpd-db/blob/main/scripts/build/db_rebuild_from_tsv.py"
    click Exp "https://github.com/digitalpalidictionary/dpd-db/tree/main/exporter/"
    click DPDdb "https://github.com/digitalpalidictionary/dpd-db/tree/main/go_modules/dpdDb/"
    click API "https://github.com/digitalpalidictionary/dpd-db/tree/main/exporter/webapp/"
    click GUI1 "https://github.com/digitalpalidictionary/dpd-db/tree/main/gui/"
    click GUI2 "https://github.com/digitalpalidictionary/dpd-db/tree/main/gui2/"
    click CI "https://github.com/digitalpalidictionary/dpd-db/tree/main/.github/workflows/"
    click Aux "https://github.com/digitalpalidictionary/dpd-db/tree/main/tools/"
```
