PHPackages                             freema/react-admin-api-bundle - 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. [API Development](/categories/api)
4. /
5. freema/react-admin-api-bundle

ActiveSymfony-bundle[API Development](/categories/api)

freema/react-admin-api-bundle
=============================

Symfony bundle for React Admin API

1.0.2(6mo ago)0139↓26.7%1MITPHPPHP &gt;=8.2CI passing

Since Aug 13Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/freema/react-admin-api-bundle)[ Packagist](https://packagist.org/packages/freema/react-admin-api-bundle)[ RSS](/packages/freema-react-admin-api-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (15)Versions (6)Used By (0)

React Admin API Bundle
======================

[](#react-admin-api-bundle)

Symfony bundle for automatically generating REST API endpoints compatible with [React Admin](https://marmelab.com/react-admin/). The bundle provides a complete infrastructure for creating CRUD APIs with minimal configuration - just create a DTO class and the bundle automatically provides all necessary endpoints.

Main Features
-------------

[](#main-features)

- ✅ **Automatic endpoint registration** - based only on resource → DTO configuration
- ✅ **CRUD operations** - GET, POST, PUT, DELETE with pagination, sorting, and filtering
- ✅ **React Admin compatibility** - standard response formats
- ✅ **Doctrine integration** - uses standard Symfony/Doctrine patterns
- ✅ **Trait-based repository implementation** - easy implementation of CRUD operations
- ✅ **Type-safe DTO objects** - clean architecture with separation of entity and API layer
- ✅ **Flexible configuration** - supports related resources

Architecture
------------

[](#architecture)

The bundle is built on the principle of **resource path → DTO class mapping**. Everything else is derived automatically:

```
Resource path "users" → UserDto::class → User::class (from DTO) → UserRepository (from EntityManager)

```

### Key Components:

[](#key-components)

1. **DTO (Data Transfer Object)** - defines the API structure and maps to entities
2. **Repository traits** - provide standard CRUD implementations
3. **Resource Configuration Service** - manages resource to DTO mappings
4. **Controllers** - automatically handle HTTP requests

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

[](#installation)

```
composer require freema/react-admin-api-bundle
```

Register the bundle in `config/bundles.php`:

```
return [
    // ...
    Freema\ReactAdminApiBundle\ReactAdminApiBundle::class => ['all' => true],
];
```

Configuration
-------------

[](#configuration)

Create configuration in `config/packages/react_admin_api.yaml`:

```
react_admin_api:
    resources:
        # Simple mapping: resource path => DTO class
        users:
            dto_class: 'App\Dto\UserDto'
        products:
            dto_class: 'App\Dto\ProductDto'
            related_resources:
                categories:
                    dto_class: 'App\Dto\CategoryDto'
                    relationship_method: 'getCategories'
```

Usage
-----

[](#usage)

### 1. Entity

[](#1-entity)

The entity must implement `AdminEntityInterface`:

```
namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Freema\ReactAdminApiBundle\Interface\AdminEntityInterface;

#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: 'users')]
class User implements AdminEntityInterface
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private ?int $id = null;

    #[ORM\Column(type: 'string', length: 255)]
    private string $name = '';

    #[ORM\Column(type: 'string', length: 255, unique: true)]
    private string $email = '';

    // getters and setters...
}
```

### 2. DTO (the most important part)

[](#2-dto-the-most-important-part)

The DTO defines the API structure and is key to the bundle:

```
namespace App\Dto;

use App\Entity\User;
use Freema\ReactAdminApiBundle\Dto\AdminApiDto;
use Freema\ReactAdminApiBundle\Interface\AdminEntityInterface;

class UserDto extends AdminApiDto
{
    public ?int $id = null;
    public string $name = '';
    public string $email = '';
    public array $roles = [];

    /**
     * Key method - tells the bundle which entity the DTO maps to
     */
    public static function getMappedEntityClass(): string
    {
        return User::class;
    }

    /**
     * Create DTO from entity (for reading)
     */
    public static function createFromEntity(AdminEntityInterface $entity): AdminApiDto
    {
        if (!$entity instanceof User) {
            throw new \InvalidArgumentException('Entity must be instance of User');
        }

        $dto = new self();
        $dto->id = $entity->getId();
        $dto->name = $entity->getName();
        $dto->email = $entity->getEmail();

        return $dto;
    }

    /**
     * Convert DTO to array for API response
     */
    public function toArray(): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'email' => $this->email,
            'roles' => $this->roles,
        ];
    }
}
```

### 3. Repository

[](#3-repository)

The repository implements CRUD operations using traits:

```
namespace App\Repository;

use App\Dto\UserDto;
use App\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Freema\ReactAdminApiBundle\CreateTrait;
use Freema\ReactAdminApiBundle\DeleteTrait;
use Freema\ReactAdminApiBundle\Dto\AdminApiDto;
use Freema\ReactAdminApiBundle\Interface\AdminEntityInterface;
use Freema\ReactAdminApiBundle\Interface\DataRepositoryCreateInterface;
use Freema\ReactAdminApiBundle\Interface\DataRepositoryDeleteInterface;
use Freema\ReactAdminApiBundle\Interface\DataRepositoryFindInterface;
use Freema\ReactAdminApiBundle\Interface\DataRepositoryListInterface;
use Freema\ReactAdminApiBundle\Interface\DataRepositoryUpdateInterface;
use Freema\ReactAdminApiBundle\ListTrait;
use Freema\ReactAdminApiBundle\UpdateTrait;

class UserRepository extends ServiceEntityRepository implements
    DataRepositoryListInterface,      // for GET /api/users
    DataRepositoryFindInterface,      // for GET /api/users/{id}
    DataRepositoryCreateInterface,    // for POST /api/users
    DataRepositoryUpdateInterface,    // for PUT /api/users/{id}
    DataRepositoryDeleteInterface     // for DELETE /api/users/{id}
{
    use ListTrait;    // implements list() method with pagination, sorting, filtering
    use CreateTrait;  // implements create() method
    use UpdateTrait;  // implements update() method
    use DeleteTrait;  // implements delete() and deleteMany() methods

    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, User::class);
    }

    /**
     * Fields for full-text search
     */
    public function getFullSearchFields(): array
    {
        return ['name', 'email'];
    }

    /**
     * Find entity and return as DTO
     */
    public function findWithDto($id): ?AdminApiDto
    {
        $user = $this->find($id);
        return $user ? UserDto::createFromEntity($user) : null;
    }

    /**
     * Map entity to DTO (used by traits)
     */
    public static function mapToDto(AdminEntityInterface $entity): AdminApiDto
    {
        return UserDto::createFromEntity($entity);
    }

    /**
     * Create entities from DTO (used by CreateTrait)
     */
    public function createEntitiesFromDto(AdminApiDto $dto): array
    {
        if (!$dto instanceof UserDto) {
            throw new \InvalidArgumentException('DTO must be instance of UserDto');
        }

        $user = new User();
        $user->setName($dto->name);
        $user->setEmail($dto->email);

        $this->getEntityManager()->persist($user);

        return [$user];
    }

    /**
     * Update entity from DTO (used by UpdateTrait)
     */
    public function updateEntityFromDto(AdminEntityInterface $entity, AdminApiDto $dto): AdminEntityInterface
    {
        if (!$entity instanceof User) {
            throw new \InvalidArgumentException('Entity must be instance of User');
        }

        if (!$dto instanceof UserDto) {
            throw new \InvalidArgumentException('DTO must be instance of UserDto');
        }

        $entity->setName($dto->name);
        $entity->setEmail($dto->email);

        return $entity;
    }
}
```

Generated Endpoints
-------------------

[](#generated-endpoints)

After configuration, the bundle automatically creates these endpoints:

MethodURLDescriptionGET`/api/users`List users with pagination, sorting, filteringGET`/api/users/{id}`User detailPOST`/api/users`Create new userPUT`/api/users/{id}`Update userDELETE`/api/users/{id}`Delete userDELETE`/api/users`Bulk delete (with filter)Request/Response Examples
-------------------------

[](#requestresponse-examples)

### GET /api/users?page=1&amp;perPage=10&amp;sort=name&amp;order=ASC

[](#get-apiuserspage1perpage10sortnameorderasc)

```
{
    "data": [
        {"id": 1, "name": "John Doe", "email": "john@example.com"},
        {"id": 2, "name": "Jane Smith", "email": "jane@example.com"}
    ],
    "total": 25
}
```

### POST /api/users

[](#post-apiusers)

Request:

```
{"name": "New User", "email": "new@example.com"}
```

Response:

```
{"id": 3, "name": "New User", "email": "new@example.com"}
```

Development Mode
----------------

[](#development-mode)

A dev application is prepared for testing in the `dev/` directory:

```
# Run via docker
task dev:up

# Or locally
cd dev && php index.php
```

The dev application uses:

- In-memory SQLite (fast testing)
- Automatic database initialization with test data
- Minimal configuration

Advanced Features
-----------------

[](#advanced-features)

### Related Resources

[](#related-resources)

```
react_admin_api:
    resources:
        users:
            dto_class: 'App\Dto\UserDto'
            related_resources:
                posts:
                    dto_class: 'App\Dto\PostDto'
                    relationship_method: 'getPosts'
```

Generates endpoint: `GET /api/users/{id}/posts`

### Custom Repository

[](#custom-repository)

If you need custom repository logic, just implement the required interfaces:

```
class CustomUserRepository implements DataRepositoryListInterface
{
    public function list(ListDataRequest $request): ListDataResult
    {
        // Your custom logic
    }
}
```

Testing
-------

[](#testing)

The bundle contains a complete test suite in the `tests/` directory:

```
composer test        # PHPUnit tests
composer test:php    # PHP syntax check
composer lint        # Code style check
```

Supported Versions
------------------

[](#supported-versions)

- PHP 8.2+
- Symfony 6.4+ / 7.1+
- Doctrine ORM 2.14+

License
-------

[](#license)

MIT License

Contributing
------------

[](#contributing)

Contributions are welcome! Please create an issue or pull request on GitHub.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance66

Regular maintenance activity

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.9% 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 ~41 days

Total

3

Last Release

196d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1feadbd856db0d9578f7e3c5221c76bd76d4cdfa745bd748be918b2cd10de70c?d=identicon)[Freema](/maintainers/Freema)

---

Top Contributors

[![freema](https://avatars.githubusercontent.com/u/2912985?v=4)](https://github.com/freema "freema (26 commits)")[![dStranska](https://avatars.githubusercontent.com/u/17758790?v=4)](https://github.com/dStranska "dStranska (2 commits)")

---

Tags

react-adminsymfonysymfony-bundle

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/freema-react-admin-api-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/freema-react-admin-api-bundle/health.svg)](https://phpackages.com/packages/freema-react-admin-api-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)

PHPackages © 2026

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