Skip to content

harshwadhwani-10/CodeCrafters-WriteStack

Repository files navigation

πŸš€ WriteStack - Modern MERN Stack Blogging Platform

Live Website

πŸ”— https://the-blog-hub-xi.vercel.app/

WriteStack Version

A modern, feature-rich blogging platform built with the MERN stack

Features β€’ Tech Stack β€’ Installation β€’ Environment Variables β€’ Usage β€’


πŸ“‹ Table of Contents


🌟 Overview

WriteStack is a comprehensive blogging platform that empowers users to create, share, and engage with blog content. Built with modern web technologies, it offers a seamless experience for both content creators and readers.

Key Highlights

  • πŸ“ Rich Text Editing - CKEditor 5 for professional content creation
  • πŸ‘₯ User Authentication - Secure JWT-based authentication with Google OAuth
  • πŸ”” Real-time Notifications - Stay updated with likes and comments
  • πŸ“Š Admin Dashboard - Comprehensive analytics and user management
  • 🎨 Modern UI - Beautiful, responsive design with Tailwind CSS
  • πŸ’Ύ Auto-save Drafts - Never lose your content with automatic draft saving
  • πŸ“± Responsive Design - Perfect experience across all devices

✨ Features

πŸ” Authentication & User Management

  • JWT Authentication - Secure token-based authentication
  • Google OAuth - One-click social login
  • User Profiles - Customizable user profiles with avatars
  • Password Reset - Email-based password recovery
  • Role-based Access - Admin and user role separation

✍️ Blog Management

  • Rich Text Editor - Powerful CKEditor 5 with extensive formatting options
  • Auto-save Drafts - Automatic saving prevents content loss
  • Image Upload - Cloudinary integration for optimized image hosting
  • Category Organization - Organize blogs into categories
  • Slug Generation - SEO-friendly URLs
  • Featured Images - Eye-catching blog covers
  • Smart Updates (PUT & PATCH) - Full updates with PUT and efficient partial updates with PATCH

πŸ’¬ Engagement Features

  • Like System - Express appreciation for blogs
  • Comments - Rich commenting system with replies
  • Real-time Notifications - Instant updates on interactions
  • Comment Counts - Track engagement metrics

πŸ” Discovery

  • Advanced Search - Find blogs instantly
  • Category Filtering - Browse by topics
  • Related Blogs - Discover similar content

πŸ‘¨β€πŸ’Ό Admin Features

  • Dashboard Analytics - Comprehensive statistics and insights
  • User Management - Full user administration
  • Report Generation - Download reports in PDF, Excel, and Word formats
  • Category Management - Create and manage blog categories
  • Charts & Graphs - Visual data representation
  • User Trend Analysis - Track growth metrics

🎨 User Interface

  • Modern Design - Clean and intuitive interface
  • Responsive Layout - Mobile-first approach
  • Dark Mode Ready - Easy theming support
  • Loading States - Smooth user experience
  • Toast Notifications - User-friendly feedback
  • Static About & Contact Pages - Header links that load backend-rendered pages without a full reload

πŸ›  Tech Stack

Frontend

Technology Version Purpose
React 18.3.1 UI Framework
Vite 6.3.5 Build Tool
React Router 7.1.0 Routing
Redux Toolkit 2.5.0 State Management
CKEditor 5 44.1.0 Rich Text Editor
Tailwind CSS 3.4.17 Styling
Radix UI Latest Component Library
React Hook Form 7.54.2 Form Management
Zod 3.24.1 Schema Validation
Recharts 2.15.2 Data Visualization
React Toastify 11.0.2 Notifications
Date-fns 4.1.0 Date Formatting
Moment.js 2.30.1 Date Utilities

Backend

Technology Version Purpose
Node.js Latest Runtime Environment
Express.js 4.21.2 Web Framework
Morgan Latest HTTP request logging
MongoDB Latest Database
Mongoose 8.9.2 ODM
JWT 9.0.2 Authentication
Bcrypt 2.4.3 Password Hashing
Cloudinary 1.30.0 Image Storage
Multer 2.0.2 File Upload
Nodemailer 6.10.1 Email Service
PDFKit Latest PDF Generation
XLSX 0.18.5 Excel Export
Docx 9.3.0 Word Export

Additional Tools

  • Firebase - Google Authentication
  • Lodash - Utility functions
  • Entities - HTML entity decoding
  • Slugify - URL slug generation
  • Cookie Parser - Cookie management
  • CORS - Cross-origin resource sharing
  • HTTP PATCH - Partial blog updates for edit flows
  • Static HTML pages - About/Contact pages served from the backend and injected into the React app

