---
schema_version: "1"
id: 00802584c3794e5515c169bcb8115f7ecfab6afac0ef5913f87c4091d126ade6
title: Best Practices to Build Mule Applications
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/mule-runtime/latest/build-app-practices.md
canonical_url: https://docs.mulesoft.com/mule-runtime/latest/build-app-practices
source_site: docs.mulesoft.com
content_type: documentation
content_hash: c844efa1b10ca2c049b6568db10e3b8d4bb8428ebcbe273d328203d4d9f37e08
description: MuleSoft Documentation Site
release: "4.13"
latest: true
---
---
product: Mule Runtime
version: 4.13
is-latest-version: true
---

# Best Practices to Build Mule Applications

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

As you build your applications, consider the following best practices for creating a clean,
organized, and sustainable project. These practices include guidelines on using Anypoint Studio,
avoiding certain app-building issues, and specific settings for using Mule runtime engine (Mule)
components and connectors.

## Anypoint Studio Best Practices

If you use Anypoint Studio to build Mule apps, consider the following practices:

- Update to the latest version of Anypoint Studio.

- Use the recommended Java version (OpenJDK) for the specific Studio version.

- Include the Mule Maven plugin for automated deployment (executed by CI/CD processes).

### Define a Project Structure

To help maintain a clean, structured, and readable project in Anypoint Studio, consider the
following recommendations:

- Create a separate XML file for global elements, for example, configuration elements.

- Create a separate XML file for each use case or resource implementation.

- Create separate XML files for common structures or logic.

- Create different packages for resources such as DataWeave, WSDLs, examples, and so on.

#### Add Indentation and Formatting

As you build your app project in Anypoint Studio, consider the following points:

- Add indentation and format to all your XML files (Mule XMLs, `pom.xml`, `log4j2.xml`, and so on)
  before committing to the source code repository.

- Define a line width in your Anypoint Studio XML editor preferences, for example `140.d`.

- Define a naming convention.

#### Manage Properties per Environment

To avoid creating a separate set of variables for each environment, Mule 4 contains a built-in
mechanism that enables you to set default values, which you manage by using Anypoint Runtime
Manager. For details, see [Mule Configuration File](https://docs.mulesoft.com/mule-runtime/latest/about-mule-configuration) and
[Configuring Properties](https://docs.mulesoft.com/mule-runtime/latest/configuring-properties).

## App-Building Best Practice

As you build your Mule app, avoid packaging the configuration files for all the environments inside
the application. Instead, use a `.yaml` file to provide default properties, and use Anypoint Runtime
Manager to override each of these properties at deployment time.

## Components and Connectors Best Practices

When building your apps using Mule components and connectors, consider the following
recommendations.

### APIkit

When using APIkit, consider these practices:

- Use APIkit features to generate flows automatically using your API specification.

- Use APIkit Exception Strategy to catch connector-related exceptions.

### DataWeave

When using DataWeave for building your app, consider these recommendations:

- Use inline scripts during the development phase.

- To have a clean XML and reusable scripts, pass the inline scripts to an external file.

### Flows

When creating flows for your app, consider the following practices:

- Have a clear flow diagram showing the steps of the use case.

- Use a Flow Reference to separate and reuse common logic.

### File Connector

If you use Anypoint Connector for File (File Connector) and share part of the path on numerous reads
or any other file operations, extract the base path into a file configuration to reuse it:

```xml
<file:config name="File_Config" >
   <file:connection workingDir="/Example/path" />
</file:config>

<flow>
   <file:read config-ref="File_Config" path="manual.txt" />
   <file:read config-ref="File_Config" path="readme.txt" />
</flow>
```

### HTTP and HTTPS

For HTTP and HTTPS ports in on-premises deployments, MuleSoft recommends using the names for
property placeholders that are reserved for CloudHub deployments. The shared load balancer in
CloudHub uses the defaults for these properties.

- In CloudHub, `${http.port}` maps to the setting `port=8081`, and `${https.port}` maps to
  `port=8082`.

- For internal ports to HTTP services in CloudHub deployments, `${http.private.port}` maps to the
  setting `port=8091`, and `${https.private.port}` maps to `port=8092`.

For details about these settings in CloudHub, see
[CloudHub Reserved Properties](https://docs.mulesoft.com/cloudhub/cloudhub-manage-props#cloudhub-reserved-properties)
and [CloudHub Networking Guide](https://docs.mulesoft.com/cloudhub/cloudhub-networking-guide).

### Apache Kafka Connector

If you use Anypoint Connector for Apache Kafka (Apache Kafka Connector) perform the following
actions:

- Use the `.properties` file to add bootstrap server configuration.

- Add property placeholders, either in a `.yaml` or a `.properties` file, and use the file in the
  configuration:

```xml
config.bootstrapServers={your Kafka Server address}
config.consumerPropertiesFile=consumer.properties
config.producerPropertiesFile=producer.properties
# Consumer specific information
consumer.topic=one-replica
consumer.topic.partitions=1
```

- Apache Kafka Connector provides various settings for producer and consumer properties, add your
  own settings in `consumer.properties` and `producer.properties` under `src/main/resource`:

```xml
<configuration-properties file="mule-app.properties"/>
```

## See Also

- [Apache Kafka Connector](https://docs.mulesoft.com/kafka-connector/latest/)

- [HTTP Connector](https://docs.mulesoft.com/http-connector/1.10/)
