Enhancing Data Modeling in Archi: Leveraging jArchi Scripts

โฑ 5 min read

Introduction: extending Archi with scripting

Archi's visual interface is excellent for interactive modeling, but enterprise architecture practices require more than manual point-and-click: bulk imports from CMDBs and spreadsheets, automated validation of naming conventions and property completeness, report generation for governance boards, and model cleanup operations that would take hours to perform manually. Sparx EA guide

JArchi โ€” Archi's JavaScript scripting plugin โ€” brings automation to ArchiMate modeling. This article covers the practical aspects of jArchi scripting: the execution model, script categories, working examples for common enterprise scenarios, integration with external data sources, and best practices for maintaining a script library. ArchiMate relationship types

For a deeper dive into advanced patterns, limitations, and governance workflows, see our companion article: Automating ArchiMate Modeling in Archi with jArchi Scripts.

How jArchi works: the execution model

Figure 1: jArchi execution model โ€” from script file through engine to model and output
Figure 1: jArchi execution model โ€” from script file through engine to model and output

JArchi scripts are plain JavaScript files with the .ajs extension. When you run a script, the jArchi engine (based on GraalVM JavaScript) executes it within Archi's process, giving the script full read-write access to the currently open model. Scripts can also write to the filesystem โ€” enabling CSV, JSON, and HTML report generation.

The key API entry point is the $() function, which queries the model using CSS-like selectors: $("application-component") returns all Application Components, $("relationship") returns all relationships, and $("view") returns all views.

Script categories and use cases

Figure 2: Four categories of jArchi scripts โ€” import, cleanup, validation, and reporting
Figure 2: Four categories of jArchi scripts โ€” import, cleanup, validation, and reporting

Category 1: Data import โ€” populating models from external sources

The most immediately valuable jArchi use case: importing application inventories, technology catalogs, or business capability lists from spreadsheets or CMDB exports. ArchiMate capability map example

// Import Application Components from CSV
var JavaFile = Java.type("java.io.BufferedReader");
var FileReader = Java.type("java.io.FileReader");
var reader = new JavaFile(new FileReader("/tmp/app_inventory.csv"));
var header = reader.readLine(); // skip header
var line;
var count = 0;

while ((line = reader.readLine()) !== null) {
    var cols = line.split(",");
    var name = cols[0].replace(/"/g, "").trim();
    var owner = cols[1] ? cols[1].replace(/"/g, "").trim() : "";
    
    // Avoid duplicates
    var existing = $("application-component").filter(function(e) {
        return e.name === name;
    }).first();
    
    if (!existing) {
        var elem = model.createElement("application-component", name);
        elem.prop("Owner", owner);
        count++;
    }
}
reader.close();
console.log("Imported " + count + " new Application Components.");

Category 2: Model cleanup โ€” removing technical debt

// Find and report orphan elements (not on any view)
var orphans = [];
$("element").forEach(function(e) {
    var refs = $("view").filter(function(v) {
        return $(v).find("#" + e.id).size() > 0;
    });
    if (refs.size() === 0) {
        orphans.push(e.type + ": " + e.name);
    }
});
console.log("Orphan elements: " + orphans.length);
orphans.forEach(function(o) { console.log("  " + o); });

Category 3: Validation โ€” enforcing modeling standards

// Validate that all Application Components have Owner and Lifecycle tags
var errors = 0;
$("application-component").forEach(function(e) {
    if (!e.prop("Owner") || e.prop("Owner").trim() === "") {
        console.log("MISSING OWNER: " + e.name); errors++;
    }
    if (!e.prop("Lifecycle Status")) {
        console.log("MISSING LIFECYCLE: " + e.name); errors++;
    }
});
console.log("Total validation errors: " + errors);

Category 4: Reporting โ€” generating stakeholder-ready output

// Export application catalog to CSV
var JavaFileWriter = Java.type("java.io.FileWriter");
var file = new JavaFileWriter("/tmp/app_catalog.csv");
file.write("Name,Type,Owner,Lifecycle,Documentation\n");

$("application-component").forEach(function(e) {
    var row = [
        '"' + (e.name || "") + '"',
        e.type,
        '"' + (e.prop("Owner") || "") + '"',
        '"' + (e.prop("Lifecycle Status") || "") + '"',
        '"' + (e.documentation || "").substring(0, 200).replace(/"/g, '""') + '"'
    ].join(",");
    file.write(row + "\n");
});
file.close();
console.log("Exported application catalog.");

Best practices for jArchi scripting

Always test on a copy. jArchi has no undo. Back up your .archimate file before running any script that modifies the model.

Use version control. Store scripts in Git alongside the model (via coArchi). This ensures all team members use the same validation rules and export formats.

Organize scripts by purpose. Use folders: validation/, import/, cleanup/, reporting/, utilities/.

Use descriptive property names. Avoid generic names like tag1 or custom. Use Owner, Lifecycle Status, Cost Center โ€” names that are meaningful in reports.

Add comments. Every script should start with a comment block explaining what it does, when to run it, and what prerequisites are needed.

Conclusion

JArchi transforms Archi from a drawing tool into a programmable architecture workbench. Start with one or two scripts that solve immediate pain points โ€” an import script that saves hours of manual entry, or a validation script that catches naming violations before they spread. Once the team sees the value, expand to reporting and cleanup scripts. The investment in scripting pays compound returns as the model grows.

If you'd like hands-on training tailored to your team (Sparx Enterprise Architect, ArchiMate, TOGAF, BPMN, SysML, or the Archi tool), you can reach us via our contact page.

Frequently Asked Questions

What is enterprise architecture?

Enterprise architecture is a discipline that aligns an organisation's strategy, business operations, information systems, and technology infrastructure. It provides a structured framework for understanding how an enterprise works today, where it needs to go, and how to manage the transition.

How is ArchiMate used in enterprise architecture practice?

ArchiMate is used as the standard modeling language in enterprise architecture practice. It enables architects to create consistent, layered models covering business capabilities, application services, data flows, and technology infrastructure โ€” all traceable from strategic goals to implementation.

What tools are used for enterprise architecture modeling?

Common enterprise architecture modeling tools include Sparx Enterprise Architect (Sparx EA), Archi, BiZZdesign Enterprise Studio, LeanIX, and Orbus iServer. Sparx EA is widely used for its ArchiMate, UML, BPMN and SysML support combined with powerful automation and scripting capabilities.