New Project

A modern, production-ready starter for building content-managed websites with Agility CMS and Next.js 15.
New to Agility CMS? Sign up for a FREE account
Clone the repository
git clone https://github.com/agility/agilitycms-nextjs-starter.gitcd agilitycms-nextjs-starterInstall dependencies
npm install# oryarn installConfigure environment variables
cp .env.local.example .env.localGet your API keys from Agility CMS
Update .env.local with your credentials:
AGILITY_GUID=your-guid-hereAGILITY_API_FETCH_KEY=your-live-api-keyAGILITY_API_PREVIEW_KEY=your-preview-api-keyAGILITY_SECURITY_KEY=your-security-keyAGILITY_LOCALES=en-usAGILITY_SITEMAP=websiteAGILITY_FETCH_CACHE_DURATION=120AGILITY_PATH_REVALIDATE_DURATION=10Run the development server
npm run dev# oryarn devOpen your browser to http://localhost:3000
npm run buildnpm run startagilitycms-nextjs-starter/āāā app/ # Next.js App Routerā āāā layout.tsx # Root layout with header/footerā āāā page.tsx # Home page (delegates to [...slug])ā āāā [...slug]/ # Dynamic catch-all routeā ā āāā page.tsx # Main page component with SSGā ā āāā error.tsx # Error boundaryā ā āāā not-found.tsx # 404 pageā āāā api/ # API routesā āāā preview/ # Preview mode endpointsā āāā preview/exit/ # Exit preview modeā āāā revalidate/ # Webhook for cache invalidationā āāā dynamic-redirect/ # ContentID-based redirectsāāā components/ # React componentsā āāā agility-components/ # CMS component modulesā ā āāā FeaturedPost.tsx # Featured post displayā ā āāā PostDetails.tsx # Dynamic post detail viewā ā āāā PostsListing/ # Infinite scroll post listā ā āāā TextBlockWithImage.tsx # Flexible layout componentā ā āāā RichTextArea.tsx # HTML content displayā ā āāā Heading.tsx # Typography componentā ā āāā index.ts # Component registryā āāā agility-pages/ # Page templatesā ā āāā MainTemplate.tsx # Main page templateā ā āāā index.ts # Template registryā āāā common/ # Shared componentsā āāā SiteHeader.tsx # Responsive header with dark modeā āāā SiteFooter.tsx # Footer with social linksā āāā PreviewBar.tsx # Preview/Live mode toggleā āāā InlineError.tsx # Error displayāāā lib/ # Utilities and helpersā āāā cms/ # CMS data fetchingā ā āāā getAgilityContext.ts # Mode detection (preview/live)ā ā āāā getAgilitySDK.ts # SDK initializationā ā āāā getAgilityPage.ts # Fetch pages with layoutā ā āāā getContentItem.ts # Fetch single content itemā ā āāā getContentList.ts # Fetch content listsā ā āāā getSitemapFlat.ts # Flat sitemap retrievalā ā āāā getSitemapNested.ts # Nested sitemap retrievalā āāā cms-content/ # Domain-specific queriesā ā āāā getPostListing.ts # Blog posts with URLsā ā āāā getHeaderContent.ts # Header navigation dataā ā āāā getPageMetaData.ts # Page SEO metadataā ā āāā resolveAgilityMetaData.ts # Advanced metadataā āāā types/ # TypeScript interfacesā āāā (IPost, IAuthor, ICategory, etc.)āāā styles/ā āāā globals.css # Tailwind imports & global stylesāāā middleware.ts # Next.js middleware for routingāāā .env.local.example # Environment templateāāā tailwind.config.js # Tailwind configurationāāā next.config.js # Next.js configurationāāā tsconfig.json # TypeScript configurationThis starter uses Next.js App Router with a catch-all dynamic route [...slug] that maps to Agility CMS pages.
How it works:
generateStaticParams() pre-renders all pages at build timeSee ARCHITECTURE.md for detailed explanation.
CMS components (modules) are mapped to React components via a registry pattern:
// components/agility-components/index.tsconst allModules = [ {name: "TextBlockWithImage", module: TextBlockWithImage}, {name: "Heading", module: Heading}, {name: "FeaturedPost", module: FeaturedPost}, {name: "PostsListing", module: PostsListing}, {name: "PostDetails", module: PostDetails}, {name: "RichTextArea", module: RichTextArea},]When Agility CMS returns a page with a "TextBlockWithImage" module, the system automatically renders the corresponding React component.
This starter uses React Server Components for optimal performance:
Example:
// Server Component (default)export default async function PostDetails({module, page}) { const post = await getContentItem({contentID: page.contentID}) return <article>...</article>}The Agility CMS instance includes the following content models:
See CONTENT-MODELS.md for complete schema documentation.
See COMPONENTS.md for complete component API documentation.
Located in lib/cms/, these utilities handle all Agility CMS interactions:
getAgilityContext()
Determines the current mode (preview vs. production):
const context = await getAgilityContext()// Returns: { isPreview: boolean, locale: string, sitemap: string }getContentItem(contentID, languageCode)
Fetches a single content item with cache tags:
const post = await getContentItem({ contentID: 123, languageCode: "en-us",})getContentList(referenceName, languageCode, options)
Fetches content lists with pagination and filtering:
const posts = await getContentList({ referenceName: "posts", languageCode: "en-us", take: 10, skip: 0, sort: "fields.date", direction: "desc",})getAgilityPage(slug, locale, sitemap)
Fetches a complete page with layout and content zones:
const page = await getAgilityPage({ slug: "/blog", locale: "en-us", sitemap: "website",})Located in lib/cms-content/, these build on the CMS utilities for specific use cases:
getPostListing() - Blog posts with category filtering and URLsgetHeaderContent() - Navigation structure and brandinggetPageMetaData() - SEO metadata for pagesSee AGILITY-CMS-GUIDE.md for complete data fetching patterns.
This starter implements a sophisticated caching strategy for optimal performance:
SDK Object Cache - Agility Fetch SDK caches content items
AGILITY_FETCH_CACHE_DURATION (default: 120 seconds)Next.js Route Cache - Next.js caches rendered pages
AGILITY_PATH_REVALIDATE_DURATION (default: 10 seconds)Content fetches use cache tags for granular invalidation:
// Automatically tagged as: agility-content-{contentID}-{locale}const post = await getContentItem({contentID: 123})When content is published in Agility CMS, a webhook triggers revalidation:
The /api/revalidate endpoint handles webhook callbacks from Agility CMS:
// Revalidates specific content items and their dependent pagesPOST /api/revalidate{ "contentID": 123, "languageCode": "en-us"}# Cache content objects for 120 secondsAGILITY_FETCH_CACHE_DURATION=120
# Revalidate page paths every 10 secondsAGILITY_PATH_REVALIDATE_DURATION=10Best Practices:
0 without webhooks for faster content updatesPreview mode allows content editors to see draft content before publishing.
Preview Endpoint (app/api/preview/route.ts):
// Validates request and enables draft modeexport async function GET(request: Request) { const {agilitypreviewkey, ContentID, slug} = searchParams
// Validate preview key if (agilitypreviewkey !== process.env.AGILITY_SECURITY_KEY) { return new Response("Invalid token", {status: 401}) }
// Enable draft mode draftMode().enable()
// Redirect to preview page redirect(slug)}Middleware (middleware.ts):
// Intercepts preview requests before they reach pagesexport function middleware(request: NextRequest) { const {pathname, searchParams} = request.nextUrl
if (searchParams.has("agilitypreviewkey")) { // Rewrite to preview API for validation return NextResponse.rewrite(new URL("/api/preview", request.url)) }}Preview Bar (components/common/PreviewBar.tsx):
Set your security key in .env.local:
AGILITY_SECURITY_KEY=your-security-key-from-agilityThis key must match the one configured in Agility CMS webhook settings.
Vercel provides the best Next.js experience with zero configuration:
.env.local valuesEnvironment Variables to Set:
AGILITY_GUIDAGILITY_API_FETCH_KEYAGILITY_API_PREVIEW_KEYAGILITY_SECURITY_KEYAGILITY_LOCALESAGILITY_SITEMAPAGILITY_FETCH_CACHE_DURATIONAGILITY_PATH_REVALIDATE_DURATIONConfigure Webhooks in Agility CMS:
https://your-site.vercel.app/api/revalidatenpm run build.next.env.local valuesThis starter can deploy to any platform supporting Next.js:
Ensure your platform supports:
This starter is designed to work seamlessly with AI coding assistants like Claude Code, GitHub Copilot, Cursor, and ChatGPT for rapid development.
"Vibe coding" is the practice of using AI assistants to help you build features by describing what you want in natural language, rather than writing every line of code manually. This starter's comprehensive documentation makes it perfect for AI-assisted development.
Create a new component:
Create a "TeamGrid" component that:- Fetches team members from a "teammembers" container- Displays them in a responsive 3-column grid- Shows name, title, photo, and bio- Supports dark mode- Follows the same patterns as PostsListingAdd a feature:
Add search functionality to the PostsListing component:- Add a search input at the top- Filter posts by title/content as user types- Maintain infinite scroll behavior- Use client component for interactivityExtend existing code:
Looking at TextBlockWithImage component, create a similar"ImageGallery" component that shows multiple images in a gridwith lightbox functionality.This project includes the Agility CMS MCP Server configuration in .vscode/mcp.json, which gives AI coding assistants (like Claude Code) direct access to your CMS instance through the Model Context Protocol.
What is MCP?
MCP (Model Context Protocol) is a standard that allows AI assistants to connect to external services. The Agility MCP Server acts as a bridge between your AI assistant and your Agility CMS instance, providing real-time access to your content structure and data.
What AI can do with MCP:
Example Workflows with MCP:
Creating a new component:
Use the Agility MCP server to get the "Products" content model,then create:1. A TypeScript interface (IProduct) with all fields2. A ProductGrid component with category filtering3. A domain helper (getProductListing) for data fetching4. Register the component in the indexValidating existing code:
Query the Agility MCP server for the "TeamMembers" model andverify that the ITeamMember interface in lib/types/ has allthe correct fields with proper types.Discovering opportunities:
Use MCP to list all content models in my instance, thensuggest 5 new components I could build based on unused models.Why MCP Makes AI Development Better:
| Without MCP | With MCP |
|---|---|
| AI guesses field names | AI sees exact field names |
| AI assumes field types | AI knows actual field types |
| Trial and error fixing typos | Works first time |
| Generic component templates | CMS-specific, accurate code |
| Manual schema documentation | Direct CMS inspection |
Getting Started with MCP:
.vscode/mcp.json exists - Already configured in this projectMCP Server Configuration:
The project includes a pre-configured MCP connection:
// .vscode/mcp.json{ "servers": { "Agility CMS": { "url": "https://mcp.agilitycms.com/api/mcp", "type": "http" } }}This connects to the public Agility MCP server, which requires your API keys (from .env.local) to access your specific instance.
Learn More:
For more advanced examples including AI integration, personalization, and complex patterns, see:
This repository includes:
Use it as a reference when asking AI to build advanced features:
Looking at the nextjs-demo-site-2025 repo, implement a similarAI search modal for this project.Reference Documentation - Point AI to specific docs:
Provide Context - Share your CMS structure:
Request Tests - Ask AI to validate:
Iterate - Refine in steps:
Use Type Safety - Let AI leverage TypeScript:
1. Describe Feature ā AI generates component ā2. Review Code ā AI refines based on feedback ā3. Create CMS Model ā AI generates TypeScript interface ā4. Register Component ā AI updates index file ā5. Test & Iterate ā AI fixes issuesThis documentation-first approach makes AI assistants highly effective at extending this starter with new features, components, and integrations.
Detailed documentation for specific topics:
AI Assistant Configuration:
.cursorrules - Rules for Cursor, Claude Code, and other AI tools (auto-loaded)Shows latest content in real-time (uses Preview API Key):
npm run devShows published content (uses Live API Key):
npm run buildnpm run startThis project uses TypeScript with strict mode. Type definitions for CMS content are in lib/types/.
npm run lintnext/core-web-vitals.prettierrc for consistent formattingContributions are welcome! Please feel free to submit a Pull Request.
If you have feedback or questions about this starter:
This project is licensed under the MIT License.
Made with ā¤ļø by Agility CMS