prisma-php 0.0.8 → 0.0.10

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.
@@ -4,6 +4,7 @@
4
4
 
5
5
  - Treat `dist/docs/index.md` as the entry point for Prisma PHP guidance in this repo.
6
6
  - Read the matching doc in `dist/docs` before generating or editing framework-specific Prisma PHP code.
7
+ - When updating AI guidance in this repo, keep `AGENTS.md`, `.github/copilot-instructions.md`, and `dist/docs` aligned.
7
8
 
8
9
  ## Route File Conventions
9
10
 
@@ -20,6 +21,16 @@
20
21
 
21
22
  ## Relevant Docs
22
23
 
24
+ - Project structure and feature placement: `dist/docs/project-structure.md`
23
25
  - Route and layout structure: `dist/docs/layouts-and-pages.md`
26
+ - Data loading, `#[Exposed]`, and SSE streaming: `dist/docs/fetching-data.md`
24
27
  - PulsePoint runtime rules: `dist/docs/pulsepoint.md`
25
- - Component and `ImportComponent` rules: `dist/docs/components.md`
28
+ - Component and `ImportComponent` rules: `dist/docs/components.md`
29
+ - Validation rules: `dist/docs/validator.md`
30
+ - File uploads and file manager behavior: `dist/docs/file-manager.md`
31
+ - Email and SMTP workflows: `dist/docs/email.md`
32
+ - WebSocket and realtime behavior: `dist/docs/websocket.md`
33
+ - MCP server and tool rules: `dist/docs/mcp.md`
34
+ - Authentication: `dist/docs/authentication.md`
35
+ - Metadata and icons: `dist/docs/metadata-and-og-images.md`
36
+ - API-style handlers and webhooks: `dist/docs/route-handlers.md`
@@ -0,0 +1,189 @@
1
+ ---
2
+ title: Email
3
+ description: Learn how Prisma PHP email works so AI agents can configure SMTP with .env and send mail with PP\PHPMailer\Mailer using the documented fluent API instead of inventing custom mail abstractions.
4
+ related:
5
+ title: Related docs
6
+ description: Read the official Prisma PHP email docs before generating or editing mail flows.
7
+ links:
8
+ - /docs/email-get-started
9
+ - /docs/env-file
10
+ - /docs/php-validator
11
+ - /docs/fetch-function
12
+ - /docs/route-php
13
+ ---
14
+
15
+ Prisma PHP email sending should follow the documented `PP\PHPMailer\Mailer` model backed by PHPMailer, not assumptions copied from Laravel Mail, Symfony Mailer, Nodemailer, or ad hoc `mail()` wrappers.
16
+
17
+ If a task involves SMTP configuration, contact forms, transactional email, HTML bodies, plain-text fallbacks, reply-to, CC, BCC, attachments, or mailer troubleshooting, AI agents should read the relevant Prisma PHP email docs first and keep the implementation aligned with the installed version.
18
+
19
+ ## AI rule: read the Email docs first
20
+
21
+ Before generating, editing, or reviewing email-related code, use this order:
22
+
23
+ 1. Read `./prisma-php.json`.
24
+ 2. Read the installed local docs in `node_modules/prisma-php/dist/docs`.
25
+ 3. Read this `email.md` file.
26
+ 4. Inspect the current `.env` file for SMTP and sender values.
27
+ 5. Inspect the route, exposed function, or handler that sends the email.
28
+ 6. Inspect the HTML body or template shape and attachment sources when present.
29
+ 7. Inspect Prisma PHP core internals only when the docs do not answer the task.
30
+
31
+ Do not assume another framework's mailer abstraction applies directly.
32
+
33
+ ## Read this doc when you need
34
+
35
+ - **SMTP setup, `.env` mail variables, `PP\PHPMailer\Mailer`, `sendEmail`, HTML email, text email, `from`, `to`, `cc`, `bcc`, `replyTo`, or attachments** → official `email-get-started`
36
+ - **contact forms or page-local email sends via PulsePoint** → `fetching-data.md` plus `email.md`
37
+ - **direct POST handlers or handler-only email routes** → `route-handlers.md` plus `email.md`
38
+ - **validation of recipient, sender, or contact-form input** → `validator.md` plus `email.md`
39
+ - **uploaded files used as email attachments** → `file-manager.md` plus `email.md`
40
+
41
+ ## Core email model AI should follow
42
+
43
+ The Prisma PHP mailer is a PHPMailer wrapper with a fluent API.
44
+
45
+ The constructor initializes a `PHPMailer` instance, forces `UTF-8`, configures SMTP transport from `.env`, and applies a default sender when `MAIL_FROM` is present and valid.
46
+
47
+ AI should preserve that model instead of replacing it with undocumented helpers or raw `mail()` calls.
48
+
49
+ ## Exact core file location
50
+
51
+ The Prisma PHP core `Mailer` class lives here:
52
+
53
+ ```txt
54
+ vendor/tsnc/prisma-php/src/PHPMailer/Mailer.php
55
+ ```
56
+
57
+ When AI needs to inspect framework internals because the docs do not fully answer an email task, this is the exact core file to review.
58
+
59
+ ## `.env` variables AI should expect
60
+
61
+ The current `Mailer` implementation reads these environment values:
62
+
63
+ ```dotenv
64
+ SMTP_HOST=smtp.example.com
65
+ SMTP_USERNAME=you@example.com
66
+ SMTP_PASSWORD=your-app-password
67
+ SMTP_ENCRYPTION=tls
68
+ SMTP_PORT=587
69
+ MAIL_FROM=no-reply@example.com
70
+ MAIL_FROM_NAME="Prisma PHP App"
71
+ ```
72
+
73
+ Behavior notes:
74
+
75
+ - `SMTP_HOST` defaults to `localhost`
76
+ - `SMTP_USERNAME` defaults to an empty string
77
+ - `SMTP_PASSWORD` defaults to an empty string
78
+ - `SMTP_ENCRYPTION` defaults to `PHPMailer::ENCRYPTION_STARTTLS`, which resolves to `tls`
79
+ - `SMTP_PORT` defaults to `587`
80
+ - `MAIL_FROM` is optional, but when it is present it must be a valid email address
81
+ - `MAIL_FROM_NAME` is optional
82
+
83
+ AI should update `.env` whenever email support is introduced and should not hardcode SMTP credentials in route files or components.
84
+
85
+ ## Public fluent methods AI should know
86
+
87
+ The current `Mailer` class exposes:
88
+
89
+ - `from(string $email, ?string $name = null)`
90
+ - `to(string $email, ?string $name = null)`
91
+ - `cc(string $email, ?string $name = null)`
92
+ - `bcc(string $email, ?string $name = null)`
93
+ - `replyTo(string $email, ?string $name = null)`
94
+ - `subject(string $subject)`
95
+ - `html(string $html, ?string $altText = null)`
96
+ - `text(string $text)`
97
+ - `attach(string $path, ?string $name = null)`
98
+ - `attachMany(array $attachments)`
99
+ - `send(): bool`
100
+ - `raw(): PHPMailer`
101
+
102
+ Do not invent undocumented convenience methods when this fluent surface already covers the normal workflow.
103
+
104
+ ## Address validation and failure behavior
105
+
106
+ The `Mailer` class validates email addresses with `PP\Validator::email(...)`.
107
+
108
+ Important behavior:
109
+
110
+ - `from`, `to`, `cc`, `bcc`, and `replyTo` throw a PHPMailer `Exception` when the email is invalid
111
+ - `attach` throws when the file does not exist
112
+ - `attachMany` accepts either plain file paths or arrays shaped like `['path' => '...', 'name' => '...']`
113
+ - `send()` returns `true` on success and throws an `Exception` on failure
114
+
115
+ For incoming form data, still validate and normalize request fields before calling the mailer. Do not depend on mailer exceptions as the only user-input validation layer.
116
+
117
+ ## Message lifecycle
118
+
119
+ `Mailer` tracks whether the current message has been modified.
120
+
121
+ On the first mutating call, it clears prior recipients, attachments, subject, and bodies so a reused `Mailer` instance starts from a clean message state. After `send()`, it clears the message state again on both success and failure.
122
+
123
+ AI should not assume recipients or attachments persist safely across separate sends on the same instance.
124
+
125
+ ## HTML and text bodies
126
+
127
+ Use `html()` for HTML messages.
128
+
129
+ Important behavior:
130
+
131
+ - `html()` sets `isHTML(true)`
132
+ - `AltBody` is generated automatically from the HTML when no explicit plain-text alternative is supplied
133
+ - line breaks are preserved from common tags such as `<br>`, `</p>`, and `</div>` before tags are stripped
134
+
135
+ Use `text()` for plain-text-only email.
136
+
137
+ ## Recommended example pattern
138
+
139
+ ```php
140
+ <?php
141
+
142
+ use PP\PHPMailer\Mailer;
143
+ use PP\Validator;
144
+
145
+ $recipient = Validator::email($_POST['email'] ?? '');
146
+
147
+ if ($recipient === null) {
148
+ return [
149
+ 'success' => false,
150
+ 'message' => 'A valid email address is required.',
151
+ ];
152
+ }
153
+
154
+ $body = <<<HTML
155
+ <h1>Welcome</h1>
156
+ <p>Your account is ready.</p>
157
+ HTML;
158
+
159
+ $mailer = new Mailer();
160
+
161
+ $mailer->to($recipient)
162
+ ->subject('Welcome to Prisma PHP')
163
+ ->html($body, "Welcome\n\nYour account is ready.")
164
+ ->send();
165
+ ```
166
+
167
+ ## Advanced configuration
168
+
169
+ Use `raw()` only when the documented fluent API is not enough and a low-level PHPMailer setting must be adjusted.
170
+
171
+ That is the correct escape hatch for:
172
+
173
+ - embedded images
174
+ - custom headers
175
+ - SMTP options
176
+ - low-level PHPMailer features not wrapped by `Mailer`
177
+
178
+ Do not start with `raw()` when the fluent API already matches the task.
179
+
180
+ ## AI rules for email tasks
181
+
182
+ - read `email.md` before generating email-related code
183
+ - inspect `.env` and add the required mail variables when email support is introduced
184
+ - prefer `PP\PHPMailer\Mailer` over raw `mail()` or custom SMTP wrappers
185
+ - keep SMTP credentials and sender defaults in `.env`, not in route files
186
+ - validate user-provided email fields before calling the mailer
187
+ - use `html()` for HTML email and provide a custom plain-text alternative when the fallback copy matters
188
+ - check attachment paths before sending or let the documented exception surface a missing file clearly
189
+ - inspect `vendor/tsnc/prisma-php/src/PHPMailer/Mailer.php` only when the docs and current app code do not answer the task
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  title: Fetching Data
3
- description: Learn how to fetch data in Prisma PHP using `pp.fetchFunction`, `#[Exposed]`, page handlers, and route handlers.
3
+ description: Learn how to fetch and stream data in Prisma PHP using `pp.fetchFunction`, `#[Exposed]`, page handlers, SSE responses, and route handlers.
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 docs.
@@ -12,15 +12,17 @@ related:
12
12
  - /docs/pages-and-layouts
