diff --git a/s3_full_stack_using_nextjs/01.introduction_to_nextjs/01.introduction_to_nextjs.md b/s3_full_stack_using_nextjs/01.introduction_to_nextjs/01.introduction_to_nextjs.md new file mode 100644 index 00000000..d8ab3e57 --- /dev/null +++ b/s3_full_stack_using_nextjs/01.introduction_to_nextjs/01.introduction_to_nextjs.md @@ -0,0 +1,396 @@ +# 01. Introduction to Next.js + +## What is Next.js? + +**Next.js** is a React-based **full-stack framework** for building modern web applications. + +React mainly provides the tools for building user interfaces with components. **Next.js** adds a complete application structure and features around React, such as routing, server-side capabilities, rendering strategies, data fetching, caching, and production optimizations. + +In simple terms: + +```text +React + ↓ +Build user interfaces + +Next.js + ↓ +Build complete web applications with React +``` + +Next.js is open source project developed and maintained by **Vercel**. + +--- + +# Library vs Framework + +Understanding the difference between a **library** and a **framework** helps explain why Next.js is built around React. + +## Library + +A library provides functionality that you can use when you need it. + +You generally control the application structure and decide how different libraries work together. + +```text +Your Application + ↓ +You choose + ↓ +Libraries and tools +``` + +### Example + +React is a library focused mainly on building user interfaces. + +You can choose additional tools for: + +- Routing +- State management +- Data fetching +- Backend communication +- Build configuration + +--- + +## Framework + +A framework provides a more complete structure for building an application. + +It gives you conventions and built-in features for common application requirements. + +```text +Framework + ↓ +Application structure + ↓ +Built-in conventions + ↓ +Application code +``` + +Next.js is a framework built on top of React. + +It provides conventions and features for building complete web applications while still allowing you to use the React ecosystem. + +--- + +# React vs Next.js + +| Feature | React | Next.js | +| ---------------------- | ----------------------------------------------- | ------------------------------------------------- | +| Type | UI library | React framework | +| UI Components | Yes | Yes | +| Routing | Usually added separately | Built in | +| Rendering Options | Client-side rendering (SPA) | Static, dynamic/server, and client-side rendering | +| Server-side Features | Not provided by React itself | Built in | +| Backend Endpoints | Requires a separate backend or additional setup | Route Handlers / server-side capabilities | +| Data Fetching | Developer chooses the approach | Provides framework-level patterns | +| Caching | Requires additional tools/patterns | Built-in caching and revalidation features | +| Image Optimization | Requires additional tools | Built in | +| Font Optimization | Requires additional tools | Built in | +| Application Structure | Flexible | Convention-based | +| Full-Stack Development | Usually requires additional setup | Supported in the same project | + +> **Important:** Next.js does not replace React. Next.js uses React and adds framework features around it. + +--- + +# Problems with a Traditional React SPA + +A traditional React SPA can work very well, especially for highly interactive applications. + +However, as the application becomes larger, several additional decisions are required. + +- Routing +- Rendering +- Server-Side Code +- Application Structure +- SEO + +--- + +# Why Choose Next.js? + +Next.js is useful when you want React's component-based development model together with a structured framework for building complete web applications. + +These features allow developers to focus more on application development instead of assembling and configuring every part of the application themselves. + +# Key Features of Next.js + +The following are the major features of Next.js. + +## 1. Built-in File-Based Routing + +Next.js uses the file system to define application routes. + +For example: + +```text +app/ +├── page.tsx +├── about/ +│ └── page.tsx +└── products/ + └── page.tsx +``` + +These files represent routes such as: + +```text +/ +/about +/products +``` + +--- + +## 2. Multiple Rendering Strategies + +Next.js supports different ways of rendering application content. + +The major concepts are: + +```text +CSR → Client-Side Rendering +SSR → Server-Side Rendering +SSG → Static Site Generation +ISR → Incremental Static Regeneration +``` + +--- + +## 3. Server and Client Components + +The App Router supports two types of components: + +```text +Server Components +Client Components +``` + +They allow developers to decide where component code should execute and which features are needed on the client. + +--- + +## 4. Server-Side Capabilities + +Next.js allows server-side functionality to be implemented within the same application. + +For example: + +```text +Frontend + ↓ +Server-side code + ↓ +Database / External APIs +``` + +This makes it possible to build full-stack applications without necessarily maintaining a completely separate frontend and backend project. + +--- + +## 5. Data Fetching and Caching + +Next.js provides patterns and features for: + +- Fetching data +- Caching data +- Revalidating cached data +- Handling loading states +- Handling errors + +These features help applications manage data efficiently. + +--- + +## 6. API Endpoints (Backend Routes) + +Next.js can provide backend HTTP endpoints using **Route Handlers**. + +For example: + +```text +app/ +└── api/ + └── products/ + └── route.ts +``` + +This can create an API endpoint such as: + +```text +GET /api/products +``` + +--- + +## 7. Built-in Optimizations + +Next.js provides several built-in performance features. + +Examples include: + +- Image optimization +- Font optimization +- Automatic code splitting +- Lazy loading +- Optimized production builds + +These features help reduce unnecessary client-side work and improve application performance. + +--- + +## 8. SEO and Metadata + +Next.js provides APIs for defining metadata such as: + +```text +Page title +Description +Open Graph metadata +Robots +Sitemap +``` + +For example: + +```text +Product Details + +``` + +--- + +## 9. Loading and Error UI + +The App Router provides special file conventions for common UI states. + +Examples: + +```text +loading.tsx +error.tsx +not-found.tsx +``` + +These allow different parts of an application to display appropriate UI while content is loading or when something goes wrong. + +--- + +## 10. TypeScript Support + +Next.js has first-class TypeScript support. + +TypeScript can be used for: + +- Components +- Props +- API responses +- Server-side code +- Database-related code + +This helps catch many errors during development and makes larger applications easier to maintain. + +### Type Safety Benefits + +- **Statically Typed Routing:** Enabling `typedRoutes` in Next.js allows TypeScript to auto-generate link definitions. It catches typos in your `` paths directly inside your code editor. +- **End-to-End Type Safety:** Because Server Components fetch data natively on the server, you do not need to convert or serialize data into plain strings. Complex data objects like `Date`, `Map`, and `Set` flow securely from data fetching layers into your UI. +- **Layout and Page Protection:** Component props, URL route parameters, and dynamic path segments are explicitly typed. This prevents accidental misconfigurations when reading variables from the App Router. +- **Server vs. Client Validation:** The custom Next.js TypeScript plugin checks configuration limits. It displays warning highlights if you accidentally use client-side hooks like `useState` inside a Server Component. + +### Developer Experience and Efficiency + +- **Zero-Configuration Setup:** Creating a project via the Next.js installation tool auto-detects TypeScript files and installs the required compiler configurations seamlessly. +- **Fewer Production Bugs:** The compiler scans code rules in real time, pointing out undefined values or wrong data structures before compilation. +- **Smart Code Completion:** Text editors like VS Code instantly leverage TypeScript to offer autocomplete suggestions and in-context tooltips for Next.js APIs. +- **Safer Code Refactoring:** If you modify an API response shape or a component design, the compiler highlights every exact location that requires updates across your repository. + +--- + +## 11. Development Experience + +Next.js provides development features such as: + +- Fast Refresh +- Development error messages +- TypeScript integration +- ESLint integration +- Production build tooling + +These features make development and debugging easier. + +--- + +# When Should You Use Next.js? + +Next.js is a good choice for applications that need one or more of the following: + +### E-commerce + +```text +Product pages +Shopping cart +User accounts +Payments +SEO +``` + +### Blogs and Content Websites + +```text +Articles +Categories +Search +SEO +Static content +``` + +### Marketing Websites + +```text +Landing pages +Product pages +Pricing +Documentation +SEO +``` + +### Full-Stack Web Applications + +```text +Frontend +Authentication +Server-side logic +Database +APIs +Admin dashboard +``` + +### Dashboards and Admin Panels + +```text +Authentication +Data fetching +Interactive UI +Charts +Forms +Server-side operations +``` + +--- + +# Summary + +- **React** is a library mainly focused on building user interfaces. +- **Next.js** is a full-stack framework built on top of React. +- React gives you the foundation for component-based UI development. +- Next.js provides conventions and features for building complete web applications. +- Next.js includes routing, rendering options, server-side capabilities, data fetching, caching, and production optimizations. +- Next.js can be used for both frontend-focused and full-stack applications. +- You do not need to use every Next.js feature in every project. +- The right features depend on the application's requirements. + +> **Next.js = React + application framework features for building production-ready web applications.** diff --git a/s3_full_stack_using_nextjs/01.introduction_to_nextjs/interview_question.md b/s3_full_stack_using_nextjs/01.introduction_to_nextjs/interview_question.md new file mode 100644 index 00000000..d66c8240 --- /dev/null +++ b/s3_full_stack_using_nextjs/01.introduction_to_nextjs/interview_question.md @@ -0,0 +1,33 @@ +# Introduction to Next.js — Interview Questions + +1. What is Next.js, and what does it provide on top of React? + +2. Why is React considered a library while Next.js is considered a framework? + +3. What is the main difference between React and Next.js? + +4. What problems can arise when building a large application with a traditional React SPA? + +5. Why would you choose Next.js over a traditional React SPA? + +6. What is file-based routing in Next.js? + +7. What rendering strategies does Next.js support? + +8. What are Server Components and Client Components in Next.js? + +9. What server-side capabilities does Next.js provide? + +10. What are Route Handlers in Next.js? + +11. What built-in performance optimizations does Next.js provide? + +12. How does Next.js support SEO and metadata? + +13. What are `loading.tsx`, `error.tsx`, and `not-found.tsx` used for? + +14. What types of applications are well suited for Next.js? + +15. Does Next.js replace React? Explain the relationship between React and Next.js. + +16. Does a Next.js application necessarily require a separate backend project? diff --git a/s3_full_stack_using_nextjs/02.project_setup_and_structure/02.project_setup_and_structure.md b/s3_full_stack_using_nextjs/02.project_setup_and_structure/02.project_setup_and_structure.md new file mode 100644 index 00000000..d2247212 --- /dev/null +++ b/s3_full_stack_using_nextjs/02.project_setup_and_structure/02.project_setup_and_structure.md @@ -0,0 +1,923 @@ +# 02. Next.js Project Setup & Structure + +Before creating a Next.js project, it is important to understand how a Next.js project is organized. + +Next.js currently provides two routing systems: + +- **Pages Router** +- **App Router** + +Both are supported, but they use different project structures and conventions. + +--- + +# 1. Pages Router vs App Router + +```text +Next.js +│ +├── Pages Router +│ └── pages/ +│ +└── App Router + └── app/ +``` + +## Pages Router + +The **Pages Router** is the traditional routing system in Next.js. + +It uses the `pages/` directory to define routes. + +```text +pages/ +├── index.tsx +├── about.tsx +└── products/ + └── index.tsx +``` + +It is still officially supported and is common in existing Next.js applications. + +--- + +## App Router + +The **App Router** is the modern routing system in Next.js. + +It uses the `app/` directory and provides newer Next.js features such as: + +- Server Components +- Client Components +- Nested layouts +- Route-level loading UI +- Route-level error UI +- Route Handlers +- Modern data-fetching and caching patterns + +```text +app/ +├── page.tsx +├── about/ +│ └── page.tsx +└── products/ + └── page.tsx +``` + +For **new projects, the App Router is the recommended choice**. + +--- + +# 2. Pages Router vs App Router — Comparison + +| Feature | Pages Router | App Router | +| ---------------------------- | ----------------------------- | -------------------- | +| Main directory | `pages/` | `app/` | +| Status | Traditional / still supported | Modern / recommended | +| Routing style | File-based | File-based | +| Main page file | `index.tsx` | `page.tsx` | +| Layout system | `_app.tsx`, custom patterns | `layout.tsx` | +| Server Components | No App Router model | Yes | +| Client Components | Traditional React model | `"use client"` | +| Loading UI | Custom implementation | `loading.tsx` | +| Error UI | Custom patterns | `error.tsx` | +| Not-found UI | `404.tsx` | `not-found.tsx` | +| API functionality | `pages/api/` | Route Handlers | +| Recommended for new projects | No | Yes | + +> The Pages Router is important to understand because many existing projects still use it. The App Router is the recommended choice for new projects. + +--- + +# 3. When Should You Use Each Router? + +## Use Pages Router When + +- Working on an existing Pages Router project +- Maintaining an older Next.js application +- Joining a project that already uses `pages/` +- Gradually migrating an existing project +- The existing architecture already works well + +You do **not** need to migrate an existing project simply because the App Router exists. + +--- + +## Use App Router When + +- Starting a new Next.js project +- Building a modern Next.js application +- You want to use Server Components +- You need nested layouts +- You want route-level loading and error UI +- You want the modern Next.js data-fetching and caching model + +### Recommendation + +```text +New project + ↓ +App Router +``` + +```text +Existing Pages Router project + ↓ +Usually keep Pages Router + ↓ +Migrate only when there is a reason +``` + +--- + +# 4. Can Both Routers Exist in One Project? + +Yes. + +A Next.js project can contain both: + +```text +my-next-app/ +├── app/ +└── pages/ +``` + +This can be useful when gradually migrating an existing application. + +However, avoid mixing the routers unnecessarily. + +For a new application, using only the **App Router** usually keeps the project simpler. + +--- + +# 5. Creating a Next.js Project + +After understanding the routing systems and project structure, you can create a Next.js project using: + +```bash +npx create-next-app@latest my-next-app +``` + +The CLI can ask about options such as: + +- TypeScript +- ESLint +- Tailwind CSS +- `src/` directory +- App Router +- Import aliases + +For a new project, choose: + +```text +App Router → Yes +``` + +For a medium or large project: + +```text +Use src/ directory → Yes +``` + +Then: + +```bash +cd my-next-app +npm run dev +``` + +The development server normally runs at: + +```text +http://localhost:3000 +``` + +--- + +# 6. Pages Router Project Structure + +The `pages/` directory contains application routes. +A typical Pages Router project looks like this: + +```text +my-next-app/ +│ +├── pages/ +│ ├── index.tsx +│ ├── about.tsx +│ │ +│ ├── products/ +│ │ ├── index.tsx +│ │ └── [id].tsx +│ │ +│ ├── 404.tsx +│ ├── _app.tsx +│ ├── _document.tsx +│ │ +│ └── api/ +│ └── products.ts +│ +├── public/ +│ └── images/ +│ +├── styles/ +│ └── globals.css +│ +├── next.config.ts +├── package.json +├── tsconfig.json +└── .env +``` + +Routes: + +```text +/ → pages/index.tsx +/about → pages/about.tsx +/products → pages/products/index.tsx +/products/123 → pages/products/[id].tsx +``` + +The filename and folder structure determine the URL. + +--- + +## `pages/api/` + +The Pages Router can create backend API endpoints using `pages/api/`. + +```text +pages/ +└── api/ + └── products.ts +``` + +This represents: + +```text +/api/products +``` + +> API Routes are specific to the Pages Router. The App Router uses Route Handlers instead. + +--- + +## `_app.tsx` + +`_app.tsx` is used to customize the top-level application component. + +Common uses include: + +- Global CSS +- Shared providers +- Global state providers + +Example: + +```tsx +import "../styles/globals.css"; + +export default function App({ Component, pageProps }) { + return ; +} +``` + +--- + +## `_document.tsx` + +`_document.tsx` allows customization of the HTML document structure. + +It is mainly used for document-level customization. + +It should not be used for normal page UI. + +--- + +## `404.tsx` + +A custom 404 page can be created using: + +```text +pages/404.tsx +``` + +Example: + +```tsx +export default function NotFound() { + return

