# q10developer/sbcrm architecture

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

- Interactive diagram: https://gitdiagram.com/q10developer/sbcrm
- Repository: https://github.com/q10developer/sbcrm

## Overview

#### Purpose and Runtime

SB CRM is a small Frappe/ERPNext-style application installed into a Bench site with `bench install-app sbcrm`. Its implemented domain surface is an “SB Opportunity” DocType. Python runs server-side in the Frappe runtime; JavaScript runs in the Frappe Desk form client.

Key app registration files: `sbcrm/hooks.py`, `sbcrm/modules.txt`, `sbcrm/__init__.py`.

#### Application Registration and Lifecycle

Frappe discovers the app package and its module definitions through `sbcrm/__init__.py` and `sbcrm/modules.txt`. Framework lifecycle hooks, integration points, and app metadata would be declared in `sbcrm/hooks.py`; this is the primary boundary between the custom app and the host Frappe site.

`sbcrm/patches.txt` provides the framework-recognized migration/patch registration boundary for versioned database changes.

#### Opportunity Domain Model

The core business entity is the SB Opportunity DocType. Its schema, permissions, field definitions, and Desk metadata are defined in `sbcrm/sb_crm/doctype/sb_opportunity/sb_opportunity.json`.

Server-side document behavior belongs in `sbcrm/sb_crm/doctype/sb_opportunity/sb_opportunity.py`, under the Frappe document lifecycle. The enclosing domain module is `sbcrm/sb_crm/doctype/__init__.py`.

#### Desk Client Behavior

Opportunity form interactions and browser-side Desk customization are implemented in `sbcrm/sb_crm/doctype/sb_opportunity/sb_opportunity.js`. This code operates against Frappe’s client APIs and the DocType schema, rather than being an independent web frontend.

Primary flow: a Desk user opens or edits an SB Opportunity; Frappe loads the JSON DocType metadata and document data; the JS form script handles client interactions; save/submit actions invoke Frappe’s server-side document processing.

#### Persistence and Customization Delivery

Frappe persists DocType records and metadata in its site database; this repository supplies declarative changes rather than a standalone database layer. Exported customization fixtures are delivered via `sbcrm/fixtures/custom_field.json` and `sbcrm/fixtures/property_setter.json`, allowing installation or migration to apply field and property changes to the host site.

#### Web and Template Boundary

The app reserves Frappe public and page-template extension points in `sbcrm/public/.gitkeep` and `sbcrm/templates/pages/__init__.py`. No separate HTTP service, SPA, or external-service integration is represented in the repository tree; web delivery remains mediated by Frappe.

#### Infrastructure Dependencies

The material infrastructure dependency is a Frappe Bench deployment and its configured site/database. Installation is performed through Bench, while Frappe supplies routing, authentication, Desk UI, ORM/document persistence, migrations, and client/server RPC. No external APIs, queues, or cloud services are indicated.

