How rust-web-app-book/rusty-book-manager works
Based on our analysis of the file tree and README, this project is a Rust-based Web application developed as part of a book (“RustによるWebアプリケーション開発 設計からリリース・運用まで”). Its purpose is to gradually introduce readers to a complete web application by evolving the code through various chapters. In this repository, the code is divided into several distinct components which correspond to different layers or responsibilities within the overall system.
Project Type and Overall Purpose
• It is a backend-centric web application built in Rust.
• The code is modularized for educational purposes, matching a step-by-step development process.
• While a separate template repo exists for the full-stack (with frontend and infra), this repository focuses on the backend/domain layers.
Main Architectural Components
a. API Layer (“api” directory):
• Contains route definitions, HTTP handlers, request extractors, and models specific to API interactions.
• This layer exposes endpoints that will be used by the client (could be frontend or other services).
• Includes tests that verify the API behavior.
b. Domain/Kernel Layer (“kernel” directory):
• Contains the core business logic. This includes domain models (like auth, book, checkout, and user), events, and repository interfaces.
• Acts as the heart of the business logic, independent of external dependencies.
c. Adapter Layer (“adapter” directory):
• Functions as an interface to external systems:
• Database integration with migrations and models (via SQL scripts in migrations, and database models inside adapter/src/database/model).
• Redis integration (adapter/src/redis) and handling of caching operations.
• Provides repository implementations that bridge the API and domain layers with external systems.
• Contains fixture data and SQL sample files to initialize or test the database.
d. Registry & Shared Components (“registry” and “shared” directories):
• “registry”: Likely used to setup dependency injection or service registration mechanisms.
• “shared”: Provides common utilities such as configuration management, environment handling, error definitions, etc.
e. Infrastructure and Orchestration:
• Presence of a Dockerfile and compose.yaml suggests containerized deployment.
• CI configuration under .github/workflows indicates continuous integration setup.
• Makefile.toml can be used to automate common build/tasks.
f. Auxiliary / Example Code (“snippets” directory):
• Contains example code and tests (with different experiments related to SQLx, expanded libraries etc.) to demonstrate or try out parts of the architecture.
g. Main Application Entry (“src/bin/app.rs”):
• Contains the entry point for the application, tying together the initialization of the API server and possibly the wiring of components.
Relationships and Interactions
• The API layer interacts with the Kernel layer to invoke business logic.
• The Adapter layer provides concrete implementations for communicating with the database and external services (like Redis) that the Kernel or API layers depend on.
• The Registry may be involved in bootstrapping and wiring up dependencies (e.g., creating repository instances, configuring middleware, etc.).
• Shared utilities are used across all layers to enforce consistency (for configurations and error handling).
• With Dockerfile and compose configurations, external services (database, cache, etc.) are likely containerized and interact with the application over defined networks.
• API → Kernel (for business logic)
• Kernel → Adapter (for persistence/communication with external services)
• Adapter ←→ External Databases / Redis (illustrate connectivity)
Architectural Pattern
• The separation into API, Kernel, and Adapter layers suggests a Hexagonal (or Ports and Adapters) architecture where the core domain (Kernel) is isolated from external concerns by well-defined interfaces.
• It embodies separation of concerns, making it easier to replace or modify adapters without impacting the core business logic.