> For the complete documentation index, see [llms.txt](https://docs.goharrier.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.goharrier.com/technical/best-practices/project-structure.md).

# Salesforce Project Structure

{% hint style="info" %}

### TODO

Merge this content with [Class Folder Organization Patterns](https://docs.goharrier.com/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](https://docs.goharrier.com/technical/frameworks/fflib-apex-framework.md) documentation.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
