Skip to content

Commit 86e400d

Browse files
authored
docs(api): add API reference (index + 4 core detail pages) (#25)
First half of the Phase 16 API documentation set. Adds `docs/api/` with an index of all 13 library subsystems and detail pages for the four subsystems any host touches first: Domain, Storage, Query, Field types. Every signature is quoted verbatim from the source and every example is lifted from the executable contract tests under `tests/Unit/Storage/*Contract.php`, so the snippets compile and are exercised on every CI run. The smaller subsystems (Cache, Templating, Http, Events, Validation) are covered with one-paragraph blurbs in the index; they'll get their own pages only if non-trivial host extension is expected. Also fixes a cosmetic CHANGELOG bug — the Phase 9 entry named the importer `FromV1Migrator`; the real class is `JsonV1Importer`, with `V1FileParser` as the AST reader.
1 parent a293308 commit 86e400d

6 files changed

Lines changed: 1546 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8787

8888
### Phase 9 — 1.x → 2.0 migration tool
8989

90-
- `Imanager\Migration\FromV1Migrator` reads 1.x's flat `buffers/` PHP
90+
- `Imanager\Migration\V1FileParser` reads 1.x's flat `buffers/` PHP
9191
files via `nikic/php-parser` (AST-safe, no `eval`/`include` of user
92-
data).
92+
data); `Imanager\Migration\JsonV1Importer` walks the parsed buffers
93+
and writes the new schema inside a single transaction.
9394
- Field-type-aware value translation; `--dry-run` produces a report.
9495
- Asset copy from legacy `data/uploads/<cat>.<id>.<field>/` into the
9596
new `data/uploads-2.0/<itemId>/<fieldId>/` layout.
@@ -150,3 +151,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
150151
updated; full test coverage (`feature/file-title-column`).
151152
- `feat(files): File::withPosition()` helper for ordered file
152153
re-numbering used by Scriptor's pages-edit drag-handle (#21).
154+
155+
### Phase 16 — Docs & examples (in progress)
156+
157+
- `DefaultBootstrap` factory wires the full standard service graph
158+
(PDO + schema migrations, Storage + 4 repositories, FieldTypeRegistry
159+
with all 16 built-ins, FilesystemCache, LocalFileStorage,
160+
ImageProcessor, NativeSessionStore, Csrf, PSR-14 dispatcher trio).
161+
`Bootstrap::boot()` stays minimal for hosts that want to swap any
162+
layer. Full test coverage in `tests/Unit/DefaultBootstrapTest`.
163+
- `README.md` rewrite — quickstart with runnable Blog example
164+
(verified against contract tests), concepts section, CLI table,
165+
roadmap pointers.
166+
- `docs/migration-guide.md` — 1.x → 2.0 walkthrough with dry-run,
167+
real, verify, and app-switch steps. Documents the deferred
168+
parent-id re-mapping issue and its SQL workaround.
169+
- `docs/api/` — API reference: index of 13 subsystems plus core
170+
detail pages for Domain (`domain.md`), Storage (`storage.md`),
171+
Query (`query.md`), and Field types (`field-types.md`). Examples
172+
lifted from `tests/Unit/Storage/*Contract.php` so every snippet
173+
compiles and is exercised on CI.

