@cloudgrid-io/mcp 0.11.2 → 0.13.0

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.
Files changed (98) hide show
  1. package/package.json +2 -1
  2. package/src/corpus/capability-map.md +40 -6
  3. package/src/corpus/examples/ai-app/index.md +237 -0
  4. package/src/corpus/examples/api-service/index.md +190 -0
  5. package/src/corpus/examples/crm/index.md +273 -0
  6. package/src/corpus/examples/kanban/index.md +256 -0
  7. package/src/corpus/templates/admin-dashboard/README.md +75 -0
  8. package/src/corpus/templates/admin-dashboard/cloudgrid.yaml +15 -0
  9. package/src/corpus/templates/admin-dashboard/index.md +78 -0
  10. package/src/corpus/templates/admin-dashboard/services/web/app/api/orders/route.js +64 -0
  11. package/src/corpus/templates/admin-dashboard/services/web/app/api/users/route.js +63 -0
  12. package/src/corpus/templates/admin-dashboard/services/web/app/layout.js +39 -0
  13. package/src/corpus/templates/admin-dashboard/services/web/app/page.js +73 -0
  14. package/src/corpus/templates/admin-dashboard/services/web/app/resource-table.js +94 -0
  15. package/src/corpus/templates/admin-dashboard/services/web/lib/db.js +32 -0
  16. package/src/corpus/templates/admin-dashboard/services/web/package.json +16 -0
  17. package/src/corpus/templates/ai-app/README.md +95 -0
  18. package/src/corpus/templates/ai-app/cloudgrid.yaml +20 -0
  19. package/src/corpus/templates/ai-app/index.md +269 -0
  20. package/src/corpus/templates/ai-app/services/web/app/api/chat/route.js +51 -0
  21. package/src/corpus/templates/ai-app/services/web/app/chat.js +60 -0
  22. package/src/corpus/templates/ai-app/services/web/app/layout.js +36 -0
  23. package/src/corpus/templates/ai-app/services/web/app/page.js +25 -0
  24. package/src/corpus/templates/ai-app/services/web/lib/db.js +32 -0
  25. package/src/corpus/templates/ai-app/services/web/package.json +17 -0
  26. package/src/corpus/templates/api-docs/README.md +28 -0
  27. package/src/corpus/templates/api-docs/cloudgrid.yaml +10 -0
  28. package/src/corpus/templates/api-docs/index.html +136 -0
  29. package/src/corpus/templates/api-docs/index.md +30 -0
  30. package/src/corpus/templates/api-service/README.md +87 -0
  31. package/src/corpus/templates/api-service/cloudgrid.yaml +18 -0
  32. package/src/corpus/templates/api-service/index.md +225 -0
  33. package/src/corpus/templates/api-service/services/api/package.json +13 -0
  34. package/src/corpus/templates/api-service/services/api/src/index.js +132 -0
  35. package/src/corpus/templates/changelog/README.md +27 -0
  36. package/src/corpus/templates/changelog/cloudgrid.yaml +10 -0
  37. package/src/corpus/templates/changelog/index.html +80 -0
  38. package/src/corpus/templates/changelog/index.md +30 -0
  39. package/src/corpus/templates/crm/README.md +72 -0
  40. package/src/corpus/templates/crm/cloudgrid.yaml +15 -0
  41. package/src/corpus/templates/crm/index.md +68 -0
  42. package/src/corpus/templates/crm/services/web/app/api/contacts/route.js +80 -0
  43. package/src/corpus/templates/crm/services/web/app/contact-manager.js +102 -0
  44. package/src/corpus/templates/crm/services/web/app/layout.js +35 -0
  45. package/src/corpus/templates/crm/services/web/app/page.js +34 -0
  46. package/src/corpus/templates/crm/services/web/lib/db.js +32 -0
  47. package/src/corpus/templates/crm/services/web/package.json +16 -0
  48. package/src/corpus/templates/docs-site/README.md +28 -0
  49. package/src/corpus/templates/docs-site/cloudgrid.yaml +10 -0
  50. package/src/corpus/templates/docs-site/index.html +122 -0
  51. package/src/corpus/templates/docs-site/index.md +30 -0
  52. package/src/corpus/templates/kanban/README.md +72 -0
  53. package/src/corpus/templates/kanban/cloudgrid.yaml +15 -0
  54. package/src/corpus/templates/kanban/index.md +68 -0
  55. package/src/corpus/templates/kanban/services/web/app/api/cards/route.js +70 -0
  56. package/src/corpus/templates/kanban/services/web/app/board.js +93 -0
  57. package/src/corpus/templates/kanban/services/web/app/layout.js +37 -0
  58. package/src/corpus/templates/kanban/services/web/app/page.js +32 -0
  59. package/src/corpus/templates/kanban/services/web/lib/db.js +32 -0
  60. package/src/corpus/templates/kanban/services/web/package.json +16 -0
  61. package/src/corpus/templates/portfolio/README.md +29 -0
  62. package/src/corpus/templates/portfolio/cloudgrid.yaml +10 -0
  63. package/src/corpus/templates/portfolio/index.html +126 -0
  64. package/src/corpus/templates/portfolio/index.md +30 -0
  65. package/src/corpus/templates/saas-marketing/README.md +30 -0
  66. package/src/corpus/templates/saas-marketing/cloudgrid.yaml +10 -0
  67. package/src/corpus/templates/saas-marketing/index.html +212 -0
  68. package/src/corpus/templates/saas-marketing/index.md +30 -0
  69. package/src/corpus/templates/status-page/README.md +28 -0
  70. package/src/corpus/templates/status-page/cloudgrid.yaml +10 -0
  71. package/src/corpus/templates/status-page/index.html +117 -0
  72. package/src/corpus/templates/status-page/index.md +30 -0
  73. package/src/corpus/templates/task-manager/README.md +72 -0
  74. package/src/corpus/templates/task-manager/cloudgrid.yaml +15 -0
  75. package/src/corpus/templates/task-manager/index.md +68 -0
  76. package/src/corpus/templates/task-manager/services/web/app/api/tasks/route.js +77 -0
  77. package/src/corpus/templates/task-manager/services/web/app/layout.js +39 -0
  78. package/src/corpus/templates/task-manager/services/web/app/page.js +33 -0
  79. package/src/corpus/templates/task-manager/services/web/app/task-list.js +110 -0
  80. package/src/corpus/templates/task-manager/services/web/lib/db.js +32 -0
  81. package/src/corpus/templates/task-manager/services/web/package.json +16 -0
  82. package/src/corpus/templates/waitlist/README.md +38 -0
  83. package/src/corpus/templates/waitlist/cloudgrid.yaml +10 -0
  84. package/src/corpus/templates/waitlist/index.html +69 -0
  85. package/src/corpus/templates/waitlist/index.md +41 -0
  86. package/src/corpus/workflows/admin-dashboard.md +102 -0
  87. package/src/corpus/workflows/ai-app.md +136 -0
  88. package/src/corpus/workflows/api-docs.md +36 -0
  89. package/src/corpus/workflows/api-service.md +118 -0
  90. package/src/corpus/workflows/changelog.md +33 -0
  91. package/src/corpus/workflows/crm.md +101 -0
  92. package/src/corpus/workflows/docs-site.md +35 -0
  93. package/src/corpus/workflows/kanban.md +102 -0
  94. package/src/corpus/workflows/portfolio.md +35 -0
  95. package/src/corpus/workflows/saas-marketing.md +37 -0
  96. package/src/corpus/workflows/status-page.md +35 -0
  97. package/src/corpus/workflows/task-manager.md +101 -0
  98. package/src/corpus/workflows/waitlist.md +42 -0
