Run artifact

evidence/prompt_outputs/20261023.144733.336Z_readinglist_plan_claude.output.txt

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

| Field | Value |
|-------|-------|
| Version | 20261023 V1 |
| Description | Modules, routes, boundaries, and technical decisions for the ReadingList web application. |
| Depends On | None |
| Provides | create_app |

## Questions

- None.

## Purpose

ReadingList is a small Flask web application that keeps an ordered list of books to read. A reader adds a book (title and author), views books in the order added, and removes a book. Empty titles or authors are rejected with a reason.

## Technology Stack

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

| Technology | Where it applies |
|------------|------------------|
| Python | Implementation language, project root, `.venv` environment, `pyproject.toml`, committed `uv.lock` |
| Flask | Web framework behind `app_server.create_app()` |
| SQLite | Persistence store behind the generated `persistence` package |
| pytest | Automated test runner, invoked as `pytest -q` from the application root |
| HTML/CSS | Server-rendered pages using Jinja templates |

## Modules

| Module | Responsibility |
|--------|----------------|
| `app_server/__init__.py` | `create_app() -> Flask` application factory; registers routes, templates, and error handlers |
| `app_server/testing.py` | `web_client()` returning a Flask test client with `TESTING` enabled |
| `app_server/templates/` | Jinja templates, including `base.html` |
| `persistence/` | Generated by Drydock from `DATABASE.md`; never written by hand |
| `tests/` | Project pytest suite; `conftest.py` exposes `web_client` and `db_session` fixtures |
| `bin/test.sh` | POSIX `sh` runner for the complete suite (owned by the verification story) |

## Module Ownership

| Boundary | Owning module | Allowed low-level access |
|----------|---------------|--------------------------|
| Persistence | `persistence/` (generated) | Only this package touches the SQLite driver |
| Configuration | `app_server/__init__.py` | Resolves `DATABASE_URL`, then `DATABASE_PATH`, then `data/app.db` |
| File store | None | Not used |
| External services | None | Not used |

Routes call `db.books.<verb>(...)` on the object returned by `open_database(...)`. SQL, table names, and column names never appear in route code.

## Routes

| Route | Owner | Purpose |
|-------|-------|---------|
| `GET /` | SCREEN-ReadingList.md | Reading list page |
| `GET /books` | FEATURE-ListBooks.md | JSON array of books in the order added |
| `POST /books` | FEATURE-AddBook.md | Add a book; validation owned by the rejection features |
| `POST /books/{id}/delete` | FEATURE-RemoveBook.md | Remove a book |

## Technical Decisions

- Success responses to form posts are `303` redirects to `/`; rejections are `400`; an unknown book id is `404`.
- Order added is the ascending integer primary key `id`; no position column exists.
- A rejection always carries a non-empty reason.

## Programmatic Acceptance

=== AC arch-create-app ===
Intent: The application factory returns a Flask application.
Suite: scoped

from flask import Flask
from app_server import create_app

app = create_app()
assert isinstance(app, Flask)
=== END AC arch-create-app ===

=== AC arch-web-client ===
Intent: The published web_client callable yields a test client that answers an unregistered path with 404.
Suite: scoped

from app_server.testing import web_client

client = web_client()
response = client.get("/arch-no-such-route")
assert response.status_code == 404
=== END AC arch-web-client ===

=== AC arch-project-root ===
Intent: The project root carries the dependency manifest, lockfile, and test conftest.
Suite: scoped

from pathlib import Path

for name in ("pyproject.toml", "uv.lock", "tests/conftest.py"):
    assert Path(name).is_file(), name
=== END AC arch-project-root ===

## User Acceptance

- None.

## Guardrails

- No SQL, session, table name, or column name appears outside the generated `persistence` package.
- No technology is introduced that `TECHNOLOGY_STACK.md` does not list.
=== END ARTIFACT ===
=== BEGIN ARTIFACT UI-GENERAL.md ===
# UI-GENERAL: ReadingList

| Field | Value |
|-------|-------|
| Version | 20261023 V1 |
| Description | Shared page layout and error region used by every ReadingList page. |
| Depends On | ARCHITECTURE.md, DATABASE.md |
| Provides | base layout template |

