How adityayaduvanshi/platejs-template works
Project Type and Purpose
• This is a full-stack Next.js 15 “App Directory” template that provides a rich-text AI-powered editor using the Plate framework, shadcn/ui components, and integrates with OpenAI and UploadThing.
• The user-facing editor lives at /editor (src/app/editor/page.tsx) and communicates with serverless API routes under src/app/api to perform AI completions and file uploads.
Main Components
a. Frontend (Browser / Client)
• Next.js App Router pages (src/app/layout.tsx, page.tsx, editor/page.tsx)
• React component tree:
– Core Plate editor (components/editor/*)
– Plugins (components/editor/plugins/*)
– UI primitives (components/ui/*)
• Custom hooks (src/hooks/*) and utility libs (src/lib/*)
b. Serverless API Layer (Next.js Route Handlers)
• /api/ai/command – handles custom AI commands
• /api/ai/copilot – handles Copilot-style completions
• /api/uploadthing – proxies file uploads via UploadThing
c. External Services
• OpenAI API (for AI completions)
• UploadThing (for file storage)
Relationships and Data Flow
1. User navigates to /editor in browser.
2. Next.js SSR/SSG serves HTML and hydration scripts.
3. The Plate editor component initializes with plugins and UI.
4. On user actions (e.g. invoke AI, upload media), the front end issues fetch() calls to /api/ai/* or /api/uploadthing.
5. API route handlers validate the request, read OPENAI_API_KEY or UPLOADTHING_TOKEN, call the external service, and return JSON or file URLs.
6. Front end updates editor state/UI based on API responses.
Architectural Patterns & Design Principles
• File-based routing via Next.js App Directory – clear separation of pages vs. API.
• Serverless functions (Route Handlers in route.ts) isolate backend logic.
• Plugin architecture in Plate – each editor feature is a self-contained module under components/editor/plugins.
• Componentize UI with shadcn/ui – low-level primitives (components/ui) ensure consistency.
• Utility layers (hooks, lib) encapsulate cross-cutting concerns (debouncing, transforms, upload helpers).