A modern, full-featured blog platform built with Next.js 16, React 19, and TypeScript.
- User Authentication: JWT-based authentication with HTTP-only cookies
- Post Management: Create, edit, delete, and publish blog posts
- Comments System: Add, edit, and delete comments on posts
- Likes System: Like/unlike posts with optimistic updates
- Tags System: Organize posts with tags
- User Profiles: View and edit user information
- Responsive Design: Mobile-first design with Tailwind CSS
- Advanced Caching: TanStack Query with optimistic updates
- State Management: Redux Toolkit for global UI state
- Framework: Next.js 16 with App Router
- UI Library: React 19
- Language: TypeScript
- State Management: Redux Toolkit + TanStack Query
- Styling: Tailwind CSS v4
- Forms: React Hook Form + Zod
- HTTP Client: Axios
- Icons: Lucide React
- Notifications: Sonner
- UI Components: shadcn/ui
- Node.js 18+
- npm or yarn
-
Clone the repository: ```bash git clone cd blog-frontend ```
-
Install dependencies: ```bash npm install ```
-
Set up environment variables: ```bash cp .env.example .env.local ```
-
Update
.env.localwith your API URL: ``` NEXT_PUBLIC_API_URL=http://localhost:3000 ```
Start the development server: ```bash npm run dev ```
Open http://localhost:3000 in your browser.
Build for production: ```bash npm run build npm start ```
``` blog-frontend/ ├── app/ # Next.js App Router │ ├── (auth)/ # Auth routes │ ├── (protected)/ # Protected routes │ ├── layout.tsx # Root layout │ └── page.tsx # Home page ├── components/ # React components │ ├── auth/ # Auth components │ ├── comments/ # Comment components │ ├── layout/ # Layout components │ ├── posts/ # Post components │ ├── tags/ # Tag components │ ├── user/ # User components │ ├── ui/ # UI components │ └── providers.tsx # Redux & Query providers ├── hooks/ # Custom React hooks ├── lib/ # Utility functions ├── services/ # API service layer ├── store/ # Redux store ├── types/ # TypeScript types └── middleware.ts # Next.js middleware ```
The frontend connects to a Blog API backend. Ensure the backend is running on the URL specified in NEXT_PUBLIC_API_URL.
POST /api/auth/register- Register new userPOST /api/auth/login- Login userGET /api/posts- Get all postsPOST /api/posts- Create post (protected)GET /api/posts/:id- Get post detailsPUT /api/posts/:id- Update post (protected)DELETE /api/posts/:id- Delete post (protected)POST /api/interactions/posts/:id/like- Like post (protected)POST /api/interactions/posts/:id/comments- Add comment (protected)
Global UI state is managed with Redux Toolkit:
authSlice: User authentication stateapiSlice: API availability stateuiSlice: UI state (modals, notifications)filterSlice: Filter and search state
Server state is managed with TanStack Query:
- Automatic caching and invalidation
- Optimistic updates for mutations
- Background refetching
- Stale-while-revalidate behavior
- User registers or logs in
- Backend returns JWT tokens in HTTP-only cookies
- Frontend automatically includes cookies in requests
- Tokens are automatically refreshed on expiry
- User state is persisted to localStorage
- Create a new route in
app/directory - Create corresponding components in
components/ - Use custom hooks for data fetching
- Handle loading and error states
- Create service function in
services/ - Create custom hook in
hooks/ - Use in components with proper error handling
- Use Tailwind CSS utility classes
- Follow the design system in
globals.css - Use shadcn/ui components for consistency
- Ensure backend is running on the correct URL
- Check
NEXT_PUBLIC_API_URLin.env.local - Verify CORS settings on backend
- Clear browser cookies and localStorage
- Check if tokens are being set correctly
- Verify backend token generation
- Clear
.nextdirectory:rm -rf .next - Reinstall dependencies:
rm -rf node_modules && npm install - Check TypeScript errors:
npm run build
- Push code to GitHub
- Connect repository to Vercel
- Set environment variables in Vercel dashboard
- Deploy
- Build the project:
npm run build - Deploy the
.nextdirectory - Set environment variables on the platform
- Ensure Node.js 18+ is available
MIT
For issues and questions, please open an issue on GitHub.