πŸ“‹ Prerequisites

Before you begin, ensure you have met the following requirements:

  • Node.js (v16 or higher)
  • MongoDB (local or cloud instance)
  • npm or yarn package manager
  • Cloudinary account (for image storage)
  • Google Cloud Console project (for OAuth)
  • Email SMTP credentials (for password reset)

πŸš€ Installation

1. Clone the Repository

git clone https://github.com/your-username/MERN_BLOG.git
cd MERN_BLOG

2. Install Dependencies

Install Backend Dependencies

cd api
npm install

Install Frontend Dependencies

cd ../client
npm install

πŸ”§ Environment Variables

Backend Environment Variables

Create a .env file in the api directory:

# Server Configuration
PORT=5000

# MongoDB Configuration
MONGODB_CONN=your_mongodb_connection_string

# JWT Configuration
JWT_SECRET=your_jwt_secret_key

# Frontend URL
FRONTEND_URL=http://localhost:5173

# Cloudinary Configuration
CLOUDINARY_APP_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret

# Email Configuration (Optional)
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USER=your_email@gmail.com
EMAIL_PASS=your_email_password

Frontend Environment Variables

Create a .env file in the client directory:

# API Base URL
VITE_API_BASE_URL=http://localhost:5000/api

# Firebase Configuration (Optional, for Google OAuth)
VITE_FIREBASE_API_KEY=your_firebase_api_key
VITE_FIREBASE_AUTH_DOMAIN=your_firebase_auth_domain
VITE_FIREBASE_PROJECT_ID=your_firebase_project_id

🎯 Usage

1. Start the Backend Server

cd api
npm run dev

The server will start on http://localhost:5000

2. Start the Frontend Development Server

cd client
npm run dev

The application will be available at http://localhost:5173

3. Build for Production

Frontend Build

cd client
npm run build

Backend Production

cd api
npm start

πŸ“ Project Structure

MERN_BLOG/
β”œβ”€β”€ api/                          # Backend API
β”‚   β”œβ”€β”€ config/                   # Configuration files
β”‚   β”‚   β”œβ”€β”€ cloudinary.js         # Cloudinary setup
β”‚   β”‚   └── multer.js             # File upload config
β”‚   β”œβ”€β”€ controllers/              # Route controllers
β”‚   β”‚   β”œβ”€β”€ Admin.controller.js   # Admin operations
β”‚   β”‚   β”œβ”€β”€ Auth.controller.js    # Authentication
β”‚   β”‚   β”œβ”€β”€ Blog.controller.js    # Blog CRUD
β”‚   β”‚   β”œβ”€β”€ Category.controller.js
β”‚   β”‚   β”œβ”€β”€ Comment.controller.js
β”‚   β”‚   β”œβ”€β”€ Draft.controller.js
β”‚   β”‚   β”œβ”€β”€ Notification.controller.js
β”‚   β”‚   └── User.controller.js
β”‚   β”œβ”€β”€ middleware/               # Custom middleware
β”‚   β”‚   β”œβ”€β”€ auth.middleware.js
β”‚   β”‚   β”œβ”€β”€ authenticate.js
β”‚   β”‚   β”œβ”€β”€ onlyadmin.js
β”‚   β”‚   └── upload.middleware.js
β”‚   β”œβ”€β”€ models/                   # MongoDB models
β”‚   β”‚   β”œβ”€β”€ ban.model.js
β”‚   β”‚   β”œβ”€β”€ blog.model.js
β”‚   β”‚   β”œβ”€β”€ category.model.js
β”‚   β”‚   β”œβ”€β”€ comment.model.js
β”‚   β”‚   β”œβ”€β”€ draft.model.js
β”‚   β”‚   β”œβ”€β”€ like.model.js
β”‚   β”‚   β”œβ”€β”€ notification.model.js
β”‚   β”‚   β”œβ”€β”€ resetToken.model.js
β”‚   β”‚   └── user.model.js
β”‚   β”œβ”€β”€ routes/                   # API routes
β”‚   β”‚   β”œβ”€β”€ Admin.route.js
β”‚   β”‚   β”œβ”€β”€ Auth.route.js
β”‚   β”‚   β”œβ”€β”€ Blog.route.js
β”‚   β”‚   β”œβ”€β”€ Category.route.js
β”‚   β”‚   β”œβ”€β”€ Comment.route.js
β”‚   β”‚   β”œβ”€β”€ Draft.route.js
β”‚   β”‚   β”œβ”€β”€ notification.routes.js
β”‚   β”‚   └── User.route.js
β”‚   β”œβ”€β”€ helpers/                  # Helper functions
β”‚   β”œβ”€β”€ utils/                    # Utility functions
β”‚   β”‚   └── email.js
β”‚   └── index.js                  # Server entry point
β”‚
β”œβ”€β”€ client/                       # Frontend React App
β”‚   β”œβ”€β”€ public/                   # Static assets
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ assets/              # Images and static files
β”‚   β”‚   β”œβ”€β”€ components/           # React components
β”‚   β”‚   β”‚   β”œβ”€β”€ ui/               # Reusable UI components
β”‚   β”‚   β”‚   β”œβ”€β”€ AppSidebar.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ AuthRouteProtechtion.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ BlogCard.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Comment.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ CommentList.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Editor.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ NotificationDropdown.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Topbar.jsx
β”‚   β”‚   β”‚   └── ...
β”‚   β”‚   β”œβ”€β”€ helpers/              # Helper functions
β”‚   β”‚   β”œβ”€β”€ hooks/                # Custom React hooks
β”‚   β”‚   β”œβ”€β”€ Layout/               # Layout components
β”‚   β”‚   β”œβ”€β”€ pages/                # Page components
β”‚   β”‚   β”‚   β”œβ”€β”€ Admin/           # Admin pages
β”‚   β”‚   β”‚   β”‚   └── Dashboard.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Blog/             # Blog pages
β”‚   β”‚   β”‚   β”œβ”€β”€ Category/         # Category pages
β”‚   β”‚   β”‚   β”œβ”€β”€ Index.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Login.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Profile.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ SearchResult.jsx
β”‚   β”‚   β”‚   └── ...
β”‚   β”‚   β”œβ”€β”€ redux/                # Redux store
β”‚   β”‚   β”œβ”€β”€ App.jsx               # Main app component
β”‚   β”‚   └── main.jsx              # App entry point
β”‚   └── package.json
β”‚
└── README.md                     # This file

