Examples

Small code that preserves design boundaries.

BEAR.Sunday code is centered on resources. Inputs, dependencies, links, and cross-cutting concerns remain visible, allowing the reader to trace the meaning of the application.

Resource

A resource corresponding to a URI decides its state and returns it.

final class Profile extends ResourceObject
{
    public function onGet(int $id): static
    {
        $this->body = $this->profileQuery->item($id);

        return $this;
    }
}

Dependency Injection

Required dependencies are made explicit in the constructor.

public function __construct(
    private readonly ProfileQuery $profileQuery,
    private readonly ClockInterface $clock,
) {
}

AOP

Cross-cutting concerns are offloaded to attributes and Interceptors.

#[Transactional]
#[Cacheable(expirySecond: 30)]
public function onPost(string $name): static
{
    $this->body = $this->command->create($name);

    return $this;
}

Hypermedia

Declare the next reachable resources as links.

#[Link(rel: 'orders', href: 'app://self/orders{?id}')]
#[Embed(rel: 'profile', src: 'app://self/profile{?id}')]
public function onGet(int $id): static
{
    return $this;
}

What this enables

Code examples show boundaries, not just usage.

Resources hold state; representation and transport are separated to the outside. Dependencies are injected; cross-cutting concerns go to AOP. This simple separation becomes the foundation for testing and extension.

  • Tests can be written per resource
  • The same resource can be used as Web API, HTML, and CLI
  • Caching and transactions are separated from business logic
  • Links and schemas make API documentation easy to assemble

Start with one resource

Start small, keep the structure.