A full-stack blog application built with the MERN stack (MongoDB, Express.js, React, Node.js) featuring user authentication, CRUD operations for blog posts, and modern UI with dark/light theme support.
- URL: [https://myblog-1-3sfd.onrender.com/]
- Platform: Render
- Status: β Deployed
- URL: https://myblog-xv15.onrender.com
- API Base: https://myblog-xv15.onrender.com/api
- Platform: Render
- Status: β Deployed
- Features
- Tech Stack
- Project Structure
- Getting Started
- Environment Variables
- Deployment
- CI/CD Pipeline
- Monitoring
- API Documentation
- Contributing
- License
- π User Authentication: JWT-based authentication with registration and login
- π Blog Posts: Create, read, update, and delete blog posts
- π·οΈ Categories: Organize posts by categories
- π Search: Search posts by title and content
- π Pagination: Efficient pagination for large datasets
- π Theme Support: Dark and light theme toggle
- π± Responsive Design: Mobile-first responsive design
- π‘οΈ Security: Input validation, rate limiting, CORS protection
- π Error Handling: Comprehensive error handling and logging
- π Real-time Updates: Optimistic UI updates
- π Performance: Optimized queries and caching strategies
- React 18 - UI library
- Vite - Build tool and dev server
- Tailwind CSS - Utility-first CSS framework
- React Router - Client-side routing
- Axios - HTTP client
- Context API - State management
- Node.js - Runtime environment
- Express.js - Web framework
- MongoDB - NoSQL database
- Mongoose - MongoDB ODM
- JWT - Authentication
- bcryptjs - Password hashing
- cors - Cross-origin resource sharing
- helmet - Security middleware
- GitHub Actions - CI/CD pipeline
- Render - Backend hosting
- Vercel - Frontend hosting
- MongoDB Atlas - Cloud database
βββ client/ # Frontend React application
β βββ src/
β β βββ components/ # React components
β β βββ contexts/ # React contexts
β β βββ hooks/ # Custom hooks
β β βββ services/ # API services
β β βββ assets/ # Static assets
β βββ public/ # Public assets
β βββ package.json
βββ server/ # Backend Node.js application
β βββ controllers/ # Route controllers
β βββ middleware/ # Custom middleware
β βββ models/ # Mongoose models
β βββ routes/ # API routes
β βββ package.json
βββ deployment/ # Deployment configuration
β βββ config/ # Platform-specific configs
β βββ scripts/ # Deployment scripts
βββ monitoring/ # Monitoring and health checks
βββ .github/workflows/ # GitHub Actions workflows
βββ env.example # Environment variables template
βββ README.md
- Node.js (v18 or higher)
- npm or yarn
- MongoDB Atlas account
- Git
-
Clone the repository
git clone https://github.com/yourusername/mern-blog-app.git cd mern-blog-app -
Install dependencies
# Install backend dependencies cd server npm install # Install frontend dependencies cd ../client npm install
-
Set up environment variables
# Copy environment template cp env.example .env # Edit .env file with your configuration nano .env
-
Start the development servers
# Start backend server (from server directory) npm run dev # Start frontend server (from client directory) npm run dev
-
Access the application
- Frontend: http://localhost:5173
- Backend API: http://localhost:5000
Copy env.example to .env and configure the following variables:
# Database
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/database
# Authentication
JWT_SECRET=your_super_secret_jwt_key
# Server
PORT=5000
NODE_ENV=development
# CORS
CORS_ORIGIN=http://localhost:5173# Rate Limiting
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100
# Logging
LOG_LEVEL=info
# JWT
JWT_EXPIRES_IN=7d-
Create a Render account at render.com
-
Connect your GitHub repository
-
Create a new Web Service
- Build Command:
cd server && npm ci && npm run build - Start Command:
cd server && npm start - Environment: Node
- Build Command:
-
Configure environment variables in Render dashboard:
MONGODB_URIJWT_SECRETNODE_ENV=productionCORS_ORIGIN=https://your-frontend-domain.vercel.app
-
Deploy - Render will automatically deploy on every push to main branch
-
Create a Vercel account at vercel.com
-
Import your GitHub repository
-
Configure build settings:
- Framework Preset: Vite
- Build Command:
npm run build - Output Directory:
dist - Install Command:
npm ci
-
Set environment variables:
VITE_API_URL=https://your-backend-domain.onrender.com/api
-
Deploy - Vercel will automatically deploy on every push to main branch
- Railway: railway.app
- Heroku: heroku.com
- DigitalOcean App Platform: digitalocean.com
- Netlify: netlify.com
- GitHub Pages: pages.github.com
- Firebase Hosting: firebase.google.com
This project uses GitHub Actions for continuous integration and deployment.
graph LR
A[Push to Main] --> B[Run Tests]
B --> C[Build Applications]
C --> D[Deploy Backend]
C --> E[Deploy Frontend]
D --> F[Health Checks]
E --> F
F --> G[Notify Team]
-
Backend CI
- Install dependencies
- Run linting
- Execute tests
- Build application
-
Frontend CI
- Install dependencies
- Run linting
- Execute tests
- Build application
- Upload build artifacts
-
Deployment
- Deploy backend to Render
- Deploy frontend to Vercel
- Run health checks
- Send notifications
The application includes automated health checks that monitor:
- Backend API endpoints
- Frontend accessibility
- Database connectivity
- Response times
Run health checks manually:
# Single health check
node monitoring/health-check.js --once
# Continuous monitoring
node monitoring/health-check.js --monitor-
Uptime Monitoring: Set up uptime monitoring with services like:
-
Error Tracking: Integrate error tracking with:
-
Performance Monitoring: Monitor application performance with:
POST /api/auth/register
Content-Type: application/json
{
"username": "john_doe",
"email": "john@example.com",
"password": "password123"
}POST /api/auth/login
Content-Type: application/json
{
"email": "john@example.com",
"password": "password123"
}GET /api/posts?page=1&limit=10&category=tech
Authorization: Bearer <token>POST /api/posts
Authorization: Bearer <token>
Content-Type: application/json
{
"title": "My First Blog Post",
"content": "This is the content of my blog post...",
"category": "60f7b3b3b3b3b3b3b3b3b3b3"
}PUT /api/posts/:id
Authorization: Bearer <token>
Content-Type: application/json
{
"title": "Updated Blog Post Title",
"content": "Updated content..."
}DELETE /api/posts/:id
Authorization: Bearer <token>GET /api/categoriesPOST /api/categories
Authorization: Bearer <token>
Content-Type: application/json
{
"name": "Technology",
"description": "Tech-related posts"
}- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow the existing code style
- Write tests for new features
- Update documentation as needed
- Ensure all tests pass before submitting PR
This project is licensed under the MIT License - see the LICENSE file for details.
- React - A JavaScript library for building user interfaces
- Express.js - Fast, unopinionated, minimalist web framework
- MongoDB - The database for modern applications
- Tailwind CSS - A utility-first CSS framework
- Vite - Next Generation Frontend Tooling
If you have any questions or need help with the application:
- Issues: GitHub Issues
- Email: your-email@example.com
- Documentation: Wiki
Made with β€οΈ by [Your Name]