La Ricetta Base
“‘A ricetta è ‘a legge — ma ‘o cuoco è ‘o re.” (The recipe is the law — but the cook is the king.)
Every kitchen needs a recipe. In Pasta Protocol, the recipe is a .ricetta file — a declarative configuration document that describes your cluster’s topology, resource limits, consensus strategy, and operational parameters. The framework reads this file at startup and uses it to construct the entire runtime environment. No code required for basic configuration: if it’s in the .ricetta, it will be made so.
This guide walks you through creating your first .ricetta, initialising the kitchen, adding your first node, and starting your first cook cycle. By the end you will have a running single-node cluster ready to serve its first requests.
-
Crea il file
.ricettaCreate a file named
kitchen.ricettain the root of your project. This is the primary configuration file thatKitchenManagerwill look for by default. You can use either YAML or TOML syntax — both are fully supported.kitchen.ricetta kitchen:name: "La Mia Prima Cucina"region: "napoli-1"log_level: VOCEnodes:- id: "nodo-uno"host: "localhost"port: 3000role: primaryconsensus:strategy: pestoquorum: 1timeout_cotture: 3healthcheck:endpoint: /sono-vivointerval_cotture: 5threshold: 3garlicbreadcast:topics:- ordini- notifiche- errorikitchen.ricetta [kitchen]name = "La Mia Prima Cucina"region = "napoli-1"log_level = "VOCE"[[nodes]]id = "nodo-uno"host = "localhost"port = 3000role = "primary"[consensus]strategy = "pesto"quorum = 1timeout_cotture = 3[healthcheck]endpoint = "/sono-vivo"interval_cotture = 5threshold = 3[garlicbreadcast]topics = ["ordini", "notifiche", "errori"]The
timeout_cottureandinterval_cotturefields are expressed in cotture — Pasta Protocol’s native time unit, equal to one second. This deliberate naming choice exists to remind operators that distributed systems, like good cooking, cannot be rushed. -
Inizializza la cucina
In your main application file, import
KitchenManagerand point it at your ricetta:main.ts import { KitchenManager } from '@pasta-protocol/core';const kitchen = await KitchenManager.fromRicetta('./kitchen.ricetta');console.log(`Kitchen "${kitchen.name}" initialised in region ${kitchen.region}`);// => Kitchen "La Mia Prima Cucina" initialised in region napoli-1KitchenManager.fromRicetta()is an async factory that parses the configuration, validates all fields, instantiates internal subsystems, and returns a fully-wiredKitchenManagerinstance. If the configuration contains errors, it throws aBRUSCHETTA-levelConfigurationErrorwith a descriptive message and the line number of the offending field. -
Aggiungi il primo nodo
With the kitchen initialised, register your first worker node. The node ID must match one of the entries declared in your
.ricettafile:main.ts import { KitchenManager, WorkerNode } from '@pasta-protocol/core';const kitchen = await KitchenManager.fromRicetta('./kitchen.ricetta');const nodoUno = await kitchen.addNode('nodo-uno');console.log(`Node "${nodoUno.id}" joined the kitchen — status: ${nodoUno.status}`);// => Node "nodo-uno" joined the kitchen — status: READYkitchen.addNode()binds the node’s network socket, registers it with theTermometrohealth subsystem, and announces its presence overGarlicBreadcastso any other nodes in the cluster are immediately aware. When running a single-node development kitchen the node reachesREADYstatus almost instantly. -
Avvia la cottura
Call
kitchen.startCooking()to begin the kitchen’s main event loop. This method returns aPromise<void>that resolves only when the kitchen is explicitly shut down viakitchen.shutdown()or when aTERREMOTO-level error occurs.main.ts import { KitchenManager } from '@pasta-protocol/core';const kitchen = await KitchenManager.fromRicetta('./kitchen.ricetta');await kitchen.addNode('nodo-uno');// Graceful shutdown on SIGTERMprocess.on('SIGTERM', () => kitchen.shutdown('SIGTERM received'));await kitchen.startCooking();// Kitchen is now running. Press Ctrl+C or send SIGTERM to stop.You should see structured log output in
VOCElevel:{"level":"VOCE","ts":"2024-03-15T10:00:00.000Z","msg":"Kitchen started","kitchen":"La Mia Prima Cucina","nodes":1}{"level":"VOCE","ts":"2024-03-15T10:00:00.001Z","msg":"Healthcheck active","endpoint":"/sono-vivo","port":3000}Navigate to
http://localhost:3000/sono-vivoin your browser. You should see:{ "status": "vivo", "kitchen": "La Mia Prima Cucina", "nodes": 1, "uptime_cotture": 3 }
Configurazione Avanzata
Once you’re comfortable with the base ricetta, you can extend it with additional sections:
[dispensa]— configures the persistence layer (requires@pasta-protocol/dispensa)[pesto]— fine-tunes the consensus engine parameters[ragu]— configures long-running orchestration workflows[certificazione]— declares DOC-certified endpoints that enforce strict SLA guarantees
Each of these is documented in detail in their respective sections. For now, the base ricetta is enough to proceed to your first real workload in the next section.