# The same data shape in several layers (DTO, model, entity)

*Code that already exists*: one of the ways AI coding agents bloat software, from lessloc's [pattern catalog](https://lessloc.org/patterns/index.md). What lessloc does: [`copy`](https://lessloc.org/guide/reference.md#tier-1) catches identical type bodies.

## What makes the same data shape in several layers (DTO, model, entity) a bad practice?

The standard that calls it a bad practice: DRY.

## What does lessloc do about the same data shape in several layers (DTO, model, entity)?

[`copy`](https://lessloc.org/guide/reference.md#tier-1) catches identical type bodies.

- `copy` (tier 1): A block of `dupLines` code lines that also exists elsewhere, or a function with the same body as another under other names.

## Examples

Caught as `copy`:

```python [cs.py]
from dataclasses import dataclass


@dataclass
class UserDTO:
    id: int
    name: str
    email: str
    active: bool
    plan: str
    seats: int
    created: str
    region: str


@dataclass
class UserRecord:
    id: int
    name: str
    email: str
    active: bool
    plan: str
    seats: int
    created: str
    region: str
```

Written well:

```python [cs.py]
from dataclasses import dataclass


@dataclass
class Account:
    owner: str
    limit: int
```

## Related patterns

The other patterns in [Code that already exists](https://lessloc.org/patterns/index.md#code-that-already-exists):

- [Reimplementing a helper the project already has](https://lessloc.org/patterns/reuse-helper.md): lessloc gives every session the rule: take what is already in the codebase before new code.
- [Copying a rule another function owns](https://lessloc.org/patterns/copied-rule.md): lessloc catches it as `repeated-literal`.
- [Keeping old and new versions side by side](https://lessloc.org/patterns/side-by-side.md): lessloc gives every session the rule: one implementation per rule.
- [Rebuilding what the standard library or framework has](https://lessloc.org/patterns/rebuilt-library.md): lessloc gives every session a rule against it and catches it as `simpler` and `reinvented`.
- [Copy-pasted test cases instead of one parametrized test](https://lessloc.org/patterns/copied-tests.md): lessloc catches it as `copied-tests`.
- [A second library for a job an installed one already does](https://lessloc.org/patterns/second-library.md): `new-dependency` names the library that is already installed.
- [The same CSS declarations under another selector](https://lessloc.org/patterns/css-copy.md): lessloc catches it as `style-copy`.
