# 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 |

## 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.