13
13
  ---
14
14
 
15
- This page will walk you through how you can fetch data in Prisma PHP, when to use `pp.fetchFunction(...)`, when to use `index.php`, when to use `route.php`, and how to validate incoming data correctly on the PHP side.
15
+ This page will walk you through how you can fetch and stream data in Prisma PHP, when to use `pp.fetchFunction(...)`, when to use `index.php`, when to use `route.php`, and how to validate incoming data correctly on the PHP side.
16
16
 
17
- Prisma PHP has a different mental model from Next.js. Instead of focusing on React Server Components, Suspense streaming, and client data libraries, Prisma PHP gives you direct function invocation from the frontend to PHP, plus file-based routing for page UI and direct route handlers.
17
+ Prisma PHP has a different mental model from Next.js. Instead of focusing on React Server Components, Suspense-driven HTML streaming, and client data libraries, Prisma PHP gives you direct function invocation from the frontend to PHP, plus file-based routing for page UI and direct route handlers.
18
18
 
19
19
  When using `pp.fetchFunction(...)`, the PHP function must be explicitly exposed with `#[Exposed]`. Functions are private by default, so a non-exposed function cannot be called from the client.
20
20
 
21
21
  For validation, the default backend pattern should be **`PP\Validator`**. Use it to sanitize, cast, and validate values inside exposed functions and route handlers. This keeps the browser reactive while keeping the authoritative validation on the server.
