Skip to content

huntsyea/classical-virtues

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

101 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Classical Virtues

Vercel Deploy Next.js TypeScript Tailwind CSS BaseHub shadcn/ui

A modern web application exploring classical virtues through interactive storytelling and content. Built with Next.js, powered by BaseHub CMS, and enhanced with beautiful typography and responsive design.

๐Ÿ—๏ธ Architecture Overview

This project implements a dual-content architecture with BaseHub CMS as the primary content source and MDX fallback capabilities:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   BaseHub CMS   โ”‚โ”€โ”€โ”€โ”€โ”‚  Next.js App     โ”‚โ”€โ”€โ”€โ”€โ”‚  Static Site    โ”‚
โ”‚                 โ”‚    โ”‚                  โ”‚    โ”‚                 โ”‚
โ”‚ โ€ข Stories       โ”‚    โ”‚ โ€ข ISR Caching    โ”‚    โ”‚ โ€ข SEO Optimized โ”‚
โ”‚ โ€ข Images        โ”‚    โ”‚ โ€ข Type Safety    โ”‚    โ”‚ โ€ข Performance   โ”‚
โ”‚ โ€ข Rich Content  โ”‚    โ”‚ โ€ข Webhooks       โ”‚    โ”‚ โ€ข Responsive    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿš€ Tech Stack

Core Framework:

  • Next.js 14 with App Router and TypeScript
  • BaseHub CMS for headless content management
  • Tailwind CSS with custom design system

Content & Media:

  • BaseHub for story content, images, and metadata
  • MDX support for rich content authoring
  • Next/Image for optimized image delivery
  • Audio Player component for story narration

Developer Experience:

  • TypeScript with BaseHub's generated types
  • shadcn/ui component library
  • ESLint and Prettier for code quality
  • Vercel deployment with automatic CI/CD

Performance & SEO:

  • ISR (Incremental Static Regeneration) caching
  • Dynamic sitemap generation
  • OpenGraph and Twitter Card meta tags
  • JSON-LD structured data
  • Vercel Analytics integration

๐Ÿ› ๏ธ Getting Started

Prerequisites

  • Node.js 18+ and pnpm
  • BaseHub account and project setup
  • Vercel account for deployment

Local Development

  1. Clone and install dependencies:

    git clone <your-repo>
    cd classical-virtues
    pnpm install
  2. Environment setup:

    cp .env.example .env.local
    # Add your BaseHub token and webhook secret
  3. Generate BaseHub types and start development:

    pnpm run dev  # Runs: basehub dev & next dev
  4. Open http://localhost:3000

Available Commands

pnpm run dev      # Start development server with BaseHub type generation
pnpm run build    # Generate types and build for production
pnpm run start    # Start production server
pnpm run lint     # Run ESLint
pnpm run basehub  # Generate BaseHub types only

๐Ÿ“ Project Structure

src/
โ”œโ”€โ”€ app/                    # Next.js App Router
โ”‚   โ”œโ”€โ”€ page.tsx           # Home page with story grid
โ”‚   โ”œโ”€โ”€ stories/[slug]/    # Dynamic story pages
โ”‚   โ”œโ”€โ”€ sitemap.ts         # Dynamic sitemap generation
โ”‚   โ””โ”€โ”€ revalidate-sitemap/ # BaseHub webhook endpoint
โ”œโ”€โ”€ components/            # Reusable UI components
โ”‚   โ”œโ”€โ”€ ui/               # shadcn/ui components
โ”‚   โ”œโ”€โ”€ AudioPlayer.tsx   # Story audio narration
โ”‚   โ””โ”€โ”€ summaryCard.tsx   # Story preview cards
โ”œโ”€โ”€ lib/                  # Core utilities and data layer
โ”‚   โ”œโ”€โ”€ basehub.ts        # BaseHub API client and types
โ”‚   โ””โ”€โ”€ stories.ts        # Unified story data interface
โ””โ”€โ”€ types/               # TypeScript definitions

๐Ÿ”— BaseHub CMS Integration

Content Architecture

BaseHub Schema:

  • Stories Collection: Main content with rich text, images, audio
  • Generated Types: Full TypeScript safety with auto-generated interfaces
  • Draft Mode: Development preview of unpublished content

Data Flow:

BaseHub CMS โ†’ basehub().query() โ†’ Type-safe data โ†’ Next.js pages โ†’ Static site

Webhook Setup