## Questions

- None.

## Layout

All pages extend `app_server/templates/base.html`.

| Element | Template name | Behavior |
|---------|---------------|----------|
| Page title | `block title` | Defaults to `Reading List` |
| Main content | `block content` | Filled by each page |
| Error region | variable `error` | When `error` is set and non-empty, an element with `role="alert"` shows the text; otherwise nothing is rendered |

## Wiring

`create_app()` configures the Jinja template folder `app_server/templates` and initializes persistence through `open_database(...)` using the configured store. No book routes are registered by this story.

## Programmatic Acceptance

=== AC ui-base-template-loads ===
Intent: The base layout template is available to the application.
Suite: scoped

from app_server import create_app

app = create_app()
template = app.jinja_env.get_template("base.html")
assert template is not None
=== END AC ui-base-template-loads ===

=== AC ui-base-shows-error ===
Intent: The base layout renders the supplied error text in its error region.
Suite: scoped

from flask import render_template
from app_server import create_app

app = create_app()
message = "bound error reason"
with app.test_request_context("/"):
    html = render_template("base.html", error=message)
assert message in html
=== END AC ui-base-shows-error ===

=== AC ui-base-without-error ===
Intent: The base layout renders without an error and does not show an alert region.
Suite: scoped

from flask import render_template
from app_server import create_app

app = create_app()
with app.test_request_context("/"):
    html = render_template("base.html")
assert 'role="alert"' not in html
=== END AC ui-base-without-error ===

## User Acceptance

- The page looks clean and readable in a browser.

## Guardrails

- The layout never hides a supplied error message.
=== END ARTIFACT ===
=== BEGIN ARTIFACT FEATURE-AddBook.md ===
# FEATURE: Add Book

| Field | Value |
|-------|-------|
| Version | 20261023 V1 |
| Description | A reader adds a book with a title and an author and it is stored. |
| Depends On | ARCHITECTURE.md, DATABASE.md, UI-GENERAL.md |
| Provides | POST /books |
| Consumes | books.create |

## Questions

- None.

## Purpose

Let a reader add a book to the end of the reading list.

## Trigger

A form post to `POST /books` with fields `title` and `author`.

## Sequence

1. Read `title` and `author` from the form, trimmed of surrounding whitespace.
2. Validation of empty values is owned by FEATURE-RejectEmptyTitle.md and FEATURE-RejectEmptyAuthor.md; this feature handles valid submissions.
3. Store the book through `db.books.create(title=..., author=...)`.
4. Answer `303` redirecting to `/`.

## Reads

- None.

## Writes

- One new book via `books.create`.

## Database Interface

- `FEATURE-BOOKS-001` — write: create a book - supplies: `title`, `author` - returns: `id`, `title`, `author`

## Programmatic Acceptance

=== AC add-book-redirects ===
Intent: A valid submission is accepted with a 303 redirect.
Suite: scoped

from app_server.testing import web_client

client = web_client()
marker = "ac-add-redirect"

def cleanup():
    for row in client.get("/books").get_json():
        if marker in row["title"]:
            client.post(f"/books/{row['id']}/delete")

cleanup()
try:
    response = client.post("/books", data={"title": marker + " title", "author": marker + " author"})
    assert response.status_code == 303
finally:
    cleanup()
=== END AC add-book-redirects ===

=== AC add-book-round-trip ===
Intent: An added book is read back through GET /books with the supplied title and author.
Suite: scoped

from app_server.testing import web_client

client = web_client()
marker = "ac-add-roundtrip"
title = marker + " title"
author = marker + " author"

def cleanup():
    for row in client.get("/books").get_json():
        if marker in row["title"]:
            client.post(f"/books/{row['id']}/delete")

cleanup()
try:
    response = client.post("/books", data={"title": title, "author": author})
    assert response.status_code == 303
    listed = client.get("/books")
    assert listed.status_code == 200
    ours = [row for row in listed.get_json() if row["title"] == title]
    assert len(ours) == 1
    assert ours[0]["author"] == author
    assert ours[0]["id"] is not None