docs/api/README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# API Reference
2+
3+
Reference documentation for the iManager 2.0 library — every public class
4+
you can wire, extend, or call from a host application.
5+
6+
> **Where to start:** the [README quickstart](../../README.md#quickstart)
7+
> shows the shortest path from `composer require` to a saved item using
8+
> `Imanager\DefaultBootstrap::boot()`. This reference picks up from
9+
> there. It documents the *contracts* you can program against, not the
10+
> SQLite internals.
11+
12+
---
13+
14+
## Core (covered in detail here)
15+
16+
The four pages below cover ~90 % of what host code touches. Read them
17+
in order if you're new — each one builds on the previous.
18+
19+
- **[Domain](domain.md)**`Category`, `Field`, `Item`, `File`,
20+
`FieldValueBag`, and the nine domain events (`*Created`, `*Updated`,
21+
`*Deleted`). All domain objects are `final readonly`; you mutate by
22+
saving a new value.
23+
- **[Storage](storage.md)** — the `Storage` interface and its four
24+
repositories (`CategoryRepository`, `FieldRepository`,
25+
`ItemRepository`, `FileRepository`), `SqliteStorage` (the only
26+
bundled implementation), and the `transactional()` boundary. Also
27+
covers `SchemaManager` and `Migration`.
28+
- **[Query](query.md)** — the immutable `Query` builder, the
29+
`Clause` / `Operator` / `OrderBy` / `Direction` value objects,
30+
`Pagination`, and the `SelectorParser` shorthand
31+
(`name=Hello*, position>=5`).
32+
- **[Field types](field-types.md)** — the `FieldTypePlugin`
33+
interface, `FieldTypeRegistry`, the 16 built-in plugins, and the
34+
`ValidationResult` / `RenderContext` value objects you return /
35+
receive when writing your own type.
36+
37+
---
38+
39+
## Subsystem index
40+
41+
Every namespace under `Imanager\` at a glance. The "Reference" column
42+
either points to the detail page or — for the smaller subsystems —
43+
tells you which source file to read next.
44+
45+
| Namespace | What it does | Reference |
46+
|---|---|---|
47+
| `Imanager\Domain` | Typed primitives (`Category`, `Field`, `Item`, `File`) and domain events. The whole model is `final readonly`. | [Domain](domain.md) |
48+
| `Imanager\Storage` | Repository contracts and the SQLite implementation. Items are persisted as a `JSON` column with hot fields promoted to generated columns. | [Storage](storage.md) |
49+
| `Imanager\Query` | Immutable query builder + `SelectorParser` string DSL. `ItemRepository::query()` is the single execution entrypoint. | [Query](query.md) |
50+
| `Imanager\Field` | Field-type plugin system: 16 built-in types and the registry that resolves them by name. | [Field types](field-types.md) |
51+
| `Imanager\Enum` | `FieldType` (the 16 built-in enum cases), `SqliteAffinity` (storage class hint), `InputErrorCode` (validation error codes). | `src/Enum/` |
52+
| `Imanager\Files` | File-storage abstraction (`FileStorage` interface, `LocalFileStorage`), upload validation, and `ImageProcessor` for on-demand thumbnails. `FileRepository` (under `Storage`) tracks file *metadata*; this subsystem moves the bytes. | `src/Files/` |
53+
| `Imanager\Http` | Small request-layer toolkit: `SessionStore` (with `NativeSessionStore` default), `Csrf` (per-form tokens, capped LRU), and request/URL helpers. iManager does *not* ship a router. | `src/Http/` |
54+
| `Imanager\Cache` | PSR-16 cache contract and `FilesystemCache` (hash-keyed, two-level directory fanout, TTL metadata in-file). Used by Scriptor for section-cache; library itself stays uncached for predictability. | `src/Cache/` |
55+
| `Imanager\Search` | `FullTextSearch` over a SQLite FTS5 mirror of `items`. CLI command `fts:rebuild` rebuilds the index from scratch. | `src/Search/` |
56+
| `Imanager\Templating` | Single-purpose `{{var}}` substitution for short strings (pagination links, alerts). Caller is responsible for escaping. **Not** a view layer. | `src/Templating/` |
57+
| `Imanager\Validation` | `Sanitizer` facade over HTMLPurifier (sanitize) and Parsedown (markdown). Pure functions; safe to call repeatedly. | `src/Validation/` |
58+
| `Imanager\Events` | PSR-14 dispatcher (`SyncEventDispatcher`) and provider (`SubscriberListenerProvider`). Domain events flow through this; subscribe in your bootstrap. | `src/Events/` |
59+
| `Imanager\Exception` | Hierarchy rooted at the `ImanagerException` marker interface: `StorageException`, `ValidationException`, `NotFoundException`, `SchemaException`, `FieldTypeNotRegisteredException`. Catch the marker if you want a single net. | `src/Exception/` |
60+
| `Imanager\Cli` | Symfony Console application (`vendor/bin/imanager`). Commands: `schema:status`, `schema:migrate`, `migrate:from-v1`, `fts:rebuild`, `optimize`, `repair`, `dump`. | `src/Cli/` and the [README CLI table](../../README.md#cli) |
61+
62+
---
63+
64+
## Conventions used in this reference
65+
66+
- **`final readonly`** — every domain primitive and most value objects
67+
are immutable. Operations like `withId()`, `withTitle()`, or the
68+
builder methods on `Query` return a new instance.
69+
- **Method signatures** are quoted **verbatim** from the source — same
70+
parameter names, defaults, and return types. If something looks
71+
surprising, check the file path at the top of each page; the source
72+
wins, this doc follows.
73+
- **Examples** are lifted from the contract tests under
74+
`tests/Unit/Storage/*Contract.php`. Those tests run against both
75+
`SqliteStorage` and the `InMemory` storage shipped for testing — so
76+
every example you see compiles and is exercised on every CI run.
77+
- **Exceptions thrown** are listed under each method that can throw.
78+
Methods without a "Throws" line never throw in normal operation
79+
(errors surface as `null` returns or empty lists where appropriate).
80+
81+
---
82+
83+
## Roadmap
84+
85+
The four core pages cover the public API any application boots
86+
against. Still to come in Phase 16:
87+
88+
- `docs/field-types.md`**cookbook** (distinct from
89+
`docs/api/field-types.md` reference): how to write a custom field
90+
type end-to-end, including form rendering and validation patterns.
91+
- `docs/query-cookbook.md` — recipes for the `Query` builder and
92+
selector strings (faceted lookups, pagination flows, FTS hand-off).
93+
- `docs/deployment.md` — production deployment (Caddy / nginx, file
94+
permissions, backup, scheduled `optimize`).
95+
96+
The smaller subsystems (Cache, Templating, Http, Events, Validation)
97+
will get their own reference pages **only if** non-trivial host
98+
extension is expected — for now their source files are short and
99+
documented inline.

0 commit comments

Comments
 (0)