prisma-php 0.0.10 → 0.0.12

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.
@@ -2,9 +2,11 @@
2
2
 
3
3
  ## Source Of Truth
4
4
 
5
- - Treat `dist/docs/index.md` as the entry point for Prisma PHP guidance in this repo.
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.
5
+ - For Prisma PHP applications, treat `node_modules/prisma-php/dist/docs/index.md` as the entry point for the installed framework version.
6
+ - Read the matching doc in `node_modules/prisma-php/dist/docs` before generating or editing framework-specific Prisma PHP code.
7
+ - Expect `AGENTS.md` in the project root and keep it aligned with the installed Prisma PHP docs contract.
8
+ - When updating Prisma PHP package/docs sources in this repo, keep `AGENTS.md`, `.github/copilot-instructions.md`, and `dist/docs` aligned so the published docs remain correct after install.
9
+ - Keep every `dist/docs/*.md` page AI-discoverable on its own: the frontmatter description and opening section should clearly say when agents should read that file and which adjacent docs to consult next.
8
10
 
9
11
  ## Route File Conventions
10
12
 
@@ -16,21 +18,32 @@
16
18
  ## Component Boundary Rules
17
19
 
18
20
  - Distinguish PHPX class components from `ImportComponent` partials.
19
- - `ImportComponent` partials must output exactly one root element because Prisma PHP attaches serialized props and a stable `pp-component` attribute to that root.
21
+ - `ImportComponent` partials must output exactly one root element because Prisma PHP uses that root as the imported component boundary and serializes props there.
20
22
  - Do not manually add `pp-component` inside `ImportComponent` partial source; Prisma PHP injects it there. For normal PulsePoint-aware route files, add `pp-component` to the single root element yourself.
21
23
 
22
24
  ## Relevant Docs
23
25
 
24
26
  - Project structure and feature placement: `dist/docs/project-structure.md`
27
+ - CLI project creation and update commands: `dist/docs/commands.md`
28
+ - First-time project installation and local setup: `dist/docs/installation.md`
29
+ - Existing-project upgrades and feature refreshes: `dist/docs/upgrading.md`
30
+ - TypeScript frontend tooling, the `typescript` flag, and `ts/main.ts` registration: `dist/docs/typescript.md`
31
+ - Backend-only API usage and `backendOnly`: `dist/docs/backend-only.md`
25
32
  - Route and layout structure: `dist/docs/layouts-and-pages.md`
33
+ - AI integration, provider-backed chat, streaming, and MCP boundary: `dist/docs/get-started-ia.md`
26
34
  - Data loading, `#[Exposed]`, and SSE streaming: `dist/docs/fetching-data.md`
27
35
  - PulsePoint runtime rules: `dist/docs/pulsepoint.md`
28
36
  - Component and `ImportComponent` rules: `dist/docs/components.md`
37
+ - Cache behavior and `CacheHandler`: `dist/docs/caching.md`
29
38
  - Validation rules: `dist/docs/validator.md`
39
+ - Prisma ORM schema, migrations, and generated PHP classes: `dist/docs/prisma-php-orm.md`
40
+ - Environment variables and `PP\Env` usage: `dist/docs/env.md`
30
41
  - File uploads and file manager behavior: `dist/docs/file-manager.md`
31
42
  - Email and SMTP workflows: `dist/docs/email.md`
32
43
  - WebSocket and realtime behavior: `dist/docs/websocket.md`
33
44
  - MCP server and tool rules: `dist/docs/mcp.md`
34
45
  - Authentication: `dist/docs/authentication.md`
46
+ - Error handling, expected failures, and route error files: `dist/docs/error-handling.md`
35
47
  - Metadata and icons: `dist/docs/metadata-and-og-images.md`
