create-apexjs 0.5.2 → 0.5.3
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.
- package/package.json +1 -1
- package/templates/default/AGENTS.md +85 -0
package/package.json
CHANGED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# AGENTS.md — building this app with an AI agent
|
|
2
|
+
|
|
3
|
+
This is an **Apex JS** app. Apex is a full-stack, AI-native meta-framework for
|
|
4
|
+
Alpine.js: file-based routing, SSR, islands, and **every typed API route is also
|
|
5
|
+
an MCP tool**. This file tells you (the agent) how to work here effectively.
|
|
6
|
+
|
|
7
|
+
## Golden rules
|
|
8
|
+
1. **Prefer generators over hand-writing.** Run `apex make …` / `apex extend …` /
|
|
9
|
+
`apex add …` to create files — they produce correct, conventional, typed code.
|
|
10
|
+
Hand-writing boilerplate is where you make mistakes.
|
|
11
|
+
2. **Everything has one place.** Follow the structure below; don't invent folders.
|
|
12
|
+
3. **Security is the framework's job, not yours.** Use `auth`/`can`/`scope` — never
|
|
13
|
+
hand-roll auth. Defaults are fail-closed.
|
|
14
|
+
4. **Verify your work.** Add tests with `createTestApp` and run `apex test`.
|
|
15
|
+
5. **TypeScript is strict.** If it compiles, it's probably right; lean on the types.
|
|
16
|
+
|
|
17
|
+
## Do things with the CLI (this is the fast path)
|
|
18
|
+
```bash
|
|
19
|
+
apex make page dashboard # pages/dashboard.alpine (a route → /dashboard)
|
|
20
|
+
apex make component Card # components/Card.alpine (<Card /> in templates)
|
|
21
|
+
apex make model Post title:string body:string # models/Post.ts → migration + REST + MCP CRUD
|
|
22
|
+
apex make api webhooks # server/api/webhooks.ts (defineApexRoute; also an MCP tool)
|
|
23
|
+
apex make service Billing # services/BillingService.ts
|
|
24
|
+
apex extend auth # add sealed-cookie sessions + login/logout + /account
|
|
25
|
+
apex extend data # add a DB-backed model + /guestbook demo (Supabase-ready)
|
|
26
|
+
apex extend i18n # add locales/*.json + /fr routing
|
|
27
|
+
apex add button card modal # copy themeable UI components in
|
|
28
|
+
apex migrate # apply DB migrations
|
|
29
|
+
apex build --preset vercel # build + Vercel config (also: netlify, docker); then deploy
|
|
30
|
+
apex test # run Vitest
|
|
31
|
+
```
|
|
32
|
+
`apex make <kind> …` kinds: `page component api service store layout middleware test model migration auth`.
|
|
33
|
+
|
|
34
|
+
## Project structure
|
|
35
|
+
```
|
|
36
|
+
pages/**/*.alpine Routes. File path → URL. [param] = dynamic. index.alpine → parent path.
|
|
37
|
+
layouts/*.alpine Shared shells; default.alpine wraps every page (<slot/>).
|
|
38
|
+
components/*.alpine Reusable <PascalCase/> components (props via attributes).
|
|
39
|
+
server/api/*.ts Typed routes (defineApexRoute) / model resources → REST + MCP.
|
|
40
|
+
server/auth.ts Identity (sessionAuth) → ctx.user everywhere. (from `apex extend auth`)
|
|
41
|
+
models/*.ts defineModel → schema + migration + table + REST/MCP CRUD.
|
|
42
|
+
db/ createDb + migrations. Uses DATABASE_URL (Postgres) or in-memory libSQL.
|
|
43
|
+
locales/*.json i18n catalogs. (from `apex extend i18n`)
|
|
44
|
+
services/*.ts Business logic (classes). Keep routes thin; delegate here.
|
|
45
|
+
stores/*.ts Global SSR-safe state ($store.x).
|
|
46
|
+
composables/*.ts Reusable client logic (useX) for <script client>.
|
|
47
|
+
shared/*.ts Types shared by server + client.
|
|
48
|
+
tests/*.test.ts Vitest. createTestApp boots the whole app in-process.
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## The `.alpine` single-file component
|
|
52
|
+
```alpine
|
|
53
|
+
<script server lang="ts">
|
|
54
|
+
// Runs on the server. loader() data becomes the page's x-data (real HTML first).
|
|
55
|
+
export function loader() { return { title: 'Hello' } }
|
|
56
|
+
export function head() { return { title: 'Hello' } } // SEO
|
|
57
|
+
</script>
|
|
58
|
+
<script client lang="ts">
|
|
59
|
+
// Optional client-only logic; import composables here.
|
|
60
|
+
</script>
|
|
61
|
+
<template x-data>
|
|
62
|
+
<h1 x-text="title"></h1>
|
|
63
|
+
<Counter start="0" client:load /> <!-- island: client:load | client:visible | client:idle -->
|
|
64
|
+
</template>
|
|
65
|
+
<style scoped> h1 { color: var(--color-primary); } </style>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## APIs you'll use (import from `@apex-stack/core`, `/server`, `/testing`; data from `@apex-stack/data`)
|
|
69
|
+
- **Route** → `defineApexRoute({ method, input: { …zod }, mcp: true, auth: true, can, handler })`. `mcp: true` makes it an AI-callable tool at `/mcp`.
|
|
70
|
+
- **Model** → `defineModel('posts', { fields: {…}, use: [timestamps(), owned()] })` → `.resource(handle)` mounts REST + MCP CRUD.
|
|
71
|
+
- **Auth** → `server/auth.ts` default-exports `sessionAuth({ password })`; gate routes with `auth: true` / `can`. In loaders, the user is `locals.user`.
|
|
72
|
+
- **Config** → `apex.config.ts`: `defineConfig({ runtimeConfig: { …, public: {…} }, i18n: {…} })`. Read with `useRuntimeConfig()`.
|
|
73
|
+
- **Test** → `createTestApp({ root })` → `app.get/post(path, body?, { user })`, `app.mcp.listTools()`.
|
|
74
|
+
|
|
75
|
+
The full stability contract of public APIs is in the framework's `API.md` — 🟢 Stable ones won't break; 🟡 Experimental ones might.
|
|
76
|
+
|
|
77
|
+
## Deploy
|
|
78
|
+
`apex build --preset vercel|netlify|docker`. Set `DATABASE_URL` (Supabase/Neon/Postgres or Turso) + `APEX_SESSION_PASSWORD` (≥32 chars) in the host env. See the deploy docs.
|
|
79
|
+
|
|
80
|
+
## Drive Apex as MCP tools (optional, powerful)
|
|
81
|
+
Apex ships an MCP server for its own CLI — run `apex mcp-server` (stdio). Point your
|
|
82
|
+
agent host at it to get `apex_make`, `apex_extend`, `apex_add`, `apex_build`, and
|
|
83
|
+
`apex_list` as structured tools, so you scaffold by calling tools instead of shelling out.
|
|
84
|
+
|
|
85
|
+
Docs: https://apexjs.site/docs/
|