22
22
  Read `validator.md` alongside this page when you need the detailed helper list, rule syntax options, or the `Validator::withRules(...)` return contract.
23
23
 
24
+ Prisma PHP can also stream incremental chunks back through `pp.fetchFunction(...)` when an exposed function **yields** values. Prisma PHP handles the SSE response for you, which makes this a good fit for long-running actions, progressive assistant output, status logs, and similar incremental UI updates.
25
+
24
26
  ## Default AI decision rule
25
27
 
26
28
  For **normal interactive full-stack Prisma PHP work**, AI should default to this stack:
@@ -93,7 +95,7 @@ For normal interactive UI work in Prisma PHP, the default approach should be:
93
95
  3. call PHP from the frontend with `pp.fetchFunction(...)`
94
96
  4. expose callable functions with `#[Exposed]`
95
97
 
96
- This is the preferred pattern for live search, inline validation, toggles, quick edits, filtering, lightweight mutations, pagination, modal workflows, and similar route-local interactions.
98
+ This is the preferred pattern for live search, inline validation, toggles, quick edits, filtering, lightweight mutations, pagination, modal workflows, streaming assistants, progress logs, and similar route-local interactions.
97
99
 
98
100
  Do **not** default to building extra `route.php` endpoints for every interactive action when `pp.fetchFunction(...)` is the better fit. Also do **not** default to a PHP-only interaction model for normal reactive page behavior unless the user explicitly asks for that style. Reserve `route.php` for explicit API-style endpoints, webhooks, JSON handlers, or routes that must be called independently of the page.
