PHPackages                             milpa/live - 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. [Framework](/categories/framework)
4. /
5. milpa/live

ActiveLibrary[Framework](/categories/framework)

milpa/live
==========

Render-target-agnostic live component primitives for the Milpa PHP framework: contracts, value objects, components, data sources, and the event-driven mount/handle/render lifecycle.

v0.4.1(3w ago)01.4k↑890%5Apache-2.0PHPPHP &gt;=8.3CI passing

Since Jul 8Pushed 1mo agoCompare

[ Source](https://github.com/getmilpa/live)[ Packagist](https://packagist.org/packages/milpa/live)[ RSS](/packages/milpa-live/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (18)Versions (7)Used By (5)

 [   ![Milpa](https://raw.githubusercontent.com/getmilpa/core/main/art/lockup/milpa-lockup-v-color-light.svg)  ](https://github.com/getmilpa)

Milpa Live
==========

[](#milpa-live)

> **Render-target-agnostic live components** for the Milpa PHP framework — the same component definition renders to **web AND terminal**; state, data sources, and an event-driven interception seam, no HTML or ANSI in the component itself.

[![CI](https://github.com/getmilpa/live/actions/workflows/ci.yml/badge.svg)](https://github.com/getmilpa/live/actions/workflows/ci.yml)[![Packagist](https://camo.githubusercontent.com/1efdca239d28eab8d0a77ac39eca133d1f3a94272b1730d047eb8591189ba5ee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d696c70612f6c6976652e737667)](https://packagist.org/packages/milpa/live)[![PHP](https://camo.githubusercontent.com/ca03f11ea27dac4dedc8ad56a7bdfc4a9ff5feb825055f9d2983616115076607/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d254532253839254135253230382e332d3737376262342e737667)](https://www.php.net/)[![License](https://camo.githubusercontent.com/798509b4df525f56802b56f8096862487f08023e3d7561c68656f8dab10d0d6e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4170616368652d2d322e302d626c75652e737667)](LICENSE)[![Docs](https://camo.githubusercontent.com/c6dc6a3411e15b0ac7cc4583e8e6a8144181caedb82f5d98753353decda06d77/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63732d4150492532307265666572656e63652d626c75652e737667)](https://getmilpa.github.io/live/)

`milpa/live` is the render-target-agnostic core of Milpa's live component system: a component owns its **contract** (props/state schema, declared actions), its **initial state** (`mount()`), and how it reacts to client-originated actions (`handle()`) — but never how it turns into markup or terminal output. That's a [`ComponentRendererInterface`](src/Contracts/Rendering/ComponentRendererInterface.php)'s job, paired with the component at the call site. One component, any number of renderers.

Install
-------

[](#install)

```
composer require milpa/live
```

Quick example
-------------

[](#quick-example)

A minimal component plus two renderers — one for HTML, one for TUI — sharing the exact same `mount()`/`handle()` logic:

```
use Milpa\Live\Contracts\Component\ComponentDefinitionInterface;
use Milpa\Live\Contracts\Rendering\ComponentRendererInterface;
use Milpa\Live\ValueObjects\{
    ComponentContext, ComponentContract, InteractionRequest,
    InteractionResult, RenderRequest, RenderResult, RenderTarget, StateSnapshot,
};

final class CounterComponent implements ComponentDefinitionInterface
{
    public static function contract(): ComponentContract
    {
        return new ComponentContract(name: 'counter', contractVersion: '1.0.0', actions: ['increment' => []]);
    }

    public function mount(array $props, ComponentContext $context): StateSnapshot
    {
        return new StateSnapshot(
            componentId: $context->componentId,
            componentName: 'counter',
            version: '1.0.0',
            data: ['count' => (int) ($props['start'] ?? 0)],
        );
    }

    public function handle(InteractionRequest $request): InteractionResult
    {
        return new InteractionResult(state: new StateSnapshot(
            componentId: $request->state->componentId,
            componentName: $request->state->componentName,
            version: $request->state->version,
            data: ['count' => $request->state->data['count'] + 1],
        ));
    }
}

final class HtmlCounterRenderer implements ComponentRendererInterface
{
    public function supportsTarget(RenderTarget $target): bool
    {
        return $target === RenderTarget::HTML;
    }

    public function render(ComponentDefinitionInterface $component, RenderRequest $request): RenderResult
    {
        $state = $request->state ?? $component->mount($request->props, $request->context);

        return new RenderResult(
            output: sprintf('Count: %d', $state->data['count'], $state->data['count']),
            state: $state,
            format: RenderTarget::HTML,
        );
    }
}

final class TuiCounterRenderer implements ComponentRendererInterface
{
    public function supportsTarget(RenderTarget $target): bool
    {
        return $target === RenderTarget::TUI;
    }

    public function render(ComponentDefinitionInterface $component, RenderRequest $request): RenderResult
    {
        $state = $request->state ?? $component->mount($request->props, $request->context);

        return new RenderResult(output: "[ Count: {$state->data['count']} ]", state: $state, format: RenderTarget::TUI);
    }
}

$component = new CounterComponent();
$context = new ComponentContext('demo-1');

$html = (new HtmlCounterRenderer())->render($component, new RenderRequest(context: $context, target: RenderTarget::HTML));
echo $html->output; // Count: 0

$tui = (new TuiCounterRenderer())->render($component, new RenderRequest(context: $context, target: RenderTarget::TUI));
echo $tui->output; // [ Count: 0 ]
```

`CounterComponent` never printed a single tag or escape code — both renderers turned the exact same `StateSnapshot` into their own output, independently.

Web + TUI from one component
----------------------------

[](#web--tui-from-one-component)

That's the thesis this package is built around: **a component definition is a pure description of state and behavior; rendering is a separate, swappable concern.** A `ComponentRendererInterface` declares which [`RenderTarget`](src/ValueObjects/RenderTarget.php)(s) it supports (`HTML`, `TUI`, or the forward-looking `ANSI`) and turns a mounted `StateSnapshot` into output for that target — nothing in `ComponentDefinitionInterface`ever needs to know which renderer, or how many, will consume it.

`milpa/live` ships the component contracts, the mount/handle lifecycle, data sources, and the event-driven interception seam (`component.mounting`/`mounted`, `component.handling`/`handled`, `component.rendering`/`rendered` — see [`LiveEventEmitter`](src/Events/LiveEventEmitter.php)) — but **no HTML and no ANSI renderer**. The web surface (`AutocompleteHtmlRenderer` and friends) lives in `milpa/live-web`; a TUI renderer is a live candidate in the Milpa lab. This package is the seam both build on, not either surface itself.

Requirements
------------

[](#requirements)

- PHP **≥ 8.3**
- `milpa/core` **^0.6**
- `psr/log` **^3**

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

[](#documentation)

**Full API reference: [getmilpa.github.io/live](https://getmilpa.github.io/live/)** — generated straight from the source DocBlocks and dressed with the Milpa design system.

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

[](#contributing)

Contributions are welcome — see [CONTRIBUTING.md](CONTRIBUTING.md). Please report security issues via [SECURITY.md](SECURITY.md), and note that this project follows a [Code of Conduct](CODE_OF_CONDUCT.md).

License
-------

[](#license)

[Apache-2.0](LICENSE) © Rodrigo Vicente - TeamX Agency.

---

Milpa is designed, built, and maintained by **[Rodrigo Vicente - TeamX Agency](https://teamx.agency/?utm_source=github&utm_medium=readme&utm_campaign=milpa&utm_content=live)**.

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance93

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.8% 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 ~5 days

Total

6

Last Release

24d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1993784?v=4)[rodrigomx](/maintainers/rodrigomx)[@rodrigomx](https://github.com/rodrigomx)

---

Top Contributors

[![rodrigoteamx](https://avatars.githubusercontent.com/u/269849276?v=4)](https://github.com/rodrigoteamx "rodrigoteamx (7 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (2 commits)")

---

Tags

frameworklive-componentsphprender-agnosticphpframeworkcomponentsreactivelive-componentsmilparender-agnostic

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/milpa-live/health.svg)

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

###  Alternatives

[laravel/framework

The Laravel Framework.

34.9k556.2M21.6k](/packages/laravel-framework)[symfony/symfony

The Symfony PHP framework

31.4k87.4M2.2k](/packages/symfony-symfony)

PHPackages © 2026

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