Next.js Blog & YouTube Portfolio
Instructions for building a Next.js portfolio application featuring blog posts, YouTube video showcase, and admin content management.
Project Overview
This skill guides you in creating a TypeScript-based Next.js application with:
Frontend blog post showcase with SEO optimizationYouTube video integration with thumbnails and linksAdmin interface for content managementAPI routes for backend data operationsArchitecture Guidelines
TypeScript & Type Safety
Use TypeScript for all components, API routes, and utility functionsDefine proper interfaces and types in `/src/types`Avoid `any` types; use strict typing throughoutCreate type definitions for: - Blog post structures
- YouTube video metadata
- API request/response payloads
- Component props
Component Structure
Use Server Components by default for performanceReserve Client Components for interactive elements (use `"use client"` directive)Separate components into logical, reusable modules in `/src/components`Implement proper component composition patternsCreate shared components for common UI elements (headers, footers, cards)Styling Approach
Use TailwindCSS for stylingAvoid inline styles; create CSS modules in `/src/styles` for complex stylingFollow responsive design principles (mobile-first approach)Maintain consistent spacing, colors, and typographyCreate utility classes for repeated patternsFile Organization
```
/src/app - App Router pages, layouts, and route handlers
/src/components - Reusable React components
/src/styles - CSS modules and global styles
/src/lib - Utility functions, configurations, helpers
/src/types - TypeScript type definitions and interfaces
/src/data - Static data, mock data, content files
```
Implementation Steps
1. Set Up Project Structure
Initialize Next.js project with TypeScript and TailwindCSSCreate directory structure as outlined aboveSet up environment variables in `.env.local` (YouTube API keys, database URLs)Configure `next.config.ts` for image domains and optimization2. Define Type Definitions
Create interfaces in `/src/types` for:
Blog posts (title, content, author, date, slug, tags, featured image)YouTube videos (videoId, title, description, thumbnail, publishedAt)Admin operations (create, update, delete payloads)User sessions (if authentication is required)3. Build Frontend Components
**Blog Components:**
`BlogCard` - Display blog post preview`BlogList` - Grid/list of blog cards`BlogPost` - Full blog post view with markdown rendering`BlogSidebar` - Tags, categories, recent posts**YouTube Components:**
`VideoCard` - YouTube video thumbnail with metadata`VideoGrid` - Responsive grid of video cards`VideoPlayer` - Embedded YouTube player component**Layout Components:**
`Header` - Navigation with responsive menu`Footer` - Site information and links`Layout` - Main layout wrapper4. Implement API Routes
Create API routes in `/src/app/api`:
`GET /api/blogs` - Fetch all blog posts`GET /api/blogs/[slug]` - Fetch single blog post`POST /api/blogs` - Create new blog post (admin)`PUT /api/blogs/[slug]` - Update blog post (admin)`DELETE /api/blogs/[slug]` - Delete blog post (admin)`GET /api/youtube` - Fetch YouTube videos`POST /api/youtube` - Add YouTube video (admin)**Error Handling:**
Implement proper try-catch blocksReturn appropriate HTTP status codesProvide meaningful error messagesLog errors server-side for debugging5. Build Admin Interface
Create admin pages in `/src/app/admin`:
Dashboard overview with content statsBlog post editor (markdown or rich text)YouTube video manager (add/edit video IDs and metadata)Content preview functionality**Security Considerations:**
Implement authentication (NextAuth.js recommended)Protect admin routes with middlewareValidate all inputs server-sideUse environment variables for sensitive data6. Optimize Performance & SEO
Use Next.js Image component for optimized imagesImplement proper metadata for all pagesAdd structured data (JSON-LD) for blog postsUse Server Components for data fetchingImplement loading states with Suspense boundariesAdd proper alt text to imagesCreate sitemap and robots.txtBest Practices
Code Quality
Follow consistent naming conventions (camelCase for variables, PascalCase for components)Write descriptive comments for complex logicKeep components small and focused (single responsibility)Extract repeated logic into custom hooks or utilitiesUse meaningful variable and function namesData Management
Fetch data server-side when possible (Server Components)Implement caching strategies for API responsesUse SWR or React Query for client-side data fetching when neededValidate data before renderingAccessibility
Use semantic HTML elementsAdd proper ARIA labelsEnsure keyboard navigation worksMaintain sufficient color contrastTest with screen readersEnvironment Variables
Store in `.env.local`:
`YOUTUBE_API_KEY` - YouTube Data API v3 key`DATABASE_URL` - Database connection string (if using)`NEXTAUTH_SECRET` - Authentication secret`NEXTAUTH_URL` - Application URLExample Usage
When creating a new blog post component:
```typescript
// src/types/blog.ts
export interface BlogPost {
slug: string;
title: string;
excerpt: string;
content: string;
author: string;
publishedAt: string;
tags: string[];
featuredImage: string;
}
// src/components/BlogCard.tsx
interface BlogCardProps {
post: BlogPost;
}
export function BlogCard({ post }: BlogCardProps) {
// Component implementation using TailwindCSS
// Use Next.js Image and Link components
}
```
When creating an API route:
```typescript
// src/app/api/blogs/route.ts
import { NextResponse } from 'next/server';
import type { BlogPost } from '@/types/blog';
export async function GET() {
try {
// Fetch blog posts from data source
const posts: BlogPost[] = await fetchPosts();
return NextResponse.json(posts);
} catch (error) {
console.error('Error fetching posts:', error);
return NextResponse.json(
{ error: 'Failed to fetch posts' },
{ status: 500 }
);
}
}
```
Testing
Write unit tests for utility functionsTest API routes with mock dataImplement E2E tests for critical user flowsTest responsive design across devicesValidate accessibility with automated toolsDeployment Considerations
Set environment variables in productionConfigure proper caching headersEnable compressionSet up analytics (Google Analytics, Vercel Analytics)Monitor performance with Next.js Speed InsightsImplement proper error logging (Sentry, LogRocket)