# Frappe Architecture A map of the whole stack — server → bench → sites → apps — and exactly where everything built in this project actually lives. Use this to explain the hierarchy, and to reason correctly about what a new site would and wouldn't inherit. --- ## 1. The hierarchy, top to bottom One **bench** is one running Frappe process group — the workers, scheduler, and shared app code all live here. It can host **many sites**, each a fully separate tenant with its own database. **Apps** are installed once per bench (shared code), but each site decides which of those installed apps it actually uses. ```mermaid graph TD Server["Server / VPS"] --> Bench subgraph Bench["ONE BENCH — shared process group"] direction LR AppsDir["apps/ — shared CODE
installed once per bench"] SitesDir["sites/ — one folder per tenant"] end AppsDir --> Frappe["frappe
(the framework itself)"] AppsDir --> ERPNext["erpnext
(built on Frappe)"] AppsDir --> CustomApp["your_custom_app
(optional — not used in this project)"] SitesDir --> Common["common_site_config.json
bench-wide settings"] SitesDir --> SiteA["sightbox.localhost/
its own database"] SitesDir --> SiteB["client2.localhost/
(hypothetical) its own database"] ``` Confirmed against this actual deployment: `common_site_config.json` holds exactly one thing we set — `server_script_enabled: true` — while `sites/sightbox.localhost/site_config.json` holds everything specific to this one tenant: DB credentials, `installed_apps: [frappe, erpnext]`, `pause_scheduler`. --- ## 2. What "app" actually means here Frappe isn't a platform that ERPNext plugs into from outside — **Frappe itself is architected as an app**. It's the base layer: the DocType engine, the Desk UI, the permission system, the REST API, the Workflow engine, the Server/Client Script sandbox. **ERPNext is a second app, built entirely using Frappe's own tools** — Stock Entry, Serial No, Item, Warehouse are just DocTypes ERPNext defines, exactly the same mechanism available to any other app. A **custom app** (this project explicitly chose not to build one — see `CLAUDE.md`) would be a third app installed the same way, adding its own DocTypes/code on top of both. Nothing architecturally distinguishes "ERPNext" from "a custom app" — one just happens to be the one Frappe's own team publishes. | Layer | Provides | Installed | |---|---|---| | **frappe** | DocType engine, Desk UI, auth, permissions, REST API, Workflow engine, Server/Client Script sandbox, email | Always — every bench has it | | **erpnext** | Business DocTypes built on Frappe: Stock, Item, Warehouse, Serial No, Sales, Accounts, etc. | Per-site opt-in (`bench install-app erpnext`) | | **a custom app** | Whatever you build — new DocTypes, custom routes, background jobs | Per-site opt-in, same mechanism | --- ## 3. Where everything we built actually sits Every modification this project made — Custom Fields, Client Scripts, Server Scripts, Workflow, Role Permission grants, Notifications, the Tool Kit DocType, the QR integration, Warehouses/Items/Company data — was made through the Desk UI or `bench console`, never by editing app source files. That means all of it landed in exactly one place: **this site's own database.** ``` ┌───────────────────────────────────────────────────────────┐ │ sightbox.localhost's DATABASE — site data │ │ Custom Fields, Client/Server Scripts, Workflow, Custom │ │ DocPerm, Notifications, Tool Kit DocType (module: Custom), │ │ Warehouses, Items, Company, System Settings │ ├───────────────────────────────────────────────────────────┤ │ erpnext — shared app code (bench-wide) │ │ Stock module, Serial No, Item, Warehouse, Material Request │ ├───────────────────────────────────────────────────────────┤ │ frappe — shared framework code (bench-wide) │ │ DocType engine, Desk UI, REST API, Script sandbox, Workflow│ └───────────────────────────────────────────────────────────┘ ``` Everything in the top band is unique to this one site. Everything below it is shared, unmodified, bench-wide code. | If you built... | It lives in... | New site, same bench, gets it? | |---|---|---| | Custom Field / Property Setter | Site database | **No** | | Client Script / Server Script | Site database | **No** | | Workflow / Workflow State & Action | Site database | **No** | | Role Permission Manager grant | Site database (Custom DocPerm) | **No** | | A new DocType via Desk UI (`module: Custom`) | Site database | **No** | | Notification | Site database | **No** | | Warehouses, Items, Company, Users | Site database | **No** | | `server_script_enabled` | `common_site_config.json` (bench-wide) | **Yes** | | ERPNext's own out-of-box features | erpnext app code (bench-wide) | **Yes**, if erpnext is installed there too | | A real custom Frappe app you build and install | Bench-wide code, but must be explicitly installed per site | Only if you also run `install-app` on it | --- ## 4. How one bench serves many domains Every site on a bench shares the same running process and the exact same app code. What separates them at request time is nothing more than the HTTP **Host header** — Frappe matches it against a folder name under `sites/` and connects to that site's database for the duration of the request. ```mermaid graph LR Browser["Browser requests
sightbox.localhost"] --> Router["frontend / nginx
reads Host header"] Browser2["Browser requests
client2.localhost"] --> Router Router -->|"Host: sightbox.localhost"| SiteA["sites/sightbox.localhost/
own database"] Router -->|"Host: client2.localhost"| SiteB["sites/client2.localhost/
own database"] SiteA --> Code["same frappe + erpnext code
(one shared bench)"] SiteB --> Code ``` **What this means for this project:** `CLAUDE.md` and the Installation Playbook deliberately chose **one dedicated docker-compose stack per client** instead of this multi-site-per-bench pattern — each client gets their own bench, own containers, own `backend-billing`. Frappe's multi-site capability shown above is real and works, but nothing in this project currently relies on it — every custom feature would need to be re-provisioned per site exactly as if it were a separate bench. --- See [`playbook.md`](./playbook.md) for every other guide in this project. Written from the actual sightbox.localhost deployment — every config value shown above was read from the live files, not assumed.