Digital twin is a virtual copy of a physical system or object that helps to understand and analyze the behavior of the system. It uses real-time data from sensors, IoT devices, and digital input devices in order to monitor, analyse, visualise, and simulate the behaviour of the systems. Engineers can operate and test these systems virtually, without the need for direct physical interaction. Then the faults and errors in the systems are reported before the actual launching of the system, making the system more robust and less error-prone. Therefore, performance monitoring, efficiency analysis, and maintenance are also performed in a virtual environment. This approach enhances efficiency, reduces cost, and supports better decision-making. Digital twin systems need architecural structures that helps to deign, deploy and integrate these systems. The architectural representation of these systems is called digital twin frameworks.
The technology of digital twin is used in various sectors like healthcare, industry, Robotics, Military/aviation, Agriculture, Manufacturing, and aerospace. The environment of a digital twin is created by using IoT devices, data analytics and sensors. The concept of digital twin was introduced by NASA [1] in the Apollo space program. NASA referred to DT as ‘Virtual Digital Fleet Leader’.

The architecture of Digital Twin consists of four layers: Physical layer, Communication layer, Data Collection Layer, Data Storage and Management Layer, and Modelling and Simulation layer.
Eclipse Ditto [2], an open-source digital twin(DT) framework, used to analyse whether digital twin frameworks follow good coding practices or not. Eclipse Ditto is an open source Digital Twin framework used to create and manage a digital twin environment for IoT devices.
There is a need to improve the framework for DT systems for the improved productivity. Digital frameworks are are oftenly designed in different programming languages. Therefore, these frmework aslo need to follow the good programming practises as part of other systems. We used SonarQube [3] to know about the code quality of DT frameworks. SonarQube is a widely used static analysis tool designed to assess code quality, detect vulnerabilities, and identify issues such as security vulnerabilities, code smells, and bugs. We investigate the Eclipse Ditto repository code with the help of SonarQube.

The above figure shows the generic information about the code quality of Eclipse Ditto framework after successfully analysing the codebase. The issues indeitfy by the SonarQube were saved with their rule, message, type, severity, line and effort. We identified total 4832 code issues in which 704 are bugs, 4075 are code smells and 52 are vulnerabilities shown in the figure below.

We analyse these issues and filter them based on their number of occurrences. The digital twin framework is a combination of different programming languages, so the code smells are also associated with different programming languages. Among the top five code smells, three of them are related to programs written in java and two are associated to the files written in JavaScript. SonarQube identified the code smells in the digital twin framework but can not classify those smells as the digital twin framework is designed based on source code written in Java, JavaScript. We identified that the issue named “Define a constant instead of duplicating this literal” having rule “java:S1192” came most of the time labelled as a code smell. Similarly, “Use another way to initialise this instance” with rule “javascript:S3504” came 540 times, also labelled as Code Smell.
SonarQube labelled all of these issues as Code Smell, but it does not identify the further category of the Code Smell. There is a need to label the code smells based on the message associated to each code smell. For this, we manually classify the code smells based on the problem reported as well as the suggestion proposed. Each message reports the issue with the name but categorises this with a generic name as ‘Code smell’. The top five code smells are reported in Table1.
Let's take an example of a code smell that reports the problem associated with duplicating a literal. The message shows the literal used as duplication is "foo.bar.baz" 4 times”. After inspecting this problem manually, we identified that this is associated to the use of a metasyntactic variable name without any logic. Therefore, the suggestion is to use a constant instead of using a metasyntactic variable name. We further identified that the digital twin framework often creates so many duplicates without following specific rules that make code more complicated and often create unnecessary information for the network connection to respond on time.
|
Rule |
Message |
Type |
Count |
|
java:S1192 |
Define a constant instead of
duplicating this literal |
CODE SMELL |
922 |
|
java:S3599 |
Use another way to initialize this
instance. |
CODE SMELL |
540 |
|
java:S1171 |
Move the contents of this
initializer to a standard constructor or to field initializers. |
CODE SMELL |
545 |
|
javascript:S3504 |
Unexpected var; use let or const
instead. |
CODE SMELL |
415 |
|
css:S125, javascript:S125, xml:S125 |
Remove this commented out code |
CODE SMELL |
248 |
Table 1:Top 5 Issue in Eclipse Ditto
Categorizing the Code Smells, Bugs, and Vulnerabilities manually is a hectic process, so there is a need to make a tool to identify the good practices in the Digital Twin framework after inspecting code and logic that maps each smells vulnerability and bugs with the data connection, storage, cloud and network layers.
References:
[1] https://ntrs.nasa.gov/api/citations/20120008178/downloads/20120008178.pdf
[2] https://github.com/eclipse-ditto/ditto
[3] https://docs.sonarsource.com/sonarqube-server/quality-standards-administration/managing-rules/rules