Server architecture

Server architecture

MVC Controllers represent a front-end interface for the server part of DWKit. We've already mentioned them earlier.

  • UserInterfaceController - getting of a form via the GetForm method.
  • DataController - getting data via the GetData method, changing data via the ChangeData method, deleting data via the DeleteData method.
  • WorkflowController - getting a list of commands and states via the GetData method, execution of commands via the ExecuteCommand method, setting states via the SetState method.
  • ConfigAPIController - a controller, via which the Admin application saves and loads the metadata.

On the server side, you will mainly interact with two subsystems: a static class DWKitRuntime and a subsystem ORM. We will take a closer look at how ORM operates in DWKit in the next section. DWKitRuntime is the key point of configuration and locator of the system services of DWKit, such as:

  • MetadataProvider - inherits the IMetadataProvider interface, enables to save metadata and provide them to the application. In DWKit, the metadata are stored in the following places:
  • metadata.json file - a serialized Data model, Server user-defined functions, Business flow (coming soon) are stored here.
  • Descriptions of forms are stored in the Forms subfolder. Each form can contain 1-3 files. FormName.json - a serialized form layout, i.e. settings of all its controls and their position. FormName-settings.json - workflow settings and binding of the data model to form controls. FormName-code.json - code of client user actions
  • The metadata related to Security are stored in the database in dwSecurity* tables.

Any component of DWKit that needs system metadata requests them from this service.

  • ApplicationSettings - enables access to connection strings, cache settings, license key, etc. It is not a separate service; all these settings can be adjusted via the Dashboard page in the Admin application.
  • WorkflowRuntime - the main Workflow Engine object that manages processes. Learn more about Workflow Engine's architecture.
  • ServerActionsProvider - enables access to server user actions, such as server filters or triggers, before and after changing your data. You can write the code of these actions in the Admin application or in your projects, inheriting the IServerActionsProvider interface and registering your provider in the main ServerActionsProvider.
  • DbProvider - enables physical communication with the database, processes all database queries except for those coming from WorkflowRuntime, which uses its own providers. The distribution includes providers for MSSql Server and Postgre Sql.
  • SecurityProvider is responsible for getting information about authorized users and checking their permissions.

There are several system tables in the database:

  • dwSecurity... tables - store the description of the security system. For more details, refer to the corresponding section.
  • Workflow... tables - correspond to Workflow Engine. Have a look at their description.

The DWKitRuntime object should be configured. It has already been done in the OptimaJet.DWKit.Application project, the Configurator class. Let's consider the key points.

  public static class Configurator
    {
        public static void Configure(IHttpContextAccessor httpContextAccessor,IConfigurationRoot configuration, string connectionstringName = "default")
        {
            #region License
            var licensefile = "license.key";
            if (File.Exists(licensefile))
            {
                try
                {
                    var licenseText = File.ReadAllText(licensefile);
                    DWKitRuntime.RegisterLicense(licenseText);
                }
                catch (Exception ex)
                {
                    //TODO add write to log
                }
            }
            #endregion

#if (DEBUG)
            DWKitRuntime.UseMetadataCache = false;
            DWKitRuntime.UseExecutorCache = false;
#elif (RELEASE)
            DWKitRuntime.UseMetadataCache = true;
            DWKitRuntime.UseExecutorCache = true;
#endif

            DWKitRuntime.ConnectionStringData = configuration[$"ConnectionStrings:{connectionstringName}"];
            DWKitRuntime.DbProvider = AutoDetectProvider();
            DWKitRuntime.Security = new SecurityProvider(httpContextAccessor);
            DWKitRuntime.Metadata = new DefaultMetadataProvider("Metadata/metadata.json", "Metadata/Forms");

            CodeActionsCompiller.RegisterAssembly(typeof(WorkflowRuntime).Assembly);
            CodeActionsCompiller.DebugMode = true;
            DWKitRuntime.CompileAllCodeActionsAsync().Wait();
            DWKitRuntime.ServerActions.RegisterUsersProvider("filters", new Filters());
            DWKitRuntime.ServerActions.RegisterUsersProvider("triggers", new Triggers());
            var runtime = WorkflowInit.Runtime;
        }

        public static IDbProvider AutoDetectProvider()
        {
          ...
          //Provider auto detection
          ...
        }
    }
}
  • DWKitRuntime.RegisterLicense(licenseText); registers a license key read from the file.
  • turns on/off metadata caching, depending on build configuration. Given that the conversion from Data model or form binding into metadata format used by the ORM is a frequent and time-consuming procedure, it is reasonable to turn caching on in the RELEASE configuration to speed up operation of the application.
#if (DEBUG)
            DWKitRuntime.UseMetadataCache = false;
            DWKitRuntime.UseExecutorCache = false;
#elif (RELEASE)
            DWKitRuntime.UseMetadataCache = true;
            DWKitRuntime.UseExecutorCache = true;
#endif
  • DWKitRuntime.ConnectionStringData = configuration[$"ConnectionStrings:{connectionstringName}"] - installation of a connection string from the configuration file.
  • DWKitRuntime.DbProvider = AutoDetectProvider(); - automatic creation of the DbProvider by the connection string.
  • DWKitRuntime.Security = new SecurityProvider(httpContextAccessor); - creation of the SecurityProvider with access to the HttpContext
  • DWKitRuntime.Metadata = new DefaultMetadataProvider("Metadata/metadata.json", "Metadata/Forms") - creation of the MetadataProvider with the specified pathnames that lead to metadata.json and form metadata.
  • registration of server user actions and compilation of those created in the Admin application.
CodeActionsCompiller.RegisterAssembly(typeof(WorkflowRuntime).Assembly);
CodeActionsCompiller.DebugMode = true;
DWKitRuntime.CompileAllCodeActionsAsync().Wait();
DWKitRuntime.ServerActions.RegisterUsersProvider("filters", new Filters());
DWKitRuntime.ServerActions.RegisterUsersProvider("triggers", new Triggers());