99
101
 
@@ -113,7 +115,7 @@ Use this rule of thumb:
113
115
  - use `pp.fetchFunction(...)` when frontend interactivity should call backend PHP directly without creating a dedicated route file
114
116
  - use `route.php` when you need a direct API-style endpoint, JSON handler, webhook, or no-view request path
115
117
 
116
- In a full-stack Prisma PHP project, normal page data is usually loaded in `index.php`, and interactive frontend updates are commonly handled with `pp.fetchFunction(...)`.
118
+ In a full-stack Prisma PHP project, normal page data is usually loaded in `index.php`, and interactive frontend updates are commonly handled with `pp.fetchFunction(...)`. That same fetch path can also deliver incremental SSE chunks when the response is streamed.
117
119
 
118
120
  ## Fetching data in `index.php`
119
121
 
@@ -333,6 +335,164 @@ This is useful for search inputs, streaming responses, uploads, and other rapid
333
335
 
334
336
  As with every `pp.fetchFunction(...)` call, `searchUsers` must be decorated with `#[Exposed]` on the PHP side.
335
337
 
338
+ ### What the promise resolves to
339
+
340
+ Normal `pp.fetchFunction(...)` calls resolve with the parsed backend result.
341
+
342
+ There are three important response modes:
343
+
344
+ - JSON or JSON-compatible response: the promise resolves with the parsed value
345
+ - redirect response: Prisma PHP handles the redirect and returns a small redirect object
346
+ - generator or `text/event-stream` response: Prisma PHP reads the stream incrementally and the promise resolves after the stream finishes, usually with no final JSON payload
347
+
348
+ When you expect a stream, put your UI updates inside `onStream`, `onStreamError`, and `onStreamComplete` instead of waiting for a final response object.
349
+
350
+ ## Streaming responses with SSE
351
+
352
+ Prisma PHP supports incremental streaming through **Server-Sent Events** when `pp.fetchFunction(...)` receives a streaming response.
353
+
354
+ The current runtime already sends these request headers for `pp.fetchFunction(...)`:
355
+
356
+ - `Accept: application/json, text/event-stream`
357
+ - `X-PP-Function: ...`
358
+ - the normal Prisma PHP AJAX and wire-request headers
359
+
360
+ That means a normal fetch function can return JSON for short requests or a stream for long-running work, progressive generation, status logs, or assistant-style responses.
361
+
362
+ ### Simple server-side pattern
363
+
364
+ For normal `pp.fetchFunction(...)` streaming, you usually do **not** need to manually create `SSE` or `ServerSentEvent` objects.
365
+
366
+ The simplest pattern is:
367
+
368
+ 1. mark the function with `#[Exposed]`
369
+ 2. make the function yield plain strings or arrays
370
+ 3. let Prisma PHP handle the SSE response automatically
371
+
372
+ That is the pattern to prefer for chat responses, AI output, progress updates, and incremental UI messages.
373
+
374
+ ```php filename="src/app/assistant/index.php"
375
+ <?php
376
+
377
+ use PP\Attributes\Exposed;
378
+ use PP\Validator;
379
+
380
+ #[Exposed]
381
+ function streamSummary($data)
382
+ {
383
+ $topic = Validator::string(trim((string)($data->topic ?? '')));
384
+
385
+ if ($topic === '') {
386
+ yield ['error' => true, 'chunk' => 'Topic is required.'];
387
+ return;
388
+ }
389
+
390
+ yield ['chunk' => 'Reading docs...'];
391
+ yield ['chunk' => 'Collecting facts...'];
392
+ yield ['chunk' => 'Writing summary...'];
393
+
394
+ foreach (['Point one. ', 'Point two. ', 'Point three.'] as $delta) {
395
+ yield ['chunk' => $delta];
396
+ }
397
+ }
398
+ ```
399
+
400
+ For AI streaming specifically, the common pattern is even simpler: as the provider returns text deltas, just yield them.
401
+
402
+ ```php filename="src/app/chat/index.php"
403
+ <?php
404
+
405
+ use PP\Attributes\Exposed;
406
+
407
+ #[Exposed]
408
+ function aiSendMessageStream($data)
409
+ {
410
+ foreach ($aiClient->streamReply($data->message ?? '') as $delta) {
411
+ if ($delta !== '') {
412
+ yield ['chunk' => $delta];
413
+ }
414
+ }
415
+ }
416
+ ```
417
+
418
+ Prisma PHP handles the rest of the streaming response.
419
+
420
+ ### Low-level helpers when you need manual control
421
+
422
+ If you need explicit control over raw SSE event metadata, Prisma PHP also includes these streaming helpers:
423
+
424
+ - `PP\Streaming\SSE`
425
+ - `PP\Streaming\ServerSentEvent`
426
+
427
+ Core locations in Prisma PHP:
428
+
429
+ ```txt
430
+ vendor/tsnc/prisma-php/src/SSE.php
431
+ vendor/tsnc/prisma-php/src/Streaming/ServerSentEvent.php
432
+ ```
433
+
434
+ `SSE` wraps a `Generator`, sets the default SSE headers, and flushes each yielded item.
435
+ `ServerSentEvent` lets you send `data`, plus optional `event`, `id`, and `retry` metadata for each chunk.
436
+
437
+ By default, the low-level `SSE` helper sends these response headers:
438
+
439
+ - `Content-Type: text/event-stream`
440
+ - `Cache-Control: no-cache`
441
+ - `Connection: keep-alive`
442
+ - `X-Accel-Buffering: no`
443
+
444
+ ### Client-side usage with `pp.fetchFunction(...)`
445
+
446
+ ```html
447
+ <script>
448
+ const [streamText, setStreamText] = pp.state('');
449
+ const [streamDone, setStreamDone] = pp.state(false);
450
+
451
+ async function loadSummary() {
452
+ let buffer = '';
453
+
454
+ setStreamText('');
455
+ setStreamDone(false);
456
+
457
+ await pp.fetchFunction(
458
+ 'streamSummary',
459
+ { topic: 'Prisma PHP streaming' },
460
+ {
461
+ onStream(data) {
462
+ if (data.error) {
463
+ setStreamText(data.chunk || 'Stream failed.');
464
+ return;
465
+ }
466
+
467
+ const delta = data.chunk || '';
468
+ buffer += delta;
469
+ setStreamText(buffer);
470
+ },
471
+ onStreamComplete() {
472
+ setStreamDone(true);
473
+ },
474
+ onStreamError(error) {
475
+ setStreamText(`Stream failed: ${error.message}`);
476
+ },
477
+ }
478
+ );
479
+ }
480
+ </script>
481
+ ```
482
+
483
+ ### Current stream parsing rules
484
+
485
+ When an exposed function yields, Prisma PHP sends the streamed payload as SSE `data:` lines. The current `pp.fetchFunction(...)` stream parser reads those SSE lines one at a time and only forwards `data:` lines to `onStream`.
486
+
487
+ That means:
488
+
489
+ - JSON-looking chunks such as objects, arrays, booleans, `null`, numbers, and quoted strings are parsed into JavaScript values
490
+ - plain text chunks stay as strings
491
+ - `event:`, `id:`, and `retry:` can be emitted by `ServerSentEvent`, but the built-in `pp.fetchFunction(...)` stream callback currently ignores them
492
+ - because the current encoder writes one `data:` line per event, prefer JSON values or single-line strings instead of multi-line text blobs
493
+
494
+ If your client logic depends on named events, event IDs, or retry hints, use a lower-level SSE client instead of relying on the default `pp.fetchFunction(...)` chunk parser alone.
495
+
336
496
  ## File upload support
