# sapphirefountains/erpnext_enhancements architecture

> Architecture diagram of the GitHub repository sapphirefountains/erpnext_enhancements, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sapphirefountains/erpnext_enhancements
- Repository: https://github.com/sapphirefountains/erpnext_enhancements

## Overview

1. **Overall shape**
   - This is a **Frappe/ERPNext custom app**. Its architecture is organized around Frappe primitives: **DocTypes**, **Pages**, **hooks**, **fixtures**, **patches**, and **public JS/CSS overrides**.
   - Most business logic lives in Python modules under `erpnext_enhancements/`, while UI behavior is added through desk/page scripts in `public/js` and per-DocType client scripts.

2. **Main functional boundaries**
   - The codebase is split into feature areas rather than a single monolith:
     - `project_enhancements`
     - `task_enhancements`
     - `enhancements_core`
     - `quickbooks_time_integration`
     - `sapphire_maintenance`
     - `travel_management`
     - `crm_enhancements`
     - `global_enhancements`
   - Each area contains its own DocTypes, pages, and support code, which makes it easier to diagram as separate subsystems sharing the same ERPNext backend.

3. **ERPNext data model extensions**
   - The custom DocTypes are the durable state layer. Examples include:
     - project and dashboard settings
     - `User Form Draft`
     - `Time Kiosk Log` / `Job Interval`
     - `GA4 Settings`
     - QuickBooks sync records and mappings
     - maintenance templates, records, and results
   - These DocTypes are the main persistence boundary between user-facing scripts and server-side logic.

4. **Project management subsystem**
   - `project_enhancements` is one of the core domains. It adds:
     - `Master Project`
     - project dashboard settings and permitted roles
     - project form/list customizations
     - an interactive `project_dashboard` page
     - helper logic for address setup and opportunity-to-project flows
   - Client-side scripts in `public/js/project_enhancements` provide gantt, task tree, and dashboard components, so the browser-side UI is a major part of this subsystem.

5. **Task and hierarchical planning**
   - `task_enhancements` adds a hierarchical task view and task-specific behavior.
   - It includes both a custom page and custom task DocType script, suggesting the UI tree structure is assembled client-side, with Python backing for data retrieval and permissions.

6. **Time kiosk workflow**
   - The time-tracking subsystem centers on `enhancements_core/page/time_kiosk` and the related `Time Kiosk Log` / `Job Interval` records.
   - The readme describes the flow: employee uses the kiosk UI to **clock in/out**, selects project/task context, location is captured, and completed intervals are later consolidated into standard ERPNext timesheets.
   - This is a clear ingestion-and-sync pipeline: kiosk page → server APIs → persisted interval/log records → timesheet synchronization.

7. **Analytics dashboard**
   - `GA4 Dashboard` is implemented as a custom page backed by `GA4 Settings`.
   - The dashboard pulls data from **Google Analytics 4** and **Google Search Console** using a service account and private JSON credentials.
   - The architecture is request-driven from the ERPNext page to external Google APIs; the readme explicitly notes multiple concurrent API calls per load and quota constraints, which is an important system boundary.

8. **QuickBooks Online integration**
   - `quickbooks_time_integration` is a full integration subsystem with its own API layer, client, mapping, sync, webhook, task, and utility modules.
   - Its DocTypes (`QuickBooks Online Settings`, raw payload, sync log, sync mapping) show a standard integration pattern:
     - authenticate/configure in a settings record
     - ingest or exchange payloads
     - map external entities to ERPNext entities
     - log sync activity for traceability
   - This is likely asynchronous or event-driven in parts, especially given the presence of tasks and webhooks.

9. **CRM and Google Drive linkage**
   - `crm_enhancements` contains Google Drive-related settings and utilities, indicating external document storage or folder management tied to CRM/project data.
   - The subsystem sits at the boundary between ERPNext records and Google Drive APIs, with settings stored in a DocType and operational logic in `drive_utils.py` and API wrappers.

10. **Global UX and behavior overrides**
   - `global_enhancements` and many files under `public/js`/`public/css` alter ERPNext behavior globally rather than in one domain.
   - Examples include navigation guards, unified tab handling, mention behavior, sidebar changes, delete/unlink helpers, and UI styling fixes.
   - These are cross-cutting browser-side patches that affect the whole ERPNext desk experience.

11. **Fixtures, hooks, and patches**
   - `fixtures/` contains exported ERPNext metadata such as custom fields, notifications, print formats, workflows, and workflow actions.
   - `patches/` contains migration scripts for schema/data changes, renames, reorderings, and cleanup; this is the repository’s upgrade path.
   - `hooks.py` is the integration point where the app registers its overrides, asset bundles, fixtures, and lifecycle behavior.

