PHPackages                             alamellama/carapace - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. alamellama/carapace

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

alamellama/carapace
===================

Framework-agnostic DTOs for PHP

v2.0.2(4mo ago)133.6k↓43.9%[7 issues](https://github.com/ALameLlama/carapace/issues)MITPHPPHP ^8.2CI passing

Since Aug 5Pushed 4mo agoCompare

[ Source](https://github.com/ALameLlama/carapace)[ Packagist](https://packagist.org/packages/alamellama/carapace)[ GitHub Sponsors](https://github.com/alamellama)[ RSS](/packages/alamellama-carapace/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (5)Versions (11)Used By (0)

 [![Carapace Logo](.art/logo.webp)](.art/logo.webp)

 [![Packagist License](https://camo.githubusercontent.com/302a14a3a249b77d8f4fedcb9f54ebf50d033aded0529cd7b27f9438115dfb24/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f414c616d654c6c616d612f6361726170616365)](https://camo.githubusercontent.com/302a14a3a249b77d8f4fedcb9f54ebf50d033aded0529cd7b27f9438115dfb24/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f414c616d654c6c616d612f6361726170616365) [![Packagist Version](https://camo.githubusercontent.com/f304b5b45c519538b6d1c7a7153054b847f097289b116f8849834b557edb1dc6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f414c616d654c6c616d612f6361726170616365)](https://camo.githubusercontent.com/f304b5b45c519538b6d1c7a7153054b847f097289b116f8849834b557edb1dc6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f414c616d654c6c616d612f6361726170616365) [![Packagist Stars](https://camo.githubusercontent.com/5e90223ec676097ee377729155d3844324acc03ebab3d7cd8d6a1545eee50a07/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f73746172732f414c616d654c6c616d612f6361726170616365)](https://camo.githubusercontent.com/5e90223ec676097ee377729155d3844324acc03ebab3d7cd8d6a1545eee50a07/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f73746172732f414c616d654c6c616d612f6361726170616365) [![Packagist Downloads](https://camo.githubusercontent.com/ee25a4d6d920ef6ff1fdfb1b58b8241af3f11201532312b2db4f776508dd3115/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f414c616d654c6c616d612f6361726170616365)](https://camo.githubusercontent.com/ee25a4d6d920ef6ff1fdfb1b58b8241af3f11201532312b2db4f776508dd3115/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f414c616d654c6c616d612f6361726170616365)

Carapace is a lightweight PHP library for building immutable, strictly typed Data Transfer Objects (DTOs). It leverages PHP attributes for casting, property mapping, and serialization, while providing a simple, expressive API.

Features
--------

[](#features)

- **Mutable + Immutable DTOs**: Define data objects by extending the Data base class, or use ImmutableData for readonly DTOs.
- **Attribute-Driven Mapping**: Use PHP attributes like CastWith, MapFrom, MapTo, and Hidden to control how data is hydrated, transformed, and serialized with minimal boilerplate.
- **Strictly Typed**: Leverage PHP's type system for predictable data structures.
- **Framework-Agnostic**: Works in Laravel, Symfony, or plain PHP projects.
- **Simple API**: Create, hydrate, and transform DTOs with minimal boilerplate.

Installation
------------

[](#installation)

```
composer require alamellama/carapace
```

Usage
-----

[](#usage)

```
use Alamellama\Carapace\Data;
use Alamellama\Carapace\Attributes\CastWith;
use Alamellama\Carapace\Attributes\Hidden;
use Alamellama\Carapace\Attributes\MapFrom;

class User extends Data
{
    public function __construct(
        public string $name,
        #[MapFrom('email_address')]
        public string $email,

        #[Hidden]
        public string $password,

        #[CastWith(Address::class)]
        public Address $address,
    ) {}
}

// Create from an array
$user = User::from([
    'name' => 'John Doe',
    'email_address' => 'john@example.com',
    'password' => 'secret',
    'address' => [
        'street' => '123 Main St',
        'city' => 'Anytown',
    ],
]);

// Create a modified copy
$updatedUser = $user->with(name: 'Jane Doe');

// Serialize
$array = $user->toArray(); // Password will be excluded
$json = $user->toJson();
```

Documentation
-------------

[](#documentation)

For detailed documentation, visit our [documentation site](https://alamellama.github.io/carapace/).

Code Quality
------------

[](#code-quality)

Carapace follows PSR-12 coding standards with Laravel-style modifications. We use Laravel Pint for code style enforcement and Rector for automated refactoring. PHPStan is configured at a high strictness level.

```
# Apply automated fixes (Pint + Rector)
composer fix

# Run tests and quality checks
composer test
```

Testing
-------

[](#testing)

Carapace uses Pest PHP for testing and aims for 100% test coverage.

```
# Run all tests
composer test
```

Acknowledgements &amp; Inspirations
-----------------------------------

[](#acknowledgements--inspirations)

In particular, we drew inspiration and ideas from:

- Spatie's data libraries, including [spatie/data-transfer-object](https://github.com/spatie/data-transfer-object) and [spatie/laravel-data](https://github.com/spatie/laravel-data)
- [CuyZ/Valinor](https://github.com/CuyZ/Valinor)
- [Symfony Serializer](https://symfony.com/doc/current/components/serializer.html)

We also rely on fantastic tooling that keeps this project reliable and maintainable:

- [Pest PHP](https://pestphp.com/) for testing
- [PHPStan](https://phpstan.org/) for static analysis
- [Laravel Pint](https://laravel.com/docs/pint) for code style
- [Rector](https://github.com/rectorphp/rector) for automated refactoring

License
-------

[](#license)

Carapace is open-sourced software licensed under the MIT license. See the [LICENSE](LICENSE) file for details.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance66

Regular maintenance activity

Popularity30

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~23 days

Recently: every ~37 days

Total

8

Last Release

123d ago

Major Versions

v1.2.1 → v2.0.02025-09-30

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/55490546?v=4)[Nicholas Ciechanowski](/maintainers/ALameLlama)[@ALameLlama](https://github.com/ALameLlama)

---

Top Contributors

[![ALameLlama](https://avatars.githubusercontent.com/u/55490546?v=4)](https://github.com/ALameLlama "ALameLlama (42 commits)")

---

Tags

dtophp

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/alamellama-carapace/health.svg)

```
[![Health](https://phpackages.com/badges/alamellama-carapace/health.svg)](https://phpackages.com/packages/alamellama-carapace)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
