@cloudgrid-io/mcp 0.13.0 → 0.14.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.
- package/package.json +1 -1
- package/src/corpus/capability-map.md +68 -7
- package/src/corpus/templates/_cloudgrid.yaml.reference +228 -0
- package/src/corpus/templates/admin-dashboard/cloudgrid.yaml +226 -8
- package/src/corpus/templates/admin-dashboard/index.md +3 -0
- package/src/corpus/templates/ai-app/cloudgrid.yaml +225 -11
- package/src/corpus/templates/ai-app/index.md +3 -11
- package/src/corpus/templates/ai-knowledge-base/AGENTS.md +254 -0
- package/src/corpus/templates/ai-knowledge-base/README.md +28 -0
- package/src/corpus/templates/ai-knowledge-base/cloudgrid.yaml +238 -0
- package/src/corpus/templates/ai-knowledge-base/index.md +81 -0
- package/src/corpus/templates/analytics-dashboard/README.md +85 -0
- package/src/corpus/templates/analytics-dashboard/cloudgrid.yaml +232 -0
- package/src/corpus/templates/analytics-dashboard/index.md +316 -0
- package/src/corpus/templates/analytics-dashboard/services/web/app/api/events/route.js +60 -0
- package/src/corpus/templates/analytics-dashboard/services/web/app/event-form.js +100 -0
- package/src/corpus/templates/analytics-dashboard/services/web/app/layout.js +41 -0
- package/src/corpus/templates/analytics-dashboard/services/web/app/page.js +54 -0
- package/src/corpus/templates/analytics-dashboard/services/web/lib/db.js +32 -0
- package/src/corpus/templates/analytics-dashboard/services/web/package.json +16 -0
- package/src/corpus/templates/api-dashboard/README.md +84 -0
- package/src/corpus/templates/api-dashboard/cloudgrid.yaml +233 -0
- package/src/corpus/templates/api-dashboard/index.md +310 -0
- package/src/corpus/templates/api-dashboard/services/web/app/api/requests/route.js +62 -0
- package/src/corpus/templates/api-dashboard/services/web/app/dashboard.js +156 -0
- package/src/corpus/templates/api-dashboard/services/web/app/layout.js +42 -0
- package/src/corpus/templates/api-dashboard/services/web/app/page.js +39 -0
- package/src/corpus/templates/api-dashboard/services/web/lib/db.js +32 -0
- package/src/corpus/templates/api-dashboard/services/web/package.json +16 -0
- package/src/corpus/templates/api-docs/cloudgrid.yaml +222 -4
- package/src/corpus/templates/api-docs/index.md +3 -5
- package/src/corpus/templates/api-service/cloudgrid.yaml +224 -9
- package/src/corpus/templates/api-service/index.md +3 -11
- package/src/corpus/templates/app-with-data/cloudgrid.yaml +226 -8
- package/src/corpus/templates/app-with-data/index.md +3 -8
- package/src/corpus/templates/appointment-booking/AGENTS.md +223 -0
- package/src/corpus/templates/appointment-booking/README.md +16 -0
- package/src/corpus/templates/appointment-booking/cloudgrid.yaml +250 -0
- package/src/corpus/templates/appointment-booking/index.md +72 -0
- package/src/corpus/templates/approval-workflow/AGENTS.md +170 -0
- package/src/corpus/templates/approval-workflow/README.md +12 -0
- package/src/corpus/templates/approval-workflow/cloudgrid.yaml +237 -0
- package/src/corpus/templates/approval-workflow/index.md +58 -0
- package/src/corpus/templates/billing-dashboard/AGENTS.md +199 -0
- package/src/corpus/templates/billing-dashboard/README.md +18 -0
- package/src/corpus/templates/billing-dashboard/cloudgrid.yaml +235 -0
- package/src/corpus/templates/billing-dashboard/index.md +87 -0
- package/src/corpus/templates/blog-cms/README.md +94 -0
- package/src/corpus/templates/blog-cms/cloudgrid.yaml +233 -0
- package/src/corpus/templates/blog-cms/index.md +358 -0
- package/src/corpus/templates/blog-cms/services/web/app/admin/admin-editor.js +133 -0
- package/src/corpus/templates/blog-cms/services/web/app/admin/page.js +33 -0
- package/src/corpus/templates/blog-cms/services/web/app/api/posts/route.js +84 -0
- package/src/corpus/templates/blog-cms/services/web/app/layout.js +47 -0
- package/src/corpus/templates/blog-cms/services/web/app/page.js +56 -0
- package/src/corpus/templates/blog-cms/services/web/app/posts/[slug]/page.js +45 -0
- package/src/corpus/templates/blog-cms/services/web/lib/db.js +32 -0
- package/src/corpus/templates/blog-cms/services/web/package.json +16 -0
- package/src/corpus/templates/booking-system/AGENTS.md +189 -0
- package/src/corpus/templates/booking-system/README.md +17 -0
- package/src/corpus/templates/booking-system/cloudgrid.yaml +248 -0
- package/src/corpus/templates/booking-system/index.md +86 -0
- package/src/corpus/templates/calendar-scheduler/AGENTS.md +226 -0
- package/src/corpus/templates/calendar-scheduler/README.md +25 -0
- package/src/corpus/templates/calendar-scheduler/cloudgrid.yaml +259 -0
- package/src/corpus/templates/calendar-scheduler/index.md +85 -0
- package/src/corpus/templates/changelog/cloudgrid.yaml +222 -4
- package/src/corpus/templates/changelog/index.md +3 -5
- package/src/corpus/templates/company-website/README.md +54 -0
- package/src/corpus/templates/company-website/cloudgrid.yaml +233 -0
- package/src/corpus/templates/company-website/index.html +309 -0
- package/src/corpus/templates/company-website/index.md +29 -0
- package/src/corpus/templates/course-platform/AGENTS.md +161 -0
- package/src/corpus/templates/course-platform/README.md +26 -0
- package/src/corpus/templates/course-platform/cloudgrid.yaml +237 -0
- package/src/corpus/templates/course-platform/index.md +70 -0
- package/src/corpus/templates/crm/cloudgrid.yaml +226 -8
- package/src/corpus/templates/crm/index.md +3 -0
- package/src/corpus/templates/dashboard/cloudgrid.yaml +228 -4
- package/src/corpus/templates/dashboard/index.md +3 -5
- package/src/corpus/templates/deck/cloudgrid.yaml +228 -4
- package/src/corpus/templates/deck/index.md +3 -5
- package/src/corpus/templates/directory/README.md +75 -0
- package/src/corpus/templates/directory/cloudgrid.yaml +233 -0
- package/src/corpus/templates/directory/index.md +334 -0
- package/src/corpus/templates/directory/services/web/app/api/entries/route.js +63 -0
- package/src/corpus/templates/directory/services/web/app/directory-list.js +146 -0
- package/src/corpus/templates/directory/services/web/app/layout.js +44 -0
- package/src/corpus/templates/directory/services/web/app/page.js +38 -0
- package/src/corpus/templates/directory/services/web/lib/db.js +32 -0
- package/src/corpus/templates/directory/services/web/package.json +16 -0
- package/src/corpus/templates/docs-site/cloudgrid.yaml +222 -4
- package/src/corpus/templates/docs-site/index.md +3 -5
- package/src/corpus/templates/erp/AGENTS.md +116 -0
- package/src/corpus/templates/erp/README.md +17 -0
- package/src/corpus/templates/erp/cloudgrid.yaml +235 -0
- package/src/corpus/templates/erp/index.md +81 -0
- package/src/corpus/templates/event-board/README.md +74 -0
- package/src/corpus/templates/event-board/cloudgrid.yaml +233 -0
- package/src/corpus/templates/event-board/index.md +299 -0
- package/src/corpus/templates/event-board/services/web/app/api/events/route.js +61 -0
- package/src/corpus/templates/event-board/services/web/app/event-form.js +118 -0
- package/src/corpus/templates/event-board/services/web/app/layout.js +39 -0
- package/src/corpus/templates/event-board/services/web/app/page.js +34 -0
- package/src/corpus/templates/event-board/services/web/lib/db.js +32 -0
- package/src/corpus/templates/event-board/services/web/package.json +16 -0
- package/src/corpus/templates/expense-tracker/README.md +76 -0
- package/src/corpus/templates/expense-tracker/cloudgrid.yaml +233 -0
- package/src/corpus/templates/expense-tracker/index.md +305 -0
- package/src/corpus/templates/expense-tracker/services/web/app/api/expenses/route.js +61 -0
- package/src/corpus/templates/expense-tracker/services/web/app/expense-form.js +145 -0
- package/src/corpus/templates/expense-tracker/services/web/app/layout.js +42 -0
- package/src/corpus/templates/expense-tracker/services/web/app/page.js +34 -0
- package/src/corpus/templates/expense-tracker/services/web/lib/db.js +32 -0
- package/src/corpus/templates/expense-tracker/services/web/package.json +16 -0
- package/src/corpus/templates/feature-request-board/README.md +87 -0
- package/src/corpus/templates/feature-request-board/cloudgrid.yaml +233 -0
- package/src/corpus/templates/feature-request-board/index.md +317 -0
- package/src/corpus/templates/feature-request-board/services/web/app/api/requests/route.js +92 -0
- package/src/corpus/templates/feature-request-board/services/web/app/board.js +91 -0
- package/src/corpus/templates/feature-request-board/services/web/app/layout.js +43 -0
- package/src/corpus/templates/feature-request-board/services/web/app/page.js +35 -0
- package/src/corpus/templates/feature-request-board/services/web/lib/db.js +32 -0
- package/src/corpus/templates/feature-request-board/services/web/package.json +16 -0
- package/src/corpus/templates/financial-dashboard/README.md +80 -0
- package/src/corpus/templates/financial-dashboard/cloudgrid.yaml +233 -0
- package/src/corpus/templates/financial-dashboard/index.md +326 -0
- package/src/corpus/templates/financial-dashboard/services/web/app/api/entries/route.js +63 -0
- package/src/corpus/templates/financial-dashboard/services/web/app/entry-board.js +130 -0
- package/src/corpus/templates/financial-dashboard/services/web/app/layout.js +46 -0
- package/src/corpus/templates/financial-dashboard/services/web/app/page.js +31 -0
- package/src/corpus/templates/financial-dashboard/services/web/lib/db.js +32 -0
- package/src/corpus/templates/financial-dashboard/services/web/package.json +16 -0
- package/src/corpus/templates/forum/AGENTS.md +196 -0
- package/src/corpus/templates/forum/README.md +12 -0
- package/src/corpus/templates/forum/cloudgrid.yaml +237 -0
- package/src/corpus/templates/forum/index.md +66 -0
- package/src/corpus/templates/hr-portal/AGENTS.md +174 -0
- package/src/corpus/templates/hr-portal/README.md +14 -0
- package/src/corpus/templates/hr-portal/cloudgrid.yaml +237 -0
- package/src/corpus/templates/hr-portal/index.md +56 -0
- package/src/corpus/templates/internal-tools-portal/AGENTS.md +201 -0
- package/src/corpus/templates/internal-tools-portal/README.md +17 -0
- package/src/corpus/templates/internal-tools-portal/cloudgrid.yaml +237 -0
- package/src/corpus/templates/internal-tools-portal/index.md +62 -0
- package/src/corpus/templates/inventory/README.md +71 -0
- package/src/corpus/templates/inventory/cloudgrid.yaml +233 -0
- package/src/corpus/templates/inventory/index.md +68 -0
- package/src/corpus/templates/inventory/services/web/app/api/items/route.js +88 -0
- package/src/corpus/templates/inventory/services/web/app/inventory-manager.js +101 -0
- package/src/corpus/templates/inventory/services/web/app/layout.js +36 -0
- package/src/corpus/templates/inventory/services/web/app/page.js +37 -0
- package/src/corpus/templates/inventory/services/web/lib/db.js +32 -0
- package/src/corpus/templates/inventory/services/web/package.json +16 -0
- package/src/corpus/templates/invoice/README.md +71 -0
- package/src/corpus/templates/invoice/cloudgrid.yaml +233 -0
- package/src/corpus/templates/invoice/index.md +68 -0
- package/src/corpus/templates/invoice/services/web/app/api/invoices/route.js +82 -0
- package/src/corpus/templates/invoice/services/web/app/invoice-manager.js +101 -0
- package/src/corpus/templates/invoice/services/web/app/layout.js +35 -0
- package/src/corpus/templates/invoice/services/web/app/page.js +34 -0
- package/src/corpus/templates/invoice/services/web/lib/db.js +32 -0
- package/src/corpus/templates/invoice/services/web/package.json +16 -0
- package/src/corpus/templates/job-board/README.md +71 -0
- package/src/corpus/templates/job-board/cloudgrid.yaml +233 -0
- package/src/corpus/templates/job-board/index.md +68 -0
- package/src/corpus/templates/job-board/services/web/app/api/jobs/route.js +66 -0
- package/src/corpus/templates/job-board/services/web/app/job-board.js +73 -0
- package/src/corpus/templates/job-board/services/web/app/layout.js +35 -0
- package/src/corpus/templates/job-board/services/web/app/page.js +32 -0
- package/src/corpus/templates/job-board/services/web/lib/db.js +32 -0
- package/src/corpus/templates/job-board/services/web/package.json +16 -0
- package/src/corpus/templates/kanban/cloudgrid.yaml +226 -8
- package/src/corpus/templates/kanban/index.md +3 -0
- package/src/corpus/templates/landing-page/cloudgrid.yaml +228 -4
- package/src/corpus/templates/landing-page/index.md +3 -5
- package/src/corpus/templates/lms/AGENTS.md +193 -0
- package/src/corpus/templates/lms/README.md +27 -0
- package/src/corpus/templates/lms/cloudgrid.yaml +237 -0
- package/src/corpus/templates/lms/index.md +79 -0
- package/src/corpus/templates/marketplace/AGENTS.md +208 -0
- package/src/corpus/templates/marketplace/README.md +22 -0
- package/src/corpus/templates/marketplace/cloudgrid.yaml +233 -0
- package/src/corpus/templates/marketplace/index.md +76 -0
- package/src/corpus/templates/membership-site/AGENTS.md +160 -0
- package/src/corpus/templates/membership-site/README.md +18 -0
- package/src/corpus/templates/membership-site/cloudgrid.yaml +236 -0
- package/src/corpus/templates/membership-site/index.md +66 -0
- package/src/corpus/templates/monitoring-dashboard/README.md +84 -0
- package/src/corpus/templates/monitoring-dashboard/cloudgrid.yaml +233 -0
- package/src/corpus/templates/monitoring-dashboard/index.md +328 -0
- package/src/corpus/templates/monitoring-dashboard/services/web/app/api/checks/route.js +76 -0
- package/src/corpus/templates/monitoring-dashboard/services/web/app/check-form.js +124 -0
- package/src/corpus/templates/monitoring-dashboard/services/web/app/layout.js +44 -0
- package/src/corpus/templates/monitoring-dashboard/services/web/app/page.js +49 -0
- package/src/corpus/templates/monitoring-dashboard/services/web/lib/db.js +32 -0
- package/src/corpus/templates/monitoring-dashboard/services/web/package.json +16 -0
- package/src/corpus/templates/online-store/AGENTS.md +153 -0
- package/src/corpus/templates/online-store/README.md +16 -0
- package/src/corpus/templates/online-store/cloudgrid.yaml +234 -0
- package/src/corpus/templates/online-store/index.md +81 -0
- package/src/corpus/templates/portfolio/cloudgrid.yaml +222 -4
- package/src/corpus/templates/portfolio/index.md +3 -5
- package/src/corpus/templates/product-catalog/README.md +74 -0
- package/src/corpus/templates/product-catalog/cloudgrid.yaml +232 -0
- package/src/corpus/templates/product-catalog/index.md +330 -0
- package/src/corpus/templates/product-catalog/services/web/app/api/products/route.js +69 -0
- package/src/corpus/templates/product-catalog/services/web/app/catalog.js +153 -0
- package/src/corpus/templates/product-catalog/services/web/app/layout.js +49 -0
- package/src/corpus/templates/product-catalog/services/web/app/page.js +36 -0
- package/src/corpus/templates/product-catalog/services/web/lib/db.js +32 -0
- package/src/corpus/templates/product-catalog/services/web/package.json +16 -0
- package/src/corpus/templates/product-launch/README.md +46 -0
- package/src/corpus/templates/product-launch/cloudgrid.yaml +234 -0
- package/src/corpus/templates/product-launch/index.html +320 -0
- package/src/corpus/templates/product-launch/index.md +34 -0
- package/src/corpus/templates/project-management/README.md +83 -0
- package/src/corpus/templates/project-management/cloudgrid.yaml +233 -0
- package/src/corpus/templates/project-management/index.md +346 -0
- package/src/corpus/templates/project-management/services/web/app/api/projects/route.js +48 -0
- package/src/corpus/templates/project-management/services/web/app/api/tasks/route.js +85 -0
- package/src/corpus/templates/project-management/services/web/app/board.js +182 -0
- package/src/corpus/templates/project-management/services/web/app/layout.js +45 -0
- package/src/corpus/templates/project-management/services/web/app/page.js +49 -0
- package/src/corpus/templates/project-management/services/web/lib/db.js +32 -0
- package/src/corpus/templates/project-management/services/web/package.json +16 -0
- package/src/corpus/templates/property-listings/README.md +76 -0
- package/src/corpus/templates/property-listings/cloudgrid.yaml +233 -0
- package/src/corpus/templates/property-listings/index.md +335 -0
- package/src/corpus/templates/property-listings/services/web/app/api/properties/route.js +73 -0
- package/src/corpus/templates/property-listings/services/web/app/layout.js +45 -0
- package/src/corpus/templates/property-listings/services/web/app/listings.js +152 -0
- package/src/corpus/templates/property-listings/services/web/app/page.js +53 -0
- package/src/corpus/templates/property-listings/services/web/lib/db.js +32 -0
- package/src/corpus/templates/property-listings/services/web/package.json +16 -0
- package/src/corpus/templates/quiz-platform/README.md +84 -0
- package/src/corpus/templates/quiz-platform/cloudgrid.yaml +233 -0
- package/src/corpus/templates/quiz-platform/index.md +313 -0
- package/src/corpus/templates/quiz-platform/services/web/app/api/questions/route.js +69 -0
- package/src/corpus/templates/quiz-platform/services/web/app/layout.js +47 -0
- package/src/corpus/templates/quiz-platform/services/web/app/page.js +37 -0
- package/src/corpus/templates/quiz-platform/services/web/app/quiz.js +188 -0
- package/src/corpus/templates/quiz-platform/services/web/lib/db.js +32 -0
- package/src/corpus/templates/quiz-platform/services/web/package.json +16 -0
- package/src/corpus/templates/report/cloudgrid.yaml +228 -4
- package/src/corpus/templates/report/index.md +3 -5
- package/src/corpus/templates/restaurant-reservations/AGENTS.md +258 -0
- package/src/corpus/templates/restaurant-reservations/README.md +17 -0
- package/src/corpus/templates/restaurant-reservations/cloudgrid.yaml +258 -0
- package/src/corpus/templates/restaurant-reservations/index.md +62 -0
- package/src/corpus/templates/revenue-dashboard/README.md +75 -0
- package/src/corpus/templates/revenue-dashboard/cloudgrid.yaml +233 -0
- package/src/corpus/templates/revenue-dashboard/index.md +307 -0
- package/src/corpus/templates/revenue-dashboard/services/web/app/api/sales/route.js +60 -0
- package/src/corpus/templates/revenue-dashboard/services/web/app/layout.js +40 -0
- package/src/corpus/templates/revenue-dashboard/services/web/app/page.js +87 -0
- package/src/corpus/templates/revenue-dashboard/services/web/app/sale-form.js +63 -0
- package/src/corpus/templates/revenue-dashboard/services/web/lib/db.js +32 -0
- package/src/corpus/templates/revenue-dashboard/services/web/package.json +16 -0
- package/src/corpus/templates/saas-marketing/cloudgrid.yaml +222 -4
- package/src/corpus/templates/saas-marketing/index.md +3 -5
- package/src/corpus/templates/status-page/cloudgrid.yaml +222 -4
- package/src/corpus/templates/status-page/index.md +3 -5
- package/src/corpus/templates/subscription-management/AGENTS.md +191 -0
- package/src/corpus/templates/subscription-management/README.md +21 -0
- package/src/corpus/templates/subscription-management/cloudgrid.yaml +236 -0
- package/src/corpus/templates/subscription-management/index.md +73 -0
- package/src/corpus/templates/task-manager/cloudgrid.yaml +226 -8
- package/src/corpus/templates/task-manager/index.md +3 -0
- package/src/corpus/templates/ticket-system/README.md +71 -0
- package/src/corpus/templates/ticket-system/cloudgrid.yaml +233 -0
- package/src/corpus/templates/ticket-system/index.md +68 -0
- package/src/corpus/templates/ticket-system/services/web/app/api/tickets/route.js +81 -0
- package/src/corpus/templates/ticket-system/services/web/app/layout.js +36 -0
- package/src/corpus/templates/ticket-system/services/web/app/page.js +35 -0
- package/src/corpus/templates/ticket-system/services/web/app/ticket-queue.js +112 -0
- package/src/corpus/templates/ticket-system/services/web/lib/db.js +32 -0
- package/src/corpus/templates/ticket-system/services/web/package.json +16 -0
- package/src/corpus/templates/time-tracking/README.md +81 -0
- package/src/corpus/templates/time-tracking/cloudgrid.yaml +233 -0
- package/src/corpus/templates/time-tracking/index.md +298 -0
- package/src/corpus/templates/time-tracking/services/web/app/api/entries/route.js +66 -0
- package/src/corpus/templates/time-tracking/services/web/app/entry-form.js +106 -0
- package/src/corpus/templates/time-tracking/services/web/app/layout.js +39 -0
- package/src/corpus/templates/time-tracking/services/web/app/page.js +30 -0
- package/src/corpus/templates/time-tracking/services/web/lib/db.js +32 -0
- package/src/corpus/templates/time-tracking/services/web/package.json +16 -0
- package/src/corpus/templates/travel-booking/AGENTS.md +207 -0
- package/src/corpus/templates/travel-booking/README.md +17 -0
- package/src/corpus/templates/travel-booking/cloudgrid.yaml +249 -0
- package/src/corpus/templates/travel-booking/index.md +88 -0
- package/src/corpus/templates/waitlist/cloudgrid.yaml +222 -4
- package/src/corpus/templates/waitlist/index.md +3 -5
- package/src/corpus/templates/web-app/cloudgrid.yaml +228 -4
- package/src/corpus/templates/web-app/index.md +3 -5
- package/src/corpus/workflows/ai-knowledge-base.md +137 -0
- package/src/corpus/workflows/analytics-dashboard.md +104 -0
- package/src/corpus/workflows/api-dashboard.md +102 -0
- package/src/corpus/workflows/appointment-booking.md +143 -0
- package/src/corpus/workflows/approval-workflow.md +124 -0
- package/src/corpus/workflows/billing-dashboard.md +120 -0
- package/src/corpus/workflows/blog-cms.md +104 -0
- package/src/corpus/workflows/booking-system.md +116 -0
- package/src/corpus/workflows/calendar-scheduler.md +134 -0
- package/src/corpus/workflows/company-website.md +46 -0
- package/src/corpus/workflows/course-platform.md +126 -0
- package/src/corpus/workflows/directory.md +101 -0
- package/src/corpus/workflows/erp.md +125 -0
- package/src/corpus/workflows/event-board.md +102 -0
- package/src/corpus/workflows/expense-tracker.md +102 -0
- package/src/corpus/workflows/feature-request-board.md +105 -0
- package/src/corpus/workflows/financial-dashboard.md +103 -0
- package/src/corpus/workflows/forum.md +128 -0
- package/src/corpus/workflows/hr-portal.md +115 -0
- package/src/corpus/workflows/internal-tools-portal.md +125 -0
- package/src/corpus/workflows/inventory.md +101 -0
- package/src/corpus/workflows/invoice.md +101 -0
- package/src/corpus/workflows/job-board.md +101 -0
- package/src/corpus/workflows/lms.md +113 -0
- package/src/corpus/workflows/marketplace.md +123 -0
- package/src/corpus/workflows/membership-site.md +128 -0
- package/src/corpus/workflows/monitoring-dashboard.md +104 -0
- package/src/corpus/workflows/online-store.md +114 -0
- package/src/corpus/workflows/product-catalog.md +105 -0
- package/src/corpus/workflows/product-launch.md +43 -0
- package/src/corpus/workflows/project-management.md +106 -0
- package/src/corpus/workflows/property-listings.md +101 -0
- package/src/corpus/workflows/quiz-platform.md +105 -0
- package/src/corpus/workflows/restaurant-reservations.md +123 -0
- package/src/corpus/workflows/revenue-dashboard.md +102 -0
- package/src/corpus/workflows/subscription-management.md +141 -0
- package/src/corpus/workflows/ticket-system.md +101 -0
- package/src/corpus/workflows/time-tracking.md +104 -0
- package/src/corpus/workflows/travel-booking.md +115 -0
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
# Template: quiz-platform (persistent Next.js + Mongo)
|
|
2
|
+
|
|
3
|
+
A minimal but real, deployable quiz / trivia app. Questions live in the
|
|
4
|
+
grid-shared MongoDB, so they survive refresh and are shared across sessions —
|
|
5
|
+
unlike a static page. Visitors take the quiz (pick one option per question,
|
|
6
|
+
submit for a score); an admin form adds new questions.
|
|
7
|
+
|
|
8
|
+
Domain: a `questions` collection of `{ prompt: string, options: string[],
|
|
9
|
+
answerIndex: number }` documents. `answerIndex` is the 0-based index of the
|
|
10
|
+
correct option; the score compares each chosen index against it.
|
|
11
|
+
|
|
12
|
+
**Key rules (all proven by a real end-to-end deploy):**
|
|
13
|
+
|
|
14
|
+
1. **Service code MUST live under `services/<name>/`, not the repo/template
|
|
15
|
+
root.** `path:` in `cloudgrid.yaml` is the URL mount, NOT the filesystem path.
|
|
16
|
+
The service named `web` → the CLI looks for `services/web/`. App files at the
|
|
17
|
+
root fail with `Error: Service directory not found: …/services/web`.
|
|
18
|
+
2. **Read the DB connection string LAZILY (inside the getter), never at module
|
|
19
|
+
top level.** The grid injects it as the `DATABASE_MONGODB_URL` environment
|
|
20
|
+
variable (plus the legacy `MONGODB_URL` alias) at dev-time and runtime; the
|
|
21
|
+
app reads `process.env.DATABASE_MONGODB_URL || process.env.MONGODB_URL` inside
|
|
22
|
+
`getDb`. A top-level `const uri = process.env.DATABASE_MONGODB_URL; if (!uri)
|
|
23
|
+
throw` fails `next build` (the module is imported for route analysis before
|
|
24
|
+
the grid injects the var). Never hardcode a connection string; never commit a
|
|
25
|
+
secret.
|
|
26
|
+
3. **Declare the datastore with `needs: { database: true }`.** This is the
|
|
27
|
+
canonical shape — the deployer provisions Mongo and injects
|
|
28
|
+
`DATABASE_MONGODB_URL` (plus the legacy `MONGODB_URL` alias). `requires:` is
|
|
29
|
+
the deprecated v1 alias; don't author new yaml with it, and never set `needs:`
|
|
30
|
+
and `requires:` together (the validator rejects the combination).
|
|
31
|
+
|
|
32
|
+
Write these files into the scaffolded app folder — the app code goes under
|
|
33
|
+
`services/web/` — adapt the collection/fields to the user's quiz, then `grid dev`
|
|
34
|
+
(local) / `grid plug` (deploy, async — poll to a live URL).
|
|
35
|
+
|
|
36
|
+
## File tree
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
cloudgrid.yaml # name + services.web (nextjs) + needs: { database: true }
|
|
40
|
+
services/web/package.json # next, react, react-dom, mongodb driver only
|
|
41
|
+
services/web/lib/db.js # lazy Mongo client from DATABASE_MONGODB_URL (legacy MONGODB_URL fallback)
|
|
42
|
+
services/web/app/layout.js # root layout + inline CSS
|
|
43
|
+
services/web/app/page.js # server component: reads questions from Mongo
|
|
44
|
+
services/web/app/quiz.js # client: take-quiz UI (score) + admin add-question form
|
|
45
|
+
services/web/app/api/questions/route.js # GET (list) / POST (add) / DELETE (remove)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## cloudgrid.yaml
|
|
49
|
+
|
|
50
|
+
```yaml
|
|
51
|
+
# On disk this file is the full-annotated reference (templates/_cloudgrid.yaml.reference) with EVERY
|
|
52
|
+
# field present as a comment; only the fields below are uncommented, so it
|
|
53
|
+
# deploys to exactly these active fields.
|
|
54
|
+
name: quiz-platform
|
|
55
|
+
services:
|
|
56
|
+
web:
|
|
57
|
+
type: nextjs
|
|
58
|
+
path: /
|
|
59
|
+
needs:
|
|
60
|
+
database: true
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
> **Capability:** this template's need is `database: true`. The deployer
|
|
64
|
+
> provisions Mongo and injects `DATABASE_MONGODB_URL` (plus the legacy
|
|
65
|
+
> `MONGODB_URL` alias), so an app reading either var works. `requires:` is the
|
|
66
|
+
> deprecated v1 alias — don't mix it with `needs:` (the validator rejects the
|
|
67
|
+
> combination). See the capability-map for the full injection table.
|
|
68
|
+
|
|
69
|
+
## services/web/package.json
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"name": "quiz-platform",
|
|
74
|
+
"version": "0.1.0",
|
|
75
|
+
"private": true,
|
|
76
|
+
"scripts": {
|
|
77
|
+
"dev": "next dev",
|
|
78
|
+
"build": "next build",
|
|
79
|
+
"start": "next start"
|
|
80
|
+
},
|
|
81
|
+
"dependencies": {
|
|
82
|
+
"next": "^15.1.0",
|
|
83
|
+
"react": "^19.0.0",
|
|
84
|
+
"react-dom": "^19.0.0",
|
|
85
|
+
"mongodb": "^6.12.0"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## services/web/lib/db.js
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
// Cached MongoDB client for the App Router. Read the connection string LAZILY
|
|
94
|
+
// (inside getDb), never at module top level — a top-level read fails next build.
|
|
95
|
+
import { MongoClient } from "mongodb";
|
|
96
|
+
|
|
97
|
+
function clientPromise() {
|
|
98
|
+
const uri = process.env.DATABASE_MONGODB_URL || process.env.MONGODB_URL;
|
|
99
|
+
if (!uri) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
"DATABASE_MONGODB_URL is not set. The grid injects it automatically — run " +
|
|
102
|
+
"this app with `grid dev` locally, or deploy it with `grid plug`. Do not set it by hand.",
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
if (!globalThis.__mongoClientPromise) {
|
|
106
|
+
globalThis.__mongoClientPromise = new MongoClient(uri).connect();
|
|
107
|
+
}
|
|
108
|
+
return globalThis.__mongoClientPromise;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export async function getDb() {
|
|
112
|
+
const client = await clientPromise();
|
|
113
|
+
return client.db();
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## services/web/app/layout.js
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
export const metadata = {
|
|
121
|
+
title: "Quiz Platform",
|
|
122
|
+
description: "A persistent quiz/trivia app on CloudGrid, backed by grid-shared Mongo.",
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const css = `
|
|
126
|
+
:root { color-scheme: light dark; }
|
|
127
|
+
body { margin: 0; font-family: system-ui, sans-serif; }
|
|
128
|
+
main { max-width: 42rem; margin: 3rem auto; padding: 0 1.25rem; }
|
|
129
|
+
.card { border: 1px solid #8883; border-radius: .75rem; padding: 1rem 1.15rem; margin-bottom: 1rem; }
|
|
130
|
+
.options { list-style: none; padding: 0; margin: 0; display: grid; gap: .4rem; }
|
|
131
|
+
.opt { width: 100%; text-align: left; padding: .5rem .7rem; border: 1px solid #8886; border-radius: .5rem; cursor: pointer; }
|
|
132
|
+
.opt.selected { border-color: #4a90d9; background: #4a90d933; }
|
|
133
|
+
.opt.correct { border-color: #3ba55d; background: #3ba55d33; }
|
|
134
|
+
.opt.wrong { border-color: #d9534f; background: #d9534f33; }
|
|
135
|
+
input { padding: .5rem .75rem; border: 1px solid #8886; border-radius: .5rem; }
|
|
136
|
+
button { padding: .5rem .9rem; border: 1px solid #8886; border-radius: .5rem; cursor: pointer; }
|
|
137
|
+
button.primary { background: #4a90d9; border-color: #4a90d9; color: #fff; }
|
|
138
|
+
`;
|
|
139
|
+
|
|
140
|
+
export default function RootLayout({ children }) {
|
|
141
|
+
return (
|
|
142
|
+
<html lang="en">
|
|
143
|
+
<head><style dangerouslySetInnerHTML={{ __html: css }} /></head>
|
|
144
|
+
<body>{children}</body>
|
|
145
|
+
</html>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## services/web/app/page.js
|
|
151
|
+
|
|
152
|
+
```js
|
|
153
|
+
import { getDb } from "../lib/db.js";
|
|
154
|
+
import Quiz from "./quiz.js";
|
|
155
|
+
|
|
156
|
+
export const dynamic = "force-dynamic";
|
|
157
|
+
|
|
158
|
+
async function listQuestions() {
|
|
159
|
+
const db = await getDb();
|
|
160
|
+
const items = await db.collection("questions").find({}).sort({ createdAt: -1 }).toArray();
|
|
161
|
+
return items.map((q) => ({
|
|
162
|
+
id: q._id.toString(),
|
|
163
|
+
prompt: q.prompt,
|
|
164
|
+
options: Array.isArray(q.options) ? q.options : [],
|
|
165
|
+
answerIndex: typeof q.answerIndex === "number" ? q.answerIndex : 0,
|
|
166
|
+
}));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export default async function Page() {
|
|
170
|
+
const questions = await listQuestions();
|
|
171
|
+
return (
|
|
172
|
+
<main>
|
|
173
|
+
<h1>Quiz Platform</h1>
|
|
174
|
+
<p className="hint">Take the quiz, then add your own questions — persisted in grid-shared Mongo.</p>
|
|
175
|
+
<Quiz initialQuestions={questions} />
|
|
176
|
+
</main>
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## services/web/app/quiz.js
|
|
182
|
+
|
|
183
|
+
```js
|
|
184
|
+
"use client";
|
|
185
|
+
import { useState } from "react";
|
|
186
|
+
|
|
187
|
+
export default function Quiz({ initialQuestions }) {
|
|
188
|
+
const [questions, setQuestions] = useState(initialQuestions);
|
|
189
|
+
const [answers, setAnswers] = useState({});
|
|
190
|
+
const [submitted, setSubmitted] = useState(false);
|
|
191
|
+
const [prompt, setPrompt] = useState("");
|
|
192
|
+
const [options, setOptions] = useState(["", "", "", ""]);
|
|
193
|
+
const [answerIndex, setAnswerIndex] = useState(0);
|
|
194
|
+
|
|
195
|
+
const score = questions.reduce((n, q) => (answers[q.id] === q.answerIndex ? n + 1 : n), 0);
|
|
196
|
+
|
|
197
|
+
async function addQuestion(e) {
|
|
198
|
+
e.preventDefault();
|
|
199
|
+
const cleanPrompt = prompt.trim();
|
|
200
|
+
const cleanOptions = options.map((o) => o.trim()).filter(Boolean);
|
|
201
|
+
if (!cleanPrompt || cleanOptions.length < 2) return;
|
|
202
|
+
const res = await fetch("/api/questions", {
|
|
203
|
+
method: "POST",
|
|
204
|
+
headers: { "content-type": "application/json" },
|
|
205
|
+
body: JSON.stringify({ prompt: cleanPrompt, options: cleanOptions, answerIndex: Math.min(answerIndex, cleanOptions.length - 1) }),
|
|
206
|
+
});
|
|
207
|
+
if (res.ok) { setQuestions((p) => [await res.json(), ...p]); setPrompt(""); setOptions(["", "", "", ""]); setAnswerIndex(0); setSubmitted(false); }
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async function remove(id) {
|
|
211
|
+
const res = await fetch(`/api/questions?id=${encodeURIComponent(id)}`, { method: "DELETE" });
|
|
212
|
+
if (res.ok) setQuestions((p) => p.filter((q) => q.id !== id));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return (
|
|
216
|
+
<div>
|
|
217
|
+
<h2>Take the quiz</h2>
|
|
218
|
+
<form onSubmit={(e) => { e.preventDefault(); setSubmitted(true); }}>
|
|
219
|
+
{questions.map((q) => (
|
|
220
|
+
<div className="card" key={q.id}>
|
|
221
|
+
<p className="prompt">{q.prompt}</p>
|
|
222
|
+
<ul className="options">
|
|
223
|
+
{q.options.map((opt, i) => {
|
|
224
|
+
let cls = "opt";
|
|
225
|
+
if (submitted && i === q.answerIndex) cls += " correct";
|
|
226
|
+
else if (submitted && answers[q.id] === i) cls += " wrong";
|
|
227
|
+
else if (answers[q.id] === i) cls += " selected";
|
|
228
|
+
return (
|
|
229
|
+
<li key={i}>
|
|
230
|
+
<button type="button" className={cls} disabled={submitted}
|
|
231
|
+
onClick={() => !submitted && setAnswers((p) => ({ ...p, [q.id]: i }))}>{opt}</button>
|
|
232
|
+
</li>
|
|
233
|
+
);
|
|
234
|
+
})}
|
|
235
|
+
</ul>
|
|
236
|
+
<button type="button" onClick={() => remove(q.id)}>Delete</button>
|
|
237
|
+
</div>
|
|
238
|
+
))}
|
|
239
|
+
{questions.length > 0 && !submitted && <button type="submit" className="primary">Submit quiz</button>}
|
|
240
|
+
</form>
|
|
241
|
+
{submitted && <p className="score">Score: {score} / {questions.length}</p>}
|
|
242
|
+
|
|
243
|
+
<h2>Add a question</h2>
|
|
244
|
+
<form onSubmit={addQuestion}>
|
|
245
|
+
<input value={prompt} onChange={(e) => setPrompt(e.target.value)} placeholder="Question prompt…" />
|
|
246
|
+
{options.map((opt, i) => (
|
|
247
|
+
<div className="row" key={i}>
|
|
248
|
+
<input value={opt} onChange={(e) => setOptions((p) => p.map((o, j) => (j === i ? e.target.value : o)))} placeholder={`Option ${i + 1}`} />
|
|
249
|
+
<label><input type="radio" name="ans" checked={answerIndex === i} onChange={() => setAnswerIndex(i)} /> correct</label>
|
|
250
|
+
</div>
|
|
251
|
+
))}
|
|
252
|
+
<button type="submit" className="primary">Add question</button>
|
|
253
|
+
</form>
|
|
254
|
+
</div>
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## services/web/app/api/questions/route.js
|
|
260
|
+
|
|
261
|
+
```js
|
|
262
|
+
import { NextResponse } from "next/server";
|
|
263
|
+
import { ObjectId } from "mongodb";
|
|
264
|
+
import { getDb } from "../../../lib/db.js";
|
|
265
|
+
|
|
266
|
+
export const dynamic = "force-dynamic";
|
|
267
|
+
|
|
268
|
+
async function questions() {
|
|
269
|
+
const db = await getDb();
|
|
270
|
+
return db.collection("questions");
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const shape = (q) => ({
|
|
274
|
+
id: q._id.toString(),
|
|
275
|
+
prompt: q.prompt,
|
|
276
|
+
options: Array.isArray(q.options) ? q.options : [],
|
|
277
|
+
answerIndex: typeof q.answerIndex === "number" ? q.answerIndex : 0,
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
export async function GET() {
|
|
281
|
+
const col = await questions();
|
|
282
|
+
const items = await col.find({}).sort({ createdAt: -1 }).toArray();
|
|
283
|
+
return NextResponse.json(items.map(shape));
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export async function POST(request) {
|
|
287
|
+
const body = await request.json().catch(() => ({}));
|
|
288
|
+
const prompt = typeof body.prompt === "string" ? body.prompt.trim() : "";
|
|
289
|
+
const options = Array.isArray(body.options) ? body.options.map((o) => String(o).trim()).filter(Boolean) : [];
|
|
290
|
+
let answerIndex = Number.isInteger(body.answerIndex) ? body.answerIndex : 0;
|
|
291
|
+
if (!prompt || options.length < 2) return NextResponse.json({ error: "prompt and at least 2 options are required" }, { status: 400 });
|
|
292
|
+
if (answerIndex < 0 || answerIndex >= options.length) answerIndex = 0;
|
|
293
|
+
const col = await questions();
|
|
294
|
+
const res = await col.insertOne({ prompt, options, answerIndex, createdAt: new Date() });
|
|
295
|
+
return NextResponse.json({ id: res.insertedId.toString(), prompt, options, answerIndex }, { status: 201 });
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export async function DELETE(request) {
|
|
299
|
+
const id = new URL(request.url).searchParams.get("id");
|
|
300
|
+
if (!id || !ObjectId.isValid(id)) return NextResponse.json({ error: "valid id is required" }, { status: 400 });
|
|
301
|
+
const col = await questions();
|
|
302
|
+
await col.deleteOne({ _id: new ObjectId(id) });
|
|
303
|
+
return NextResponse.json({ ok: true });
|
|
304
|
+
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
## Adapt it
|
|
308
|
+
|
|
309
|
+
- Rename the `questions` collection to your data.
|
|
310
|
+
- Change the document fields; add categories, difficulty, explanations, an owner.
|
|
311
|
+
- Persist quiz attempts / build a leaderboard as a second collection.
|
|
312
|
+
- Add `cache: true` to `needs:` only if you actually need Redis.
|
|
313
|
+
- Run `grid dev` to test locally, `grid plug` to deploy (async — poll to live).
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// App Router route handler for the `questions` collection.
|
|
2
|
+
// GET -> list questions, POST -> add a question, DELETE -> remove one by id.
|
|
3
|
+
//
|
|
4
|
+
// A question document is { prompt: string, options: string[], answerIndex: number }.
|
|
5
|
+
// To adapt this app, rename the collection and change the fields to match your
|
|
6
|
+
// own data.
|
|
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
|
+
async function questions() {
|
|
15
|
+
const db = await getDb();
|
|
16
|
+
return db.collection("questions");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function shape(q) {
|
|
20
|
+
return {
|
|
21
|
+
id: q._id.toString(),
|
|
22
|
+
prompt: q.prompt,
|
|
23
|
+
options: Array.isArray(q.options) ? q.options : [],
|
|
24
|
+
answerIndex: typeof q.answerIndex === "number" ? q.answerIndex : 0,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// GET /api/questions — list all questions, newest first.
|
|
29
|
+
export async function GET() {
|
|
30
|
+
const col = await questions();
|
|
31
|
+
const items = await col.find({}).sort({ createdAt: -1 }).toArray();
|
|
32
|
+
return NextResponse.json(items.map(shape));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// POST /api/questions — add a question.
|
|
36
|
+
// Body: { prompt: string, options: string[], answerIndex: number }.
|
|
37
|
+
export async function POST(request) {
|
|
38
|
+
const body = await request.json().catch(() => ({}));
|
|
39
|
+
const prompt = typeof body.prompt === "string" ? body.prompt.trim() : "";
|
|
40
|
+
const options = Array.isArray(body.options)
|
|
41
|
+
? body.options.map((o) => String(o).trim()).filter(Boolean)
|
|
42
|
+
: [];
|
|
43
|
+
let answerIndex = Number.isInteger(body.answerIndex) ? body.answerIndex : 0;
|
|
44
|
+
if (!prompt || options.length < 2) {
|
|
45
|
+
return NextResponse.json(
|
|
46
|
+
{ error: "prompt and at least 2 options are required" },
|
|
47
|
+
{ status: 400 },
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
if (answerIndex < 0 || answerIndex >= options.length) answerIndex = 0;
|
|
51
|
+
const col = await questions();
|
|
52
|
+
const doc = { prompt, options, answerIndex, createdAt: new Date() };
|
|
53
|
+
const res = await col.insertOne(doc);
|
|
54
|
+
return NextResponse.json(
|
|
55
|
+
{ id: res.insertedId.toString(), prompt, options, answerIndex },
|
|
56
|
+
{ status: 201 },
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// DELETE /api/questions?id=<id> — remove a question.
|
|
61
|
+
export async function DELETE(request) {
|
|
62
|
+
const id = new URL(request.url).searchParams.get("id");
|
|
63
|
+
if (!id || !ObjectId.isValid(id)) {
|
|
64
|
+
return NextResponse.json({ error: "valid id is required" }, { status: 400 });
|
|
65
|
+
}
|
|
66
|
+
const col = await questions();
|
|
67
|
+
await col.deleteOne({ _id: new ObjectId(id) });
|
|
68
|
+
return NextResponse.json({ ok: true });
|
|
69
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Root layout + plain inline CSS (no external CDNs, fonts, or stylesheets).
|
|
2
|
+
export const metadata = {
|
|
3
|
+
title: "Quiz Platform",
|
|
4
|
+
description: "A persistent quiz/trivia app 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: 42rem; margin: 3rem auto; padding: 0 1.25rem; }
|
|
12
|
+
h1 { margin: 0 0 .25rem; }
|
|
13
|
+
h2 { margin: 2.5rem 0 .75rem; font-size: 1.15rem; }
|
|
14
|
+
.hint { margin: 0 0 1.5rem; opacity: .7; font-size: .9rem; }
|
|
15
|
+
.card { border: 1px solid #8883; border-radius: .75rem; padding: 1rem 1.15rem; margin-bottom: 1rem; }
|
|
16
|
+
.prompt { font-weight: 600; margin: 0 0 .6rem; }
|
|
17
|
+
.options { list-style: none; padding: 0; margin: 0; display: grid; gap: .4rem; }
|
|
18
|
+
.options li { margin: 0; }
|
|
19
|
+
.opt { display: flex; align-items: center; gap: .55rem; width: 100%; text-align: left;
|
|
20
|
+
padding: .5rem .7rem; border: 1px solid #8886; border-radius: .5rem; background: #6661; font: inherit; cursor: pointer; }
|
|
21
|
+
.opt:hover:not(:disabled) { background: #6663; }
|
|
22
|
+
.opt.selected { border-color: #4a90d9; background: #4a90d933; }
|
|
23
|
+
.opt.correct { border-color: #3ba55d; background: #3ba55d33; }
|
|
24
|
+
.opt.wrong { border-color: #d9534f; background: #d9534f33; }
|
|
25
|
+
.opt:disabled { cursor: default; }
|
|
26
|
+
.row { display: flex; gap: .5rem; margin: .5rem 0; flex-wrap: wrap; }
|
|
27
|
+
input { flex: 1; min-width: 8rem; padding: .5rem .75rem; border: 1px solid #8886; border-radius: .5rem; font: inherit; }
|
|
28
|
+
label.ans { display: flex; align-items: center; gap: .4rem; font-size: .9rem; opacity: .85; }
|
|
29
|
+
button { padding: .5rem .9rem; border: 1px solid #8886; border-radius: .5rem; background: #6663; font: inherit; cursor: pointer; }
|
|
30
|
+
button:disabled { opacity: .5; cursor: default; }
|
|
31
|
+
button.primary { background: #4a90d9; border-color: #4a90d9; color: #fff; }
|
|
32
|
+
.score { font-size: 1.1rem; font-weight: 600; margin: 1rem 0; }
|
|
33
|
+
.empty { opacity: .6; }
|
|
34
|
+
form.admin { border: 1px dashed #8886; border-radius: .75rem; padding: 1rem 1.15rem; }
|
|
35
|
+
.del { font-size: .8rem; padding: .3rem .55rem; margin-left: auto; }
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
export default function RootLayout({ children }) {
|
|
39
|
+
return (
|
|
40
|
+
<html lang="en">
|
|
41
|
+
<head>
|
|
42
|
+
<style dangerouslySetInnerHTML={{ __html: css }} />
|
|
43
|
+
</head>
|
|
44
|
+
<body>{children}</body>
|
|
45
|
+
</html>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Home page: a server component reads the questions straight from Mongo, and a
|
|
2
|
+
// client component runs the quiz (compute a score) plus an admin form to add
|
|
3
|
+
// questions. Data persists across refresh and across users because it lives in
|
|
4
|
+
// the grid-shared Mongo, not in memory.
|
|
5
|
+
import { getDb } from "../lib/db.js";
|
|
6
|
+
import Quiz from "./quiz.js";
|
|
7
|
+
|
|
8
|
+
export const dynamic = "force-dynamic";
|
|
9
|
+
|
|
10
|
+
async function listQuestions() {
|
|
11
|
+
const db = await getDb();
|
|
12
|
+
const items = await db
|
|
13
|
+
.collection("questions")
|
|
14
|
+
.find({})
|
|
15
|
+
.sort({ createdAt: -1 })
|
|
16
|
+
.toArray();
|
|
17
|
+
return items.map((q) => ({
|
|
18
|
+
id: q._id.toString(),
|
|
19
|
+
prompt: q.prompt,
|
|
20
|
+
options: Array.isArray(q.options) ? q.options : [],
|
|
21
|
+
answerIndex: typeof q.answerIndex === "number" ? q.answerIndex : 0,
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default async function Page() {
|
|
26
|
+
const questions = await listQuestions();
|
|
27
|
+
return (
|
|
28
|
+
<main>
|
|
29
|
+
<h1>Quiz Platform</h1>
|
|
30
|
+
<p className="hint">
|
|
31
|
+
Take the quiz, then add your own questions. Persisted in the grid-shared
|
|
32
|
+
Mongo — survives refresh and is shared across everyone.
|
|
33
|
+
</p>
|
|
34
|
+
<Quiz initialQuestions={questions} />
|
|
35
|
+
</main>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// Client component: renders the take-quiz UI (pick one option per question,
|
|
4
|
+
// submit to compute a score), plus an admin form that POSTs new questions to
|
|
5
|
+
// /api/questions and a delete control per question.
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
|
|
8
|
+
export default function Quiz({ initialQuestions }) {
|
|
9
|
+
const [questions, setQuestions] = useState(initialQuestions);
|
|
10
|
+
const [answers, setAnswers] = useState({}); // questionId -> chosen option index
|
|
11
|
+
const [submitted, setSubmitted] = useState(false);
|
|
12
|
+
const [busy, setBusy] = useState(false);
|
|
13
|
+
|
|
14
|
+
// admin form state
|
|
15
|
+
const [prompt, setPrompt] = useState("");
|
|
16
|
+
const [options, setOptions] = useState(["", "", "", ""]);
|
|
17
|
+
const [answerIndex, setAnswerIndex] = useState(0);
|
|
18
|
+
|
|
19
|
+
function choose(qId, optIdx) {
|
|
20
|
+
if (submitted) return;
|
|
21
|
+
setAnswers((prev) => ({ ...prev, [qId]: optIdx }));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Compute the score client-side against each question's answerIndex.
|
|
25
|
+
const score = questions.reduce(
|
|
26
|
+
(n, q) => (answers[q.id] === q.answerIndex ? n + 1 : n),
|
|
27
|
+
0,
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
function submit(e) {
|
|
31
|
+
e.preventDefault();
|
|
32
|
+
setSubmitted(true);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function reset() {
|
|
36
|
+
setAnswers({});
|
|
37
|
+
setSubmitted(false);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function addQuestion(e) {
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
const cleanPrompt = prompt.trim();
|
|
43
|
+
const cleanOptions = options.map((o) => o.trim()).filter(Boolean);
|
|
44
|
+
if (!cleanPrompt || cleanOptions.length < 2) return;
|
|
45
|
+
const idx = Math.min(answerIndex, cleanOptions.length - 1);
|
|
46
|
+
setBusy(true);
|
|
47
|
+
const res = await fetch("/api/questions", {
|
|
48
|
+
method: "POST",
|
|
49
|
+
headers: { "content-type": "application/json" },
|
|
50
|
+
body: JSON.stringify({
|
|
51
|
+
prompt: cleanPrompt,
|
|
52
|
+
options: cleanOptions,
|
|
53
|
+
answerIndex: idx,
|
|
54
|
+
}),
|
|
55
|
+
});
|
|
56
|
+
if (res.ok) {
|
|
57
|
+
const q = await res.json();
|
|
58
|
+
setQuestions((prev) => [q, ...prev]);
|
|
59
|
+
setPrompt("");
|
|
60
|
+
setOptions(["", "", "", ""]);
|
|
61
|
+
setAnswerIndex(0);
|
|
62
|
+
setSubmitted(false);
|
|
63
|
+
}
|
|
64
|
+
setBusy(false);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function remove(id) {
|
|
68
|
+
setBusy(true);
|
|
69
|
+
const res = await fetch(`/api/questions?id=${encodeURIComponent(id)}`, {
|
|
70
|
+
method: "DELETE",
|
|
71
|
+
});
|
|
72
|
+
if (res.ok) {
|
|
73
|
+
setQuestions((prev) => prev.filter((q) => q.id !== id));
|
|
74
|
+
setAnswers((prev) => {
|
|
75
|
+
const next = { ...prev };
|
|
76
|
+
delete next[id];
|
|
77
|
+
return next;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
setBusy(false);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function setOption(i, value) {
|
|
84
|
+
setOptions((prev) => prev.map((o, j) => (j === i ? value : o)));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div>
|
|
89
|
+
<h2>Take the quiz</h2>
|
|
90
|
+
{questions.length === 0 && (
|
|
91
|
+
<p className="empty">No questions yet — add one below.</p>
|
|
92
|
+
)}
|
|
93
|
+
|
|
94
|
+
<form onSubmit={submit}>
|
|
95
|
+
{questions.map((q) => (
|
|
96
|
+
<div className="card" key={q.id}>
|
|
97
|
+
<p className="prompt">{q.prompt}</p>
|
|
98
|
+
<ul className="options">
|
|
99
|
+
{q.options.map((opt, i) => {
|
|
100
|
+
const chosen = answers[q.id] === i;
|
|
101
|
+
let cls = "opt";
|
|
102
|
+
if (submitted && i === q.answerIndex) cls += " correct";
|
|
103
|
+
else if (submitted && chosen) cls += " wrong";
|
|
104
|
+
else if (chosen) cls += " selected";
|
|
105
|
+
return (
|
|
106
|
+
<li key={i}>
|
|
107
|
+
<button
|
|
108
|
+
type="button"
|
|
109
|
+
className={cls}
|
|
110
|
+
disabled={submitted}
|
|
111
|
+
onClick={() => choose(q.id, i)}
|
|
112
|
+
>
|
|
113
|
+
<span>{opt}</span>
|
|
114
|
+
</button>
|
|
115
|
+
</li>
|
|
116
|
+
);
|
|
117
|
+
})}
|
|
118
|
+
</ul>
|
|
119
|
+
<div className="row">
|
|
120
|
+
<button
|
|
121
|
+
type="button"
|
|
122
|
+
className="del"
|
|
123
|
+
onClick={() => remove(q.id)}
|
|
124
|
+
disabled={busy}
|
|
125
|
+
>
|
|
126
|
+
Delete
|
|
127
|
+
</button>
|
|
128
|
+
</div>
|
|
129
|
+
</div>
|
|
130
|
+
))}
|
|
131
|
+
|
|
132
|
+
{questions.length > 0 && !submitted && (
|
|
133
|
+
<button type="submit" className="primary">
|
|
134
|
+
Submit quiz
|
|
135
|
+
</button>
|
|
136
|
+
)}
|
|
137
|
+
</form>
|
|
138
|
+
|
|
139
|
+
{submitted && (
|
|
140
|
+
<div>
|
|
141
|
+
<p className="score">
|
|
142
|
+
Score: {score} / {questions.length}
|
|
143
|
+
</p>
|
|
144
|
+
<button type="button" onClick={reset}>
|
|
145
|
+
Try again
|
|
146
|
+
</button>
|
|
147
|
+
</div>
|
|
148
|
+
)}
|
|
149
|
+
|
|
150
|
+
<h2>Add a question</h2>
|
|
151
|
+
<form className="admin" onSubmit={addQuestion}>
|
|
152
|
+
<div className="row">
|
|
153
|
+
<input
|
|
154
|
+
value={prompt}
|
|
155
|
+
onChange={(e) => setPrompt(e.target.value)}
|
|
156
|
+
placeholder="Question prompt…"
|
|
157
|
+
aria-label="Question prompt"
|
|
158
|
+
/>
|
|
159
|
+
</div>
|
|
160
|
+
{options.map((opt, i) => (
|
|
161
|
+
<div className="row" key={i}>
|
|
162
|
+
<input
|
|
163
|
+
value={opt}
|
|
164
|
+
onChange={(e) => setOption(i, e.target.value)}
|
|
165
|
+
placeholder={`Option ${i + 1}`}
|
|
166
|
+
aria-label={`Option ${i + 1}`}
|
|
167
|
+
/>
|
|
168
|
+
<label className="ans">
|
|
169
|
+
<input
|
|
170
|
+
type="radio"
|
|
171
|
+
name="answerIndex"
|
|
172
|
+
checked={answerIndex === i}
|
|
173
|
+
onChange={() => setAnswerIndex(i)}
|
|
174
|
+
style={{ flex: "none", minWidth: 0 }}
|
|
175
|
+
/>
|
|
176
|
+
correct
|
|
177
|
+
</label>
|
|
178
|
+
</div>
|
|
179
|
+
))}
|
|
180
|
+
<div className="row">
|
|
181
|
+
<button type="submit" className="primary" disabled={busy}>
|
|
182
|
+
Add question
|
|
183
|
+
</button>
|
|
184
|
+
</div>
|
|
185
|
+
</form>
|
|
186
|
+
</div>
|
|
187
|
+
);
|
|
188
|
+
}
|
|
@@ -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
|
+
}
|