Skip to content

A comprehensive Next.js 16 project demonstrating modern web development concepts, routing patterns, API integration, and best practices. This project is perfect for learning Next.js fundamentals and advanced features.

Notifications You must be signed in to change notification settings

DevAmirHub/Next.js-Learning-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Next.js Learning Project

A comprehensive Next.js 16 project demonstrating modern web development concepts, routing patterns, API integration, and best practices. This project is perfect for learning Next.js fundamentals and advanced features.

πŸš€ Tech Stack

  • Next.js 16.0.4 - React framework with App Router
  • React 19.2.0 - UI library
  • TypeScript 5 - Type-safe JavaScript
  • Tailwind CSS 4 - Utility-first CSS framework
  • ESLint - Code linting

πŸ“š Next.js Concepts Demonstrated

1. App Router Architecture

  • Modern file-based routing system
  • Nested layouts and route groups
  • Server and Client Components

2. Dynamic Routes

  • Single dynamic segments: [post_id], [course_id], [album_id]
  • Multiple dynamic segments: [...product] (catch-all routes)
  • Nested dynamic routes with categories

3. Route Groups

  • (frontend) - Organizes frontend routes without affecting URL structure
  • Shared layouts for grouped routes

4. Layouts & Nested Layouts

  • Root layout (app/layout.tsx) - Global layout with fonts and metadata
  • Route group layout (app/(frontend)/layout.tsx) - Shared Navigation and Footer
  • Layout composition and nesting

5. Server Components & Async Components

  • Server-side data fetching
  • Async/await in Server Components
  • Promise-based params handling (Next.js 16 feature)

6. Data Fetching

  • Server-side API calls
  • Data revalidation with next: { revalidate }
  • Error handling in data fetching
  • TypeScript interfaces for API responses

7. API Service Layer

  • Separated API logic in app/lib/api/
  • Reusable API functions
  • Centralized error handling
  • Type-safe API calls

8. Middleware

  • Request interception
  • Cookie-based authentication checks
  • Route protection patterns

9. Metadata & SEO

  • Dynamic metadata configuration
  • Title templates
  • SEO-friendly structure

10. Error Handling

  • Custom not-found.tsx page
  • Error boundaries
  • API error handling

11. Styling

  • Tailwind CSS utility classes
  • Dark mode support
  • Responsive design patterns
  • Component-based styling

πŸ“ Project Structure

app/
β”œβ”€β”€ layout.tsx                 # Root layout with fonts & metadata
β”œβ”€β”€ page.tsx                   # Home page
β”œβ”€β”€ not-found.tsx              # 404 error page
β”œβ”€β”€ globals.css                # Global styles
β”‚
β”œβ”€β”€ (frontend)/                 # Route group (doesn't affect URL)
β”‚   β”œβ”€β”€ layout.tsx              # Frontend layout (Navigation + Footer)
β”‚   β”œβ”€β”€ page.tsx                # Home page
β”‚   β”‚
β”‚   β”œβ”€β”€ posts/                  # Posts section
β”‚   β”‚   β”œβ”€β”€ page.tsx            # Posts list
β”‚   β”‚   └── [post_id]/          # Dynamic route
β”‚   β”‚       └── page.tsx
β”‚   β”‚
β”‚   β”œβ”€β”€ albums/                 # Albums section
β”‚   β”‚   β”œβ”€β”€ page.tsx
β”‚   β”‚   └── [album_id]/
β”‚   β”‚       └── page.tsx
β”‚   β”‚
β”‚   β”œβ”€β”€ comments/               # Comments section
β”‚   β”‚   β”œβ”€β”€ page.tsx
β”‚   β”‚   └── [comment_id]/
β”‚   β”‚       └── page.tsx
β”‚   β”‚
β”‚   β”œβ”€β”€ blog/                   # Blog with nested routes
β”‚   β”‚   β”œβ”€β”€ page.tsx
β”‚   β”‚   └── category/
β”‚   β”‚       β”œβ”€β”€ page.tsx
β”‚   β”‚       β”œβ”€β”€ education/
β”‚   β”‚       β”‚   β”œβ”€β”€ page.tsx
β”‚   β”‚       β”‚   └── [blog_id]/
β”‚   β”‚       └── sports/
β”‚   β”‚           β”œβ”€β”€ page.tsx
β”‚   β”‚           └── [blog_id]/
β”‚   β”‚
β”‚   β”œβ”€β”€ course/                 # Course section
β”‚   β”‚   β”œβ”€β”€ page.tsx
β”‚   β”‚   └── [course_id]/
β”‚   β”‚       └── page.tsx
β”‚   β”‚
β”‚   └── shop/                   # Shop with catch-all routes
β”‚       β”œβ”€β”€ page.tsx
β”‚       └── products/
β”‚           β”œβ”€β”€ page.tsx
β”‚           └── [...product]/   # Catch-all route
β”‚               └── page.tsx
β”‚
β”œβ”€β”€ Components/                 # Reusable components
β”‚   β”œβ”€β”€ Navigation.tsx
β”‚   β”œβ”€β”€ Footer.tsx
β”‚   β”œβ”€β”€ RedirectClientButton.tsx
β”‚   └── RedirectServerButton.tsx
β”‚
└── lib/
    └── api/                    # API service layer
        β”œβ”€β”€ index.ts            # Central exports
        β”œβ”€β”€ posts.ts
        β”œβ”€β”€ albums.ts
        └── cumments.ts

