prisma-php 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,480 @@
1
+ ---
2
+ title: AI Integration
3
+ description: Build chat, assistant, and streamed AI features in Prisma PHP with PulsePoint, pp.fetchFunction(...), PP\Validator, and MCP when you need agent-facing tools.
4
+ related:
5
+ title: Related docs
6
+ description: Read the core Prisma PHP docs that support provider-backed AI UIs, streaming, and agent tooling.
7
+ links:
8
+ - /docs/env
9
+ - /docs/fetch-function
10
+ - /docs/php-validator
11
+ - /docs/pulsepoint
12
+ - /docs/prisma-php-ai-mcp
13
+ - /docs/websocket-chat-app
14
+ ---
15
+
16
+ Prisma PHP is a good fit for AI features, but the right Prisma PHP pattern depends on what you are actually building.
17
+
18
+ For a normal user-facing chat box, assistant panel, prompt form, streamed summary, or similar page-local AI feature, the recommended Prisma PHP approach is:
19
+
20
+ 1. render the UI in `index.php`
21
+ 2. keep browser-side interactivity in **PulsePoint**
22
+ 3. call backend PHP with **`pp.fetchFunction(...)`**
23
+ 4. mark callable PHP functions with **`#[Exposed]`**
24
+ 5. validate and normalize incoming data with **`PP\Validator`**
25
+ 6. stream incremental output by **yielding** from PHP when the provider supports streaming
26
+
27
+ That keeps the **frontend reactive** while keeping the **AI call, validation, secrets, and business logic on the PHP side**.
28
+
29
+ Do **not** default to `route.php` for page-local chat or assistant UI just because AI is involved. In Prisma PHP, `route.php` is still useful, but it is the better fit for standalone APIs, webhooks, third-party integrations, or endpoints that must exist independently of the current page.
30
+
31
+ If the real goal is to expose **agent-callable tools** instead of a user chat interface, read `mcp.md` and the official `prisma-php-ai-mcp` docs. MCP is about serving tools to agents; it is not the default answer for a page-local chat box.
32
+
33
+ ## The default AI architecture in Prisma PHP
34
+
35
+ When the user is building a normal AI feature inside a Prisma PHP app, AI should usually prefer this stack:
36
+
37
+ 1. `index.php` for the route UI
38
+ 2. PulsePoint for browser-side state
39
+ 3. `pp.fetchFunction(...)` for frontend-to-PHP RPC
40
+ 4. `#[Exposed]` for callable PHP functions
41
+ 5. `PP\Validator` for server-side validation
42
+ 6. streamed `yield` responses for incremental assistant output
43
+
44
+ This is the right default for:
45
+
46
+ - single-user chat pages
47
+ - assistant sidebars
48
+ - prompt forms
49
+ - streamed summaries
50
+ - content generation tools
51
+ - classification or extraction actions
52
+ - AI-backed search or suggestion panels
53
+ - route-local progress logs
54
+
55
+ Reserve `route.php` for cases where the endpoint must be called without the page, and reserve websocket-based transport for cases where you need true server push, multi-user realtime chat, or presence-style features.
56
+
57
+ ## Pick the right AI surface
58
+
59
+ Prisma PHP has three different AI-related surfaces, and they should not be mixed up.
60
+
61
+ ### 1. User-facing AI in a page
62
+
63
+ Use this when a human is interacting with a Prisma PHP page.
64
+
65
+ Default stack:
66
+
67
+ - `index.php`
68
+ - PulsePoint
69
+ - `pp.fetchFunction(...)`
70
+ - `#[Exposed]`
71
+ - `PP\Validator`
72
+
73
+ This is the default for chat, prompt forms, streamed output, inline assistants, or route-local AI actions.
74
+
75
+ ### 2. Standalone AI endpoint
76
+
77
+ Use `route.php` when the request should exist independently of the rendered page.
78
+
79
+ Examples:
80
+
81
+ - webhooks
82
+ - provider callbacks
83
+ - public JSON APIs
84
+ - integration endpoints
85
+ - non-UI automation calls
86
+
87
+ ### 3. Agent-facing tools
88
+
89
+ Use MCP when an external agent should call business actions in your app.
90
+
91
+ Read:
92
+
93
+ - `mcp.md`
94
+ - official `prisma-php-ai-mcp`
95
+ - official `ai-tools`
96
+
97
+ ### Quick rule of thumb
98
+
99
+ - user chat box on a page -> `index.php` + PulsePoint + `pp.fetchFunction(...)`
100
+ - endpoint with no page dependency -> `route.php`
101
+ - tools for agents -> MCP
102
+
103
+ ## Install an AI client
104
+
105
+ Prisma PHP is intentionally unopinionated about AI providers. You can use OpenAI, Anthropic, Groq, or another PHP SDK that fits your application.
106
+
107
+ For OpenAI-compatible providers, a common starting point is:
108
+
109
+ ```bash package="composer"
110
+ composer require openai-php/client
111
+ ```
112
+
113
+ Use the provider package that matches your model host, but keep the Prisma PHP architecture the same: the browser calls PHP, and PHP talks to the model provider.
114
+
115
+ ## Configure secrets in `.env`
116
+
117
+ Keep provider secrets on the server side.
118
+
119
+ Example:
120
+
121
+ ```dotenv
122
+ OPENAI_API_KEY="sk-..."
123
+ OPENAI_MODEL="gpt-4o-mini"
124
+ ```
125
+
126
+ Do **not** push provider API keys into PulsePoint state or browser-side JavaScript.
127
+ When reading these values in PHP, prefer `PP\Env` over raw `getenv()` so defaults and typed access stay consistent with Prisma PHP's env helper.
128
+
129
+ ## Recommended non-streaming chat pattern
130
+
131
+ For a simple AI response, keep the entire route in `index.php`, expose one PHP function, validate the prompt on the PHP side, and call the provider there.
132
+
133
+ ```php filename="src/app/chat/index.php"
134
+ <?php
135
+
136
+ use PP\Attributes\Exposed;
137
+ use PP\Env;
138
+ use PP\MainLayout;
139
+ use PP\Rule;
140
+ use PP\Validator;
141
+
142
+ MainLayout::$title = 'AI Chat';
143
+ MainLayout::$description = 'Chat with a provider from Prisma PHP using PulsePoint and pp.fetchFunction(...).';
144
+
145
+ #[Exposed]
146
+ function sendChatMessage($data)
147
+ {
148
+ $message = Validator::string($data->message ?? '');
149
+ $result = Validator::withRules(
150
+ $message,
151
+ Rule::required()->min(1)->max(4000)
152
+ );
153
+
154
+ if ($result !== true) {
155
+ return [
156
+ 'success' => false,
157
+ 'errors' => [
158
+ 'message' => $result,
159
+ ],
160
+ ];
161
+ }
162
+
163
+ $client = \OpenAI::client(Env::string('OPENAI_API_KEY', ''));
164
+ $model = Env::string('OPENAI_MODEL', 'gpt-4o-mini');
165
+
166
+ $response = $client->chat()->create([
167
+ 'model' => $model,
168
+ 'messages' => [
169
+ ['role' => 'system', 'content' => 'You are a helpful Prisma PHP assistant.'],
170
+ ['role' => 'user', 'content' => $message],
171
+ ],
172
+ ]);
173
+
174
+ return [
175
+ 'success' => true,
176
+ 'errors' => [],
177
+ 'assistant' => [
178
+ 'role' => 'assistant',
179
+ 'content' => trim($response->choices[0]->message->content ?? ''),
180
+ ],
181
+ ];
182
+ }
183
+ ?>
184
+
185
+ <section pp-component="chat-page">
186
+ <header>
187
+ <h1>AI Chat</h1>
188
+ <p>Send a prompt from PulsePoint and keep the provider call in PHP.</p>
189
+ </header>
190
+
191
+ <div>
192
+ <template pp-for="(item, index) in messages">
193
+ <article key="{`${item.role}-${index}`}">
194
+ <strong>{item.role}</strong>
195
+ <p>{item.content}</p>
196
+ </article>
197
+ </template>
198
+ </div>
199
+
200
+ <form onsubmit="event.preventDefault(); submitMessage()">
201
+ <textarea value="{draft}" oninput="setDraft(event.target.value)"></textarea>
202
+ <p hidden="{!error}">{error}</p>
203
+ <button type="submit" disabled="{loading}">Send</button>
204
+ </form>
205
+
206
+ <script>
207
+ const [draft, setDraft] = pp.state('');
208
+ const [messages, setMessages] = pp.state([]);
209
+ const [error, setError] = pp.state('');
210
+ const [loading, setLoading] = pp.state(false);
211
+
212
+ async function submitMessage() {
213
+ const text = draft.trim();
214
+
215
+ if (!text || loading) {
216
+ return;
217
+ }
218
+
219
+ setError('');
220
+ setDraft('');
221
+ setMessages((current) => [...current, { role: 'user', content: text }]);
222
+ setLoading(true);
223
+
224
+ try {
225
+ const response = await pp.fetchFunction('sendChatMessage', { message: text });
226
+
227
+ if (!response.success) {
228
+ setError(response.errors?.message ?? 'Message failed.');
229
+ return;
230
+ }
231
+
232
+ setMessages((current) => [...current, response.assistant]);
233
+ } catch (error) {
234
+ setError(error.message || 'Request failed.');
235
+ } finally {
236
+ setLoading(false);
237
+ }
238
+ }
239
+ </script>
240
+ </section>
241
+ ```
242
+
243
+ Why this pattern is preferred:
244
+
245
+ - the route UI stays in `index.php`
246
+ - PulsePoint owns the browser state
247
+ - the provider call stays in PHP
248
+ - secrets stay on the server
249
+ - `Validator` remains the authoritative validation layer
250
+ - the route avoids extra endpoint boilerplate when the action belongs to the page
251
+
252
+ ## Recommended streaming chat pattern
253
+
254
+ For streamed assistant output, keep the same architecture and change only the backend response shape: make the exposed PHP function **yield** chunks.
255
+
256
+ That gives you incremental SSE delivery through `pp.fetchFunction(...)` without hand-writing a separate transport layer for normal assistant output.
257
+
258
+ ```php filename="src/app/chat/index.php"
259
+ <?php
260
+
261
+ use PP\Attributes\Exposed;
262
+ use PP\Env;
263
+ use PP\Rule;
264
+ use PP\Validator;
265
+
266
+ #[Exposed]
267
+ function streamChatMessage($data)
268
+ {
269
+ $message = Validator::string($data->message ?? '');
270
+ $result = Validator::withRules(
271
+ $message,
272
+ Rule::required()->min(1)->max(4000)
273
+ );
274
+
275
+ if ($result !== true) {
276
+ yield [
277
+ 'type' => 'error',
278
+ 'message' => $result,
279
+ ];
280
+ return;
281
+ }
282
+
283
+ $client = \OpenAI::client(Env::string('OPENAI_API_KEY', ''));
284
+ $model = Env::string('OPENAI_MODEL', 'gpt-4o-mini');
285
+
286
+ $stream = $client->chat()->createStreamed([
287
+ 'model' => $model,
288
+ 'messages' => [
289
+ ['role' => 'system', 'content' => 'You are a helpful Prisma PHP assistant.'],
290
+ ['role' => 'user', 'content' => $message],
291
+ ],
292
+ ]);
293
+
294
+ foreach ($stream as $response) {
295
+ $delta = $response->choices[0]->delta->content ?? '';
296
+
297
+ if ($delta !== '') {
298
+ yield [
299
+ 'type' => 'chunk',
300
+ 'chunk' => $delta,
301
+ ];
302
+ }
303
+ }
304
+ }
305
+ ```
306
+
307
+ If your provider uses a different streaming API, keep the Prisma PHP shape the same:
308
+
309
+ 1. validate in PHP first
310
+ 2. start the provider stream in PHP
311
+ 3. loop over provider deltas
312
+ 4. yield strings or arrays back to the client
313
+
314
+ ### Client-side streaming with PulsePoint
315
+
316
+ ```html
317
+ <script>
318
+ const [draft, setDraft] = pp.state('');
319
+ const [messages, setMessages] = pp.state([]);
320
+ const [error, setError] = pp.state('');
321
+ const [streaming, setStreaming] = pp.state(false);
322
+
323
+ async function sendStream() {
324
+ const text = draft.trim();
325
+
326
+ if (!text || streaming) {
327
+ return;
328
+ }
329
+
330
+ setError('');
331
+ setDraft('');
332
+ setStreaming(true);
333
+ setMessages((current) => [
334
+ ...current,
335
+ { role: 'user', content: text },
336
+ { role: 'assistant', content: '' },
337
+ ]);
338
+
339
+ try {
340
+ await pp.fetchFunction(
341
+ 'streamChatMessage',
342
+ { message: text },
343
+ {
344
+ onStream(data) {
345
+ if (data.type === 'error') {
346
+ setError(data.message || 'Invalid message.');
347
+ return;
348
+ }
349
+
350
+ const delta = data.chunk || '';
351
+
352
+ if (delta === '') {
353
+ return;
354
+ }
355
+
356
+ setMessages((current) => {
357
+ if (current.length === 0) {
358
+ return current;
359
+ }
360
+
361
+ const next = current.slice();
362
+ const last = next[next.length - 1];
363
+
364
+ next[next.length - 1] = {
365
+ ...last,
366
+ content: `${last.content}${delta}`,
367
+ };
368
+
369
+ return next;
370
+ });
371
+ },
372
+ onStreamError(error) {
373
+ setError(error.message || 'Stream failed.');
374
+ },
375
+ }
376
+ );
377
+ } finally {
378
+ setStreaming(false);
379
+ }
380
+ }
381
+ </script>
382
+ ```
383
+
384
+ Important streaming rule:
385
+
386
+ - do not wait for one final JSON object to render the reply
387
+ - update the UI from `onStream`
388
+ - use `onStreamError` and `onStreamComplete` for stream lifecycle handling
389
+
390
+ For the current SSE behavior and low-level streaming helpers, read `fetching-data.md`.
391
+
392
+ ## Validate everything on the PHP side
393
+
394
+ When building AI features, do not trust browser-side checks as the final source of truth.
395
+
396
+ Use this split:
397
+
398
+ - PulsePoint for local UX state
399
+ - `pp.fetchFunction(...)` for calling PHP
400
+ - `PP\Validator` for sanitization and casting
401
+ - `Validator::withRules(...)` for business rules
402
+ - structured return values for expected validation failures
403
+
404
+ Good server-side validation targets include:
405
+
406
+ - prompt text
407
+ - prompt length
408
+ - selected model name
409
+ - message arrays or prior history
410
+ - temperature or option values
411
+ - tool selection input
412
+ - database IDs tied to retrieval or conversation threads
413
+
414
+ If you are sending prior messages or advanced options back to PHP, validate those values before they are stored, queried against the database, or forwarded to the provider.
415
+
416
+ ## Conversation state and persistence
417
+
418
+ For small page-local chat flows, PulsePoint can hold the visible message list while PHP handles the provider call.
419
+
420
+ When you need durable chat history or retrieval-backed context:
421
+
422
+ - load and store conversation records on the PHP side
423
+ - use Prisma ORM from PHP, not from the browser
424
+ - validate inbound message payloads before persistence
425
+ - shape the final provider request in PHP, not in client-side JavaScript
426
+
427
+ That keeps the conversation contract authoritative on the server.
428
+
429
+ ## SSE vs websocket vs MCP
430
+
431
+ These three features solve different problems.
432
+
433
+ ### Use streamed `pp.fetchFunction(...)` when
434
+
435
+ - the user triggered a request from the current page
436
+ - the assistant response should appear incrementally
437
+ - the page owns the request lifecycle
438
+ - normal request-response semantics are still correct
439
+
440
+ This is the default for AI text streaming.
441
+
442
+ ### Use websocket when
443
+
444
+ - the server must push updates without a fresh page request
445
+ - multiple users must see shared realtime changes
446
+ - you need presence, rooms, or bidirectional messaging
447
+
448
+ Read `websocket.md` when that is the actual requirement.
449
+
450
+ ### Use MCP when
451
+
452
+ - an external agent needs callable tools
453
+ - the goal is tool exposure, not page-local chat UI
454
+ - you want agent workflows to query your app or database
455
+
456
+ Read `mcp.md` when that is the actual requirement.
457
+
458
+ ## When `route.php` is still correct
459
+
460
+ `route.php` still makes sense for AI-related work when:
461
+
462
+ - the endpoint must be called from outside the current page
463
+ - the request is an integration or webhook
464
+ - you are exposing a standalone API
465
+ - the response is not part of a page-local interactive workflow
466
+
467
+ For example, provider webhooks, background callbacks, or public machine-facing AI endpoints are reasonable `route.php` use cases.
468
+
469
+ What should change is the **default assumption**: a chat screen inside a Prisma PHP page should usually start with `index.php` + PulsePoint + `pp.fetchFunction(...)`, not with a separate endpoint first.
470
+
471
+ ## Good to know
472
+
473
+ - Prisma PHP is unopinionated about AI SDK choice.
474
+ - For page-local AI UI, keep the browser reactive and keep the provider call in PHP.
475
+ - Use `#[Exposed]` for any PHP function called from `pp.fetchFunction(...)`.
476
+ - Use `PP\Validator` as the default validation layer for AI request payloads.
477
+ - Stream assistant replies by yielding from PHP and consuming chunks with `onStream`.
478
+ - Prefer `route.php` only when the endpoint must exist independently of the page.
479
+ - Use websocket for true server push or multi-user realtime behavior.
480
+ - Use MCP for agent-facing tools, not as the default transport for a page-local chat box.
@@ -1,14 +1,16 @@
1
1
  ---
