App layout
The folders of an app and the keys of its app.exs manifest.
cardinal app new NAME writes the skeleton. The folders below it are read by name, so keep them where the table puts them.
cardinal app new library --with-frontend --requires erp--with-frontend adds a desk plugin in frontend/. CLI commands lists every file it writes. Each --requires APP names an app already in apps/. It goes into the manifest's requires and into mix.exs as a path dependency, so that app compiles first.
Folders
| Path | Holds |
|---|---|
app.exs | The manifest |
mix.exs | The Mix project. It depends on cardinal_core and cardinal_jobs |
lib/<app>.ex | The module that calls use Cardinal.App |
lib/controllers/ | Lifecycle hooks, one module per RecType |
lib/rpc/ | @rpc functions, served at /api/rpc/... |
lib/workers/ | Background job workers |
rectypes/ | One YAML file per RecType |
permissions/ | Rules the app adds to other apps' RecTypes |
fixtures/ | Records the app ships, one file per RecType |
patches/<version>/ | One-off data migrations |
www/, templates/ | Public web pages and Jinja templates |
locale/ | Translation catalogs (.pot, .po) |
frontend/ | The desk plugin and the app's own frontend |
test/ | ExUnit tests |
as_system_allowlist.txt | Reviewed as_system call sites |
use Cardinal.App reads the manifest and every YAML file at compile time and embeds them in the module. A release reads no app files.
defmodule Library do
use Cardinal.App
endThe manifest
app.exs is a keyword list. A misspelt key fails the build.
[
name: :library,
version: "0.1.0",
requires: [cardinal: "~> 0.1"],
modules: ["Library"],
roles: ["Librarian"],
fixtures: []
]| Key | Meaning |
|---|---|
name | The app's name, an atom |
version | A semantic version. Installs record it, and a downgrade is refused |
requires | Cardinal's version range and each app this one needs |
modules | The module names its RecTypes may use |
roles | The roles the app declares |
fixtures | RecTypes whose records the app ships, in install order |
A required app can carry where to fetch it:
requires: [
cardinal: "~> 0.6",
erp: [version: "~> 1.2", git: "https://github.com/acme/erp", tag: "v1.2.0", commit: "3f2a9c1"]
]Optional keys
The common ones are below. Manifest reference lists every key.
| Key | Example from a real app |
|---|---|
scheduler | [{:daily, Crm.Workers.InvitationExpiryWorker}] |
rec_events | [{"Purchase Invoice", GstCompliance.Controllers.PurchaseInvoiceEvents}], hooks on another app's RecType |
apps_screen | [%{name: "crm", title: "CRM", logo: "handshake", route: "/desk/frappe-crm"}] |
sidebars | A module's panel rows, %{link_to: "CRM Lead", label: "Leads"} |
folded_modules | %{"Lead Syncing" => "FCRM"} |
route_rules | [%{from_route: "/crm-form/<route>", to_route: "crm-form"}] |
redirects | [%{source: "/old-hello/(.*)", target: "/hello?n=\\1"}] |
create | Entries in a form's Create menu, each %{from, to, rpc} |
connections | Groups on a record's Connections panel |
global_search | RecType names in search priority order |
pages | [[name: "Gate Board", module: "Gate", roles: ["Gate Manager"]]], desk pages a plugin renders |
widgets | Workspace widgets, each %{name, label, sizes} |
cli | [{"repost-stock", Erp.CLI.RepostStock}], run as cardinal erp:repost-stock |
env | Environment variables the app reads. Install adds missing ones to .env |
frontend | %{mount: "hrms", entry: "app/index.html"}, a single-page app at /hrms/ |
priority | An integer that orders apps no requirement orders, lower first |
Module callbacks
The use Cardinal.App module may also define these functions.
| Function | Runs |
|---|---|
after_install(ctx) | Once, in the install transaction, after the fixtures |
after_migrate(ctx) | On every install and migrate. It must change nothing when there is nothing to do |
boot(ctx) | On every desk boot. Its map reaches the desk under apps.<name> |
setup_wizard(ctx, args) | During the first-run setup, with the wizard's fields and the app's own slides under args["app"]. An app installed after setup is marked complete and never runs it |
Check the build
cardinal app check # requires, versions and cycles; prints the hook order
cardinal meta check # every app's RecType, permission and website filesHooks run in requires order, then by priority, then by app name. That order is the same on every node.