Run artifact

evidence/prompt_outputs/20261023.174534.245Z_readinglist_plan_claude.output.txt

=== BEGIN ARTIFACT ARCHITECTURE.md ===
# ARCHITECTURE: ReadingList

| Field | Value |
|-------|-------|
| Version | 20261023 V1 |
| Description | Modules, boundaries, and technical decisions for the ReadingList Flask web application. |
| Depends On | None |
| Provides | project tree, pytest -q |

## Questions

- None.

## Purpose

ReadingList is a single-reader web application. A reader adds a book with a title and author, views books in the order added, and removes books. Empty titles or authors are rejected with a clear error. The application ships automated tests and a POSIX `bin/test.sh`.

## Technology Stack

Derived from `TECHNOLOGY_STACK.md`; that file is the decision of record.

| Technology | Where it applies |
|------------|------------------|
| Python | Implementation language; project tree and environment. |
| Flask | Web framework; application factory `app_server.create_app()`. |
| SQLite | Persistence through the generated `persistence` package. |
| pytest | Automated tests, run as `pytest -q`. |
| HTML/CSS | Server-rendered pages with minimal CSS, no client-side JavaScript. |

## Project Layout

| Path | Role |
|------|------|
| `pyproject.toml`, `uv.lock` | Dependency manifest (Flask, pytest) and committed lockfile. |
| `.venv` | Environment created by `uv venv`. |
| `app_server/__init__.py` | `create_app() -> Flask`. |
| `app_server/testing.py` | `web_client()` plain callable. |
| `app_server/routes/` | Flask blueprints: JSON routes (`books.py`) and page routes (`pages.py`). |
| `app_server/services/books.py` | Book service: `add_book`, `list_books`, `remove_book`, `validate_book_input`. |
| `app_server/templates/` | Jinja templates (base layout, reading list page). |
| `persistence/` | Generated by Drydock from `DATABASE.md`; never hand-written. |
| `tests/` | pytest suite with `conftest.py` exposing the `web_client` and `db_session` fixtures. |
| `bin/test.sh` | POSIX test runner. |

## Module Ownership

| Boundary | Owning module | Allowed low-level access |
|----------|---------------|--------------------------|
| Persistence | `persistence` (generated) | The only module that touches SQLite. |
| Book rules and orchestration | `app_server.services.books` | Calls `db.books.<verb>(...)` only. |
| HTTP routes | `app_server.routes` | Call the service; never the database. |
| Configuration | `app_server.__init__` | Resolves `DATABASE_URL`, then `DATABASE_PATH`, then `data/app.db`. |
| File stores / external services | None | Not used. |

## Layering

Routes call services; services call `db.<table>.<verb>(...)`. SQL, sessions, table names, and column names never cross the persistence boundary. Books are always returned ordered by id ascending, which is the order added.

## Technical Decisions

- Test runner command is `pytest -q` from the application root.
- Rejected input returns 400; removal of an unknown book returns 404 (see `DECISIONS.json`).
- Server-rendered forms provide the user interface; JSON routes share the same services.

## Programmatic Acceptance

=== AC architecture-manifest ===
Intent: pyproject.toml parses and declares Flask and pytest as dependencies.
Requires: executable=python3; scope=test

import tomllib
from pathlib import Path

with open(Path("pyproject.toml"), "rb") as handle:
    data = tomllib.load(handle)

project = data["project"]
declared = list(project.get("dependencies", []))
for group in data.get("dependency-groups", {}).values():
    declared.extend(entry for entry in group if isinstance(entry, str))
declared.extend(
    entry
    for group in project.get("optional-dependencies", {}).values()
    for entry in group
)
names = [entry.lower() for entry in declared]
assert any(name.startswith("flask") for name in names)
assert any(name.startswith("pytest") for name in names)
=== END AC architecture-manifest ===

=== AC architecture-tree ===
Intent: The lockfile, tests directory, and conftest exist at the application root.

from pathlib import Path