12. **Maintenance, travel, and other domain modules**
   - Several smaller but still self-contained modules exist:
     - `sapphire_maintenance` for maintenance records/templates/results
     - `travel_management` for trips, flights, accommodation, agenda, and POIs
     - `enhancements_core` for settings, notes, reminders, kiosk logs, GA4/triton settings
   - These appear as vertical slices: data model + server logic + optional client script/page.

13. **Testing and verification**
   - The repository includes Python tests under `erpnext_enhancements/tests` and feature-local tests beside specific doctypes/pages.
   - There are also utility scripts at the repo root for search, kiosk syncing, and verification, indicating the team validates both backend behavior and the kiosk/integration flows outside the main app surface.

14. **Architecture summary for diagramming**
   - A good diagram would show ERPNext/Frappe at the center, with:
     - **server-side app modules** handling business rules and integrations
     - **DocTypes** as persistent configuration/state
     - **Pages and public JS/CSS** as the interactive UI layer
     - **external services** on the edges: Google APIs, QuickBooks Online, Google Drive, and any telephony/AI integrations implied by the API modules
     - **patches/fixtures/hooks** as the deployment and customization backbone

Main entry points: [`erpnext_enhancements/public/js`](https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/public/js) (Public JS/CSS), [`erpnext_enhancements/hooks.py`](https://github.com/sapphirefountains/erpnext_enhancements/blob/main/erpnext_enhancements/hooks.py) (Hooks), [`erpnext_enhancements/project_enhancements`](https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/project_enhancements) (Project enhancements), [`erpnext_enhancements/api`](https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/api) (Core APIs)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_platform["Frappe app core"]
  node_hooks["Hooks<br/>app wiring<br/>[hooks.py]"]
  node_fixtures["Fixtures<br/>metadata export"]
  node_patches["Patches<br/>migrations"]
  node_core_api["Core APIs<br/>shared server APIs"]
end

subgraph group_projects["Project planning"]
  node_project_enhancements["Project enhancements<br/>project domain"]
  node_project_dashboard["Project dashboard<br/>page"]
  node_project_doctypes[("Project DocTypes<br/>project state")]
  node_task_enhancements["Task enhancements<br/>task domain"]
  node_task_view["Task tree<br/>page"]
end

subgraph group_integrations["External integrations"]
  node_quickbooks_integration["QuickBooks sync<br/>integration subsystem"]
  node_quickbooks_doctypes[("QB DocTypes<br/>integration state")]
  node_ga4_dashboard["GA4 dashboard<br/>analytics page<br/>[ga4_dashboard.js]"]
  node_time_kiosk["Time kiosk<br/>ingestion workflow<br/>[time_kiosk.js]"]
  node_time_records[("Time records<br/>kiosk state")]
end

subgraph group_domains["Operational domains"]
  node_crm_drive["CRM Drive<br/>crm integration"]
  node_maintenance["Maintenance"]
  node_travel["Travel mgmt<br/>travel domain"]
end

subgraph group_ui["Browser overrides"]
  node_global_overrides["Global overrides<br/>cross-cutting UI"]
  node_public_ui["Public JS/CSS<br/>client assets"]
end

node_hooks -->|"loads"| node_fixtures
node_hooks -->|"applies"| node_patches
node_hooks -->|"bundles"| node_public_ui
node_hooks -->|"enables"| node_global_overrides
node_core_api -->|"supports"| node_time_kiosk
node_core_api -->|"supports"| node_ga4_dashboard
node_project_enhancements -->|"persists"| node_project_doctypes
node_project_enhancements -->|"serves"| node_project_dashboard
node_project_enhancements -->|"extends"| node_public_ui
node_project_dashboard -->|"reads"| node_project_doctypes
node_task_enhancements -->|"serves"| node_task_view
node_task_enhancements -->|"extends"| node_public_ui
node_quickbooks_integration -->|"stores"| node_quickbooks_doctypes
node_quickbooks_integration -->|"extends"| node_public_ui
node_time_kiosk -->|"writes"| node_time_records
node_ga4_dashboard -->|"calls"| node_core_api
node_crm_drive -->|"extends"| node_public_ui
node_maintenance -->|"extends"| node_public_ui
node_travel -->|"extends"| node_public_ui
node_global_overrides -->|"shapes"| node_public_ui

click node_hooks "https://github.com/sapphirefountains/erpnext_enhancements/blob/main/erpnext_enhancements/hooks.py"
click node_fixtures "https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/fixtures"
click node_patches "https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/patches"
click node_core_api "https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/api"
click node_project_enhancements "https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/project_enhancements"
click node_project_dashboard "https://github.com/sapphirefountains/erpnext_enhancements/blob/main/erpnext_enhancements/project_enhancements/page/project_dashboard/project_dashboard.js"
click node_project_doctypes "https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/project_enhancements/doctype"
click node_task_enhancements "https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/task_enhancements"
click node_task_view "https://github.com/sapphirefountains/erpnext_enhancements/blob/main/erpnext_enhancements/task_enhancements/page/hierarchical_task_view/hierarchical_task_view.js"
click node_quickbooks_integration "https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/quickbooks_time_integration"
click node_quickbooks_doctypes "https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/quickbooks_time_integration/doctype"
click node_ga4_dashboard "https://github.com/sapphirefountains/erpnext_enhancements/blob/main/erpnext_enhancements/enhancements_core/page/ga4_dashboard/ga4_dashboard.js"
click node_time_kiosk "https://github.com/sapphirefountains/erpnext_enhancements/blob/main/erpnext_enhancements/enhancements_core/page/time_kiosk/time_kiosk.js"
click node_time_records "https://github.com/sapphirefountains/erpnext_enhancements/blob/main/erpnext_enhancements/enhancements_core/doctype/time_kiosk_log/time_kiosk_log.json"
click node_crm_drive "https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/crm_enhancements"
click node_maintenance "https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/sapphire_maintenance"
click node_travel "https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/travel_management"
click node_global_overrides "https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/global_enhancements"
click node_public_ui "https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/public/js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_hooks,node_fixtures,node_patches,node_core_api toneBlue
class node_project_enhancements,node_project_dashboard,node_project_doctypes,node_task_enhancements,node_task_view toneAmber
class node_quickbooks_integration,node_quickbooks_doctypes,node_ga4_dashboard,node_time_kiosk,node_time_records toneMint
class node_crm_drive,node_maintenance,node_travel toneRose
class node_global_overrides,node_public_ui toneIndigo
```

## Components

### Frappe app core

App wiring, shared APIs, fixtures, patches, and cross-cutting desk behavior.

- [Hooks](https://github.com/sapphirefountains/erpnext_enhancements/blob/main/erpnext_enhancements/hooks.py): app wiring · Registers app-level overrides, assets, fixtures, and lifecycle integration. · `erpnext_enhancements/hooks.py`
- [Fixtures](https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/fixtures): metadata export · Custom fields, workflows, notifications, print formats, and property setters. · `erpnext_enhancements/fixtures`
- [Patches](https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/patches): migrations · Upgrade scripts for schema changes, renames, cleanup, and data reordering. · `erpnext_enhancements/patches`
- [Core APIs](https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/api): shared server APIs · Common backend endpoints for analytics, search, kiosk, drafts, comments, telephony, and workspace helpers. · `erpnext_enhancements/api`

### Project planning

Project and task management extensions, including dashboards and hierarchical views.

- [Project enhancements](https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/project_enhancements): project domain · Project-specific server logic, DocTypes, and helper flows around dashboards and setup. · `erpnext_enhancements/project_enhancements`
- [Project dashboard](https://github.com/sapphirefountains/erpnext_enhancements/blob/main/erpnext_enhancements/project_enhancements/page/project_dashboard/project_dashboard.js): page · Interactive project dashboard page backed by server-side data and client widgets. · `erpnext_enhancements/project_enhancements/page/project_dashboard/project_dashboard.js`
- [Project DocTypes](https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/project_enhancements/doctype): project state · Master project, dashboard settings, permitted roles, and project customizations. · `erpnext_enhancements/project_enhancements/doctype`
- [Task enhancements](https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/task_enhancements): task domain · Hierarchical task view and task-specific behavior for planning workflows. · `erpnext_enhancements/task_enhancements`
- [Task tree](https://github.com/sapphirefountains/erpnext_enhancements/blob/main/erpnext_enhancements/task_enhancements/page/hierarchical_task_view/hierarchical_task_view.js): page · Custom hierarchical task view page and supporting client script. · `erpnext_enhancements/task_enhancements/page/hierarchical_task_view/hierarchical_task_view.js`

### External integrations

Google, QuickBooks, telephony, and sync-oriented boundaries.

- [QuickBooks sync](https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/quickbooks_time_integration): integration subsystem · QuickBooks Online client, sync, mapping, webhook, and task modules. · `erpnext_enhancements/quickbooks_time_integration`
- [QB DocTypes](https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/quickbooks_time_integration/doctype): integration state · Settings, raw payload, sync log, and entity mapping records. · `erpnext_enhancements/quickbooks_time_integration/doctype`
- [GA4 dashboard](https://github.com/sapphirefountains/erpnext_enhancements/blob/main/erpnext_enhancements/enhancements_core/page/ga4_dashboard/ga4_dashboard.js): analytics page · Desk page for Google Analytics 4 and Search Console reporting. · `erpnext_enhancements/enhancements_core/page/ga4_dashboard/ga4_dashboard.js`
- [Time kiosk](https://github.com/sapphirefountains/erpnext_enhancements/blob/main/erpnext_enhancements/enhancements_core/page/time_kiosk/time_kiosk.js): ingestion workflow · Clock-in/clock-out kiosk page and interval consolidation flow. · `erpnext_enhancements/enhancements_core/page/time_kiosk/time_kiosk.js`
- [Time records](https://github.com/sapphirefountains/erpnext_enhancements/blob/main/erpnext_enhancements/enhancements_core/doctype/time_kiosk_log/time_kiosk_log.json): kiosk state · Time Kiosk Log, Job Interval, and related settings/state records. · `erpnext_enhancements/enhancements_core/doctype/time_kiosk_log/time_kiosk_log.json`

### Operational domains

Standalone business modules for maintenance, travel, and CRM support.

- [CRM Drive](https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/crm_enhancements): crm integration · Google Drive settings and helpers for CRM/project document linkage. · `erpnext_enhancements/crm_enhancements`
- [Maintenance](https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/sapphire_maintenance): maintenance domain · Templates, records, consumables, visits, and results for maintenance workflows. · `erpnext_enhancements/sapphire_maintenance`
- [Travel mgmt](https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/travel_management): travel domain · Trips and related itinerary entities such as flights, accommodation, agenda, and POIs. · `erpnext_enhancements/travel_management`

### Browser overrides

Shared public JS/CSS and client scripts that reshape the ERPNext desk experience.

- [Global overrides](https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/global_enhancements): cross-cutting UI · Global desk behavior patches, widgets, and styling shared across ERPNext. · `erpnext_enhancements/global_enhancements`
- [Public JS/CSS](https://github.com/sapphirefountains/erpnext_enhancements/tree/main/erpnext_enhancements/public/js): client assets · Desk-wide browser scripts and styles, including project, task, and integration UI behavior. · `erpnext_enhancements/public/js`

## Connections

- Hooks → Fixtures: loads · Registers exported metadata used during installation and updates.
- Hooks → Patches: applies · Runs migration scripts as part of app upgrades.
- Hooks → Public JS/CSS: bundles · Serves public JavaScript and CSS overrides into the desk.
- Hooks → Global overrides: enables · Activates global behavior changes across ERPNext.
- Core APIs → Time kiosk: supports · Provides shared endpoints used by kiosk flows and related status checks.
- Core APIs → GA4 dashboard: supports · Supplies shared API helpers for dashboard requests.
- Project enhancements → Project DocTypes: persists · Stores project settings, roles, and master project state.
- Project enhancements → Project dashboard: serves · Backs the interactive dashboard page.
- Project enhancements → Public JS/CSS: extends · Adds project-specific browser behavior and dashboard widgets.
- Project dashboard → Project DocTypes: reads · Uses project dashboard settings and permitted roles.
- Task enhancements → Task tree: serves · Implements the hierarchical task page and related client logic.
- Task enhancements → Public JS/CSS: extends · Adds task tree and task form client behavior.
- QuickBooks sync → QB DocTypes: stores · Uses settings, payload, logs, and mappings for sync traceability.
- QuickBooks sync → Public JS/CSS: extends · Includes QuickBooks-specific browser assets and dashboard UI.
- Time kiosk → Time records: writes · Creates logs and intervals that later consolidate into ERPNext timesheets.
- GA4 dashboard → Core APIs: calls · Uses shared backend helpers while requesting external analytics data.
- CRM Drive → Public JS/CSS: extends · Adds CRM-facing client behavior around Drive-linked records.
- Maintenance → Public JS/CSS: extends · Uses client scripts and forms for maintenance record entry and review.
- Travel mgmt → Public JS/CSS: extends · Adds travel-related client interactions.
- Global overrides → Public JS/CSS: shapes · Implements desk-wide patches, widgets, and UI fixes.
