Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

How to structure your Component Translator projects is critical to fast, scalable development. Before taking a look at the details of Lua, it’s good to understand how to organize functions and modules in the Translator.

All you need to use are the Rules of Threes.

Hardly anything is unique. A few things are, but most are not. When you know which parts you’ve seen before, you can spend your time where it will make the most difference.

Any component can be broken down into three parts – know them and cut your workload in half: Each Translator project is made up of different types of files. Knowing how those files relate to each other and using the concept of separation of concerns is key to determining how to structure your projects.

In general, what files make up a Translator project?

...

Interacting with external entities - Your native API or your site-wide EMR.

The thing you always need to talk to
Expand
title1) Systems Main.lua - the base level
heart

Main.lua is called when you start a component. Every other file in your project is called from main.lua. Best practice is to keep this like a table of contents, as small and easy to read as possible.

Functions that do things - Logic, mappings, networking, and rules used in many places. When you see yourself creating rules or logic thats used multiple times - create a library. Copying and pasting is natures way of telling you to create a library
Expand
title2) Processes Local Files and Folders - the middle level
concerns

Local files are used for creating functions that are specific to a single component. They help separate concerns ensuring your project remains easy to read and maintain.

Keep local files small.

Give them descriptive names.

Expand
title3) Configurations - component or environment specific

Every project has a config.json file you can use to create Custom fields. This is where you should store component or environment-specific configurations.

For more details, see Configuration Management.

...

Expand
title34) The Snowflake - the top level

These are the specific mappings and transformations - The “snowflake.” The tiny part of an interface that is like no other. Learn to spot the “snowflake”: this is the reason you’re building a new interface

Using these three levels helps you recognize patterns, recognize uniqueness, and work on what matters.

...

Libraries - shared concerns

Libraries contain common code that can be used by multiple components. A key strategy in creating component templates and speeding up interface development.

In general, if you use a function more than one interface, it belongs in a library.

If you have any libraries added to a project, a .gitmodules file automatically updates to list any referenced libraries.

Expand
title5) Sample Data Folder

The Samples folder holds all of the sample messages you need to use to develop and test your interfaces.