A "Zero to Hero" resource for Google's dotprompt applying the Model-View-Controller (MVC) pattern to AI Engineering.
"Prompts are Code." This repository demonstrates how to decouple prompt logic (View) from application logic (Controller) while enforcing strict data contracts (Model).
-
Install Dependencies
npm install
-
Set up Environment Copy
.env.exampleto.envand add your Google API Key (Gemini).cp .env.example .env
-
Run Examples
-
Example 0: The Legacy Nightmare (How NOT to do it)
npm run legacy
-
Example 1: The MVC Basic (Separation of Concerns)
npm run basic
-
Example 2: The Contract (Type Safety with Picoschema)
npm run schema
-
Example 3: The Component (Reusability with Partials)
npm run partials
-
Example 4: The Eyes (Multi-modal Vision)
npm run vision
-
Example 5: The Memory (Chat History)
npm run chat
-
/dotprompt-mvc-demo
├── prompts/ # THE VIEW LAYER (Templates)
│ ├── _system.prompt # (Partial) Shared System Persona
│ ├── 01_basic.prompt
│ ├── 02_schema.prompt
│ ├── 03_partials.prompt
│ ├── 04_vision.prompt
│ └── 05_chat.prompt
└── src/ # THE CONTROLLER LAYER (Logic)
├── 00_legacy.ts # The "Before" (Spaghetti)
├── 01_basic.ts # The "View" (Separation)
├── 02_schema.ts # The "Model" (Type Safety)
├── 03_partials.ts # The "Component" (Reusability)
├── 04_vision.ts # The "Eyes" (Multi-modal)
└── 05_chat.ts # The "Memory" (History/Context)
Read the full guide in docs/medium.md.
Run the test suite to verify all examples are correctly structured:
npm testThe tests verify:
- All prompt files exist and have correct structure
- Prompts use the correct model (
gemini-2.5-flash-lite) - Picoschema syntax is valid
- TypeScript files compile correctly
For live LLM tests (which call the actual Gemini API), set your GOOGLE_API_KEY environment variable before running tests.

