> ## Documentation Index
> Fetch the complete documentation index at: https://aegean.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Domain Model

> Configuration and data model using Domain-Driven Design principles

## Configuration and Data Model

We have adopted elements of a lightweight version of the [Domain-Driven Design (DDD)](https://learn.microsoft.com/en-us/archive/msdn-magazine/2009/february/best-practice-an-introduction-to-domain-driven-design) in the implementation of the project.

### Hydra-based configuration

We have separated the configuration of the application from the application itself. We have used [Hydra](https://hydra.cc/docs/intro/) as the configuration engine - typically used in machine learning projects that run on different environments (e.g., edge server, development laptop, etc.). In addition we have connected Hydra and the experiment monitoring component that allow us to view the lineage of the produced models.

### Pydantic-based data model

We have defined the entities of the application using [Pydantic](https://docs.pydantic.dev/latest/) classes. The data model is used to *validate* the configuration data. Choosing Pydantic allows us also to [future proof the solution around Large Language and Vision Model agents](https://ai.pydantic.dev/) by using the same data model in the API layer.

```python theme={null}
from pydantic import BaseModel
from typing import Optional, List
from datetime import datetime

class ProductImage(BaseModel):
    """Domain entity representing a product seam image."""
    image_id: str
    machine_setting: str
    timestamp: datetime
    image_data: bytes
    anomaly_label: Optional[str] = None

class Dataset(BaseModel):
    """Domain entity representing a dataset of product images."""
    name: str
    version: str
    images: List[ProductImage]
    created_at: datetime

class InferenceResult(BaseModel):
    """Domain entity representing an anomaly detection inference result."""
    image_id: str
    anomaly_score: float
    is_anomalous: bool
    confidence: float
    inference_time_ms: float
```

***

<Callout icon="pen-to-square" iconType="regular">
  [Edit this page on GitHub](https://github.com/aegean-ai/eaia/edit/main/src/products/applications/anomaly-detection/manufacturing/architecture/domain-model.mdx) or [file an issue](https://github.com/aegean-ai/eaia/issues/new/choose).
</Callout>
