Metadata-Version: 2.5
Name: aoa-demo
Version: 3.18.0
Summary: Example FastAPI and MCP services demonstrating ActionMachine.
Project-URL: Homepage, https://github.com/action-machine/action-machine
Project-URL: Documentation, https://action-machine.readthedocs.io
Project-URL: Repository, https://github.com/action-machine/action-machine
Author: @Bystrov.Maxim
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Requires-Python: >=3.12
Requires-Dist: aoa-action-machine<2.0.0,>=1.2.0b1
Requires-Dist: aoa-ocel>=1.0.0a0
Requires-Dist: pydantic<3.0,>=2.0
Provides-Extra: fastapi
Requires-Dist: aoa-fastapi-adapter>=1.3.0; extra == 'fastapi'
Provides-Extra: mcp
Requires-Dist: aoa-mcp-adapter>=1.0.0a0; extra == 'mcp'
Provides-Extra: postgres
Requires-Dist: asyncpg<1.0,>=0.29; extra == 'postgres'
Description-Content-Type: text/markdown

<p align="center">
  <img src="https://raw.githubusercontent.com/bystrovmaxim/aoa/main/docs/assets/aoa-logo.png" alt="AOA" width="660"><br><br>
  <a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.12%2B-blue?logo=python&logoColor=white" alt="Python 3.12+"></a>
  <a href="https://github.com/bystrovmaxim/aoa"><img src="https://img.shields.io/badge/license-Apache_2.0-blue" alt="Apache-2.0"></a>
  <a href="https://github.com/bystrovmaxim/aoa/actions/workflows/ci.yml"><img src="https://github.com/bystrovmaxim/aoa/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
  <img src="https://img.shields.io/badge/tests-87-brightgreen" alt="87 tests">
  <img src="https://img.shields.io/badge/version-3.5.1-informational" alt="3.5.1">
</p>

# aoa-demo: Reference Services for AOA

`aoa-demo` contains two runnable reference services — a FastAPI HTTP service and an MCP server — built on the same domain model: orders, products, and customers. Both services expose the same `Action` operations over different transports, demonstrating how a single piece of business logic is published via `FastApiAdapter` for REST clients and via `McpAdapter` for AI agents without duplicating any logic. The package also serves as the integration fixture used in the AOA test suite.

## The identity domain: one connection per call, with or without a database

`POST /api/v1/identity/lookup` and the MCP tool `identity.lookup` are the reference
for a database-backed resource. The action declares `IdentityStoreBase` under the
connection key `identity`; the route supplies a value per call — created for the call
and closed after it — so concurrent calls never share a connection and each
transaction belongs to one caller. The domain asks storage for two things — a person,
and a login recorded inside a transaction — and each store supplies them its own way:
over PostgreSQL the domain runs its statements through the driver's protected helpers
(`_execute`, `_fetchrow`) from methods of its own, and in memory it answers from
dictionaries.

It runs in two modes, and only the supplied value differs:

| Mode | When | What the route supplies |
| --- | --- | --- |
| in memory | `AOA_DEMO_POSTGRES_DSN` is unset | `IdentityStoreStub` — the same two operations, no database, no driver |
| over a pool | the variable names a database | `IdentityStore(data_source=…)` — one connection per call from `IdentityDataSource`'s pool |

The identity data source, and with it the pool, is opened once when the service starts and closed when it stops. An MCP
service has no request-scoped startup hook, but its server has one, so both
transports pass the same `pool_lifespan` to `build()` — no wrapper to write.

```bash
# Database-free: answers from memory; needs no PostgreSQL and no driver.
uv run uvicorn aoa.demo.fastapi_mcp_services.app_fastapi_service:app --port 8000

# Over a pool: install the extra and name the database.
uv add "aoa-demo[postgres]"
AOA_DEMO_POSTGRES_DSN=postgresql://user:pass@localhost/db \
  uv run uvicorn aoa.demo.fastapi_mcp_services.app_fastapi_service:app --port 8000
```

The pool states its size bounds (`min_size=1, max_size=10`) where the data source is
created; the wait for a free connection is bounded on the data source
(`IdentityDataSource.acquire_timeout = 30.0`), because `create_pool` has no such parameter
— a `timeout=` there would bound connecting, not waiting.

What each mode is for, and what the resource does with its connection, is in
[`src/aoa/demo/model/identity/README.md`](src/aoa/demo/model/identity/README.md).

## Its databases: resources that share one store

A resource is often a part of a database rather than the whole of it. The demo's model has
three databases, each a data source (`aoa.demo.model.data_sources`) that several of its
resources name as their type argument — `class SupportStorage(BaseStorage[ShopDataSource])`:

| Data source | Resources | What it shows |
| --- | --- | --- |
| `ShopDataSource` | `StorefrontDatabase` (Store), `SupportStorage` (Support), `InventoryStorage` (Inventory) | a support ticket relates to the order and the customer it is about — across resources and across domains, inside one database |
| `MessagingDataSource` | `OutboxPrimaryDatabase`, `MessagingDeadLetterStore` (Messaging) | a replay ticket in the dead-letter queue relates to the outbox message it replays |
| `CatalogDataSource` | `CatalogObjectStore` (Catalog) | a database with one resource |

Every other resource names no data source and keeps its relations to itself; a relation
across two databases is refused when the model is built. The graph shows each data source
on the application, with a `resource_data_source` edge from each of its resources. The
identity route's `IdentityDataSource` is the runtime pool of the section above; its resource
imports the PostgreSQL driver and is reached lazily, so it is not in the graph.

## Its graph history

The demo keeps its graph in [`graph.json`](graph.json), rebuilt by `graph-builder write` with every change of its model, so the file's git history is the graph's history. Paste this link into Maxitor's **AOA Service URL** field to walk through it, compare any two versions, and see the open pull requests after the newest one:

```text
https://github.com/bystrovmaxim/aoa/blob/main/packages/aoa-demo/graph.json?version_link=https%3A%2F%2Fgithub.com%2Fbystrovmaxim%2Faoa%2Fblob%2Fmain%2Fpackages%2Faoa-demo%2Fpyproject.toml&version_key=project.version
```

The version under each point comes from this package's `pyproject.toml`. How to read the track is in [Open a service's graph history](https://github.com/bystrovmaxim/gnomon/blob/main/docs/how-to/open-a-graph-history.md).