2
2
  title: Prisma PHP Docs
3
- description: Welcome to the Prisma PHP Documentation.
3
+ description: Prisma PHP documentation with AI-aware routing to the right local docs before framework-specific code generation.
4
4
  related:
5
5
  title: Next Steps
6
6
  description: Create your first Prisma PHP application and learn the core framework features.
7
7
  links:
8
8
  - /docs/get-started
9
+ - /docs/commands
10
+ - /docs/get-started-ia
9
11
  ---
10
12
 
11
- {/_AI agent hint: Prisma PHP uses local installed docs as the source of truth for the active project version. Before generating framework-specific code, read `prisma-php.json` first, then read the relevant docs from `node_modules/prisma-php/dist/docs`. For authentication, read `authentication.md` first, then verify the official auth docs: `auth-get-started`, `credentials`, and `state-manager-auth`. For file uploads, `multipart/form-data`, `$_FILES`, `PP\FileManager\UploadFile`, rename/delete flows, or file manager screens, read `file-manager.md` first, then verify the official File Manager docs: `get-started-file`. For email sending, SMTP config, `.env` mail variables, `PP\PHPMailer\Mailer`, HTML or text bodies, recipients, reply-to, or attachments, read `email.md` first, then verify the official Email docs: `email-get-started`. For websocket support, Ratchet setup, `IoServer`, `HttpServer`, `WsServer`, `ConnectionManager`, connection lifecycle methods, browser `WebSocket`, or realtime UI flows, read `websocket.md` first, then verify the official websocket docs: `websocket-get-started` and `websocket-chat-app`. For MCP support, `#[McpTool]`, `#[Schema]`, `PhpMcp\Server\Server`, `StreamableHttpServerTransport`, or `src/Lib/MCP/mcp-server.php`, read `mcp.md` first, then verify the official MCP docs: `prisma-php-ai-mcp` and `ai-tools`. For ORM work, read `prisma-php-orm.md` before choosing schema, migration, or generation commands. For PulsePoint runtime behavior specifically, read `pulsepoint.md` before generating reactive UI code. For normal interactive full-stack page work, default to PulsePoint plus `pp.fetchFunction(...)` unless the user explicitly asks for a PHP-only interaction style. For normal PulsePoint-aware route files such as `index.php` and nested `layout.php`, keep PHP first, then one parent HTML element that acts as the route-view boundary; when PulsePoint logic is present, put `pp-component` on that root and keep the `<script>` as the last child inside it. For imported partial components rendered with `ImportComponent::render(...)`, keep exactly one root element and place any component-local `<script>` inside that root; Prisma PHP injects `pp-component` on the imported root automatically. Do not confuse the route-file pattern with the imported-partial pattern. For backend validation, sanitization, `Validator`, `Rule`, `pp.fetchFunction(...)` validation flows, or request validation in `route.php`, read `validator.md` first, then use `fetching-data.md`, `error-handling.md`, and `route-handlers.md` for context-specific patterns, then consult the official Validator docs. `PP\Validator` is a Prisma PHP core class located in `vendor/tsnc/prisma-php/src/Validator.php`. Route creation is file-based from `src/app`; Prisma PHP auto-generates route listings such as `files-list.json`, so AI agents must not create, edit, or maintain that file manually._/}
13
+ {/_AI agent hint: Prisma PHP uses local installed docs as the source of truth for the active project version. Before generating framework-specific code, read `prisma-php.json` first, then read the relevant docs from `node_modules/prisma-php/dist/docs`. For authentication, read `authentication.md` first, then verify the official auth docs: `auth-get-started`, `credentials`, and `state-manager-auth`. For environment variables, `.env`, `PP\Env`, `Env::get(...)`, `Env::string(...)`, `Env::bool(...)`, `Env::int(...)`, or runtime configuration, read `env.md` first, then verify the official env docs: `env` and `env-file`. For file uploads, `multipart/form-data`, `$_FILES`, `PP\FileManager\UploadFile`, rename/delete flows, or file manager screens, read `file-manager.md` first, then verify the official File Manager docs: `get-started-file`. For email sending, SMTP config, `.env` mail variables, `PP\PHPMailer\Mailer`, HTML or text bodies, recipients, reply-to, or attachments, read `email.md` first, then verify the official Email docs: `email-get-started`. For websocket support, Ratchet setup, `IoServer`, `HttpServer`, `WsServer`, `ConnectionManager`, connection lifecycle methods, browser `WebSocket`, or realtime UI flows, read `websocket.md` first, then verify the official websocket docs: `websocket-get-started` and `websocket-chat-app`. For MCP support, `#[McpTool]`, `#[Schema]`, `PhpMcp\Server\Server`, `StreamableHttpServerTransport`, or `src/Lib/MCP/mcp-server.php`, read `mcp.md` first, then verify the official MCP docs: `prisma-php-ai-mcp` and `ai-tools`. For ORM work, read `prisma-php-orm.md` before choosing schema, migration, or generation commands. For PulsePoint runtime behavior specifically, read `pulsepoint.md` before generating reactive UI code. For normal interactive full-stack page work, default to PulsePoint plus `pp.fetchFunction(...)` unless the user explicitly asks for a PHP-only interaction style. For normal PulsePoint-aware route files such as `index.php` and nested `layout.php`, keep PHP first, then one parent HTML element that acts as the route-view boundary; when PulsePoint logic is present, put `pp-component` on that root and keep the `<script>` as the last child inside it. For imported partial components rendered with `ImportComponent::render(...)`, keep exactly one root element and place any component-local `<script>` inside that root; Prisma PHP injects `pp-component` on the imported root automatically. Do not confuse the route-file pattern with the imported-partial pattern. For backend validation, sanitization, `Validator`, `Rule`, `pp.fetchFunction(...)` validation flows, or request validation in `route.php`, read `validator.md` first, then use `fetching-data.md`, `error-handling.md`, and `route-handlers.md` for context-specific patterns, then consult the official Validator docs. `PP\Validator` is a Prisma PHP core class located in `vendor/tsnc/prisma-php/src/Validator.php`. Route creation is file-based from `src/app`; Prisma PHP auto-generates route listings such as `files-list.json`, so AI agents must not create, edit, or maintain that file manually._/}
12
14
 