The project includes automated content revalidation when BaseHub content changes:

  1. Configure BaseHub Webhook:

    • URL: https://your-domain.com/revalidate-sitemap
    • Method: POST
    • Enable Svix signature verification
    • Secret: Set BASEHUB_WEBHOOK_SECRET environment variable
  2. Webhook Security:

    • Uses Svix HMAC-SHA256 signature verification
    • Implements timestamp validation (5-minute window)
    • Validates all required headers (svix-id, svix-timestamp, svix-signature)
  3. Revalidation Behavior:

    // src/app/revalidate-sitemap/route.ts
    revalidatePath('/sitemap.xml')  # Updates sitemap with new stories
    revalidatePath('/stories')      # Clears story list cache

Environment Variables

# Required for BaseHub integration
BASEHUB_TOKEN=bshb_pk_...           # BaseHub API token
BASEHUB_WEBHOOK_SECRET=whsec_...    # Webhook signature secret

# Optional
NEXT_PUBLIC_VERCEL_URL=...          # For absolute URLs in production

๐Ÿš€ Deployment

Vercel Deployment

  1. Connect repository to Vercel
  2. Configure environment variables:
    BASEHUB_TOKEN=bshb_pk_...
    BASEHUB_WEBHOOK_SECRET=whsec_...
  3. Deploy automatically on git push

Production Considerations

  • ISR Caching: Stories are statically generated with on-demand revalidation
  • Image Optimization: BaseHub images are automatically optimized by Next.js
  • SEO: Dynamic sitemaps and meta tags are generated from BaseHub content
  • Performance: Lazy-loaded audio player and optimized font loading

๐Ÿ”ฎ Future Improvements

Phase 1: Real-time Content Updates

Implement BaseHub Pump Component:

// Potential implementation in src/app/stories/[slug]/page.tsx
import { Pump } from 'basehub/next-pump'

export default function StoryPage() {
  return (
    <Pump
      queries={[{ stories: { items: { /* fields */ } } }]}
      next={{ revalidate: 60 }}
    >
      {async ([data]) => {
        // Real-time content rendering
        return <StoryContent story={data.stories.items[0]} />
      }}
    </Pump>
  )
}

Benefits:

  • Real-time content updates without full page reloads
  • Automatic cache management
  • Better developer experience for content editing
  • Reduced server load with intelligent caching

Phase 2: Architecture Simplification

Option A: Remove Abstraction Layer

// Direct BaseHub usage in components
import { basehub } from 'basehub'
import type { StoriesItem } from '../../../basehub-types'

// Components use BaseHub's native field names (_title, _slug)
function StoryCard({ story }: { story: StoriesItem }) {
  return <h2>{story._title}</h2>  // Direct BaseHub field access
}

Option B: Enhanced Abstraction

// Improved abstraction with better type inference
export const useStories = () => {
  return useMemo(() => basehub().query(STORIES_QUERY), [])
}

Phase 3: Advanced Features

Content Management Enhancements:

  • Rich text editor integration for BaseHub
  • Image gallery component for multiple story images
  • Category/tag system for story organization
  • Search functionality with full-text search
  • Content scheduling for timed story releases

Performance Optimizations:

  • Edge caching strategy with Vercel Edge Functions
  • Prefetching for story navigation
  • Image placeholder generation
  • Progressive Web App features

Developer Experience:

  • Storybook integration for component development
  • E2E testing with Playwright
  • Performance monitoring with Core Web Vitals
  • Content validation schemas

Phase 4: Advanced CMS Features

Multi-language Support:

// i18n with BaseHub
const { stories } = await basehub().query({
  stories: {
    __args: { filter: { locale: { eq: 'es' } } }
  }
})

Advanced Analytics:

  • Story reading time tracking
  • Popular content analytics
  • User engagement metrics
  • A/B testing for content presentation

๐Ÿ› ๏ธ Current Implementation Status

โœ… Completed Features:

  • BaseHub CMS integration with type safety
  • Webhook-based content revalidation
  • SEO optimization with dynamic sitemaps
  • Audio player for story narration
  • Responsive design with Tailwind CSS
  • Vercel deployment with CI/CD

๐Ÿ”„ In Progress:

  • Content workflow optimization
  • Performance monitoring setup

๐Ÿ“‹ Planned:

  • Pump component integration for real-time updates
  • Abstraction layer evaluation and potential simplification
  • Enhanced content management features

๐Ÿ“š Learn More

Core Technologies:

Advanced Concepts:

๐Ÿ“„ License

MIT

About

A modern web application exploring classical virtues through interactive storytelling and content. Built with Next.js and enhanced with beautiful typography and responsive design.

Topics

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors