Skip to main content

Introduction To Sanity CMS

Sanity is a headless Content Management System (CMS) that provides a flexible, API-driven approach to content management. In the Charles Schwab NextJS Web Monorepo, Sanity serves as the primary content backend for managing structured content across multiple applications.

Overview

Our Sanity implementation consists of two main components:

  1. Sanity Studio (apps/sanity-studio) - The content editing interface
  2. Sanity Next (apps/sanity-next) - Demo frontend application for content preview

Sanity Studio Application

Purpose and Function

Application: apps/sanity-studio
Port: 3333
Purpose: Content authoring and management interface
Version: 1.0.9

Sanity Studio is a customizable content management interface built on top of Next.js 15.3.2 that allows content creators and editors to manage structured content.

Key Features

FeatureDescriptionImplementation
Multi-language SupportContent internationalization for Chinese, Spanish, and English@sanity/document-internationalization
SAML AuthenticationEnterprise authentication via Schwab SSOCustom auth store configuration
Asset ManagementIntegration with Bynder DAM and UnsplashPlugins: bynder-input, unsplash-asset-source
Content ValidationSchema-based content validationZod integration with custom validation rules
Preview ModeLive preview integration with frontend appsPresentation tool with draft mode
Taxonomy ManagementStructured content categorizationsanity-plugin-taxonomy-manager
AI AssistantContent translation and assistance@sanity/assist plugin
Table SupportRich table editing capabilities@sanity/table plugin

Technical Architecture

Core Dependencies

{
"sanity": "^3.81.0",
"next": "15.5.7",
"next-sanity": "^9.9.6",
"@sanity/ui": "^2.15.10",
"@sanity/vision": "^3.81.0"
}

Project Configuration

  • Project ID: fvuvea00
  • Dataset: production
  • Authentication: SAML with Schwab enterprise login

Supported Languages

Language CodeLanguage Name
zh-CNChinese (China)
zh-TWChinese (Taiwan-Traditional)
es-USSpanish (US)
en-USEnglish (US)

Content Schema Architecture

Document Types

Document TypePurposeKey Fields
storyArticles, blog posts, content pagestitle, slug, summary, body, language
landingPageMarketing and product landing pagestitle, slug, summary, components
cardDeckCard-based content layoutscardType, cards, styling
dataTableStructured tabular dataheaders, rows, styling
taxonomyTermContent categorizationname, parent, attributes
taxonomyAttributeTaxonomy metadataname, type, values
querySetDynamic content queriesquery, parameters, caching
dynamicCtaCall-to-action componentstext, link, styling
bynderBlockDigital asset managementasset references, metadata

Object Types

Object TypePurposeUsage
buttonInteractive button componentsCTAs, navigation
marqueeScrolling text displaysAnnouncements, alerts
seoDataSEO metadataPage optimization
seoItemIndividual SEO elementsMeta tags, structured data
stylingVariationVisual style optionsTheme variations
taxonomyItemTaxonomy referencesContent categorization

Workspace Configuration

Sanity Studio supports multiple workspaces for different content domains:

Default Workspace

  • Name: default
  • Title: "Charles Schwab"
  • Path: /default
  • Purpose: Primary content management for public-facing content

Charitable Workspace

  • Name: charitable
  • Title: "Charitable"
  • Path: /charitable
  • Purpose: Content management for Charles Schwab Charitable programs

Sanity Next Demo Application

Purpose and Function

Application: apps/sanity-next
Purpose: Demo Next.js application for Sanity content preview
Preview URL: https://schwab-sanity-next.vercel.app
Status: Proof-of-concept application

Sanity Next is a demonstration frontend application that showcases how to integrate Sanity CMS with Next.js for content delivery and preview capabilities. This app serves as a reference implementation for connecting Sanity to production applications.

Key Features

FeatureDescriptionPurpose
Draft Mode PreviewLive preview of unpublished contentEnables content editors to preview changes before publishing
Content RoutingDynamic routing for stories and landing pagesDemonstrates content-driven page generation
API IntegrationContent delivery via Sanity APIShows proper API connection patterns
Multi-language SupportPreview content in multiple languagesTests internationalization capabilities

Technical Integration

Preview Configuration

The Sanity Studio is configured to use sanity-next as its preview environment:

{
previewUrl: {
origin: "https://schwab-sanity-next.vercel.app",
draftMode: {
enable: "/api/draft"
}
}
}