13
15
  Welcome to the Prisma PHP documentation!
14
16
 
@@ -26,6 +28,8 @@ Whether you're building an internal dashboard, a content-rich platform, or a cus
26
28
 
27
29
  If you are using AI-assisted development, do not guess framework behavior from other ecosystems.
28
30
 
31
+ Every major page in `dist/docs` is intended to be AI-routable on its own. When a task clearly matches one of those pages, read that file before generating Prisma PHP code.
32
+
29
33
  Use this order:
30
34
 
31
35
  1. Read `./prisma-php.json` first.
@@ -110,9 +114,13 @@ Do not confuse the route-file pattern with the `ImportComponent` partial pattern
110
114
  ### Read this doc when you need
111
115
 
112
116
  - **project setup or file placement** → `project-structure.md`
117
+ - **CLI project creation, starter kits, create-prisma-php-app flags, or project update commands** → `commands.md`
118
+ - **backend-only Prisma PHP usage, API-first projects, `backendOnly`, CORS, separate frontend clients, or choosing `route.php` as the default route file** → `backend-only.md`
113
119
  - **pages, layouts, route creation, nested routes, or PulsePoint-aware `index.php` and `layout.php` structure** → `layouts-and-pages.md`
114
120
  - **PHPX components, props, children, fragments, icons, buttons, accordions, or component composition** → `components.md`
