# Salesforce Project Structure

{% hint style="info" %}

### TODO

Merge this content with [Class Folder Organization Patterns](/technical/best-practices/class-folder-organization.md), and complete the content here.
{% endhint %}

### Module-Based Architecture

In Salesforce development, the lack of traditional package systems and folder structures presents unique challenges. All Apex classes exist in a global namespace, making code organization and modularity crucial for maintainable enterprise applications.

Our Salesforce projects follow a module-based architecture where functionality is organized into discrete modules within the `src` folder. Each module represents a specific business domain or technical capability.

Example project structure:

```
src/
├── core/
│   ├── main/default/classes/
│   │   ├── Application.cls
│   │   ├── services/
│   │   │   └── CasesService.cls
│   │   └── triggerActions/
│   │       └── TA_Case_InitDefaults.cls
│   └── test/default/classes/
│       ├── services/
│       │   └── CasesServiceTest.cls
│       └── triggerActions/
│           └── TA_Case_InitDefaultsTest.cls
├── document-explorer/
│   ├── main/default/classes/
│   │   ├── Application_DE.cls
│   │   ├── services/
│   │   │   └── DocumentService_DE.cls
│   └── test/default/classes/
│       ├── services/
│       │   └── DocumentServiceTest_DE.cls
└── lead-management/
    ├── main/default/classes/
    │   ├── Application_LM.cls
    │   ├── services/
    │   │   └── LeadService_LM.cls
    └── test/default/classes/
        ├── services/
        │   └── LeadServiceTest_PM.cls
```

Since Salesforce operates with a global class namespace, we use consistent naming patterns and suffixes to maintain module isolation and code clarity.

**Exception:** Classes in the `core` module do not use suffixes.

**Benefits of This Approach:**

1. Module Isolation: Each module contains related functionality, making it easier to understand and maintain specific business domains.
2. Reduced Naming Conflicts: Descriptive suffixes minimize the risk of class name collisions across different modules.
3. Enhanced Testability: Module boundaries make it easier to write focused unit tests and mock dependencies.

### Standard Class Organization Patterns

To further classify and organize classes within each module, we use standardized folder structures and naming patterns. These are some of the most common folders, but modules are not limited to just these organizational patterns:

```
module-name/
├── main/default/classes/
│   ├── constants/
│   ├── domains/
│   │   ├── interfaces/
│   │   │   └── IAccounts.cls
│   │   └── Accounts.cls
│   ├── selectors/
│   │   ├── interfaces/
│   │   │   └── IAccountsSelector.cls
│   │   └── AccountsSelector.cls
│   ├── services/
│   │   ├── implementations/
│   │   │   └── DocumentsServiceImpl.cls
│   │   ├── interfaces/
│   │   │   └── IDocumentsService.cls
│   │   └── DocumentsService.cls
│   ├── triggerActions/
│   └── Application.cls
```

**Folder Descriptions:**

* `constants/`: Static values and configuration constants
* `domains/`: Business logic and domain models with their interfaces
* `selectors/`: Data access layer classes with their interfaces
* `services/`: Business service layer with implementations and interfaces
* `triggerActions/`: Trigger handler classes

> **Note:** For a deeper understanding of the domains, selectors, services, and trigger actions architectural patterns, refer to the [fflib - Apex Framework](/technical/frameworks/fflib-apex-framework.md) documentation.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.goharrier.com/technical/best-practices/project-structure.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
