From 3f0fba7228dc8e332ca4625c09d8a313d904f840 Mon Sep 17 00:00:00 2001 From: Alberto Moretti Date: Tue, 16 Jun 2026 14:08:30 +0200 Subject: [PATCH] docs: improve docs --- README.md | 36 ++++++++++++++++++++++++++++-------- docs/architecture.md | 33 --------------------------------- 2 files changed, 28 insertions(+), 41 deletions(-) delete mode 100644 docs/architecture.md diff --git a/README.md b/README.md index 14519ce..9d9cda5 100644 --- a/README.md +++ b/README.md @@ -70,19 +70,39 @@ Example response: `/pokemon/translated/{name}` applies Yoda when the Pokémon is legendary or its habitat is `cave`; otherwise it applies Shakespeare. If translation fails or returns an empty result, the API falls back to the standard PokéAPI description. -## Architecture +# Architecture + +This is a small Rust service, so the structure is intentionally a lightweight hexagonal/onion layout rather than a framework-heavy one. ```mermaid flowchart LR - CLI[CLI helper] --> HTTP[HTTP layer] - HTTP --> APP[Application service] - APP --> DOMAIN[Domain] - APP --> CLIENTS[External clients] - HTTP --> OTEL[Telemetry] - APP --> OTEL + CLI[CLI helper] --> HTTP + HTTP[HTTP layer: axum routes, handlers, middleware] --> Application + Application[Application service: use cases and translation rules] --> Domain + Application --> Clients + Clients[External clients: PokéAPI and FunTranslations] + HTTP --> Telemetry + Application --> Telemetry ``` -See `docs/architecture.md` for the design notes. +## Layers + +- `domain`: core data and business concepts (`PokemonInfo`, `TranslationKind`). +- `application`: orchestration and business rules, including Yoda vs Shakespeare selection and fallback behavior. +- `clients`: adapters for external providers (`PokéAPI`, `FunTranslations`). +- `http`: API transport concerns, routing, handlers, request IDs, metrics middleware, and rate limiting. +- `telemetry`: OpenTelemetry metrics and tracing setup. +- `bin`: executable entrypoints for the API and the local CLI helper. + +## Deliberate trade-offs + +The application service currently depends on concrete clients instead of trait-based ports. For this challenge that keeps the code easier to read and avoids abstractions that do not buy much yet. In a larger enterprise codebase, those clients would likely become traits owned by the application layer, with HTTP clients as adapters, so providers could be swapped or mocked without depending on concrete implementations. + +PokéAPI species data changes rarely, so production deployments would add a bounded LRU cache with TTL for successful species responses. That would avoid unnecessary random upstream hits, reduce latency, and make transient provider failures less visible to users. + +Rate limiting is intentionally simple and in-memory. In production, this should usually live in an API gateway or shared rate-limiting service so limits are consistent across instances and can be keyed by API key, user, or client IP. + +External contract tests are separated from the normal deterministic test suite. Unit and integration tests use mocks; the nightly workflow calls real providers to detect contract drift early. ## Configuration diff --git a/docs/architecture.md b/docs/architecture.md deleted file mode 100644 index f89eaed..0000000 --- a/docs/architecture.md +++ /dev/null @@ -1,33 +0,0 @@ -# Architecture - -This is a small Rust service, so the structure is intentionally a lightweight hexagonal/onion layout rather than a framework-heavy one. - -```mermaid -flowchart LR - CLI[CLI helper] --> HTTP - HTTP[HTTP layer: axum routes, handlers, middleware] --> Application - Application[Application service: use cases and translation rules] --> Domain - Application --> Clients - Clients[External clients: PokéAPI and FunTranslations] - HTTP --> Telemetry - Application --> Telemetry -``` - -## Layers - -- `domain`: core data and business concepts (`PokemonInfo`, `TranslationKind`). -- `application`: orchestration and business rules, including Yoda vs Shakespeare selection and fallback behavior. -- `clients`: adapters for external providers (`PokéAPI`, `FunTranslations`). -- `http`: API transport concerns, routing, handlers, request IDs, metrics middleware, and rate limiting. -- `telemetry`: OpenTelemetry metrics and tracing setup. -- `bin`: executable entrypoints for the API and the local CLI helper. - -## Deliberate trade-offs - -The application service currently depends on concrete clients instead of trait-based ports. For this challenge that keeps the code easier to read and avoids abstractions that do not buy much yet. In a larger enterprise codebase, those clients would likely become traits owned by the application layer, with HTTP clients as adapters, so providers could be swapped or mocked without depending on concrete implementations. - -PokéAPI species data changes rarely, so production deployments would add a bounded LRU cache with TTL for successful species responses. That would avoid unnecessary random upstream hits, reduce latency, and make transient provider failures less visible to users. - -Rate limiting is intentionally simple and in-memory. In production, this should usually live in an API gateway or shared rate-limiting service so limits are consistent across instances and can be keyed by API key, user, or client IP. - -External contract tests are separated from the normal deterministic test suite. Unit and integration tests use mocks; the nightly workflow calls real providers to detect contract drift early.