πŸ›£ API Endpoints

Authentication Routes

POST   /api/auth/signup          # User registration
POST   /api/auth/signin          # User login
POST   /api/auth/logout          # User logout
POST   /api/auth/google           # Google OAuth
POST   /api/auth/forgot-password # Request password reset
POST   /api/auth/reset-password  # Reset password

Blog Routes

GET    /api/blog/blogs                    # Get all blogs
GET    /api/blog/get-blog/:slug           # Get single blog by slug
POST   /api/blog/add                      # Create blog
PUT    /api/blog/update/:blogid           # Full update (all fields)
PATCH  /api/blog/patch-update/:blogid     # Partial update (only changed fields)
DELETE /api/blog/delete/:blogid           # Delete blog

Category Routes

GET    /api/category/all-category # Get all categories
GET    /api/category/:id          # Get single category
POST   /api/category/add          # Create category (Admin only)
PUT    /api/category/update/:id   # Update category (Admin only)
DELETE /api/category/delete/:id   # Delete category (Admin only)

Comment Routes

GET    /api/comment/get/:blogid   # Get comments for blog
POST   /api/comment/add            # Add comment
PUT    /api/comment/update/:id    # Update comment
DELETE /api/comment/delete/:id    # Delete comment

Draft Routes

GET    /api/drafts                # Get user's draft
POST   /api/drafts                # Save draft
PUT    /api/drafts                # Update draft
DELETE /api/drafts                # Delete draft

Notification Routes

GET    /api/notifications                # Get notifications
PATCH  /api/notifications/:id/read      # Mark a single notification as read
PATCH  /api/notifications/read-all      # Mark all notifications as read

Admin Routes

GET    /api/admin/dashboard                        # Get dashboard data
GET    /api/admin/download-report/:type/:format   # Download reports
GET    /api/admin/users                            # Get all users
PUT    /api/admin/ban-user/:id                     # Ban user
PUT    /api/admin/unban-user/:id                   # Unban user

🀝 Contributing

Contributions are always welcome! Please feel free to submit a Pull Request.

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ‘¨β€πŸ’» Author

Your Name


πŸ™ Acknowledgments

  • CKEditor team for the amazing rich text editor
  • Tailwind CSS for the utility-first CSS framework
  • All the open-source contributors
  • MongoDB for the robust database solution
  • Cloudinary for seamless image hosting

Made with ❀️ using the MERN Stack

⭐ Star this repo if you found it helpful!

About

WriteStack is a full-stack blogging platform built with the MERN stack, offering authentication, role-based access, rich text editing, and complete blog management.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors