Project Overview
This project is a web application that functions as a calculator for pizza dough recipes. It allows users to input various parameters to determine the precise quantities of ingredients needed for their desired pizza dough, offering both yeast and sourdough options.
Tech Stack
- Ruby on Rails
- StimulusJS
- Hotwired Turbo
- SCSS
- ViewComponent
- Docker
High-Level Architecture
The application is built using Ruby on Rails.
- Controllers (
calculator/app/controllers/): Handle incoming requests and determine the response.StaticControlleris the primary controller, responsible for rendering the main calculator interface and results. - Views (
calculator/app/views/): Render the HTML for the user interface. This includes layouts (layouts/mailer.html.erb,layouts/mailer.text.erb) and the main view for the calculator (static/dough.html.erb). - Components (
calculator/app/components/): Reusable UI elements, such asInputComponent, which is used to render input fields for the calculator. - JavaScript (
calculator/app/javascript/): Manages client-side interactivity, primarily using StimulusJS for controller-based JavaScript. - Stylesheets (
calculator/app/assets/stylesheets/): Contains SCSS for styling the application. - Configuration (
calculator/config/): Rails application configuration files, including routing (routes.rb), environment settings (environment.rb), and asset management (importmap.rb,assets.rb). - Docker (
calculator/docker-compose.yml,calculator/Dockerfile): Defines the containerized environment for running the application.
Entry Points
- User Request: A user navigates to the application's URL (e.g.,
http://localhost:3000). - Routing: The request is matched against the routes defined in
calculator/config/routes.rb. The root route (/) directs to theindexaction of thestaticcontroller. - Controller Action: The
static#indexaction is executed. This action likely sets up any necessary instance variables and renders thestatic/index.html.erbview. - View Rendering: The
static/index.html.erbview is rendered, which likely contains the form for the pizza dough calculator. - Form Submission: When the user submits the form, a GET request is made to the
/doughpath with query parameters representing the input values. - Routing (again): The
/doughroute is defined incalculator/config/routes.rband maps to thedoughaction of thestaticcontroller. - Controller Action (calculation): The
static#doughaction is executed. It retrieves the parameters from the request, performs the pizza dough calculations, and likely assigns the results to instance variables. - View Rendering (results): The
static#dough.html.erbview is rendered, using the calculated ingredient quantities to display the results to the user.
Key Concepts
- Pizza Dough Calculation Logic: The core functionality of the application lies in calculating ingredient quantities based on user inputs. This logic is likely implemented within the
static#doughcontroller action, utilizing "baker's math" as described in theREADME.md. - Input Component (
InputComponent): This reusable component (calculator/app/components/input_component.rbandcalculator/app/components/input_component.html.erb) is used to render form input fields for the calculator. Understanding how this component is initialized and rendered is key to understanding the form structure. - Routing (
calculator/config/routes.rb): Therootroute and theget "dough", to: "static#dough"route define the main entry points and how user requests are mapped to controller actions. Theredirectroute for/resultalso shows how URLs are handled. - StimulusJS Controllers (
calculator/app/javascript/controllers/): While the provided code doesn't show specific controller implementations, theimportmap.rbandindex.jsfiles indicate the use of StimulusJS for managing client-side interactivity. Understanding how Stimulus controllers are defined and attached to HTML elements is important for any dynamic behavior. - Dockerization (
calculator/Dockerfile,calculator/docker-compose.yml): TheDockerfileanddocker-compose.ymlfiles define how to build and run the application in a containerized environment. This is crucial for local development and deployment.
