# Pizza Dough

> This recipe is dedicated to helping you make the best possible pizza dough.

**Showcase URL:** https://shipdocs.sh/showcase/af9afef9-48e9-4a55-95aa-47eafe5bdb71
**Repository:** https://github.com/hendricius/pizza-dough
**Docs count:** 4

## Overview

## What this project actually is
A small Ruby‑on‑Rails web app that lets users calculate the ingredients needed for Neapolitan‑style pizza dough.
The user submits parameters (number of pizzas, weight per pizza, hydration, yeast/sourdough percentages, etc.) via a form rendered by `StaticController#index`. The controller builds a `Dough` object (`Dough.from_params`) and displays the calculated recipe on `/dough`.

Sources
- `README.md` (project description)
- `config/routes.rb` (root and `/dough` routes)
- `app/controllers/static_controller.rb` (uses `Dough.from_params`)

---

Sources:
- `README.md`
- `calculator/app/controllers/static_controller.rb`
- `calculator/app/javascript/controllers/index.js`
- `calculator/config/routes.rb`
## Tech stack
| Layer | Libraries / Gems | Files |
|-------|---|-------|
| **Backend** | Ruby 3.x, Rails 8 (edge), Puma | `Gemfile`, `config/application.rb`, `config/environments/*.rb` |
| **Web framework** | ActionController, ActionView, ActionCable | `app/controllers/*`, `app/views/*`, `app/channels/*` |
| **Front‑end** | Turbo (`turbo-rails`), Stimulus (`stimulus-rails`, `stimulus-loading`) | `app/javascript/application.js`, `app/javascript/controllers/index.js`, `config/importmap.rb` |
| **Styling** | Sass via Dartsass (`dartsass-rails`) | `app/assets/stylesheets/application.scss`, `app/assets/stylesheets/styles.scss` |
| **Components** | ViewComponent (`view_component`) | `app/components/input_component.rb`, `.html.erb` |
| **Deployment** | Capistrano (`capistrano`, `capistrano-rails`, etc.) | `Capfile`, `config/deploy.rb`, `config/deploy/production.rb` |
| **Testing** | Minitest + Capybara + Selenium | `test/*` files |

Sources
- `Gemfile`
- `config/importmap.rb`
- `app/javascript/application.js`
- `app/javascript/controllers/index.js`
- `app/components/input_component.rb`

---

Sources:
- `calculator/app/assets/stylesheets/application.scss`
- `calculator/app/assets/stylesheets/styles.scss`
- `calculator/app/javascript/controllers/application.js`
- `calculator/app/javascript/controllers/index.js`
## High‑level architecture
```
client ──► Turbo (SPA navigation) ──► Stimulus controllers (dynamic UI) ──►
 Rails MVC
 ├─ StaticController
 │ ├─ index → renders form (InputComponent)
 │ └─ dough → shows calculated recipe
 ├─ Dough model (logic in app/models/dough.rb – not shown)
 └─ Views (ERB + ViewComponent)
```

* **Routes** – defined in `config/routes.rb`. The root path maps to `StaticController#index`; `/dough` renders the result.
* **Controllers** – only one real controller (`StaticController`) handles all user interactions.
* **Models** – the core calculation lives in a separate model (`Dough`). It is instantiated from request parameters.
* **Views & Components** – ERB templates use the reusable `<%= render InputComponent.new(...) %>` component for numeric inputs.
* **Stimulus** – all controllers are eagerly loaded via `eagerLoadControllersFrom("controllers", application)` in `calculator/app/javascript/controllers/index.js`. They provide client‑side interactivity (e.g., live updates of calculated values).
* **Assets** – SCSS compiled by Dartsass; images served from `/public/images`.

Sources
- `config/routes.rb`
- `app/controllers/static_controller.rb`
- `app/components/input_component.rb`
- `calculator/app/javascript/controllers/index.js`
- `calculator/app/javascript/application.js`

---