@@ -0,0 +1,72 @@
1
+ # crm template — persistent Next.js + Mongo contact manager
2
+
3
+ A real, deployable CRM. Contacts live in the grid-shared MongoDB, so they survive
4
+ refresh and are shared across users/sessions. Same proven shape as
5
+ `app-with-data`, adapted to a `contacts` domain (name, email, company, stage,
6
+ note) with a table view and per-row stage changes.
7
+
8
+ ## How the grid gives you a database
9
+
10
+ You do **not** provision a database or set a connection string. In
11
+ `cloudgrid.yaml` you declare `needs: { database: true }`, and the grid:
12
+
13
+ - provisions shared Mongo for the app, and
14
+ - injects the connection string as the **`DATABASE_MONGODB_URL`** environment
15
+ variable (plus the legacy `MONGODB_URL` alias) — at dev-time (`grid dev`) and
16
+ at runtime (after `grid plug`).
17
+
18
+ The app reads it via `process.env.DATABASE_MONGODB_URL` (with a legacy
19
+ `process.env.MONGODB_URL` fallback) in `services/web/lib/db.js` — **lazily,
20
+ inside the `getDb` getter, never at module top level** (a top-level read fails
21
+ `next build`, which imports the module for route analysis before the grid injects
22
+ the var). Never hardcode a connection string; never commit a secret.
23
+
24
+ > **Declare `needs: { database: true }` (the canonical shape).** The deployer
25
+ > provisions Mongo and injects `DATABASE_MONGODB_URL` (plus the legacy
26
+ > `MONGODB_URL` alias). `requires:` is the deprecated v1 alias — don't author new
27
+ > yaml with it, and never set `needs:` and `requires:` together (the validator
28
+ > rejects the combination).
29
+
30
+ ## Service layout
31
+
32
+ App code lives under **`services/web/`**, not the template root. `path:` in
33
+ `cloudgrid.yaml` is the URL mount, not the filesystem path — the service named
34
+ `web` means the CLI looks for `services/web/`. Files at the root fail with
35
+ `Error: Service directory not found: …/services/web`.
36
+
37
+ ## Run locally
38
+
39
+ ```bash
40
+ npm install
41
+ grid dev # runs Next.js with DATABASE_MONGODB_URL injected against dev Mongo
42
+ ```
43
+
44
+ ## Deploy
45
+
46
+ ```bash
47
+ grid plug # builds + deploys the folder (async — poll status until live)
48
+ ```
49
+
50
+ A runtime deploy is asynchronous: `plug` returns `status: building`; poll status
51
+ until the app is live, then use the returned live URL. Re-plug the same entity
52
+ to update the same URL.
53
+
54
+ ## File tree
55
+
56
+ ```
57
+ cloudgrid.yaml # name + services.web (nextjs) + needs: { database: true }
58
+ services/web/package.json # next, react, react-dom, mongodb driver only
59
+ services/web/lib/db.js # lazy Mongo client from DATABASE_MONGODB_URL (legacy MONGODB_URL fallback)
60
+ services/web/app/layout.js # root layout + inline CSS
61
+ services/web/app/page.js # server component: reads contacts from Mongo
62
+ services/web/app/contact-manager.js # client table: POST / PATCH (stage) / DELETE via the API
63
+ services/web/app/api/contacts/route.js # GET (list) / POST (add) / PATCH (stage) / DELETE (remove)
64
+ ```
65
+
66
+ ## Adapt it
67
+
68
+ - Rename the `contacts` collection in `services/web/app/api/contacts/route.js`
69
+ and `services/web/app/page.js` (e.g. `deals`, `companies`).
70
+ - Change the document fields (stages, owners, timestamps, deal values).
71
+ - Add more routes/collections as the CRM grows (companies, deals, activities).
72
+ - Add `cache: true` to `needs:` only if you actually need Redis.
@@ -0,0 +1,15 @@
1
+ # Rename this app. The grid injects the DB connection string as an environment
2
+ # variable at runtime — do NOT set it yourself, and never commit a connection
3
+ # string or secret.
4
+ #
5
+ # `needs: { database: true }` is the canonical, recommended shape. The deployer
6
+ # provisions Mongo and injects DATABASE_MONGODB_URL (plus the legacy MONGODB_URL
7
+ # alias). `requires:` is the deprecated v1 alias — don't author new yaml with it,
8
+ # and never set `needs:` and `requires:` together (the validator rejects it).
9
+ name: my-crm
10
+ services:
11
+ web:
12
+ type: nextjs
13
+ path: /
14
+ needs:
15
+ database: true
@@ -0,0 +1,68 @@
1
+ # Template: crm (persistent Next.js + Mongo contact manager)
2
+
3
+ A real, deployable CRM. Contacts live in the grid-shared MongoDB, so they survive
4
+ refresh and are shared across sessions. Same proven shape as `app-with-data`,
5
+ adapted to a `contacts` domain (name, email, company, stage, note) with a table
6
+ view and per-row stage changes.
7
+
8
+ **Key rules (all proven by the app-with-data end-to-end deploy):**
9
+
10
+ 1. **Service code MUST live under `services/<name>/`, not the repo/template
11
+ root.** `path:` in `cloudgrid.yaml` is the URL mount, NOT the filesystem path.
12
+ The service named `web` → the CLI looks for `services/web/`. App files at the
13
+ root fail with `Error: Service directory not found: …/services/web`.
14
+ 2. **Read the DB connection string LAZILY (inside the getter), never at module
15
+ top level.** The grid injects it as `DATABASE_MONGODB_URL` (plus the legacy
16
+ `MONGODB_URL` alias) at dev-time and runtime; the app reads
17
+ `process.env.DATABASE_MONGODB_URL || process.env.MONGODB_URL` inside `getDb`.
18
+ A top-level read fails `next build`. Never hardcode a connection string; never
19
+ commit a secret.
20
+ 3. **Declare the datastore with `needs: { database: true }`.** The deployer
21
+ provisions Mongo and injects the connection string. `requires:` is the
22
+ deprecated v1 alias; don't author new yaml with it, and never set `needs:` and
23
+ `requires:` together (the validator rejects the combination).
24
+
25
+ ## File tree
26
+
27
+ ```
28
+ cloudgrid.yaml # name + services.web (nextjs) + needs: { database: true }
29
+ services/web/package.json # next, react, react-dom, mongodb driver only
30
+ services/web/lib/db.js # lazy Mongo client from DATABASE_MONGODB_URL (legacy MONGODB_URL fallback)
31
+ services/web/app/layout.js # root layout + inline CSS
32
+ services/web/app/page.js # server component: reads contacts from Mongo
33
+ services/web/app/contact-manager.js # client table: POST / PATCH (stage) / DELETE via the API
34
+ services/web/app/api/contacts/route.js # GET (list) / POST (add) / PATCH (stage) / DELETE (remove)
35
+ ```
36
+
37
+ ## cloudgrid.yaml
38
+
39
+ ```yaml
40
+ name: my-crm
41
+ services:
42
+ web:
43
+ type: nextjs
44
+ path: /
45
+ needs:
46
+ database: true
47
+ ```
48
+
49
+ > **Capability:** this template's need is `database: true`. The deployer
50
+ > provisions Mongo and injects `DATABASE_MONGODB_URL` (plus the legacy
51
+ > `MONGODB_URL` alias). `requires:` is the deprecated v1 alias — don't mix it with
52
+ > `needs:` (the validator rejects the combination). See the capability-map for
53
+ > the full injection table.
54
+
55
+ ## The contacts collection
56
+
57
+ Documents: `{ name, email, company, stage, note, createdAt }` where `stage` is
58
+ one of `lead` / `qualified` / `customer`. The API route on `contacts` does GET
59
+ (list), POST (add), PATCH (change stage), DELETE (remove); the page is a server
60
+ component that reads the collection and hands it to a client table.
61
+
62
+ ## Adapt it
63
+
64
+ - Rename the `contacts` collection to your data (`deals`, `companies`).
65
+ - Change the document fields; add owners, timestamps, deal values.
66
+ - Add more routes/collections as the CRM grows.
67
+ - Add `cache: true` to `needs:` only if you actually need Redis.
68
+ - Run `grid dev` to test locally, `grid plug` to deploy (async — poll to live).
@@ -0,0 +1,80 @@
1
+ // App Router route handler for the `contacts` collection.
2
+ // GET -> list contacts, POST -> add a contact, PATCH -> update stage/fields,
3
+ // DELETE -> remove a contact by id.
4
+ //
5
+ // To adapt this app, rename the collection and change the fields to match your
6
+ // own data (e.g. a `companies` or `deals` collection).
7
+ import { NextResponse } from "next/server";
8
+ import { ObjectId } from "mongodb";
9
+ import { getDb } from "../../../lib/db.js";
10
+
11
+ // Never cache — always read/write live data.
12
+ export const dynamic = "force-dynamic";
13
+
14
+ const STAGES = ["lead", "qualified", "customer"];
15
+
16
+ async function contacts() {
17
+ const db = await getDb();
18
+ return db.collection("contacts");
19
+ }
20
+
21
+ function shape(c) {
22
+ return {
23
+ id: c._id.toString(),
24
+ name: c.name || "",
25
+ email: c.email || "",
26
+ company: c.company || "",
27
+ stage: STAGES.includes(c.stage) ? c.stage : "lead",
28
+ note: c.note || "",
29
+ };
30
+ }
31
+
32
+ // GET /api/contacts — list all contacts, newest first.
33
+ export async function GET() {
34
+ const col = await contacts();
35
+ const items = await col.find({}).sort({ createdAt: -1 }).toArray();
36
+ return NextResponse.json(items.map(shape));
37
+ }
38
+
39
+ // POST /api/contacts — add a contact. Body: { name, email, company, stage, note }.
40
+ export async function POST(request) {
41
+ const body = await request.json().catch(() => ({}));
42
+ const name = typeof body.name === "string" ? body.name.trim() : "";
43
+ if (!name) {
44
+ return NextResponse.json({ error: "name is required" }, { status: 400 });
45
+ }
46
+ const doc = {
47
+ name,
48
+ email: typeof body.email === "string" ? body.email.trim() : "",
49
+ company: typeof body.company === "string" ? body.company.trim() : "",
50
+ stage: STAGES.includes(body.stage) ? body.stage : "lead",
51
+ note: typeof body.note === "string" ? body.note.trim() : "",
52
+ createdAt: new Date(),
53
+ };
54
+ const col = await contacts();
55
+ const res = await col.insertOne(doc);
56
+ return NextResponse.json({ id: res.insertedId.toString(), ...doc }, { status: 201 });
57
+ }
58
+
59
+ // PATCH /api/contacts — update a contact's stage (or other fields). Body: { id, stage }.
60
+ export async function PATCH(request) {
61
+ const body = await request.json().catch(() => ({}));
62
+ const { id, stage } = body;
63
+ if (!id || !ObjectId.isValid(id) || !STAGES.includes(stage)) {
64
+ return NextResponse.json({ error: "valid id and stage required" }, { status: 400 });
65
+ }
66
+ const col = await contacts();
67
+ await col.updateOne({ _id: new ObjectId(id) }, { $set: { stage } });
68
+ return NextResponse.json({ ok: true });
69
+ }
70
+
71
+ // DELETE /api/contacts?id=<id> — remove a contact.
72
+ export async function DELETE(request) {
73
+ const id = new URL(request.url).searchParams.get("id");
74
+ if (!id || !ObjectId.isValid(id)) {
75
+ return NextResponse.json({ error: "valid id is required" }, { status: 400 });
76
+ }
77
+ const col = await contacts();
78
+ await col.deleteOne({ _id: new ObjectId(id) });
79
+ return NextResponse.json({ ok: true });
80
+ }
@@ -0,0 +1,102 @@
1
+ "use client";
2
+
3
+ // Small client component: renders the contacts table and posts to /api/contacts.
4
+ import { useState } from "react";
5
+
6
+ const STAGES = ["lead", "qualified", "customer"];
7
+ const LABELS = { lead: "Lead", qualified: "Qualified", customer: "Customer" };
8
+
9
+ export default function ContactManager({ initialContacts }) {
10
+ const [contacts, setContacts] = useState(initialContacts);
11
+ const [name, setName] = useState("");
12
+ const [email, setEmail] = useState("");
13
+ const [company, setCompany] = useState("");
14
+ const [busy, setBusy] = useState(false);
15
+
16
+ async function add(e) {
17
+ e.preventDefault();
18
+ const value = name.trim();
19
+ if (!value) return;
20
+ setBusy(true);
21
+ const res = await fetch("/api/contacts", {
22
+ method: "POST",
23
+ headers: { "content-type": "application/json" },
24
+ body: JSON.stringify({ name: value, email, company }),
25
+ });
26
+ if (res.ok) {
27
+ const contact = await res.json();
28
+ setContacts((prev) => [contact, ...prev]);
29
+ setName("");
30
+ setEmail("");
31
+ setCompany("");
32
+ }
33
+ setBusy(false);
34
+ }
35
+
36
+ async function setStage(id, stage) {
37
+ setBusy(true);
38
+ const res = await fetch("/api/contacts", {
39
+ method: "PATCH",
40
+ headers: { "content-type": "application/json" },
41
+ body: JSON.stringify({ id, stage }),
42
+ });
43
+ if (res.ok) setContacts((prev) => prev.map((c) => (c.id === id ? { ...c, stage } : c)));
44
+ setBusy(false);
45
+ }
46
+
47
+ async function remove(id) {
48
+ setBusy(true);
49
+ const res = await fetch(`/api/contacts?id=${encodeURIComponent(id)}`, { method: "DELETE" });
50
+ if (res.ok) setContacts((prev) => prev.filter((c) => c.id !== id));
51
+ setBusy(false);
52
+ }
53
+
54
+ return (
55
+ <div>
56
+ <form onSubmit={add} className="row">
57
+ <input value={name} onChange={(e) => setName(e.target.value)} placeholder="Name" aria-label="Name" />
58
+ <input value={email} onChange={(e) => setEmail(e.target.value)} placeholder="Email" aria-label="Email" />
59
+ <input value={company} onChange={(e) => setCompany(e.target.value)} placeholder="Company" aria-label="Company" />
60
+ <button type="submit" disabled={busy}>Add</button>
61
+ </form>
62
+ <table>
63
+ <thead>
64
+ <tr>
65
+ <th>Name</th>
66
+ <th>Email</th>
67
+ <th>Company</th>
68
+ <th>Stage</th>
69
+ <th></th>
70
+ </tr>
71
+ </thead>
72
+ <tbody>
73
+ {contacts.length === 0 && (
74
+ <tr><td className="empty" colSpan={5}>No contacts yet.</td></tr>
75
+ )}
76
+ {contacts.map((c) => (
77
+ <tr key={c.id}>
78
+ <td>{c.name}</td>
79
+ <td>{c.email}</td>
80
+ <td>{c.company}</td>
81
+ <td>
82
+ <select
83
+ value={c.stage}
84
+ onChange={(e) => setStage(c.id, e.target.value)}
85
+ disabled={busy}
86
+ aria-label="Stage"
87
+ >
88
+ {STAGES.map((s) => (
89
+ <option key={s} value={s}>{LABELS[s]}</option>
90
+ ))}
91
+ </select>
92
+ </td>
93
+ <td>
94
+ <button type="button" onClick={() => remove(c.id)} disabled={busy}>Delete</button>
95
+ </td>
96
+ </tr>
97
+ ))}
98
+ </tbody>
99
+ </table>
100
+ </div>
101
+ );
102
+ }
@@ -0,0 +1,35 @@
1
+ // Root layout + plain inline CSS (no external CDNs, fonts, or stylesheets).
2
+ export const metadata = {
3
+ title: "CRM",
4
+ description: "A persistent contact CRM on CloudGrid, backed by grid-shared Mongo.",
5
+ };
6
+
7
+ const css = `
8
+ :root { color-scheme: light dark; }
9
+ * { box-sizing: border-box; }
10
+ body { margin: 0; font-family: system-ui, -apple-system, sans-serif; line-height: 1.5; }
11
+ main { max-width: 60rem; margin: 3rem auto; padding: 0 1.25rem; }
12
+ h1 { margin: 0 0 .25rem; }
13
+ .hint { margin: 0 0 1.5rem; opacity: .7; font-size: .9rem; }
14
+ .row { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.5rem; }
15
+ input, select { padding: .5rem .75rem; border: 1px solid #8886; border-radius: .5rem; font: inherit; }
16
+ input { flex: 1; min-width: 8rem; }
17
+ button { padding: .5rem .9rem; border: 1px solid #8886; border-radius: .5rem; background: #6663; font: inherit; cursor: pointer; }
18
+ button:disabled { opacity: .5; cursor: default; }
19
+ table { width: 100%; border-collapse: collapse; }
20
+ th, td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid #8883; vertical-align: top; }
21
+ th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; opacity: .7; }
22
+ .stage { font-size: .8rem; padding: .15rem .5rem; border: 1px solid #8886; border-radius: 1rem; }
23
+ .empty { opacity: .6; }
24
+ `;
25
+
26
+ export default function RootLayout({ children }) {
27
+ return (
28
+ <html lang="en">
29
+ <head>
30
+ <style dangerouslySetInnerHTML={{ __html: css }} />
31
+ </head>
32
+ <body>{children}</body>
33
+ </html>
34
+ );
35
+ }
@@ -0,0 +1,34 @@
1
+ // Home page: a server component reads the contacts straight from Mongo, and a
2
+ // small client component adds / restages / removes them via the API route. Data
3
+ // persists across refresh and across users because it lives in the grid-shared
4
+ // Mongo, not in memory.
5
+ import { getDb } from "../lib/db.js";
6
+ import ContactManager from "./contact-manager.js";
7
+
8
+ export const dynamic = "force-dynamic";
9
+
10
+ const STAGES = ["lead", "qualified", "customer"];
11
+
12
+ async function listContacts() {
13
+ const db = await getDb();
14
+ const items = await db.collection("contacts").find({}).sort({ createdAt: -1 }).toArray();
15
+ return items.map((c) => ({
16
+ id: c._id.toString(),
17
+ name: c.name || "",
18
+ email: c.email || "",
19
+ company: c.company || "",
20
+ stage: STAGES.includes(c.stage) ? c.stage : "lead",
21
+ note: c.note || "",
22
+ }));
23
+ }
24
+
25
+ export default async function Page() {
26
+ const contacts = await listContacts();
27
+ return (
28
+ <main>
29
+ <h1>Contacts</h1>
30
+ <p className="hint">Persisted in the grid-shared Mongo — survives refresh.</p>
31
+ <ContactManager initialContacts={contacts} />
32
+ </main>
33
+ );
34
+ }
@@ -0,0 +1,32 @@
1
+ // Cached MongoDB client for the App Router.
2
+ //
3
+ // The grid injects the connection string as the DATABASE_MONGODB_URL environment
4
+ // variable (plus the legacy MONGODB_URL alias) at dev-time (`grid dev`) and
5
+ // runtime (after `grid plug`). Read the canonical var first, fall back to the
6
+ // legacy alias. Never hardcode a connection string here and never commit a secret.
7
+ //
8
+ // The env var and client are resolved LAZILY (inside getDb), never at module top
9
+ // level — otherwise `next build` throws when it imports this module for route
10
+ // analysis, before the grid injects the var.
11
+ import { MongoClient } from "mongodb";
12
+
13
+ function clientPromise() {
14
+ const uri = process.env.DATABASE_MONGODB_URL || process.env.MONGODB_URL;
15
+ if (!uri) {
16
+ throw new Error(
17
+ "DATABASE_MONGODB_URL is not set. The grid injects it automatically — run " +
18
+ "this app with `grid dev` locally, or deploy it with `grid plug` (the grid " +
19
+ "injects the DB connection string at runtime). Do not set it by hand.",
20
+ );
21
+ }
22
+ if (!globalThis.__mongoClientPromise) {
23
+ globalThis.__mongoClientPromise = new MongoClient(uri).connect();
24
+ }
25
+ return globalThis.__mongoClientPromise;
26
+ }
27
+
28
+ export async function getDb() {
29
+ const client = await clientPromise();
30
+ // The default DB comes from the connection-string path segment the grid injects.
31
+ return client.db();
32
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "my-crm",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "scripts": {
6
+ "dev": "next dev",
7
+ "build": "next build",
8
+ "start": "next start"
9
+ },
10
+ "dependencies": {
11
+ "next": "^15.1.0",
12
+ "react": "^19.0.0",
13
+ "react-dom": "^19.0.0",
14
+ "mongodb": "^6.12.0"
15
+ }
16
+ }
@@ -0,0 +1,28 @@
1
+ # docs-site
2
+
3
+ A single self-contained HTML documentation site: a sidebar nav, a scrolling content column with headings and code blocks, and a client-side search box that filters the nav. No backend.
4
+
5
+ Static inspiration — a single self-contained `index.html` (inline CSS and JS,
6
+ no external CDNs). It deploys instantly via `gridctl_drop` and works on every
7
+ CloudGrid edition, including hosted.
8
+
9
+ ## Fill it in
10
+
11
+ Fetch the template with `gridctl_fetch("template", "docs-site")`, then replace the
12
+ placeholders:
13
+
14
+ - The project/doc name and the sidebar section links.
15
+ - One content section per topic (heading + prose + optional code block).
16
+ - The code blocks are plain `<pre><code>` — no external highlighter or CDN.
17
+ - The search box filters the sidebar links client-side with inline JS; leave the script inline.
18
+
19
+ Keep it a single self-contained HTML file. Do not add external scripts,
20
+ stylesheets, fonts, or large embedded media.
21
+
22
+ ## Deploy
23
+
24
+ - Hosted MCP edition: call the drop tool with the HTML.
25
+ - Local MCP / CLI edition: write the HTML to a file and run `gridctl plug`.
26
+
27
+ It deploys as an inspiration and returns a live share URL right away. Re-deploy
28
+ with the same entity id to update the same URL.
@@ -0,0 +1,10 @@
1
+ # static — deploys as an inspiration (instant, works on hosted) via gridctl_drop;
2
+ # this yaml is only for plugging it as an OWNED static runtime (async, local
3
+ # edition only). To publish the page, prefer gridctl_drop, not grid plug.
4
+ #
5
+ # needs: {} # none — static, no infrastructure
6
+ name: docs-site
7
+ services:
8
+ web:
9
+ type: static
10
+ path: /
@@ -0,0 +1,122 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>{{PROJECT_NAME}} docs</title>
7
+ <style>
8
+ :root {
9
+ --bg: #0b0f17; --panel: #121826; --fg: #e8edf5; --muted: #9aa7bd;
10
+ --accent: #5b8cff; --border: #223049; --code-bg: #0f1523;
11
+ }
12
+ * { box-sizing: border-box; margin: 0; padding: 0; }
13
+ html { scroll-behavior: smooth; }
14
+ body {
15
+ background: var(--bg); color: var(--fg);
16
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
17
+ -webkit-font-smoothing: antialiased; line-height: 1.6;
18
+ }
19
+ .layout { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
20
+ aside {
21
+ border-right: 1px solid var(--border); padding: 1.5rem 1.25rem;
22
+ position: sticky; top: 0; align-self: start; height: 100vh; overflow-y: auto;
23
+ }
24
+ aside .brand { font-weight: 600; letter-spacing: -0.01em; margin-bottom: 1rem; display: block; }
25
+ .search { width: 100%; padding: 0.6rem 0.8rem; border-radius: 8px; border: 1px solid var(--border);
26
+ background: var(--code-bg); color: var(--fg); font-size: 0.9rem; margin-bottom: 1.25rem; }
27
+ .search::placeholder { color: var(--muted); }
28
+ nav.toc { display: grid; gap: 0.15rem; }
29
+ nav.toc a { color: var(--muted); text-decoration: none; padding: 0.35rem 0.5rem; border-radius: 6px; font-size: 0.92rem; }
30
+ nav.toc a:hover { color: var(--fg); background: var(--panel); }
31
+ nav.toc .group { color: var(--fg); font-weight: 600; font-size: 0.8rem; text-transform: uppercase;
32
+ letter-spacing: 0.04em; margin: 1rem 0 0.35rem; }
33
+ main { padding: clamp(1.5rem, 4vw, 3.5rem); max-width: 820px; }
34
+ main h1 { font-size: clamp(2rem, 5vw, 2.8rem); letter-spacing: -0.02em; margin-bottom: 0.5rem; }
35
+ main .lede { color: var(--muted); font-size: 1.1rem; margin-bottom: 2.5rem; }
36
+ section.doc { padding-top: 1rem; margin-bottom: 2.5rem; border-top: 1px solid var(--border); }
37
+ section.doc:first-of-type { border-top: none; }
38
+ section.doc h2 { font-size: 1.6rem; letter-spacing: -0.01em; margin: 1rem 0 0.75rem; }
39
+ section.doc h3 { font-size: 1.15rem; margin: 1.25rem 0 0.5rem; }
40
+ section.doc p { color: var(--muted); margin-bottom: 1rem; }
41
+ pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px;
42
+ padding: 1rem 1.1rem; overflow-x: auto; margin-bottom: 1rem; }
43
+ code { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; font-size: 0.9rem; }
44
+ p code, li code { background: var(--code-bg); border: 1px solid var(--border); border-radius: 5px; padding: 0.1rem 0.35rem; color: var(--fg); }
45
+ ul, ol { color: var(--muted); margin: 0 0 1rem 1.25rem; }
46
+ @media (max-width: 720px) {
47
+ .layout { grid-template-columns: 1fr; }
48
+ aside { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
49
+ }
50
+ </style>
51
+ </head>
52
+ <body>
53
+ <div class="layout">
54
+ <aside>
55
+ <span class="brand">{{PROJECT_NAME}}</span>
56
+ <input class="search" id="search" type="search" placeholder="Search docs" aria-label="Search docs" />
57
+ <nav class="toc" id="toc">
58
+ <!-- TOC_START -->
59
+ <div class="group">Getting started</div>
60
+ <a href="#introduction">Introduction</a>
61
+ <a href="#installation">Installation</a>
62
+ <a href="#quickstart">Quickstart</a>
63
+ <div class="group">Guides</div>
64
+ <a href="#configuration">Configuration</a>
65
+ <a href="#deployment">Deployment</a>
66
+ <!-- Add more <a href="#anchor">Label</a> links; keep anchors matching section ids. -->
67
+ <!-- TOC_END -->
68
+ </nav>
69
+ </aside>
70
+
71
+ <main>
72
+ <h1>{{PROJECT_NAME}}</h1>
73
+ <p class="lede">{{DOCS_LEDE}}</p>
74
+
75
+ <!-- SECTIONS_START -->
76
+ <section class="doc" id="introduction">
77
+ <h2>Introduction</h2>
78
+ <p>{{INTRO_BODY}}</p>
79
+ </section>
80
+
81
+ <section class="doc" id="installation">
82
+ <h2>Installation</h2>
83
+ <p>{{INSTALL_BODY}}</p>
84
+ <pre><code>{{INSTALL_CODE}}</code></pre>
85
+ </section>
86
+
87
+ <section class="doc" id="quickstart">
88
+ <h2>Quickstart</h2>
89
+ <p>{{QUICKSTART_BODY}}</p>
90
+ <pre><code>{{QUICKSTART_CODE}}</code></pre>
91
+ </section>
92
+
93
+ <section class="doc" id="configuration">
94
+ <h2>Configuration</h2>
95
+ <p>{{CONFIG_BODY}}</p>
96
+ <pre><code>{{CONFIG_CODE}}</code></pre>
97
+ </section>
98
+
99
+ <section class="doc" id="deployment">
100
+ <h2>Deployment</h2>
101
+ <p>{{DEPLOY_BODY}}</p>
102
+ </section>
103
+ <!-- SECTIONS_END -->
104
+ </main>
105
+ </div>
106
+
107
+ <script>
108
+ // Client-side sidebar filter. No network, no dependencies.
109
+ (function () {
110
+ var search = document.getElementById("search");
111
+ var links = Array.prototype.slice.call(document.querySelectorAll("#toc a"));
112
+ search.addEventListener("input", function () {
113
+ var q = search.value.trim().toLowerCase();
114
+ links.forEach(function (a) {
115
+ var match = a.textContent.toLowerCase().indexOf(q) !== -1;
116
+ a.style.display = match ? "" : "none";
117
+ });
118
+ });
119
+ })();
120
+ </script>
121
+ </body>
122
+ </html>
@@ -0,0 +1,30 @@
1
+ # Template: docs-site (static)
2
+
3
+ A single self-contained HTML documentation site: a sidebar nav, a scrolling content column with headings and code blocks, and a client-side search box that filters the nav. No backend. **No infrastructure** — no database, no backend, no `needs:`.
4
+ State (if any) lives only in memory and is lost on refresh.
5
+
6
+ ## How it deploys
7
+
8
+ To publish this page, use **`gridctl_drop`** (or `gridctl_plug` with the inline
9
+ HTML): it deploys as an **inspiration** — instant, and works on the **hosted**
10
+ edition (Claude Web) as well as local. The reference `cloudgrid.yaml` in this
11
+ directory (`type: static`) is ONLY for plugging the page as an OWNED static
12
+ runtime (async, local edition only); the fast path is `gridctl_drop`.
13
+
14
+ The fillable HTML is the real template — fetch it with
15
+ `gridctl_fetch("template", "docs-site")` and fill in the user's content.
16
+
17
+ ## cloudgrid.yaml (reference only)
18
+
19
+ ```yaml
20
+ # static — deploys as an inspiration (instant, works on hosted) via gridctl_drop;
21
+ # this yaml is only for plugging it as an OWNED static runtime (async, local
22
+ # edition only). To publish the page, prefer gridctl_drop, not grid plug.
23
+ #
24
+ # needs: {} # none — static, no infrastructure
25
+ name: docs-site
26
+ services:
27
+ web:
28
+ type: static
29
+ path: /
30
+ ```