121
+ - **environment variables, `.env`, `PP\Env`, `Env::get(...)`, `Env::string(...)`, `Env::bool(...)`, `Env::int(...)`, or runtime configuration** → `env.md`
115
122
  - **file uploads, `multipart/form-data`, `$_FILES`, `PP\FileManager\UploadFile`, rename/delete flows, file replacement, allowed file types, upload size rules, or file manager pages** → `file-manager.md`
123
+ - **AI integration, provider SDKs, chat UIs, streamed assistant responses, or deciding between page-local AI features, websocket, and MCP** → `get-started-ia.md`
116
124
  - **SMTP setup, `.env` mail variables, `PP\PHPMailer\Mailer`, HTML email, text email, recipients, reply-to, CC, BCC, or attachments** → `email.md`
117
125
  - **Ratchet websocket setup, `IoServer`, `HttpServer`, `WsServer`, `ConnectionManager`, browser `WebSocket`, or realtime messaging** → `websocket.md`
118
126
  - **MCP server setup, `#[McpTool]`, `#[Schema]`, `PhpMcp\Server\Server`, `StreamableHttpServerTransport`, AI tool endpoints, or `src/Lib/MCP/mcp-server.php`** → `mcp.md`
@@ -124,6 +132,7 @@ Do not confuse the route-file pattern with the `ImportComponent` partial pattern
124
132
  - **error handling, `error.php`, `not-found.php`, expected validation errors** → `error-handling.md`