middleware.ts                   # Request middleware
next.config.ts                  # Next.js configuration

🎯 Key Features

Routing Patterns

  • βœ… Static routes
  • βœ… Dynamic routes ([id])
  • βœ… Catch-all routes ([...slug])
  • βœ… Nested routes
  • βœ… Route groups
  • βœ… Nested layouts

Data Fetching

  • βœ… Server Components with async/await
  • βœ… API service layer separation
  • βœ… Data revalidation
  • βœ… Error handling
  • βœ… TypeScript type safety

UI/UX

  • βœ… Responsive design
  • βœ… Dark mode support
  • βœ… Navigation component
  • βœ… Footer component
  • βœ… Loading states
  • βœ… Error pages

πŸ› οΈ Getting Started

Prerequisites

  • Node.js 18+
  • npm, yarn, pnpm, or bun

Installation

# Clone the repository
git clone <your-repo-url>
cd first-nextjs-project

# Install dependencies
npm install

# Run development server
npm run dev

Open http://localhost:3000 in your browser.

Available Scripts

npm run dev      # Start development server
npm run build    # Build for production
npm run start    # Start production server
npm run lint     # Run ESLint

πŸ“– Learning Path

This project is structured to help you learn Next.js concepts progressively:

  1. Start with: Basic routing (app/page.tsx, app/(frontend)/page.tsx)
  2. Learn: Dynamic routes ([post_id], [course_id])
  3. Explore: Nested routes (blog/category/education)
  4. Understand: Layouts and route groups
  5. Master: API integration and data fetching
  6. Advanced: Middleware and route protection

πŸ” Key Concepts Explained

Route Groups (frontend)

Route groups allow you to organize routes without affecting the URL structure. All routes inside (frontend) share the same layout.

Dynamic Routes

  • [id] - Single dynamic segment
  • [...slug] - Catch-all route (matches multiple segments)

Server Components

By default, all components in the App Router are Server Components. They can directly fetch data and don't send JavaScript to the client.

Async Params (Next.js 16)

In Next.js 16, route params can be Promises. Always handle both Promise and direct params for compatibility:

export default async function Page({ params }: { 
  params: Promise<{ id: string }> | { id: string } 
}) {
  const resolvedParams = params instanceof Promise ? await params : params;
  const id = resolvedParams.id;
  // ...
}

🌐 API Integration

The project uses JSONPlaceholder as a mock API for:

  • Posts
  • Albums
  • Comments

API services are separated in app/lib/api/ for better organization and reusability.

πŸ“ Notes

  • This project uses Next.js 16 with the App Router
  • All API calls are server-side (Server Components)
  • TypeScript is used throughout for type safety
  • Tailwind CSS 4 is used for styling
  • RTL (Right-to-Left) support is configured for Persian/Farsi

🀝 Contributing

This is a learning project. Feel free to:

  • Fork the repository
  • Experiment with different Next.js features
  • Add new routes and features
  • Improve documentation

πŸ‘€ Author

DevAmir

I create web products with an emphasis on clean architecture, practical solutions, and long-term maintainability.

πŸ“„ License

This project is open source and available for learning purposes.

πŸ”— Resources


Happy Learning! πŸŽ“

About

A comprehensive Next.js 16 project demonstrating modern web development concepts, routing patterns, API integration, and best practices. This project is perfect for learning Next.js fundamentals and advanced features.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published