# A Smart Decision System for Digital Farming
## 4 Software Components  
Once the platform architecture and the rules association had been defined, it was required to develop the software part that would implement our web platform. To perform that, this section presents the implementation of server rules in the Drools engine. The server has three main components. The first one is an application that is able to register the external sensor data in the system. A device or application simply registers as a data source by sending information via socket communication to the middleware, which then prepares the data in a specified format, depending on the type of sensor. The system architecture is divided into the following layers:  
1. User interface: enables farmers, providers, and technics to interact with the system and execute computerized workflow activities. To do so, it invokes operations of the interfaces published by the business layer. It is a set of HTML and Php pages hosted on an Apache web server that are displayed in a web browser. 2. Business layer: responsible for making calculations, queries, and invoking the execution of business rules. To do this, it accesses the data layer and the rules services layer. It is a set of PHP pages hosted on an Apache web server. 3. Data layer: in charge of managing the system's database, which contains information about all the data of the process and its stages for each field. It provides interfaces so that the business layer can access it. To implement this layer, the MySQL database management system was used. Figure 4: Diagram of business process management (BMP) process. Service layer of business rules: exposes interfaces through web services to business rules. It is invoked from the business layer and executes the rules contained in the rules layer. It is made up of web services, programmed in Java, which run on a Tomcat web server. 5. Rules layer: makes it possible to manage business rules, for which it provides interfaces to the rules services layer. To implement this layer, a free, open source, java-developed BRMS was used. The BRMS is deployed on a Tomcat web server. Figure 5 shows the architecture of BRMS used by our platform. As we can see, the main component of our BRMS is an Apache web server, which uses the data stored in our database (DB). In order to enhance our server, we used a Tomcat web server. Tomcat is an extension of Apache that works as a container of servlets, and can help us to include new functionalities to our server. Using the servlets, we can extend applications held in web servers to be seen as JAVA Applets. To generate and manage the different rules we need to enhance the system performance, we used Drools, a common tool used for managing business rules that we have adapted to our application. These rules are sent to the Tomcat web server through the API. These rules are sent to the Apache web server, which combines them with the data stored in the DB. Finally, the users can see the results of these decisions by using a web browser and surfing the different options the platform offers. The following section introduces the Drools management based on the Rete pattern-matching algorithm [20]. It provides the basis for a more efficient implementation that can check each rule against facts in a knowledge base, firing the rule if necessary. Figure 6 shows the *.drl file where basic rules for operating with Drools are located. There are several benefits of this algorithm, such as reducing or removing redundancy and efficient memory erasure when the facts are retracted. The rule container refers to the part of the database where the rules of the system are saved. There are internal entities that contain the parameter rules of each individual rule set: system irrigation functionality, fertilization, pest control, agronomy parameter, and weather; there is a rule for each type only in the basic demo mode. The system needs to gain experiences and broker new rule-based relations. Each rule contains two main sections: the conditions section and the actions section.