404 - Page Not Found

; +} +``` + +--- + +# 7. App Router Project Structure + +The `app/` directory contains routes and route-specific files. + +An important difference from the Pages Router is: + +> A folder by itself does **not** create a route in the App Router. + +A route normally requires a `page.tsx` file. + +A typical App Router project looks like this: + +```text +my-next-app/ +│ +├── app/ +│ ├── layout.tsx +│ ├── page.tsx +│ ├── globals.css +│ │ +│ ├── about/ +│ │ └── page.tsx +│ │ +│ ├── products/ +│ │ ├── page.tsx +│ │ └── [id]/ +│ │ └── page.tsx +│ │ +│ ├── dashboard/ +│ │ ├── layout.tsx +│ │ └── page.tsx +│ │ +│ ├── loading.tsx +│ ├── error.tsx +│ └── not-found.tsx +│ +├── public/ +│ └── images/ +│ +├── next.config.ts +├── package.json +├── tsconfig.json +└── .env +``` + +--- + +This structure creates the following routes + +```text +/about +/products +/products/123 +/dashboard +``` + +--- + +## `page.tsx` + +`page.tsx` defines the UI for a route. + +```text +app/ +├── page.tsx +└── about/ + └── page.tsx +``` + +Example: + +```tsx +export default function AboutPage() { + return

About Page

; +} +``` + +--- + +## `layout.tsx` + +A layout provides shared UI around pages. + +```text +app/ +├── layout.tsx +├── page.tsx +└── about/ + └── page.tsx +``` + +Example: + +```tsx +export default function RootLayout({ + children, +}: { + children: React.ReactNode; +}) { + return ( + + +
Navbar
+ + {children} + + + + + ); +} +``` + +Layouts can also be nested: + +```text +app/ +├── layout.tsx +└── dashboard/ + ├── layout.tsx + └── page.tsx +``` + +The dashboard layout can provide UI shared by the dashboard and its child routes. + +--- + +## `loading.tsx` + +`loading.tsx` defines loading UI for a route segment. + +```text +app/ +└── products/ + ├── loading.tsx + └── page.tsx +``` + +Example: + +```tsx +export default function Loading() { + return

Loading products...

; +} +``` + +Detailed loading and streaming concepts are covered in **Data Fetching & UI States**. + +--- + +## `error.tsx` + +`error.tsx` provides an error UI for a route segment. + +It must be a **Client Component**. + +```text +app/ +└── products/ + ├── error.tsx + └── page.tsx +``` + +Example: + +```tsx +"use client"; + +export default function Error({ + error, + reset, +}: { + error: Error; + reset: () => void; +}) { + return ( +
+

Something went wrong.

+ + +
+ ); +} +``` + +Detailed error handling is covered later. + +--- + +## `not-found.tsx` + +`not-found.tsx` provides UI when a requested resource is not found. + +```text +app/ +└── not-found.tsx +``` + +Example: + +```tsx +export default function NotFound() { + return

404 - Page Not Found

; +} +``` + +Detailed not-found handling is covered later. + +--- + +# 8. `src/` Directory + +The `src/` directory is an optional convention for organizing application source code. + +Instead of: + +```text +my-next-app/ +├── app/ +├── components/ +└── lib/ +``` + +you can use: + +```text +my-next-app/ +├── src/ +│ ├── app/ +│ ├── components/ +│ └── lib/ +│ +├── public/ +├── next.config.ts +└── package.json +``` + +With the Pages Router: + +```text +src/ +├── pages/ +├── components/ +└── lib/ +``` + +## Why Use `src/`? + +It separates application source code from project-level files. + +```text +src/ + ↓ +Application source code + +Root + ↓ +Configuration +Dependencies +Environment files +Build files +``` + +### Recommendation + +For small learning projects: + +```text +app/ +components/ +``` + +is perfectly fine. + +For medium or large projects: + +```text +src/ +├── app/ +├── components/ +├── lib/ +└── hooks/ +``` + +is a good organizational choice. + +> `src/` is optional. It is a project organization convention, not a requirement. + +--- + +# 9. `components/` + +`components/` is a common convention for reusable UI components. + +Example: + +```text +src/ +└── components/ + ├── Navbar.tsx + ├── Button.tsx + └── ProductCard.tsx +``` + +For example, `ProductCard.tsx` can be reused on multiple pages. + +```tsx +export default function ProductCard() { + return
Product Card
; +} +``` + +The `components/` directory is **not required by Next.js**. + +> Keep shared components in a common location. Route-specific components can stay close to the route that uses them. + +--- + +# 10. `lib/` + +`lib/` is a common convention for reusable application logic that is not UI. + +Example: + +```text +src/ +└── lib/ + ├── api.ts + ├── db.ts + └── auth.ts +``` + +Typical uses include: + +- API clients +- Database clients +- Authentication helpers +- Utility functions +- Server-side business logic + +The `lib/` directory is a project convention, not a special Next.js directory. + +--- + +# 11. `hooks/` + +`hooks/` is a common convention for reusable React hooks. + +Example: + +```text +src/ +└── hooks/ + ├── useAuth.ts + └── useProducts.ts +``` + +A custom hook might look like: + +```tsx +export function useProducts() { + // reusable client-side logic +} +``` + +The `hooks/` directory is also a project organization convention. + +--- + +# 12. `public/` + +The `public/` directory contains static assets that can be accessed directly by URL. + +Example: + +```text +public/ +├── logo.png +└── images/ + └── banner.jpg +``` + +These files can be accessed as: + +```text +/logo.png +/images/banner.jpg +``` + +Example: + +```tsx +Logo +``` + +For optimized images in Next.js applications, the `next/image` component is generally preferred. + +--- + +# 13. Configuration Files + +Several important project-level files are normally kept at the root of the project. + +```text +my-next-app/ +├── next.config.ts +├── package.json +├── tsconfig.json +└── .env +``` + +--- + +## `next.config.ts` + +`next.config.ts` is used to customize Next.js behavior. + +Example: + +```ts +const nextConfig = { + images: { + remotePatterns: [ + { + protocol: "https", + hostname: "images.example.com", + }, + ], + }, +}; + +export default nextConfig; +``` + +Only add configuration when the project actually needs it. + +> Do not modify `next.config.ts` just because the file exists. + +--- + +## `package.json` + +`package.json` contains project metadata, dependencies, development dependencies, and scripts. + +Common scripts include: + +```bash +npm run dev +npm run build +npm run start +``` + +--- + +## `tsconfig.json` + +`tsconfig.json` contains TypeScript compiler configuration. + +Next.js can create and configure this file when TypeScript is enabled in the project. + +--- + +# 14. Environment Variables + +Environment variables allow configuration values to be stored outside the source code. + +Example: + +```env +DATABASE_URL="..." +API_SECRET="..." +NEXT_PUBLIC_API_URL="https://api.example.com" +``` + +## Server-Only Variables + +Variables without the `NEXT_PUBLIC_` prefix are not automatically exposed to browser code. + +Example: + +```env +DATABASE_URL="..." +API_SECRET="..." +``` + +They can be accessed on the server: + +```ts +const databaseUrl = process.env.DATABASE_URL; +``` + +## Browser-Exposed Variables + +Variables that need to be available in browser code must use the `NEXT_PUBLIC_` prefix. + +```env +NEXT_PUBLIC_API_URL="https://api.example.com" +``` + +### Important + +Never put secrets in a `NEXT_PUBLIC_` variable. + +```env +# ❌ Do not do this +NEXT_PUBLIC_API_SECRET="my-secret" +``` + +Anything using the `NEXT_PUBLIC_` prefix can be exposed to client-side code. + +### `.env.example` + +`.env.example` is a template that shows which environment variables are required by the project. + +It contains the variable names, but should not contain real secrets. + +Example: + +```env +DATABASE_URL= +API_KEY= +JWT_SECRET= +NEXT_PUBLIC_API_URL= +``` + +--- + +# 15. Recommended Project Structure + +For a new medium-sized App Router project, a good starting structure is: + +```text +my-next-app/ +│ +├── src/ +│ ├── app/ +│ │ ├── layout.tsx +│ │ ├── page.tsx +│ │ ├── globals.css +│ │ │ +│ │ ├── about/ +│ │ │ └── page.tsx +│ │ │ +│ │ └── products/ +│ │ ├── page.tsx +│ │ └── [id]/ +│ │ └── page.tsx +│ │ +│ ├── components/ +│ │ ├── Navbar.tsx +│ │ └── ProductCard.tsx +│ │ +│ ├── lib/ +│ │ └── api.ts +│ │ +│ └── hooks/ +│ └── useProducts.ts +│ +├── public/ +│ └── images/ +│ +├── next.config.ts +├── package.json +├── tsconfig.json +└── .env +└── .env.example +``` + +The structure separates the main concerns: + +```text +src/ + ↓ +Application source code + +public/ + ↓ +Static assets + +Root files/ + ↓ +Configuration and project files +``` + +For a Pages Router project, the main difference is: + +```text +src/app/ + ↓ +src/pages/ +``` + +--- + +# Summary + +- Next.js has two routing systems: **Pages Router** and **App Router**. +- The **Pages Router** uses `pages/` and is important for existing projects. +- The **App Router** uses `app/` and is recommended for new projects. +- A Pages Router route is usually created from a file such as `pages/about.tsx`. +- An App Router route normally requires a `page.tsx` file. +- `src/` is optional, but it is a useful convention for medium and large projects. +- `public/` contains static assets. +- `next.config.ts` is used to customize Next.js behavior. +- Environment variables are commonly stored in `.env`, `.env.local`, `.env.development`, `.env.production`. +- Never expose secrets using the `NEXT_PUBLIC_` prefix. +- `components/`, `lib/`, and `hooks/` are useful organization conventions, but they are not required by Next.js. +- Avoid unnecessary folders and configuration. +- For new projects, **App Router + `src/`** is a recommended starting structure. diff --git a/s3_full_stack_using_nextjs/02.project_setup_and_structure/assignment.md b/s3_full_stack_using_nextjs/02.project_setup_and_structure/assignment.md new file mode 100644 index 00000000..b658680b --- /dev/null +++ b/s3_full_stack_using_nextjs/02.project_setup_and_structure/assignment.md @@ -0,0 +1,42 @@ +# Project Setup & Structure — Assignments + +## Assignment 1 — App Router Project Structure + +**Title:** Create and Organize a Next.js App Router Project + +**Implementation:** + +- Create a new Next.js project with TypeScript, ESLint, App Router, import alias, and `src/` directory enabled +- Inside `src/`, create three folders: `components/`, `lib/`, and `hooks/` +- In `components/`, create a `Navbar` component returning a `