125
133
  - **metadata, title, description, favicon, icons** → `metadata-and-og-images.md`
126
134
  - **API-style endpoints, `route.php`, request validation with `Validator`** → `route-handlers.md`
135
+ - **Swagger or OpenAPI generation, `swaggerDocs`, `pphp-swagger.json`, `create-swagger-docs`, or `settings/prisma-schema-config.json`** → `swagger-docs.md`
127
136
  - **PulsePoint runtime APIs such as `pp.state`, `pp.effect`, `pp.ref`, `pp-for`, `pp-ref`, `pp-spread`** → `pulsepoint.md`
128
137
  - **updating the project or enabling features** → `upgrading.md`
129
138
  - **first-time project creation** → `installation.md`
@@ -135,6 +144,8 @@ Do not confuse the route-file pattern with the `ImportComponent` partial pattern
135
144
  - do not guess routing, file conventions, request helpers, component APIs, reactive syntax, or auth behavior when local docs already define them
136
145
  - create routes by adding folders and route files under `src/app`
137
146
  - do not create, edit, or maintain `files-list.json`; Prisma PHP generates route listings automatically
147
+ - when the project is API-first or backend-only, read `backend-only.md`, inspect `backendOnly` in `prisma-php.json`, and default to `route.php` for normal route behavior
148
+ - when reading runtime configuration, `.env`, or feature flags, read `env.md` first and prefer `PP\Env` typed helpers over repeated manual parsing
138
149
  - when building interactive frontend behavior, prefer the documented PulsePoint pattern with browser-side reactive state and `pp.fetchFunction(...)` for server calls; treat this as the default unless the user explicitly asks for a PHP-only interaction pattern