337
497
 
338
498
  Prisma PHP’s fetch function automatically switches to multipart handling when the payload contains a `File` or `FileList`.
@@ -359,6 +519,8 @@ That means you do not need to manually build `FormData` for many common upload f
359
519
  <button onclick="uploadAvatar()">Upload</button>
360
520
  ```
361
521
 
522
+ When you pass `onUploadProgress`, Prisma PHP switches to an **XMLHttpRequest** upload path so the browser can report progress. That upload-progress path is meant for normal request-response uploads; it is not the same code path as SSE chunk streaming.
523
+
362
524
  ## Request cancellation
363
525
 
364
526
  For fast-changing inputs such as live search, Prisma PHP can automatically cancel stale requests by using `abortPrevious: true`.
@@ -467,6 +629,7 @@ This is a better fit for:
467
629
  - external integrations
468
630
  - webhooks
469
631
  - standalone JSON endpoints
632
+ - standalone SSE endpoints that should exist independently of the current page
470
633
  - routes that should be called outside the current page context
471
634
  - API-style request handlers
472
635
 
@@ -612,7 +775,7 @@ echo json_encode([
612
775
 
613
776
  ## Loading states
614
777
 
615
- Unlike Next.js, Prisma PHP’s data-fetching story here is not centered on React Suspense or streaming server components.
778
+ Unlike Next.js, Prisma PHP’s data-fetching story here is not centered on React Suspense, page HTML streaming, or streaming server components. Prisma PHP can stream request results over SSE, but that is a separate request-response mechanism rather than a page-rendering model.
616
779
 
617
780
  Instead, loading behavior is typically handled in the UI with:
618
781
 
@@ -621,7 +784,7 @@ Instead, loading behavior is typically handled in the UI with:
621
784
  - route-level `loading.php`
622
785
  - custom interactive state patterns
623
786
 
624
- For interactive fetches, you usually manage loading state yourself:
787
+ For interactive fetches and streamed calls, you usually manage loading state yourself:
625
788
 
626
789
  ```html