assert Path("uv.lock").is_file()
assert Path("tests").is_dir()
assert Path("tests/conftest.py").is_file()
=== END AC architecture-tree ===

=== AC architecture-pytest ===
Intent: The pytest runner is installed and starts from the application root.
Requires: python-package=pytest; scope=test

import subprocess
import sys

result = subprocess.run(
    [sys.executable, "-m", "pytest", "--version"],
    capture_output=True,
    text=True,
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
assert result.returncode == 0
=== END AC architecture-pytest ===

## User Acceptance

- None.

## Guardrails

- Routes never call the database directly; they call services.
- No persistence code is written by hand; `persistence/` is generated from `DATABASE.md`.
- No technology outside `TECHNOLOGY_STACK.md` is introduced.
=== END ARTIFACT ===
=== BEGIN ARTIFACT FEATURE-AppShell.md ===
# FEATURE: App Shell

| Field | Value |
|-------|-------|
| Version | 20261023 V1 |
| Description | Flask application factory, shared page layout, test client fixture, and health route. |
| Depends On | ARCHITECTURE.md, DATABASE.md |
| Provides | create_app, app_server.testing.web_client, GET /health |
| Consumes | None |

## Questions

- None.

## Purpose

Provide the runnable Flask application that later features register routes on, plus the shared base template and the in-process test client used by acceptance and pytest.

## Trigger

A WSGI server or test harness calls `create_app()`.

## Sequence

1. `create_app()` builds a Flask app and resolves the database DSN (`DATABASE_URL`, then `DATABASE_PATH`, then `data/app.db`).
2. It opens the database with `open_database(dsn)` and keeps the handle for services.
3. It registers the book blueprints supplied by later stories; it invents no other routes.
4. `app_server.testing.web_client()` creates the app with `TESTING = True` and returns its test client.

## Routes

| Route | Behavior |
|-------|----------|
| `GET /health` | Returns 200 with a small JSON body `{"status": ...}`. |

## Layout

`app_server/templates/base.html` is the shared layout: page title block, content block, minimal inline or static CSS, no JavaScript.

## Reads

None.

## Writes

None.

## Database Interface

- None — persistence is owned by DATABASE.md.

## Programmatic Acceptance

=== AC appshell-factory ===
Intent: create_app returns a Flask application.
Requires: python-package=flask; scope=test

from flask import Flask
from app_server import create_app

app = create_app()
assert isinstance(app, Flask)
=== END AC appshell-factory ===

=== AC appshell-client ===
Intent: web_client returns a usable test client for a testing-mode app.
Requires: python-package=flask; scope=test

from app_server.testing import web_client

client = web_client()
assert client.application.config["TESTING"] is True
=== END AC appshell-client ===

=== AC appshell-health ===
Intent: GET /health is reachable and answers 200 with a JSON body.
Requires: python-package=flask; scope=test

from app_server.testing import web_client

client = web_client()
response = client.get("/health")
assert response.status_code == 200
assert isinstance(response.get_json(), dict)
=== END AC appshell-health ===

=== AC appshell-unknown-route ===
Intent: A path no feature declares is absent and answers 404.
Requires: python-package=flask; scope=test

from app_server.testing import web_client

client = web_client()
response = client.get("/route-nobody-declared")
assert response.status_code == 404
=== END AC appshell-unknown-route ===

## User Acceptance

- None.

## Guardrails

- The factory registers only routes declared by Blueprint features.
- The factory reaches the store only through `open_database`.
=== END ARTIFACT ===
=== BEGIN ARTIFACT FEATURE-AddBook.md ===
# FEATURE: Add Book

| Field | Value |
|-------|-------|
| Version | 20261023 V1 |
| Description | Add a book with a title and author, persist it, and return the stored book. |
| Depends On | FEATURE-AppShell.md, DATABASE.md |
| Provides | POST /books |
| Consumes | books.create, books.get |

## Questions

- None.

## Purpose

Let the reader add a book. A valid submission is stored and returned; the new book appears in later list reads.

## Trigger

A client sends `POST /books` with a JSON body.

## Sequence

1. The route parses the JSON body for `title` and `author`.
2. The service `app_server.services.books.add_book(db, title, author)` stores the book via `books.create`.
3. The route returns 201 with the stored book.

## Routes

| Route | Behavior |
|-------|----------|
| `POST /books` | JSON `{"title": ..., "author": ...}`. Returns 201 with JSON `{"id", "title", "author"}`. Validation of empty fields is owned by FEATURE-RejectEmptyFields.md. |

## Reads

`books.get` is used to return the stored row.

## Writes

`books.create` inserts one row per valid submission; ids ascend in insertion order.

## Database Interface

- `FEATURE-BOOK-001` — write: create a book - supplies: `title`, `author` - returns: `id`, `title`, `author`
- `FEATURE-BOOK-002` — read: retrieve a book by id - supplies: `id` - returns: `id`, `title`, `author`

## Tests

The build writes pytest tests under `tests/` covering a valid add, the 201 response fields, and a read-back of the stored row.

## Programmatic Acceptance

=== AC addbook-create ===
Intent: POST /books answers 201 and returns the title and author that were supplied, with an id.
Requires: python-package=flask; scope=test

from app_server.testing import web_client
from persistence.testing import committed_session

title = "ac-addbook-create-title"
author = "ac-addbook-create-author"
client = web_client()
created_id = None
try:
    response = client.post("/books", json={"title": title, "author": author})
    assert response.status_code == 201
    body = response.get_json()
    created_id = body["id"]
    assert isinstance(created_id, int)
    assert body["title"] == title
    assert body["author"] == author
finally:
    if created_id is not None:
        with committed_session() as db:
            db.books.delete(id=created_id)
=== END AC addbook-create ===

=== AC addbook-persisted ===
Intent: A submitted book is read back from the store with the supplied title and author.
Requires: python-package=flask; scope=test

from app_server.testing import web_client
from persistence.testing import committed_session

title = "ac-addbook-persist-title"
author = "ac-addbook-persist-author"
created_id = None
try:
    response = web_client().post("/books", json={"title": title, "author": author})
    assert response.status_code == 201
    created_id = response.get_json()["id"]
    with committed_session() as db:
        row = db.books.get(id=created_id)
        assert row.id == created_id
        assert row.title == title
        assert row.author == author
finally:
    if created_id is not None:
        with committed_session() as db:
            db.books.delete(id=created_id)
=== END AC addbook-persisted ===

=== AC addbook-ascending-ids ===
Intent: Two books added in sequence receive ascending ids, preserving insertion order.
Requires: python-package=flask; scope=test

from app_server.testing import web_client
from persistence.testing import committed_session

client = web_client()
created = []
try:
    for title in ["ac-addbook-seq-one", "ac-addbook-seq-two"]:
        response = client.post("/books", json={"title": title, "author": "ac-addbook-seq-author"})
        assert response.status_code == 201
        created.append(response.get_json()["id"])
    assert created[0] < created[1]
finally:
    with committed_session() as db:
        for book_id in created:
            db.books.delete(id=book_id)
=== END AC addbook-ascending-ids ===

## User Acceptance

- None.

## Guardrails

- The route never accesses the database directly; it calls the book service.
- A stored book keeps exactly the title and author supplied.
=== END ARTIFACT ===
=== BEGIN ARTIFACT FEATURE-RejectEmptyFields.md ===
# FEATURE: Reject Empty Fields

| Field | Value |
|-------|-------|
| Version | 20261023 V1 |
| Description | Reject a submission whose title or author is empty with a clear error and store nothing. |
| Depends On | FEATURE-AddBook.md |
| Provides | validate_book_input |
| Consumes | POST /books |

## Questions

- None.

## Purpose

Guarantee the application never accepts an empty title or empty author. Rejection reports a clear, human-readable error naming the offending field.

## Trigger

A submission to `POST /books` (or the page form route) carries a missing, empty, or whitespace-only title or author.

## Sequence

1. The service calls `validate_book_input(title, author)` in `app_server.services.books` before any store call.
2. A value that is missing, not a string, or empty after stripping surrounding whitespace raises `ValueError` whose message names the field (`title` or `author`).
3. `POST /books` converts the error to status 400 with JSON `{"error": <message>}`.
4. Nothing is stored; the book list is unchanged.

## Routes

This feature adds no route of its own; it governs `POST /books` provided by FEATURE-AddBook.md.

## Reads

None.

## Writes

None. A rejected submission writes nothing.

## Database Interface

- None — persistence is owned by FEATURE-AddBook.md.

## Tests

The build writes pytest tests for empty title, empty author, both empty, missing keys, and whitespace-only values, asserting status 400 and that the list is unchanged.

## Programmatic Acceptance

=== AC reject-empty-title ===
Intent: POST /books with an empty title answers 400 and stores nothing.
Requires: python-package=flask; scope=test

from app_server.testing import web_client
from persistence.testing import committed_session

client = web_client()
with committed_session() as db:
    before = len(list(db.books.list()))
response = client.post("/books", json={"title": "", "author": "ac-reject-author"})
assert response.status_code == 400
assert isinstance(response.get_json()["error"], str)
with committed_session() as db:
    after = len(list(db.books.list()))
assert after == before
=== END AC reject-empty-title ===

=== AC reject-empty-author ===
Intent: POST /books with an empty author answers 400 and stores nothing.
Requires: python-package=flask; scope=test

from app_server.testing import web_client
from persistence.testing import committed_session

client = web_client()
with committed_session() as db:
    before = len(list(db.books.list()))
response = client.post("/books", json={"title": "ac-reject-title", "author": ""})
assert response.status_code == 400
assert isinstance(response.get_json()["error"], str)
with committed_session() as db:
    after = len(list(db.books.list()))
assert after == before
=== END AC reject-empty-author ===

=== AC reject-both-empty ===
Intent: POST /books with both fields empty answers 400 and stores nothing.
Requires: python-package=flask; scope=test

from app_server.testing import web_client
from persistence.testing import committed_session

client = web_client()
with committed_session() as db:
    before = len(list(db.books.list()))
response = client.post("/books", json={"title": "", "author": ""})
assert response.status_code == 400
with committed_session() as db:
    after = len(list(db.books.list()))
assert after == before
=== END AC reject-both-empty ===

=== AC reject-whitespace-and-missing ===
Intent: Whitespace-only and missing fields are rejected with 400 and nothing is stored.
Requires: python-package=flask; scope=test

from app_server.testing import web_client
from persistence.testing import committed_session

client = web_client()
payloads = [
    {"title": "   ", "author": "ac-reject-ws-author"},
    {"title": "ac-reject-ws-title", "author": "   "},
    {"author": "ac-reject-missing-author"},
    {"title": "ac-reject-missing-title"},
]
with committed_session() as db:
    before = len(list(db.books.list()))
for payload in payloads:
    response = client.post("/books", json=payload)
    assert response.status_code == 400
with committed_session() as db:
    after = len(list(db.books.list()))
assert after == before
=== END AC reject-whitespace-and-missing ===

=== AC reject-validator ===
Intent: validate_book_input raises ValueError for an empty title or author.

from app_server.services.books import validate_book_input

for title, author in [("", "ac-validator-author"), ("ac-validator-title", ""), ("", "")]:
    try:
        validate_book_input(title, author)
    except ValueError:
        continue
    raise AssertionError("empty input was accepted")
=== END AC reject-validator ===

=== AC reject-valid-still-accepted ===
Intent: A submission with both fields present is still accepted with 201 after validation is in place.
Requires: python-package=flask; scope=test

from app_server.testing import web_client
from persistence.testing import committed_session

created_id = None
try:
    response = web_client().post(
        "/books", json={"title": "ac-reject-valid-title", "author": "ac-reject-valid-author"}
    )
    assert response.status_code == 201
    created_id = response.get_json()["id"]
finally:
    if created_id is not None:
        with committed_session() as db:
            db.books.delete(id=created_id)
=== END AC reject-valid-still-accepted ===

## User Acceptance

- None.

## Guardrails

- Never accept an empty title or an empty author.
- A rejected submission stores nothing.
- The error message names the offending field and is human-readable.
=== END ARTIFACT ===
=== BEGIN ARTIFACT FEATURE-ListBooks.md ===
# FEATURE: List Books

| Field | Value |
|-------|-------|
| Version | 20261023 V1 |
| Description | Return all books in the order they were added. |
| Depends On | FEATURE-AddBook.md, DATABASE.md |
| Provides | GET /books |
| Consumes | books.list |

## Questions

- None.

## Purpose

Let the reader view the books. Books are never presented in any order other than the order added.

## Trigger

A client sends `GET /books`.

## Sequence

1. The route calls `app_server.services.books.list_books(db)`.
2. The service calls `books.list`, which returns rows by id ascending.
3. The route returns 200 with a JSON array of `{"id", "title", "author"}` in that order.

## Routes

| Route | Behavior |
|-------|----------|
| `GET /books` | Returns 200 with a JSON array ordered by insertion. An empty list returns `[]`. |

## Reads

`books.list` returns every stored book ordered by id ascending.

## Writes

None.

## Database Interface

- `FEATURE-BOOK-003` — read: list books in the order added - returns: `id`, `title`, `author`

## Tests

The build writes pytest tests that add several books and assert the returned order equals the order submitted, plus the empty-list case.

## Programmatic Acceptance

=== AC listbooks-order ===
Intent: GET /books returns the books added during the check in the order they were added.
Requires: python-package=flask; scope=test

from app_server.testing import web_client
from persistence.testing import committed_session

client = web_client()
titles = ["ac-listbooks-order-first", "ac-listbooks-order-second", "ac-listbooks-order-third"]
created = []
try:
    for title in titles:
        response = client.post("/books", json={"title": title, "author": "ac-listbooks-author"})
        assert response.status_code == 201
        created.append(response.get_json()["id"])
    listing = client.get("/books")
    assert listing.status_code == 200
    body = listing.get_json()
    assert isinstance(body, list)
    mine = [book["id"] for book in body if book["id"] in created]
    assert mine == created
finally:
    with committed_session() as db:
        for book_id in created:
            db.books.delete(id=book_id)
=== END AC listbooks-order ===

=== AC listbooks-fields ===
Intent: Each listed book carries the supplied title and author and its id.
Requires: python-package=flask; scope=test

from app_server.testing import web_client
from persistence.testing import committed_session

title = "ac-listbooks-fields-title"
author = "ac-listbooks-fields-author"
client = web_client()
created_id = None
try:
    response = client.post("/books", json={"title": title, "author": author})
    assert response.status_code == 201
    created_id = response.get_json()["id"]
    body = client.get("/books").get_json()
    matches = [book for book in body if book["id"] == created_id]
    assert len(matches) == 1
    assert matches[0]["title"] == title
    assert matches[0]["author"] == author
finally:
    if created_id is not None:
        with committed_session() as db:
            db.books.delete(id=created_id)
=== END AC listbooks-fields ===

=== AC listbooks-reachable ===
Intent: GET /books is reachable and returns a JSON array even when no check data exists.
Requires: python-package=flask; scope=test

from app_server.testing import web_client

response = web_client().get("/books")
assert response.status_code == 200
assert isinstance(response.get_json(), list)
=== END AC listbooks-reachable ===

## User Acceptance

- None.

## Guardrails

- Never present books in any order other than the order they were added.
- The route never reads the database directly; it calls the book service.
=== END ARTIFACT ===