Sources:
- `calculator/app/javascript/controllers/index.js`
- `calculator/app/javascript/application.js`
- `calculator/app/javascript/controllers/application.js`
- `calculator/app/assets/stylesheets/application.scss`
## Entry points
1. **Docker** – run with `make up`. This starts a container that executes:
 ```bash
 ./bin/dev
 ```
 which launches the Rails server on port 3000.
2. **Rails server** – entry point is the standard Rails boot sequence:
 * `/opt/app/config/environment.rb` loads the application.
 * Puma starts listening on port 3000 (`config/puma.rb`).
3. **HTTP request flow** – e.g., GET `/`
 * Router dispatches to `StaticController#index`.
 * Controller builds a default or pre‑filled `Dough`.
 * View renders the form; Stimulus controllers are attached via importmap.
 * User submits → POST to `/dough`; controller recalculates and renders result page.

Sources
- Makefile (`calculator/Makefile`)
- Dockerfile (`calculator/Dockerfile`)
- `/opt/app/config/environment.rb` (boot)
- `/opt/app/config/puma.rb`

---

Sources:
- `calculator/Dockerfile`
- `calculator/Makefile`
- `calculator/app/javascript/controllers/application.js`
- `calculator/app/javascript/controllers/index.js`
## Key concepts

| Concept | What it is | Where it lives |
|---------|--|----|
| **Dough calculation** | Encapsulated in the missing but referenced class `Dough`. It parses request params and produces ingredient amounts and descriptive text (`build_title`, `build_description`). | Expected at `app/models/dough.rb`. |
| **InputComponent** | A reusable ViewComponent that renders a labeled numeric input with min/max/step constraints. Used throughout the form. | `app/components/input_component.rb / .html.erb`. |
| **Stimulus eager loading** | All Stimulus controllers are automatically registered at boot via importmap and eager loading helper. This allows dynamic updates without page reloads. | `calculator/app/javascript/controllers/index.js`. |
| **Routes mapping** | Simple REST‑like mapping: root → index; `/dough` → show result; `/result` redirects to `/dough`. | `config/routes.rb`. |
| **Asset pipeline** | SCSS compiled by Dartsass; images referenced in README are generated by a separate Flowchart submodule. | `.scss`, Flowchart Dockerfile & Makefile. |

Sources
- Reference to missing model: comment in controller (`# @dough = Dough.from_params(...)`).
- Component files (`input_component.*`).
- Importmap config (`controllers/index.js`).
- Routes file (`config/routes.rb`).

---

Sources:
- `calculator/app/javascript/controllers/index.js`
- `calculator/app/components/input_component.rb`
- `calculator/config/boot.rb`
- `calculator/config/importmap.rb`
## Where to start reading

1. **`config/routes.rb`** – understand which URLs map to which actions.
2. **`app/controllers/static_controller.rb`** – core request handling and how it builds the dough object.
3. **Missing model stub (`app/models/dough.rb`)** – locate or create this file to see calculation logic (the rest of the app depends on it).
4. **`app/components/input_component.*`** – see how form inputs are rendered and styled.
5. **`calculator/app/javascript/controllers/index.js` + importmap** – learn how Stimulus controllers are wired into the page.

These files give you the full request–response cycle from URL to rendered HTML and client‑side behavior.

Sources
- `config/routes.rb`
- `app/controllers/static_controller.rb`
- (implied) missing model path
- `app/components/input_component.*`
- `calculator/app/javascript/controllers/index.js`

---

Sources:
- `calculator/app/javascript/controllers/index.js`
- `calculator/app/components/input_component.rb`
- `calculator/app/controllers/static_controller.rb`
- `calculator/config/importmap.rb`

## All docs

- **Pizza Dough** (overview)
- **Flowchart** (module)
- **Root files** (module)
- **Calculator** (module)

Browse the interactive showcase: https://shipdocs.sh/showcase/af9afef9-48e9-4a55-95aa-47eafe5bdb71
