> For the complete documentation index, see [llms.txt](https://admincode.gitbook.io/admincode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://admincode.gitbook.io/admincode/basics/newpage/step-6-orchestrating-a-process-optional.md).

# Step 6: Orchestrating the Process \[Optional]

The **Facade layer** sits on top of the service layer and provides a simplified interface to complex business processes, orchestrating multiple services or operations behind a single entry point. This layer implements the **Facade pattern**, which aims to reduce the complexity of the underlying system by exposing only the necessary methods and hiding the intricate details of interacting with multiple services or subsystems.

In an application that follows the Facade pattern, the **Process class** typically represents a higher-level component responsible for executing a sequence of business operations or orchestrating complex workflows. This class is invoked by the Facade layer, which acts as the entry point for clients or controllers, abstracting away the complexity of the underlying business logic. When the Facade calls the **Process class**, it initiates a series of steps or processes, often involving multiple service layer calls, data transformations, or external integrations, in a predefined order.

The **Process class** ensures that the business flow is executed correctly, coordinating the interaction between various services or components, handling exceptions, and applying any necessary business rules. It encapsulates the logic required to complete a specific task or process, often representing a transaction or a multi-step operation that requires coordination across different parts of the application. By isolating this process management in a dedicated class, the system remains modular, making it easier to maintain, test, and extend over time. The Facade serves as the gateway to trigger this process, while the **Process class** handles the complexity of executing and managing the business logic required to fulfill the client’s request.

***Optional: Creating a new Process class might be reduntant for basic operations, since CRUD operations Create/Update/Delete are supported from the existing*****&#x20;CRUDProcess**.***class***

**Important:&#x20;*****Each Process should have the equivalent final String process name with the 'PROCESS\_' prefix format, as below code example. Process name is used by the the user-role management to grant access to these processes by authorized users***

```
PROCESS_COUNT_ARTICLES
```

**Creating the Process**

```java
package com.rce.process;

import org.springframework.beans.factory.annotation.Autowired;

import com.rce.service.ArticleService;

public class ArticleProcess extends BaseProcess {
	
	@Autowired
	private ArticleService ArticleService;
	
	public static final String PROCESS_COUNT_ARTICLES = "COUNT_ARTICLES";
	
	public String evaluateArticles() {
		int count = ArticleService.countArticles();
		if (count == 0) {
			return "no articles";
		}
		
		return String.format("%s articles found", count);
	}

}
```

**Creating the Facade**

```java
package com.rce.facade;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.rce.dto.BaseDTO;
import com.rce.process.ActivityProcess;
import com.rce.processmanager.IProcess;
import com.rce.processmanager.IProcessManager;

import ch.qos.logback.classic.Logger;

public class ArticleFacade {
	
	protected Logger logger = ((ch.qos.logback.classic.Logger)LoggerFactory.getLogger(this.getClass()));

	@Autowired
	protected IProcessManager processManager;
	@Autowired
	protected ArticleProcess ArticleProcess;	
	
	public Object validateSearchAccess(BaseDTO input) throws Exception {
		IProcess<?, ?, ?> process = b -> ArticleProcess.evaluateArticles();
		return processManager.runProcess(process, input, com.rce.process.ArticleProcess.PROCESS_COUNT_ARTICLES);
	}
}
```
