Run artifact

workspace/targets/Quakes/blueprint/ARCHITECTURE.md

ARCHITECTURE: Quakes

FieldValue
Version20261025 V1
DescriptionModule layout, boundaries, and technical decisions for the standard-library-only quakes command-line earthquake reporter.
Depends OnNone
Providesproject tree, pytest runner

Purpose

quakes is a single-process Python 3.11+ command-line tool at the application root. fetch downloads a USGS FDSN GeoJSON feed to a file. Five report commands (summary, top, daily, regions, near) read a saved file, filter it, compute rows, and print CSV to standard output.

Technology Stack

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

TechnologyWhere it applies
Python 3.11+ (standard library only)All application code. urllib.request for HTTP, json, csv, decimal, datetime, math, re.
CLIThe quakes executable and the cli package.
pytestTest runner behind bin/test.sh; the only development dependency.
USGS GeoJSONInput format.
POSIX shbin/test.sh.

Project Layout

PathRole
quakesExecutable launcher at the application root; calls cli.main and exits with its return value.
pyproject.toml, uv.lockDependency manifest and lockfile. Runtime dependencies: none.
.venvEnvironment created by uv venv.
conftest.pyExposes the cli_runner pytest fixture from cli.testing.
cli/__init__.pymain(argv=None) -> int, the command registry COMMANDS, exit-code mapping.
cli/errors.pyUsageError (exit 2) and OperationalError (exit 1).
cli/options.pyparse_args(argv) -> Parsed.
cli/formatting.pyformat_time, format_mag, format_mean, format_decimal, render_csv, write_csv.
cli/feed.pyread_feed(path), extract_events(features), Event, filter_events(events, min_mag).
cli/reports.pyOne pure function per report, plus haversine_km.
cli/fetch.pybuild_url, http_get, the fetch command.
cli/testing.pycli_runner(*args) -> (exit_code, stdout, stderr).
tests/Application pytest suite.
bin/test.shPOSIX sh wrapper that runs the pytest suite.
sources/Read-only scoring assets; never modified and never read by application code.

Boundaries and Interfaces

Reading the file, filtering, computing each report, and formatting are separate functions:

  1. read_feed(path) -> list[dict] validates and returns raw features.
  2. extract_events(features) -> list[Event] normalizes and drops null-magnitude events.
  3. filter_events(events, min_mag) -> list[Event] applies --min-mag.
  4. A report function maps events (and its options) to a list of rows, each row a list of already-formatted strings.
  5. write_csv(rows, stream=None) writes rows with the csv module.

Parsed (returned by parse_args) is a dataclass with fields command: str, min_mag: float | None, n: int, lat: float | None, lon: float | None, radius: float | None, start: str | None, end: str | None, out: str | None, file: str | None. n defaults to 10. min_mag is None for report commands when omitted and 2.5 for fetch when omitted.

Command handlers are registered in cli.COMMANDS: dict[str, Callable[[Parsed], str]]. A handler returns the complete standard-output text for the command. main writes that text to standard output only after the handler returns, so a failing command leaves standard output empty.

Exit Codes and Channels

CodeCause
0Success, including a report with no matching events.
1OperationalError: unreadable file, not a FeatureCollection, fetch network/HTTP/body failure.
2UsageError: any malformed invocation.

A failing command writes nothing to standard output and exactly one diagnostic line to standard error. Standard error is never compared by the grader.

Technical Decisions

Module Ownership

No persistent store, configuration file, or external service other than the USGS HTTP endpoint exists. File I/O is owned by cli.feed (reading) and cli.fetch (writing the fetched file). HTTP is owned by cli.fetch.http_get. No DATABASE.md applies.

Programmatic Acceptance

=== AC arch-project-files ===
Intent: The project root carries a dependency manifest, lockfile, tests directory, and a conftest exposing the cli_runner fixture.
Suite: scoped

from pathlib import Path

assert Path("pyproject.toml").is_file() assert Path("uv.lock").is_file() assert Path("tests").is_dir() conftest = Path("conftest.py") assert conftest.is_file() assert "cli_runner" in conftest.read_text(encoding="utf-8") === END AC arch-project-files ===

=== AC arch-stdlib-only ===
Intent: The project declares no runtime dependencies and requires Python 3.11 or newer.

import sys import tomllib from pathlib import Path

data = tomllib.loads(Path("pyproject.toml").read_text(encoding="utf-8")) project = data["project"] assert project.get("dependencies", []) == [] assert sys.version_info >= (3, 11) === END AC arch-stdlib-only ===

=== AC arch-pytest-available ===
Intent: The pytest runner is importable in the project environment.

import importlib.util

assert importlib.util.find_spec("pytest") is not None === END AC arch-pytest-available ===

User Acceptance

Guardrails