627
790
  <script>
@@ -662,10 +825,13 @@ Because Prisma PHP runs the data logic in PHP, database credentials and internal
662
825
  - `index.php` is the UI entry point for page rendering.
663
826
  - `route.php` is the direct handler entry point for API-style routes.
664
827
  - `pp.fetchFunction(...)` only works for functions that are explicitly marked with `#[Exposed]`.
665
- - `pp.fetchFunction(...)` automatically serializes and parses data.
828
+ - `pp.fetchFunction(...)` automatically serializes request data, parses normal JSON responses, and can consume SSE `data:` chunks.
666
829
  - `Validator` is the default PHP validation layer for reactive requests and backend handlers.
667
830
  - prefer `Validator::withRules(...)` with `Rule` for rule-based validation.
668
831
  - `abortPrevious: true` helps cancel stale requests.
832
+ - streamed `pp.fetchFunction(...)` calls usually resolve after the stream completes, so render stream output from `onStream` callbacks rather than expecting one final JSON object.
833
+ - the built-in stream parser currently reads `data:` lines only; `event`, `id`, and `retry` metadata are not surfaced to `onStream`.
669
834
  - file uploads can be handled automatically without manual `FormData` in many cases.
835
+ - `onUploadProgress` switches the request to an XHR upload path so progress events can be reported.
670
836
  - `Exposed` can be used to declare authentication, allowed roles, and rate limits for callable functions.
