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

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