Content Type Routing

Content TypeRoute PatternExample
story/{language}/story/{slug}/en-US/story/market-insights
landingPage/{language}/{slug}/en-US/investing

Development Workflow

Local Development

# Start both Sanity Studio and Demo App
pnpm dev-sanity

# This runs both:
# - Sanity Studio on port 3333
# - Sanity Next demo on its configured port

Build Process

# Build both applications
pnpm build-sanity

# Builds:
# - Sanity Studio
# - Sanity Next demo app

Future Plans

note

The sanity-next application is a proof-of-concept and will eventually be deprecated once Sanity content delivery is fully integrated into production applications like www.schwab.com and client.schwab.com.

Plugin Ecosystem

Core Plugins

PluginVersionPurpose
@sanity/assist^3.2.2AI-powered content assistance and translation
@sanity/code-input^5.1.2Code syntax highlighting in content
@sanity/document-internationalization^3.3.1Multi-language content management
@sanity/table^1.1.3Rich table editing capabilities
@sanity/vision^3.81.0GROQ query development tool

Integration Plugins

PluginPurposeConfiguration
sanity-plugin-bynder-inputDigital Asset ManagementBynder portal integration
sanity-plugin-asset-source-unsplashStock photographyUnsplash image library
sanity-plugin-taxonomy-managerContent categorizationSchwab vocabulary management
sanity-plugin-studio-smartlingTranslation servicesProfessional translation workflow

Development Workflow

Local Development

# Start Sanity Studio
pnpm dev-sanity

# Runs on port 3333
# URL: http://localhost:3333

Schema Management

# Generate TypeScript types from schemas
pnpm typegen

# Extracts schema and generates type definitions

Content Structure

Integration with Frontend Applications

Content Delivery Pattern

API Integration

Frontend applications integrate with Sanity using:

  1. next-sanity: Official Next.js integration package
  2. GROQ Queries: Content querying language
  3. Preview Mode: Draft content preview (demonstrated in sanity-next)
  4. Image CDN: Optimized image delivery

Preview Integration Example

The sanity-next demo application demonstrates the preview integration pattern:

// Example preview API route pattern
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const slug = searchParams.get('slug');
const type = searchParams.get('type');

// Enable draft mode for preview
draftMode().enable();

// Redirect to the preview page
redirect(`/${type}/${slug}`);
}

Content Types in Production

Content TypeUsageFrontend Integration
StoriesBlog posts, articlesDynamic routing, SEO optimization
Landing PagesMarketing pagesComponent-based rendering
Card DecksProduct showcasesGrid layouts, interactive cards
Data TablesFinancial dataResponsive tables, data visualization
TaxonomyContent categorizationFiltering, navigation

Security and Authentication

Access Control

  • SAML Integration: Enterprise SSO with Schwab credentials
  • Role-based Permissions: Administrator and editor roles
  • Workspace Isolation: Content segregation by domain
  • API Security: Token-based authentication for content delivery

Content Security

Development Guidelines

Schema Development

  1. Type Safety: Always define proper TypeScript types
  2. Validation Rules: Implement comprehensive content validation
  3. Internationalization: Support multi-language content from the start
  4. SEO Optimization: Include SEO fields in all public content types

Content Management Best Practices

  1. Content Structure: Use consistent field naming and organization
  2. Asset Management: Leverage Bynder integration for brand compliance
  3. Preview Testing: Always test content in preview mode before publishing
  4. Performance: Optimize queries and content structure for fast delivery

Testing Strategy

  • Schema Validation: Jest tests for schema integrity
  • Content Queries: GROQ query testing
  • Integration Tests: Frontend content rendering tests
  • Accessibility: Content accessibility validation

Monitoring and Maintenance

Performance Monitoring

  • API Response Times: Content delivery performance
  • Studio Performance: Editor experience optimization
  • Build Times: Schema compilation and type generation
  • Cache Efficiency: Content delivery caching strategies

Maintenance Tasks

TaskFrequencyPurpose
Schema UpdatesAs neededNew content types and fields
Plugin UpdatesMonthlySecurity and feature updates
Content CleanupQuarterlyRemove unused content and assets
Performance ReviewMonthlyOptimize queries and delivery

This Sanity CMS implementation provides a robust, scalable content management foundation for Charles Schwab's digital properties, enabling efficient content creation, management, and delivery across multiple applications and languages.