671
837
  - for full-stack routes, load page data in `index.php` and use PulsePoint plus direct function invocation for interactive updates unless the user explicitly asks for a PHP-only flow.
@@ -8,7 +8,7 @@ related:
8
8
  - /docs/get-started
9
9
  ---
10
10
 
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 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._/}
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._/}
12
12
 
13
13
  Welcome to the Prisma PHP documentation!
14
14
 
@@ -113,6 +113,9 @@ Do not confuse the route-file pattern with the `ImportComponent` partial pattern
113
113
  - **pages, layouts, route creation, nested routes, or PulsePoint-aware `index.php` and `layout.php` structure** → `layouts-and-pages.md`
114
114
  - **PHPX components, props, children, fragments, icons, buttons, accordions, or component composition** → `components.md`
115
115
  - **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`
116
+ - **SMTP setup, `.env` mail variables, `PP\PHPMailer\Mailer`, HTML email, text email, recipients, reply-to, CC, BCC, or attachments** → `email.md`
117
+ - **Ratchet websocket setup, `IoServer`, `HttpServer`, `WsServer`, `ConnectionManager`, browser `WebSocket`, or realtime messaging** → `websocket.md`
118
+ - **MCP server setup, `#[McpTool]`, `#[Schema]`, `PhpMcp\Server\Server`, `StreamableHttpServerTransport`, AI tool endpoints, or `src/Lib/MCP/mcp-server.php`** → `mcp.md`
116
119
  - **authentication strategy, `AuthConfig.php`, sign-in, sign-out, route privacy model, RBAC, credentials auth, social login, or auth state manager usage** → `authentication.md`
117
120
  - **validation, sanitization, casting, `PP\Validator`, `Rule`, or `Validator::withRules(...)`** → `validator.md`
