A full-stack, production-ready blogging platform built with microservices architecture, featuring AI-powered content generation, real-time caching, and automated CI/CD deployment to AWS EC2.
- Overview
- Architecture
- Tech Stack
- Features
- Getting Started
- Deployment
- API Endpoints
- Environment Variables
- Contributing
This project demonstrates a production-grade microservices architecture with:
- 3 Independent Backend Services (User, Author, Blog)
- AI-Powered Content Generation using Google Gemini
- Event-Driven Communication via RabbitMQ
- Redis Caching for 70% faster response times
- Multi-Database Strategy (MongoDB + PostgreSQL)
- Automated CI/CD with GitHub Actions
- Production Deployment on AWS EC2 with SSL
βββββββββββββββββββ
β Next.js Client β
ββββββββββ¬βββββββββ
β
ββββββΌβββββ
β Nginx β (Reverse Proxy + SSL)
ββββββ¬βββββ
β
ββββββ΄ββββββββββββββββββββββ
β β
βββββΌβββββ ββββββΌβββββ ββββββΌβββββ
β User β β Author β β Blog β
β :5001 β β :5002 β β :5003 β
βββββ¬βββββ ββββββ¬βββββ ββββββ¬βββββ
β β β
β ββββββΌββββββββββββββΌβββββ
β β RabbitMQ β
β βββββββββββββββββββββββββ
β β β
βββββΌβββββ βββββΌβββββ βββββΌβββββ
βMongoDB β β Neon β β Redis β
β Atlas β β PG β β Cache β
ββββββββββ ββββββββββ ββββββββββ
| Service | Port | Database | Purpose |
|---|---|---|---|
| User | 5001 | MongoDB Atlas | Authentication, profiles, Google OAuth |
| Author | 5002 | Neon PostgreSQL | Blog CRUD, AI generation, image uploads |
| Blog | 5003 | Neon PostgreSQL | Public reading, caching, comments |
- Framework: Next.js 16.1.1 (App Router)
- Language: TypeScript 5.x
- UI: React 19.2.3 + Tailwind CSS 4.x
- Components: Radix UI
- Rich Text: Jodit React 5.2.38
- Auth: Google OAuth (@react-oauth/google)
- Runtime: Node.js 20.x
- Framework: Express.js 5.2.1
- Language: TypeScript 5.9.3
- Validation: Zod 3.22.4
- Security: Helmet, CORS, JWT
- MongoDB Atlas: User profiles (Mongoose 9.0.2)
- Neon PostgreSQL: Blog data (Serverless)
- Redis 5.10.0: Caching layer
- Containerization: Docker + Docker Compose
- Web Server: Nginx (Alpine)
- Message Broker: RabbitMQ 3
- Cloud: AWS EC2 (Ubuntu)
- SSL: Let's Encrypt (Certbot)
- CI/CD: GitHub Actions
- Google Gemini AI:
@google/genai1.34.0@google/generative-ai0.24.1- Model:
gemini-2.5-flash
- Smart Title Generation: Generate catchy titles from descriptions
- Auto Description: Create SEO-friendly descriptions (< 30 words)
- Grammar Correction: Fix grammar while preserving HTML formatting
- Google OAuth integration
- JWT-based session management
- Protected routes with middleware
- Cloudinary integration for image uploads
- Support for up to 50MB files
- Automatic image optimization
- 70% faster with Redis caching
- Database query optimization
- Nginx gzip compression
- Lazy loading components
- Event-driven cache invalidation
- RabbitMQ message queue
- Cross-service communication
- Automated CI/CD pipeline
- Zero-downtime deployments
- Docker containerization
- SSL auto-renewal
- Node.js 20.x
- Docker & Docker Compose
- MongoDB Atlas account
- Neon PostgreSQL account
- Cloudinary account
- Google OAuth credentials
- Gemini API key
-
Clone the repository
git clone https://github.com/yourusername/micro-blog.git cd micro-blog -
Set up environment variables
Create
.envfiles in each service directory:services/user/.env
PORT=5001 MONGO_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret GOOGLE_CLIENT_ID=your_google_client_id GOOGLE_CLIENT_SECRET=your_google_client_secret CLOUDINARY_CLOUD_NAME=your_cloudinary_name CLOUDINARY_API_KEY=your_cloudinary_key CLOUDINARY_API_SECRET=your_cloudinary_secret
services/author/.env
PORT=5002 DATABASE_URL=your_neon_postgres_url JWT_SECRET=your_jwt_secret CLOUDINARY_CLOUD_NAME=your_cloudinary_name CLOUDINARY_API_KEY=your_cloudinary_key CLOUDINARY_API_SECRET=your_cloudinary_secret GEMINI_API_KEY=your_gemini_api_key RABBITMQ_URL=amqp://admin:admin123@localhost:5672
services/blog/.env
PORT=5003 DATABASE_URL=your_neon_postgres_url JWT_SECRET=your_jwt_secret REDIS_URL=redis://localhost:6379 RABBITMQ_URL=amqp://admin:admin123@localhost:5672 USER_SERVICE=http://localhost:5001
frontend/.env.local
NEXT_PUBLIC_USER_SERVICE=http://localhost:5001 NEXT_PUBLIC_AUTHOR_SERVICE=http://localhost:5002 NEXT_PUBLIC_BLOG_SERVICE=http://localhost:5003 NEXT_PUBLIC_GOOGLE_CLIENT_ID=your_google_client_id
-
Start RabbitMQ (Required for microservices)
docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 \ -e RABBITMQ_DEFAULT_USER=admin \ -e RABBITMQ_DEFAULT_PASS=admin123 \ rabbitmq:3-management
-
Install dependencies and run services
Option A: Using Docker Compose (Recommended)
cd services docker compose up -d --buildOption B: Manual setup
# Terminal 1 - User Service cd services/user npm install npm run dev # Terminal 2 - Author Service cd services/author npm install npm run dev # Terminal 3 - Blog Service cd services/blog npm install npm run dev # Terminal 4 - Frontend cd frontend npm install npm run dev
-
Access the application
- Frontend: http://localhost:3000
- User API: http://localhost:5001
- Author API: http://localhost:5002
- Blog API: http://localhost:5003
- RabbitMQ Management: http://localhost:15672 (admin/admin123)
- API Base: https://api-microblog.backend-portfolio-api.online
- User Service: https://api-microblog.backend-portfolio-api.online/user/
- Author Service: https://api-microblog.backend-portfolio-api.online/author/
- Blog Service: https://api-microblog.backend-portfolio-api.online/blog/
The project uses GitHub Actions for automated deployment:
-
CI Workflows (on push to service directories):
user-ci.yml- Builds and tests User serviceauthor-ci.yml- Builds and tests Author serviceblog-ci.yml- Builds and tests Blog service
-
CD Workflow (after successful CI on main branch):
deploy-cd.yml- Deploys to AWS EC2- Pulls latest code
- Rebuilds Docker containers
- Zero-downtime deployment
# SSH into EC2
ssh -i "your-key.pem" ubuntu@your-ec2-ip
# Navigate to project
cd ~/micro-blog
# Pull latest changes
git pull origin main
# Deploy services
cd services
docker compose down --remove-orphans
docker compose up -d --build
docker image prune -fPOST /api/v1/login # Google OAuth login
GET /api/v1/me # Get current user profile
GET /api/v1/user/:id # Get user by ID
GET /api/v1/health # Health check
POST /api/v1/blog/new # Create new blog (auth required)
PUT /api/v1/blog/:id # Update blog (auth required)
DELETE /api/v1/blog/:id # Delete blog (auth required)
POST /api/v1/ai/title # Generate/fix blog title
POST /api/v1/ai/description # Generate/fix description
POST /api/v1/ai/blog # Fix blog grammar
GET /api/v1/health # Health check
GET /api/v1/blog/all # Get all blogs (cached)
GET /api/v1/blog/:id # Get single blog (cached)
GET /api/v1/health # Health check
| Variable | Description | Example |
|---|---|---|
PORT |
Service port | 5001, 5002, 5003 |
JWT_SECRET |
Secret for JWT signing | your-secret-key |
| Variable | Description |
|---|---|
MONGO_URI |
MongoDB connection string |
GOOGLE_CLIENT_ID |
Google OAuth client ID |
GOOGLE_CLIENT_SECRET |
Google OAuth secret |
CLOUDINARY_CLOUD_NAME |
Cloudinary cloud name |
CLOUDINARY_API_KEY |
Cloudinary API key |
CLOUDINARY_API_SECRET |
Cloudinary API secret |
| Variable | Description |
|---|---|
DATABASE_URL |
Neon PostgreSQL connection |
GEMINI_API_KEY |
Google Gemini API key |
RABBITMQ_URL |
RabbitMQ connection URL |
CLOUDINARY_* |
Same as User service |
| Variable | Description |
|---|---|
DATABASE_URL |
Neon PostgreSQL connection |
REDIS_URL |
Redis connection URL |
RABBITMQ_URL |
RabbitMQ connection URL |
USER_SERVICE |
User service URL |
- 70% reduction in database queries (Redis caching)
- 60% smaller Docker images (multi-stage builds)
- 40% bandwidth reduction (Nginx gzip)
- 3x faster blog queries (database indexing)
- β Helmet.js security headers
- β CORS whitelist validation
- β JWT authentication
- β Environment variable protection
- β HTTPS-only in production
- β Input validation with Zod
- β SQL injection prevention
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the ISC License.
- Google Gemini AI for content generation
- Neon for serverless PostgreSQL
- Cloudinary for image management
- MongoDB Atlas for user database
- AWS for hosting infrastructure
Project Link: https://github.com/vedchaudhari/micro-blog
Live Link: https://blogmicro.vercel.app
Built with β€οΈ using modern web technologies and microservices best practices by Ved Chaudhari