# Vitruvio Development Guidelines ## What is Vitruvio Vitruvio is a Java 21 / Spring / Vaadin 7 multi-tenant BPM platform. Developers extend it by creating **content repositories** — git repos that contain panels, processes, scripts, queries, reports, endpoints, and more. Vitruvio reads these repos and renders their content at runtime. This file is one such repository. Every repository must have a `vitruvio.json` manifest at its root that declares all artifacts. That manifest is the source of truth for what the platform will register. --- ## Repository Structure Artifacts live under their own top-level directories, matching the paths declared in `vitruvio.json`: ``` vitruvio.json panels/ / -desktop.xml -mobile.xml # optional default-state.json thumbnail.png processes/ / .bpmn -desktop.xml -mobile.xml # optional scripts/ .js .md # optional documentation endpoints/ .js queries/ .sql reports/ / template.jrxml params.xml libraries/ / patches/ ``` All `key` values in `vitruvio.json` must be **kebab-case**, unique within their artifact type, and stable — changing a key is a breaking change. --- ## vitruvio.json Manifest `version` and `metadata.key` are the only required fields. All other sections are optional arrays. ### metadata ```json { "name": "Human-readable module name", "key": "module-key", // kebab-case, unique across tenants "standardProduct": false // true only for widespread modules } ``` ### Artifact sections Each section is an array. Omit the section entirely if there are no items — don't leave empty arrays unless needed. Key rules per artifact: - **panels** — UI screens built from XML forms. `forms.desktop` is the primary form path; mobile is optional. - **processes** — BPMN workflows. Can declare `schedules` (cron or simple interval triggers). Are composed from a BPMN file for Activiti, a xml file for the web form and one or two xml files for the mobile forms. - **scripts** — Reusable JS logic. `domain` is either `"SISTEMA"` (system-level) or `"USUARIO"` (user-level). Will generally be USUARIO. For non-trivial logic, see Unit Testing below. - **endpoints** — REST endpoints. `authMode` is one of `"PUBLIC"`, `"STATIC_TOKEN"`, `"VITRUVIO_WS_USER_AUTH"`, or `"HTTP_BASIC_AUTH"`. Default to `"PUBLIC"`. `active: true` to enable. For non-trivial logic, see Unit Testing below. - **queries** — Named SQL queries. `connection` references a configured datasource. Use `"vitruvio_producao"` for the default datasource. - **reports** — Jasper reports. Require a query key, a `.jrxml` template, and optionally a parameter form. - **libraries** — Static file bundles (JS/CSS/images). `type: "LOCAL"` for files in this repo. - **groups** — User groups this module manages or depends on. - **properties** — User-configurable key/value settings. - **menu** — Navigation tree. See the Menu section below for structure and type values. - **permissions** — Process-level access control per group. Mostly unused, generally defined in the bpmn file for the process. - **patches** — Path to a directory containing per-database Liquibase changelogs. Has `oracle/` and `postgresql/` subdirectories, each with its own XML changelog file. --- ## XML Forms (Panels & Processes) Forms are XML files validated against Vitruvio's XSD schema. Vaadin components are declared in XML and rendered by the platform's Java presenter layer — there is no manual Java UI code in content repos (except if imported in scripts using the Rhino engine). **Form files are named `-desktop.xml` / `-mobile.xml` and the BPMN `.bpmn`** (artifact key + suffix), so each form is searchable by its key rather than dozens of identical `form-desktop.xml` tabs. **Desktop vs mobile forms are different schemas.** Desktop (`-desktop.xml`) uses the `` / `` schemas, the 78-component desktop set, and Rhino ES5 scripts with auto-injected process variables. Mobile (`-mobile.xml`) uses the `` schema (namespace `.../vitruvio/mobile-form`), only the 18 mobile components, **modern React-Native JS on the client** (Promises) with **server-side `` blocks in Rhino ES5** for any lib/DB/service access, and **explicitly declared data** (`` variables, ``, bridges via `vCommunicationService.executeOnServer`). Use the focused skills — `vitruvio-criar-processo-bpmn`, `vitruvio-criar-form-desktop`, `vitruvio-criar-form-mobile` (driven by the `vitruvio-criar-painel` / `vitruvio-criar-processo` orchestrators) — and read `docs/components/mobile/` before building a mobile form. General rules: - **Always save form/XML files as UTF-8 *without* a BOM.** A leading byte-order mark (`EF BB BF`) — or any whitespace/content before the `` blocks with `` for inline JavaScript on components (button actions, lifecycle hooks, field validators). For non-trivial logic, delegate to a named script file rather than writing large CDATA blocks inline or repetitive code and import it using `libService.loadScript("lib_name")`. - `displayOrder` on panels controls the order they appear in listings. Use gaps (10, 20, 30…) to allow future insertions without reshuffling. --- ## JavaScript — ES5 / Rhino Engine All JavaScript in this platform runs on **Mozilla Rhino**, an ES5 interpreter embedded in the JVM. Modern JS features are not available. ### What you CANNOT use ```javascript // NO — ES6+ is not supported const x = 1; let y = 2; const fn = () => {}; `template ${literal}`; const { a, b } = obj; const [first, ...rest] = arr; class Foo {} async function bar() {} await something(); import x from 'y'; export default x; for (const item of iterable) {} Promise.resolve(); Array.from(x); Object.assign({}, a, b); ``` ### What you MUST use instead ```javascript // YES — ES5 style var x = 1; var y = 2; var fn = function() {}; "template " + variable; var a = obj.a; var b = obj.b; // loop with index for (var i = 0; i < arr.length; i++) {} // prototype-based, not class function Foo() {} Foo.prototype.bar = function() {}; // callbacks, not async/await doSomething(function(result) { ... }); ``` ### Additional Rhino caveats - `JSON.parse` and `JSON.stringify` are available. - `typeof`, `instanceof`, standard `Array`/`Object`/`String` methods from ES5 work fine. - No browser globals (`window`, `document`, `fetch`, `XMLHttpRequest`). - No Node.js globals (`require`, `process`, `Buffer`, `__dirname`). - Rhino exposes Java interop — avoid it in business scripts unless you know what you're doing. - Always declare variables with `var`. Undeclared variables become globals and cause hard-to-trace bugs. - When comparing values that originate from Java (DB query results, form field values, process variables), use `==` / `!=` — Java types do not strict-equal JavaScript primitives. Use `===` / `!==` only when you control both sides and know they are pure JS values. - `Array.prototype` iteration methods `forEach`, `map`, `filter`, `reduce`, `some`, `every` are available — they are ES5 and work fine in Rhino. --- ## Unit Testing Tests run under **Jest on Node**, not Rhino — this is the one place in the repo where modern JS (`const`, arrow functions, destructuring) is fine, because `*.test.js` files never execute on the platform. The production code they test still must be ES5/Rhino-safe. **Scope: `scripts/*.js` and `endpoints/*.js` only.** Inline `