finally:
    cleanup()
=== END AC add-book-round-trip ===

=== AC add-book-persists-in-store ===
Intent: An added book is present in the configured store when read through the persistence package.
Suite: scoped

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

client = web_client()
marker = "ac-add-store"
title = marker + " title"
author = marker + " author"

def cleanup():
    for row in client.get("/books").get_json():
        if marker in row["title"]:
            client.post(f"/books/{row['id']}/delete")

cleanup()
try:
    response = client.post("/books", data={"title": title, "author": author})
    assert response.status_code == 303
    with committed_session() as db:
        rows = [row for row in db.books.list() if row.title == title]
    assert len(rows) == 1
    assert rows[0].author == author
finally:
    cleanup()
=== END AC add-book-persists-in-store ===

## User Acceptance

- None.

## Guardrails

- A stored book always has a non-empty title and a non-empty author.
- A newly added book is appended after every existing book.
=== END ARTIFACT ===
=== BEGIN ARTIFACT FEATURE-ListBooks.md ===
# FEATURE: List Books

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

## Questions

- None.

## Purpose

Let a reader (and the reading list page) view every book in the order added.

## Trigger

A `GET /books` request.

## Sequence

1. Call `db.books.list()`, which returns rows by ascending `id`.
2. Respond `200` with a JSON array of objects carrying `id`, `title`, and `author`, in that same order.
3. An empty store yields an empty array.

## Reads

- All books via `books.list`.

## Writes

- None.

## Database Interface

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

## Programmatic Acceptance

=== AC list-books-ok ===
Intent: GET /books answers 200 with a JSON array whose items carry id, title, and author.
Suite: scoped

from app_server.testing import web_client

client = web_client()
marker = "ac-list-shape"
title = marker + " title"
author = marker + " author"

def cleanup():
    for row in client.get("/books").get_json():
        if marker in row["title"]:
            client.post(f"/books/{row['id']}/delete")

cleanup()
try:
    assert client.post("/books", data={"title": title, "author": author}).status_code == 303
    response = client.get("/books")
    assert response.status_code == 200
    body = response.get_json()
    assert isinstance(body, list)
    ours = [row for row in body if row["title"] == title]
    assert len(ours) == 1
    assert set(["id", "title", "author"]) <= set(ours[0].keys())
finally:
    cleanup()
=== END AC list-books-ok ===

=== AC list-books-order-added ===
Intent: Books are listed in the order they were added.
Suite: scoped

from app_server.testing import web_client

client = web_client()
marker = "ac-list-order"
titles = [marker + " third-added-last", marker + " a-first", marker + " m-second"]

def cleanup():
    for row in client.get("/books").get_json():
        if marker in row["title"]:
            client.post(f"/books/{row['id']}/delete")

cleanup()
try:
    for t in titles:
        assert client.post("/books", data={"title": t, "author": marker + " author"}).status_code == 303
    body = client.get("/books").get_json()
    ours = [row["title"] for row in body if marker in row["title"]]
    assert ours == titles
    ids = [row["id"] for row in body if marker in row["title"]]
    assert ids == sorted(ids)
finally:
    cleanup()
=== END AC list-books-order-added ===

=== AC list-books-matches-store ===
Intent: The listed sequence of ids matches the persistence package's own listing.
Suite: scoped

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

client = web_client()
marker = "ac-list-store"

def cleanup():
    for row in client.get("/books").get_json():
        if marker in row["title"]:
            client.post(f"/books/{row['id']}/delete")

cleanup()
try:
    for n in range(3):
        assert client.post("/books", data={"title": f"{marker} {n}", "author": marker + " author"}).status_code == 303
    http_ids = [row["id"] for row in client.get("/books").get_json()]
    with committed_session() as db:
        store_ids = [row.id for row in db.books.list()]
    assert http_ids == store_ids
finally:
    cleanup()
=== END AC list-books-matches-store ===

## User Acceptance

- None.

## Guardrails