139
150
  - when building PulsePoint inside `index.php` or `layout.php`, read `layouts-and-pages.md` together with `pulsepoint.md`, use one parent route root, put `pp-component` on that root, and keep the `<script>` inside it as the last child
140
151
  - when importing a PHP partial with `ImportComponent`, require exactly one root element and keep any partial-local `<script>` inside that root because Prisma PHP attaches serialized props and a stable `pp-component` attribute to that imported root
@@ -143,11 +154,44 @@ Do not confuse the route-file pattern with the `ImportComponent` partial pattern
143
154
  - when building backend validation logic, read `validator.md` first, then use the route-specific docs for the request entry point
144
155
  - when using `pp.fetchFunction(...)`, expose the PHP function explicitly with `#[Exposed]`
145
156
  - when changing feature flags, update `prisma-php.json` first, then follow the documented update workflow
157
+ - when the task involves OpenAPI or Swagger generation, read `swagger-docs.md`, inspect `swaggerDocs` in `prisma-php.json`, and keep the generated spec path and config file aligned with the Prisma PHP workflow
146
158
  - when building reusable PHPX components, read `components.md` first
147
159
  - when building file-upload flows, file listings, rename/delete actions, or a file manager screen, read `file-manager.md` first and keep the implementation aligned with Prisma PHP’s documented File Manager model
