Skip to main content

Lesson 8 of 10

Mini Project: Full-Stack Blog with PWA

Build a full-stack blog using Next.js App Router: ISR for posts, Server Actions for creating posts, dynamic metadata for SEO, Service Worker for offline reading, and manifest.json for PWA installability. This brings together everything from Module 12.

60 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Next.js Blog Architecture

Next.js Blog Architecture
// ---- App Structure ----
// app/
//   layout.tsx          ← Root layout with metadata + SW registration
//   page.tsx            ← Blog homepage (static SSG)
//   blog/
//     page.tsx          ← Posts list (ISR, 1 hour)
//     [slug]/
//       page.tsx        ← Post detail (ISR, 1 hour)
//       error.tsx       ← Post not found error
//   api/
//     revalidate/
//       route.ts        ← Webhook to trigger ISR revalidation
//   actions/
//     posts.ts          ← Server Actions for create/update
// public/
//   manifest.json       ← PWA manifest
//   sw.js               ← Service Worker (custom, no next-pwa needed)

// ---- app/blog/page.tsx - ISR posts list ----
import type { Metadata } from 'next';
import Link from 'next/link';

export const metadata: Metadata = {
  title: 'Blog',
  description: 'Articles about React, Next.js, and modern web development.',
};

export const revalidate = 3600; // regenerate every hour

interface Post { slug: string; title: string; excerpt: string; date: string; readTime: number; }

async function fetchPosts(): Promise<Post[]> {
  // In production: fetch from CMS/DB
  return [
    { slug: 'react-18-concurrent', title: 'React 18 Concurrent Features', excerpt: 'Explore useTransition and Suspense...', date: '2026-03-01', readTime: 8 },
    { slug: 'turborepo-guide', title: 'Monorepos with Turborepo', excerpt: 'Scale your codebase with Turborepo...', date: '2026-02-15', readTime: 12 },
  ];
}

export default async function BlogPage() {
  const posts = await fetchPosts();

  return (
    <main style={{ maxWidth: 760, margin: '0 auto', padding: '40px 24px', fontFamily: 'system-ui', color: '#0f172a' }}>
      <h1 style={{ fontSize: 32, marginBottom: 8 }}>Blog</h1>
      <p style={{ color: '#64748b', marginBottom: 40 }}>{posts.length} articles</p>
      <div style={{ display: 'flex', flexDirection: 'column', gap: 24 }}>
        {posts.map(post => (
          <article key={post.slug} style={{ borderBottom: '1px solid #e2e8f0', paddingBottom: 24 }}>
            <p style={{ fontSize: 13, color: '#94a3b8', margin: '0 0 6px' }}>
              {new Date(post.date).toLocaleDateString('en-US', { dateStyle: 'long' })}
              {' · '}{post.readTime} min read
            </p>
            <h2 style={{ margin: '0 0 8px', fontSize: 20 }}>
              <Link href={`/blog/${post.slug}`} style={{ color: 'inherit', textDecoration: 'none' }}>
                {post.title}
              </Link>
            </h2>
            <p style={{ margin: '0 0 12px', color: '#475569', lineHeight: 1.6 }}>{post.excerpt}</p>
            <Link href={`/blog/${post.slug}`} style={{ color: '#229c6b', fontSize: 14, fontWeight: 600 }}>
              Read more →
            </Link>
          </article>
        ))}
      </div>
    </main>
  );
}

// ---- app/blog/[slug]/page.tsx - ISR post detail with SEO ----
export async function generateStaticParams() {
  const posts = await fetchPosts();
  return posts.map(p => ({ slug: p.slug }));
}

export async function generateMetadata({ params }: { params: { slug: string } }): Promise<Metadata> {
  const post = await fetchPostBySlug(params.slug);
  if (!post) return { title: 'Post Not Found' };
  return {
    title: post.title,
    description: post.excerpt,
    openGraph: {
      title: post.title,
      description: post.excerpt,
      type: 'article',
      publishedTime: post.date,
      authors: [post.author],
    },
    alternates: { canonical: `https://myblog.com/blog/${params.slug}` },
  };
}

export default async function PostPage({ params }: { params: { slug: string } }) {
  const post = await fetchPostBySlug(params.slug);
  if (!post) notFound(); // triggers not-found.tsx
  return (
    <main style={{ maxWidth: 760, margin: '0 auto', padding: '40px 24px', fontFamily: 'system-ui' }}>
      <script
        type="application/ld+json"
        dangerouslySetInnerHTML={{ __html: JSON.stringify({
          '@context': 'https://schema.org',
          '@type': 'BlogPosting',
          headline: post.title,
          description: post.excerpt,
          datePublished: post.date,
          author: { '@type': 'Person', name: post.author },
        }) }}
      />
      <h1>{post.title}</h1>
      <p style={{ color: '#64748b' }}>{post.readTime} min read · {new Date(post.date).toLocaleDateString()}</p>
      <div dangerouslySetInnerHTML={{ __html: post.htmlContent }} />
    </main>
  );
}

// ---- SW registration in layout.tsx ----
// app/layout.tsx
'use client';
import { useEffect } from 'react';
function ServiceWorkerRegistration() {
  useEffect(() => {
    if ('serviceWorker' in navigator) {
      navigator.serviceWorker.register('/sw.js').catch(console.error);
    }
  }, []);
  return null;
}

What This Project Covers

  • ISR with revalidate: 3600 - blog posts update automatically every hour without rebuilding
  • generateStaticParams - known post slugs prerendered at build time for instant loading
  • Dynamic metadata with generateMetadata - per-post Open Graph and JSON-LD structured data
  • Service Worker registration - offline reading of previously visited posts
  • manifest.json - users can install the blog as a standalone PWA
  • Server Actions - create/update post operations with Zod validation and revalidatePath
  • notFound() - clean 404 handling for unknown slugs
  • CSP and security headers - production-ready security configuration

Tip

Tip

Practice Mini Project FullStack Blog with PWA in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.

Diagram
Loading diagram…

Visual architecture and flow for Mini Project: Full-Stack Blog with PWA

Practice Task

Note

Practice Task - (1) Write a working example of Mini Project FullStack Blog with PWA from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.

Quick Quiz

Common Mistake

Warning

A common mistake with Mini Project FullStack Blog with PWA is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready react code.

Key Takeaways

  • Build a full-stack blog using Next.
  • ISR with revalidate: 3600 - blog posts update automatically every hour without rebuilding
  • generateStaticParams - known post slugs prerendered at build time for instant loading
  • Dynamic metadata with generateMetadata - per-post Open Graph and JSON-LD structured data

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/10 done