# AutoMapper

**Kind:** Service

**Source:** `Pams/Logic/Pams.Business/Pams.Business.csproj` (line 1)

**Part of:** [Pams](subsystem-pams)

NuGet package dependency

AutoMapper is a NuGet dependency declared in `Pams.Business.csproj` that maps between business-layer objects and DTOs. Business services configure mapping profiles and use an injected mapper to convert data before it crosses application boundaries.

## Diagram

```mermaid
sequenceDiagram
    participant Client
    participant BusinessService
    participant Mapper as AutoMapper
    participant Repository

    Client->>BusinessService: Request data
    BusinessService->>Repository: Load domain entity
    Repository-->>BusinessService: Domain entity
    BusinessService->>Mapper: Map entity to DTO
    Mapper-->>BusinessService: DTO
    BusinessService-->>Client: Return DTO
```

## Usage

```typescript
type PamsRecordDto = {
  id: string;
  name: string;
};

async function getPamsRecord(id: string): Promise<PamsRecordDto> {
  const response = await fetch(`/api/pams-records/${id}`);

  if (!response.ok) {
    throw new Error("Unable to load PAMS record");
  }

  // The API response is mapped from a business entity to this DTO by AutoMapper.
  return response.json();
}

const record = await getPamsRecord("record-id");
console.log(record.name);
```

## AI Coding Instructions

- Keep AutoMapper configuration in mapping profiles owned by the business layer.
- Map domain entities to DTOs at service or API boundaries rather than exposing entities directly.
- Update mapping profiles when DTO or entity properties change.
- Check mappings for nested objects, nullable values, and property names that do not match.

## Used by

3 references from 3 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

### Injected or called by (3)

- `Pams.API` — `Pams/API/Pams.API/Pams.API.csproj`:1
- `Pams.Data` — `Pams/Data/Pams.Data/Pams.Data.csproj`:1
- `Pams.Business` — `Pams/Logic/Pams.Business/Pams.Business.csproj`:1
