Modules · For developers

Your own module in a few steps

Assessments and Expenses are modules themselves: plugins that bring pages, endpoints, tables and texts without the core changing. Yours is built the same way – also in a separate, private repository.

How a module comes together

A plugin is a folder under plugins/<id>. The core finds it when it builds and when it starts. A small, complete example is open in the repository: plugins/notes, personal notes.

  1. 1

    Folder and manifest

    The manifest in package.json describes the module: its id, the plugin API version, its permissions and the module an organization switches on or off.

    plugins/demo/package.json
    {
      "name": "@acme/demo",
      "apensum": {
        "id": "demo",
        "apensumApi": 2,
        "dbSchema": "demo",
        "permissions": [
          { "id": "nav.demo", "kind": "nav",
            "scopes": ["own", "all"], "caption": "nav.demo" }
        ],
        "module": { "id": "demo", "caption": "modules.demo",
                    "defaultEnabled": false, "objects": ["nav.demo"] },
        "api": "dist/api/index.js",
        "web": "web/index.tsx"
      }
    }
  2. 2

    Endpoints (API)

    NestJS controllers and services, declared with defineApiPlugin. Every request checks permissions with the same building blocks as the core.

    // plugins/demo/api/index.ts
    import { defineApiPlugin } from '@worktime3/api/plugin';
    import { DemoController } from './demo.controller';
    
    export default defineApiPlugin({
      id: 'demo',
      controllers: [DemoController],
    });
  3. 3

    User interface

    Pages, navigation, settings and texts in four languages, declared with defineWebPlugin. The module uses the core’s components, so it looks like the rest of the app.

    // plugins/demo/web/index.tsx
    import { defineWebPlugin, FolderSharedIcon } from '@worktime3/web/plugin';
    
    export default defineWebPlugin({
      id: 'demo',
      texts: DEMO_TEXTS, // en, de, fr, it
      pages: [{
        section: 'demo', hash: '#/demo', object: 'nav.demo',
        nav: { group: 'myWork', label: 'nav.demo', icon: <FolderSharedIcon /> },
        render: (ctx) => <DemoPage orgId={ctx.orgId} authHeaders={ctx.authHeaders} />,
      }],
    });
  4. 4

    Database

    Its own tables, in a Postgres schema of its own if you like, with its own Liquibase changelog. It runs after the core’s; the table definitions for the code are generated from it.

    plugins/demo/changelog/db.changelog-master.xml
    plugins/demo/changelog/001-demo-schema.sql
    
    npm run dev:migrate      # the core's changelog, then every plugin's
    npm run dev:introspect   # writes plugins/demo/api/db/schema.ts
  5. 5

    Run and test

    Clone the plugin repository into plugins/<id>, build, start: the core loads it, and npm test runs its tests too.

    git clone <your repository> plugins/demo
    npm run build --workspace=@worktime3/api
    npm run dev:api          # log: "Loaded plugins: ..., demo"
    npm run dev:web
    npm test                 # the core's tests, then the plugin's
  6. 6

    Ship

    If the plugin is in plugins/<id> when the app is built, it is part of the app’s images. Without it the core keeps working as before – CI checks that on every change.

    plugins/demo/   -> built into the API and web images
                       the core keeps working without it

What a module can add

The core offers fixed extension points. A module declares what it brings; navigation, permissions and reporting pick it up.

Pages and navigation

Its own pages with menu entries and counters, quick actions on the home page and sections in the organization settings.

Tables, permissions, demo data

Its own tables and migrations, its own permissions with default grants per role, and its own demo data.

Approvals

Its own approvals in the workflow, sent to the person’s manager if you like – even when the manager changes.

Reports and team views

Its own reports with grouping, Excel, PDF and scheduled delivery, and its own tables in the Team tab for managers and HR.

Documents and payroll

Files on the person’s Documents page and amounts in the payroll export.

AI with a cost cap

AI calls through the core’s budget: Azure in Switzerland, with a monthly limit per organization and for the whole instance.

Ground rules

Cleanly separated

So that the core and modules can evolve independently, a few rules apply. The core checks names and version when it starts.

  • A module reaches the core only through the plugin API.
  • No dependencies of its own: React, NestJS and the rest come from the core, exactly once.
  • Every name – tables, permissions, pages – starts with the module’s id.
  • The manifest states the plugin API version; if it does not match, the module does not start.
  • The core always runs without modules too.

Try Apensum yourself

The demo runs with the sample data of a fictitious company. Pick a demo account on the login page and click through – no registration needed.