118
121
  - **`pp.fetchFunction(...)`, `#[Exposed]`, page data loading, interactive validation with `Validator`** → `fetching-data.md`
@@ -142,6 +145,7 @@ Do not confuse the route-file pattern with the `ImportComponent` partial pattern
142
145
  - when changing feature flags, update `prisma-php.json` first, then follow the documented update workflow
143
146
  - when building reusable PHPX components, read `components.md` first
144
147
  - 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
+ - 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
145
149
  - 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
146
150
 
147
151
  ## File Manager
@@ -164,6 +168,61 @@ After reading `file-manager.md`, read `validator.md` when non-file request value
164
168
  2. `php-validator` when auxiliary request validation is needed
165
169
  3. `route-php` or `pages-and-layouts` depending on whether the task is a direct handler or a full-stack page
166
170
 
171
+ ## Email
172
+
173
+ Prisma PHP includes a documented email workflow centered on `PP\PHPMailer\Mailer`, SMTP configuration in `.env`, and PHPMailer-backed message delivery.
174
+
175
+ Use `email.md` as the local AI-awareness guide for:
176
+
177
+ - SMTP setup and sender defaults in `.env`
178
+ - `PP\PHPMailer\Mailer`
179
+ - HTML and plain-text email composition
180
+ - recipients, reply-to, CC, and BCC
181
+ - attachments and attachment arrays
182
+ - low-level PHPMailer access through `raw()` when necessary
183
+
184
+ After reading `email.md`, verify the matching official docs at:
185
+
186
+ 1. `email-get-started`
187
+
188
+ ## WebSocket
189
+
190
+ Prisma PHP includes a documented websocket workflow centered on a Ratchet-based PHP server, a `ConnectionManager` class under `src/Lib/Websocket`, and the browser `WebSocket` API for realtime client connections.
191
+
192
+ Use `websocket.md` as the local AI-awareness guide for:
193
+
194
+ - enabling websocket support in `prisma-php.json`
195
+ - the update workflow that scaffolds websocket support into an existing project
196
+ - `src/Lib/Websocket/websocket-server.php`
197
+ - `src/Lib/Websocket/ConnectionManager.php`
198
+ - Ratchet server setup with `IoServer`, `HttpServer`, and `WsServer`
199
+ - connection lifecycle methods such as `onOpen`, `onMessage`, `onClose`, and `onError`
200
+ - native browser websocket clients and route-local realtime UI behavior
201
+
202
+ After reading `websocket.md`, verify the matching official docs in this order:
203
+
204
+ 1. `websocket-get-started`
205
+ 2. `websocket-chat-app`
206
+
207
+ ## MCP
208
+
209
+ Prisma PHP includes a documented MCP workflow centered on a `PhpMcp\Server` HTTP entry under `src/Lib/MCP`, attribute-based tool discovery with `#[McpTool]`, and `StreamableHttpServerTransport` for agent integrations.
210
+
211
+ Use `mcp.md` as the local AI-awareness guide for:
212
+
213
+ - enabling MCP support in `prisma-php.json`
214
+ - the update workflow that scaffolds MCP support into an existing project
215
+ - `src/Lib/MCP/mcp-server.php`
216
+ - tool classes such as `src/Lib/MCP/WeatherTools.php`
217
+ - `#[McpTool]` and `#[Schema]`
218
+ - `StreamableHttpServerTransport`, JSON response debugging, and Inspector-based debugging
219
+ - auth and Prisma access inside tool methods
220
+
221
+ After reading `mcp.md`, verify the matching official docs in this order:
222
+
223
+ 1. `prisma-php-ai-mcp`
224
+ 2. `ai-tools`
225
+
167
226
  ## Authentication
168
227
 
169
228
  Prisma PHP includes a documented authentication model centered on sessions, route protection strategy, RBAC, and provider-based sign-in flows.