36
- - API-style handlers and webhooks: `dist/docs/route-handlers.md`
48
+ - API-style handlers and webhooks: `dist/docs/route-handlers.md`
49
+ - Swagger/OpenAPI generation and `swaggerDocs`: `dist/docs/swagger-docs.md`
@@ -0,0 +1,204 @@
1
+ ---
2
+ title: Backend-only API usage
3
+ nav_title: Backend-only APIs
4
+ description: Learn how Prisma PHP backend-only apps work so AI agents can choose route.php-first API patterns, connect separate clients safely, and keep backendOnly workflows aligned with the framework.
5
+ related:
6
+ title: API Reference
7
+ description: Read the official Prisma PHP API and Swagger docs alongside the local backend-only guidance.
8
+ links:
9
+ - /docs/api-get-started
10
+ - /docs/route-php
11
+ - /docs/php-validator
12
+ - /docs/swagger-docs-api
13
+ ---
14
+
15
+ ## Backend-only Prisma PHP
16
+
17
+ Prisma PHP can run as a backend-only application when the project is intended to serve JSON endpoints, webhooks, mobile clients, or a separate frontend instead of rendering route UI with `index.php`.
18
+
19
+ In that mode, the main project-level flag is `backendOnly` in `prisma-php.json`.
20
+
21
+ If a task involves API-first Prisma PHP usage, separate frontend consumers, CORS, webhooks, or machine-facing endpoints, AI agents should read this page first and keep the implementation aligned with the installed Prisma PHP version.
22
+
23
+ ## AI rule: read the backend-only docs first
24
+
25
+ Before generating backend-only Prisma PHP code, use this order:
26
+
27
+ 1. Read `prisma-php.json`.
28
+ 2. Confirm that `backendOnly` is enabled or that the user explicitly wants API-first behavior.
29
+ 3. Read this `backend-only.md` page.
30
+ 4. Use `route-handlers.md`, `validator.md`, and `swagger-docs.md` for handler, validation, and contract workflow details.
31
+ 5. Inspect the current route tree before inventing extra API structure.
32
+
33
+ ```json filename="prisma-php.json"
34
+ {
35
+ "backendOnly": true,
36
+ "swaggerDocs": true
37
+ }
38
+ ```
39
+
40
+ When `backendOnly` is `true`, the routing mental model changes:
41
+
42
+ - use `route.php` as the default route entry for normal application behavior
43
+ - treat `src/app/route.php` as the root handler for `/`
44
+ - create nested folders under `src/app` and place `route.php` inside them for additional endpoints
45
+ - do not default to `index.php` unless the project is intentionally mixing in rendered UI
46
+
47
+ This is different from the normal full-stack Prisma PHP flow, where route UI lives in `index.php` and PulsePoint usually drives interactivity.
48
+
49
+ ## When backend-only is the right fit
50
+
51
+ Backend-only Prisma PHP is the better fit when you want:
52
+
53
+ - a separate frontend such as React, Vue, Angular, Flutter, or a mobile app
54
+ - API-first development where routes return JSON instead of HTML
55
+ - webhook handlers, service-to-service endpoints, or integration APIs
56
+ - OpenAPI-driven client generation for external consumers
57
+
58
+ If the project is primarily a rendered Prisma PHP app with route-local interactivity, prefer the full-stack `index.php` plus PulsePoint model instead.
59
+
60
+ ## Route structure
61
+
62
+ Backend-only projects still use Prisma PHP's file-system routing under `src/app`.
63
+
64
+ Typical shapes look like this:
65
+
66
+ ```txt
67
+ src/
68
+ app/
69
+ route.php
70
+ products/
71
+ route.php
72
+ users/
73
+ route.php
74
+ ```
75
+
76
+ That creates handler-style routes such as:
77
+
78
+ - `/`
79
+ - `/products`
80
+ - `/users`
81
+
82
+ Use nested folders when the URL needs nested segments. Do not create routes by editing `files-list.json`; Prisma PHP manages route metadata automatically.
83
+
84
+ ## Basic route handler pattern
85
+
86
+ For backend-only apps, the default route file should stay explicit and small:
87
+
88
+ 1. guard the HTTP method
89
+ 2. read values from `Request::$params`
90
+ 3. sanitize and validate input with `PP\Validator`
91
+ 4. query Prisma or run server logic
92
+ 5. return JSON with `echo json_encode(...)`
93
+
94
+ ```php filename="src/app/products/route.php"
95
+ <?php
96
+
97
+ use Lib\Prisma\Classes\Prisma;
98
+ use PP\Header\Boom;
99
+ use PP\Request;
100
+
101
+ if (!Request::$isGet) {
102
+ Boom::methodNotAllowed()->toResponse();
103
+ exit;
104
+ }
105
+
106
+ $prisma = Prisma::getInstance();
107
+
108
+ $products = $prisma->product->findMany();
109
+
110
+ echo json_encode($products);
111
+ ```
112
+
113
+ For validation-heavy handlers, use `validator.md` together with `route-handlers.md`.
114
+
115
+ ## Request data in backend-only routes
116
+
117
+ Prisma PHP exposes unified request data through `Request::$params`, so you do not need to manually switch between `$_GET`, `$_POST`, and JSON body parsing for ordinary handler work.
118
+
119
+ ```php filename="src/app/products/search/route.php"
120
+ <?php
121
+
122
+ use Lib\Prisma\Classes\Prisma;
123
+ use PP\Request;
124
+ use PP\Validator;
125
+
126
+ $prisma = Prisma::getInstance();
127
+
128
+ $productName = Validator::string(Request::$params['productName'] ?? '');
129
+
130
+ $products = $prisma->product->findMany([
131
+ 'where' => [
132
+ 'name' => [
133
+ 'contains' => $productName,
134
+ ],
135
+ ],
136
+ ]);
137
+
138
+ echo json_encode($products);
139
+ ```
140
+
141
+ For expected input failures, prefer structured JSON error payloads or `Boom` responses instead of uncaught exceptions.
142
+
143
+ ## CORS for separate frontends
144
+
145
+ If a separate frontend will call the API directly, configure CORS in `.env`.
146
+
147
+ Typical settings include:
148
+
149
+ ```env
150
+ CORS_ALLOWED_ORIGINS=[]
151
+ CORS_ALLOW_CREDENTIALS="true"
152
+ CORS_ALLOWED_METHODS="GET,POST,PUT,PATCH,DELETE,OPTIONS"
153
+ CORS_ALLOWED_HEADERS="Content-Type,Authorization,X-Requested-With"
154
+ CORS_EXPOSE_HEADERS=""
155
+ CORS_MAX_AGE="86400"
156
+ ```
157
+
158
+ If you are using a local frontend such as Vite, add that frontend URL to `CORS_ALLOWED_ORIGINS`.
159
+
160
+ ## OpenAPI and Swagger in backend-only projects
161
+
162
+ If the project also enables Swagger docs, Prisma PHP can generate an OpenAPI 3 document that external clients can consume.
163
+
164
+ The generated JSON lives at:
165
+
166
+ ```txt
167
+ ./src/app/swagger-docs/apis/pphp-swagger.json
168
+ ```
169
+
170
+ This makes backend-only Prisma PHP projects easier to connect to:
171
+
172
+ - React or TypeScript clients
173
+ - Angular or Vue applications
174
+ - mobile SDK generation workflows
175
+ - language-specific OpenAPI generators
176
+
177
+ For the generation workflow itself, read `swagger-docs.md`.
178
+
179
+ ## Example frontend client workflow
180
+
181
+ One practical backend-only pattern is to generate a client from the Swagger JSON and validate responses in the consuming app.
182
+
183
+ For example, a TypeScript client can use tools such as `openapi-zod-client`, `openapi-typescript`, `orval`, or other OpenAPI generators.
184
+
185
+ ```bash package="npm"
186
+ npm i -D openapi-zod-client
187
+ npx openapi-zod-client --input http://localhost:3000/swagger-docs/apis/pphp-swagger.json --output ./client/src/api/pphp.ts
188
+ ```
189
+
190
+ The important idea is that Prisma PHP becomes the API backend, while the consuming frontend treats the generated OpenAPI document as the contract.
191
+
192
+ ## Decision guide
193
+
194
+ Use this page when the task is about:
195
+
196
+ - `backendOnly` in `prisma-php.json`
197
+ - API-first Prisma PHP apps
198
+ - separate frontend consumption
199
+ - CORS for external clients
200
+ - choosing `route.php` as the default route file in the project
201
+
202
+ Use `route-handlers.md` when the task is specifically about request handling behavior inside a handler.
203
+
204
+ Use `swagger-docs.md` when the task is specifically about generating or customizing the OpenAPI document.