Main entry points: [`sbcrm/sb_crm/doctype/sb_opportunity/sb_opportunity.json`](https://github.com/q10developer/sbcrm/blob/develop/sbcrm/sb_crm/doctype/sb_opportunity/sb_opportunity.json) (SB Opportunity schema), [`sbcrm/sb_crm/doctype/__init__.py`](https://github.com/q10developer/sbcrm/blob/develop/sbcrm/sb_crm/doctype/__init__.py) (DocType module), [`sbcrm/sb_crm/doctype/sb_opportunity/sb_opportunity.py`](https://github.com/q10developer/sbcrm/blob/develop/sbcrm/sb_crm/doctype/sb_opportunity/sb_opportunity.py) (Opportunity document logic), [`sbcrm/__init__.py`](https://github.com/q10developer/sbcrm/blob/develop/sbcrm/__init__.py) (App package)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["SB CRM App"]
  node_app_package["App package<br/>package discovery<br/>[__init__.py]"]
  node_modules["Module definitions<br/>module registry<br/>[modules.txt]"]
  node_hooks["App hooks<br/>framework integration<br/>[hooks.py]"]
  node_patches["Patch registry<br/>migration registry<br/>[patches.txt]"]
  node_doctype_module["DocType module<br/>domain package<br/>[__init__.py]"]
  node_opportunity_schema["SB Opportunity schema<br/>DocType metadata"]
  node_opportunity_server["Opportunity document logic<br/>Python lifecycle<br/>[sb_opportunity.py]"]
  node_opportunity_client["Opportunity Desk script<br/>Frappe client JS<br/>[sb_opportunity.js]"]
  node_fixtures["Customization fixtures<br/>declarative customization<br/>[custom_field.json]"]
  node_property_fixtures["Property fixtures<br/>declarative customization"]
  node_web_extensions["Web extension points<br/>public and templates<br/>[.gitkeep]"]
  node_page_templates["Page template package<br/>[__init__.py]"]
end

subgraph group_frappe["Frappe Host Site"]
  node_bench{{"Bench deployment<br/>runtime"}}
  node_frappe_site{{"Frappe site runtime<br/>framework runtime"}}
  node_site_db[("Site database<br/>persistence")]
end

node_bench -->|"hosts"| node_frappe_site
node_bench -->|"installs"| node_app_package
node_app_package -->|"discovers"| node_modules
node_frappe_site -->|"loads"| node_hooks
node_frappe_site -->|"runs registered patches"| node_patches
node_modules -->|"exposes"| node_doctype_module
node_doctype_module -->|"contains"| node_opportunity_schema
node_doctype_module -->|"contains"| node_opportunity_server
node_frappe_site -->|"loads metadata"| node_opportunity_schema
node_opportunity_schema -->|"drives form UI"| node_opportunity_client
node_opportunity_client -->|"saves via RPC"| node_frappe_site
node_frappe_site -->|"invokes lifecycle"| node_opportunity_server
node_opportunity_server -->|"persists documents"| node_site_db
node_opportunity_schema -->|"stored as metadata"| node_site_db
node_frappe_site -->|"applies on install or migration"| node_fixtures
node_frappe_site -->|"applies on install or migration"| node_property_fixtures
node_frappe_site -.->|"serves extension point"| node_web_extensions
node_web_extensions -.->|"supports templates"| node_page_templates

click node_app_package "https://github.com/q10developer/sbcrm/blob/develop/sbcrm/__init__.py"
click node_modules "https://github.com/q10developer/sbcrm/blob/develop/sbcrm/modules.txt"
click node_hooks "https://github.com/q10developer/sbcrm/blob/develop/sbcrm/hooks.py"
click node_patches "https://github.com/q10developer/sbcrm/blob/develop/sbcrm/patches.txt"
click node_doctype_module "https://github.com/q10developer/sbcrm/blob/develop/sbcrm/sb_crm/doctype/__init__.py"
click node_opportunity_schema "https://github.com/q10developer/sbcrm/blob/develop/sbcrm/sb_crm/doctype/sb_opportunity/sb_opportunity.json"
click node_opportunity_server "https://github.com/q10developer/sbcrm/blob/develop/sbcrm/sb_crm/doctype/sb_opportunity/sb_opportunity.py"
click node_opportunity_client "https://github.com/q10developer/sbcrm/blob/develop/sbcrm/sb_crm/doctype/sb_opportunity/sb_opportunity.js"
click node_fixtures "https://github.com/q10developer/sbcrm/blob/develop/sbcrm/fixtures/custom_field.json"
click node_property_fixtures "https://github.com/q10developer/sbcrm/blob/develop/sbcrm/fixtures/property_setter.json"
click node_web_extensions "https://github.com/q10developer/sbcrm/blob/develop/sbcrm/public/.gitkeep"
click node_page_templates "https://github.com/q10developer/sbcrm/blob/develop/sbcrm/templates/pages/__init__.py"

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_app_package,node_modules,node_hooks,node_patches,node_doctype_module,node_opportunity_schema,node_opportunity_server,node_opportunity_client,node_fixtures,node_property_fixtures,node_web_extensions,node_page_templates toneBlue
class node_bench,node_frappe_site,node_site_db toneAmber
```

## Components

### SB CRM App

- [App package](https://github.com/q10developer/sbcrm/blob/develop/sbcrm/__init__.py): package discovery · `sbcrm/__init__.py`
- [Module definitions](https://github.com/q10developer/sbcrm/blob/develop/sbcrm/modules.txt): module registry · `sbcrm/modules.txt`
- [App hooks](https://github.com/q10developer/sbcrm/blob/develop/sbcrm/hooks.py): framework integration · Lifecycle and integration boundary with Frappe. · `sbcrm/hooks.py`
- [Patch registry](https://github.com/q10developer/sbcrm/blob/develop/sbcrm/patches.txt): migration registry · Registers versioned database changes. · `sbcrm/patches.txt`
- [DocType module](https://github.com/q10developer/sbcrm/blob/develop/sbcrm/sb_crm/doctype/__init__.py): domain package · `sbcrm/sb_crm/doctype/__init__.py`
- [SB Opportunity schema](https://github.com/q10developer/sbcrm/blob/develop/sbcrm/sb_crm/doctype/sb_opportunity/sb_opportunity.json): DocType metadata · Defines fields, permissions, and Desk metadata. · `sbcrm/sb_crm/doctype/sb_opportunity/sb_opportunity.json`
- [Opportunity document logic](https://github.com/q10developer/sbcrm/blob/develop/sbcrm/sb_crm/doctype/sb_opportunity/sb_opportunity.py): Python lifecycle · Server-side behavior under Frappe document processing. · `sbcrm/sb_crm/doctype/sb_opportunity/sb_opportunity.py`
- [Opportunity Desk script](https://github.com/q10developer/sbcrm/blob/develop/sbcrm/sb_crm/doctype/sb_opportunity/sb_opportunity.js): Frappe client JS · Handles form interactions using Frappe client APIs. · `sbcrm/sb_crm/doctype/sb_opportunity/sb_opportunity.js`
- [Customization fixtures](https://github.com/q10developer/sbcrm/blob/develop/sbcrm/fixtures/custom_field.json): declarative customization · Applies exported field and property changes during installation or migration. · `sbcrm/fixtures/custom_field.json`
- [Property fixtures](https://github.com/q10developer/sbcrm/blob/develop/sbcrm/fixtures/property_setter.json): declarative customization · `sbcrm/fixtures/property_setter.json`
- [Web extension points](https://github.com/q10developer/sbcrm/blob/develop/sbcrm/public/.gitkeep): public and templates · Reserved Frappe public and page-template extension points. · `sbcrm/public/.gitkeep`
- [Page template package](https://github.com/q10developer/sbcrm/blob/develop/sbcrm/templates/pages/__init__.py): template package · `sbcrm/templates/pages/__init__.py`

### Frappe Host Site

- **Bench deployment**: runtime · Installs SB CRM into a configured Frappe site.
- **Frappe site runtime**: framework runtime · Provides Desk, RPC, document lifecycle, migrations, and ORM.
- **Site database**: persistence · Stores DocType metadata and SB Opportunity records.

## Connections

- Bench deployment → Frappe site runtime: hosts
- Bench deployment → App package: installs
- App package → Module definitions: discovers
- Frappe site runtime → App hooks: loads
- Frappe site runtime → Patch registry: runs registered patches
- Module definitions → DocType module: exposes
- DocType module → SB Opportunity schema: contains
- DocType module → Opportunity document logic: contains
- Frappe site runtime → SB Opportunity schema: loads metadata
- SB Opportunity schema → Opportunity Desk script: drives form UI
- Opportunity Desk script → Frappe site runtime: saves via RPC
- Frappe site runtime → Opportunity document logic: invokes lifecycle
- Opportunity document logic → Site database: persists documents
- SB Opportunity schema → Site database: stored as metadata
- Frappe site runtime → Customization fixtures: applies on install or migration
- Frappe site runtime → Property fixtures: applies on install or migration
- Frappe site runtime → Web extension points: serves extension point
- Web extension points → Page template package: supports templates