- Books are never presented in any order other than the order added.
- The listing never omits a stored book and never shows a removed one.
=== END ARTIFACT ===
=== BEGIN ARTIFACT FEATURE-RemoveBook.md ===
# FEATURE: Remove Book

| Field | Value |
|-------|-------|
| Version | 20261023 V1 |
| Description | A reader removes a book so it no longer appears in the list. |
| Depends On | ARCHITECTURE.md, DATABASE.md, FEATURE-AddBook.md |
| Provides | POST /books/{id}/delete |
| Consumes | books.get, books.delete |

## Questions

- None.

## Purpose

Let a reader remove a book from the reading list.

## Trigger

A form post to `POST /books/{id}/delete`.

## Sequence

1. Look up the book with `db.books.get(id=...)`.
2. If it does not exist, answer `404` and change nothing.
3. Otherwise delete it with `db.books.delete(id=...)` and answer `303` redirecting to `/`.
4. Remaining books keep their relative order.

## Reads

- One book via `books.get`.

## Writes

- One deletion via `books.delete`.

## Database Interface

- `FEATURE-BOOKS-003` — read: get a book by id - supplies: `id` - returns: `id`, `title`, `author`
- `FEATURE-BOOKS-004` — write: delete a book - supplies: `id` - returns: `id`

## Programmatic Acceptance

=== AC remove-book-omitted-on-next-read ===
Intent: A removed book is answered with 303 and is absent on the next read.
Suite: scoped

from app_server.testing import web_client

client = web_client()
marker = "ac-remove-gone"
title = marker + " title"

def cleanup():
    for row in client.get("/books").get_json():
        if marker in row["title"]:
            client.post(f"/books/{row['id']}/delete")

cleanup()
try:
    assert client.post("/books", data={"title": title, "author": marker + " author"}).status_code == 303
    ours = [row for row in client.get("/books").get_json() if row["title"] == title]
    assert len(ours) == 1
    book_id = ours[0]["id"]
    response = client.post(f"/books/{book_id}/delete")
    assert response.status_code == 303
    after = [row["id"] for row in client.get("/books").get_json()]
    assert book_id not in after
finally:
    cleanup()
=== END AC remove-book-omitted-on-next-read ===

=== AC remove-book-keeps-order ===
Intent: Removing one book leaves the other books in their original relative order.
Suite: scoped

from app_server.testing import web_client

client = web_client()
marker = "ac-remove-order"
titles = [marker + " one", marker + " two", marker + " three"]

def cleanup():
    for row in client.get("/books").get_json():
        if marker in row["title"]:
            client.post(f"/books/{row['id']}/delete")

cleanup()
try:
    for t in titles:
        assert client.post("/books", data={"title": t, "author": marker + " author"}).status_code == 303
    rows = [row for row in client.get("/books").get_json() if marker in row["title"]]
    middle = rows[1]
    assert client.post(f"/books/{middle['id']}/delete").status_code == 303
    remaining = [row["title"] for row in client.get("/books").get_json() if marker in row["title"]]
    assert remaining == [titles[0], titles[2]]
finally:
    cleanup()
=== END AC remove-book-keeps-order ===

=== AC remove-book-unknown-id ===
Intent: Removing an id that does not exist answers 404 and removes nothing.
Suite: scoped

from app_server.testing import web_client

client = web_client()
marker = "ac-remove-unknown"

def cleanup():
    for row in client.get("/books").get_json():
        if marker in row["title"]:
            client.post(f"/books/{row['id']}/delete")

cleanup()
try:
    assert client.post("/books", data={"title": marker + " title", "author": marker + " author"}).status_code == 303
    before = [row["id"] for row in client.get("/books").get_json()]
    unknown_id = max(before) + 1000000
    response = client.post(f"/books/{unknown_id}/delete")
    assert response.status_code == 404
    after = [row["id"] for row in client.get("/books").get_json()]
    assert after == before
finally:
    cleanup()
=== END AC remove-book-unknown-id ===

## User Acceptance

- None.

## Guardrails

- Removing a book never changes the relative order of the remaining books.
- An unknown id never changes stored data.
=== END ARTIFACT ===