148
160
  - when building MCP tools or server integrations, read `mcp.md` first, inspect `prisma-php.json`, and keep the implementation aligned with Prisma PHP's documented `src/Lib/MCP` server and attribute-based discovery model
149
161
  - when building auth flows, protection rules, or login/register pages, read `authentication.md` first and keep the implementation aligned with Prisma PHP’s documented auth model
150
162
 
163
+ ## AI Integration
164
+
165
+ Prisma PHP supports both provider-backed AI features inside normal pages and agent-facing MCP tooling, but those are different workflows.
166
+
167
+ For a normal chat UI, assistant panel, streamed summary, or other page-local AI feature, the default pattern is:
168
+
169
+ - render the route with `index.php`
170
+ - keep browser-side state in PulsePoint
171
+ - call PHP with `pp.fetchFunction(...)`
172
+ - expose callable PHP with `#[Exposed]`
173
+ - validate payloads with `PP\Validator`
174
+ - yield streamed chunks from PHP when incremental output is needed
175
+
176
+ Use `get-started-ia.md` as the local AI guide for provider-backed chat, streaming, and the boundary between page-local AI, websocket, and MCP tooling.
177
+
178
+ ## Env
179
+
180
+ Prisma PHP includes a documented environment helper centered on `PP\Env`, which reads already-loaded runtime values and exposes typed accessors for strings, booleans, and integers.
181
+
182
+ Use `env.md` as the local AI-awareness guide for:
183
+
184
+ - `.env` and runtime configuration boundaries
185
+ - `PP\Env`
186
+ - `Env::get(...)`, `Env::string(...)`, `Env::bool(...)`, and `Env::int(...)`
187
+ - app names, timezones, host and port settings, feature flags, and numeric limits
188
+ - provider keys, SMTP settings, and other server-only configuration values
189
+
190
+ After reading `env.md`, verify the matching official docs at:
191
+
192
+ 1. `env`
193
+ 2. `env-file` when the task is specifically about `.env` file contents or placement
194
+
151
195
  ## File Manager
152
196
 
153
197
  Prisma PHP includes a documented File Manager model for uploads and file operations based on standard PHP uploads plus `PP\FileManager\UploadFile`.
@@ -1,10 +1,29 @@
1
1
  ---
2
2
  title: Installation
3
- description: Learn how to create a new Prisma PHP application with the `create-prisma-php-app` CLI and start building locally.
3
+ description: Learn how to create a new Prisma PHP application so AI agents can use the first-time setup flow instead of existing-project update commands.
4
+ related:
5
+ title: Related docs
6
+ description: Read the full command reference and the existing-project update workflow.
7
+ links:
8
+ - /docs/commands
9
+ - /docs/upgrading
4
10
  ---
5
11
 
6
12
  Create a new Prisma PHP app and run it locally.
7
13
 
14
+ For the full create and update command reference, read `commands.md`.
15
+
16
+ If a task involves first-time Prisma PHP app creation, starter project bootstrap, or local setup, AI agents should read this page first and keep new-project setup separate from existing-project update workflows.
17
+
18
+ ## AI rule: use installation only for first-time setup
19
+
20
+ Before suggesting Prisma PHP installation steps, use this order:
21
+
22
+ 1. Use `create-prisma-php-app` only when the application does not exist yet.
23
+ 2. Read `commands.md` for feature flags, starter kits, and non-interactive creation options.
24
+ 3. Inspect the generated `prisma-php.json` after creation before generating feature-specific code.
25
+ 4. Use `upgrading.md` for existing projects instead of treating installation like an update workflow.
26
+
8
27
  ## Quick start
9
28
 
10
29
  1. Create a new Prisma PHP app.
@@ -12,7 +31,7 @@ Create a new Prisma PHP app and run it locally.
12
31
  3. Start the local development environment.
13
32
 
14
33
  ```bash package="npm"
15
- npx create-prisma-php-app@latest
34
+ npx create-prisma-php-app@latest my-app
16
35
  cd my-app
17
36
  npm run dev
18
37
  ```
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  title: Layouts and Pages
3
- description: Learn how to create your first pages and layouts in Prisma PHP, structure routes with the framework's file conventions, and keep PulsePoint-aware route files predictable.
3
+ description: Learn how AI agents should create pages and layouts in Prisma PHP, choose the correct route files, and keep PulsePoint-aware route files predictable.
4
4
  related:
5
5
  title: API Reference
6
6
  description: Learn more about the features mentioned in this page by reading the Prisma PHP routing and PulsePoint documentation.
@@ -17,6 +17,18 @@ related:
17
17
 
18
18
  Prisma PHP uses **file-system based routing**, meaning you can use folders and files to define routes. This page explains how to create pages and layouts, how to choose the correct route file, and how to keep PulsePoint-aware route files structurally consistent.
19
19
 
20
+ If a task involves pages, layouts, route folders, dynamic routes, or choosing between `index.php` and `route.php`, AI agents should read this page first and keep route-file structure aligned with the installed Prisma PHP version.
21
+
22
+ ## AI rule: read the route docs first
23
+
24
+ Before generating Prisma PHP route files, use this order:
25
+
26
+ 1. Read `prisma-php.json`.
27
+ 2. Decide whether the project is full-stack or backend-only.
28
+ 3. Use `index.php` for rendered pages, `route.php` for direct handlers, and `layout.php` for shared subtree UI.
29
+ 4. Keep PulsePoint-aware route files to one parent root element with the `<script>` inside it.
30
+ 5. Do not edit `files-list.json`; Prisma PHP derives route metadata from the route tree.
31
+
20
32
  ## Important route generation note
21
33
 
22
34
  In Prisma PHP, routes are created from folders and special files inside `src/app`.