A production-grade Instagram clone built with Node.js, Express, TypeORM, PostgreSQL, React, and TypeScript.
├── backend/ # Node.js/Express backend
│ ├── src/
│ │ ├── controllers/ # API controllers
│ │ ├── services/ # Business logic
│ │ ├── routes/ # API routes
│ │ ├── middleware/ # Express middleware
│ │ ├── models/ # TypeORM entities
│ │ ├── utils/ # Utility functions
│ │ └── config/ # Configuration
│ ├── database/
│ │ └── migrations/ # TypeORM migrations
│ └── tests/ # Test files
├── frontend/ # React/TypeScript frontend
│ ├── src/
│ │ ├── pages/ # Page components
│ │ ├── components/ # Reusable components
│ │ ├── store/ # Redux store
│ │ ├── services/ # API client
│ │ ├── utils/ # Utility functions
│ │ └── styles/ # CSS and Tailwind
│ └── public/ # Static assets
└── docker-compose.yml # Container orchestration
- Node.js v18+
- Docker & Docker Compose
- PostgreSQL 15+
- Redis 7+
- npm or yarn
# Clone the repository
git clone <repo-url>
cd instagram-clone
# Copy environment files
cp backend/.env.example backend/.env
cp frontend/.env.example frontend/.env
# Start services with Docker Compose
docker-compose up -d
# Wait for services to be ready
sleep 10
# Run migrations
docker-compose exec backend npm run migration:run
# Access the application
# Frontend: http://localhost:3000
# Backend: http://localhost:5000
# API Docs: http://localhost:5000/api-docscd backend
# Install dependencies
npm install
# Create .env file
cp .env.example .env
# Edit .env with your configuration
# Make sure PostgreSQL and Redis are running locally
# Run migrations
npm run migration:generate
npm run migration:run
# Start development server
npm run devcd frontend
# Install dependencies
npm install
# Create .env file
cp .env.example .env
# Start development server
npm run devRequired variables:
DB_HOST,DB_PORT,DB_USERNAME,DB_PASSWORD,DB_NAMEREDIS_HOST,REDIS_PORTJWT_ACCESS_SECRET,JWT_REFRESH_SECRETAWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,S3_BUCKET_NAMEEMAIL_USER,EMAIL_PASSWORDFRONTEND_URL
Required variables:
VITE_API_URL: Backend API base URLVITE_SOCKET_URL: WebSocket server URL
The application includes 12 main tables:
- Users
- Posts
- Likes
- Comments
- Follows
- Messages
- Conversations
- Notifications
- Stories
- Story_Views
- Hashtags
- Post_Hashtags
Once the backend is running, access the Swagger API documentation at:
http://localhost:5000/api-docs
cd backend
# Run all tests
npm test
# Run tests with coverage
npm test:cov
# Run tests in watch mode
npm test:watchcd frontend
# Run all tests
npm test
# Run tests with coverage
npm test:cov
# Run tests in watch mode
npm test:watch- User registration with email validation
- Login with email/password
- JWT token-based authentication
- Email verification with OTP
- Password reset functionality
- Logout
- View user profiles
- Edit profile information
- Follow/unfollow users
- View followers/following
- Private/public account toggle
- Create posts (1-10 images)
- View home feed
- Edit post captions
- Delete posts
- Post detail page
- Like/unlike posts
- Comment on posts
- Edit/delete comments
- Reply to comments
- WebSocket integration
- Live like counts
- Live comments
- Follow notifications
- Real-time feed updates
- Bcrypt password hashing (12 rounds)
- JWT token-based authentication
- CSRF protection
- Rate limiting
- XSS protection
- SQL injection prevention (via TypeORM)
- Input validation with Joi
- Secure headers with Helmet
- CORS configuration
- FCP: < 1.5s
- LCP: < 2.5s
- TTI: < 3s
- Bundle: < 150KB (gzipped)
- Lighthouse: > 90
- API response (p95): < 200ms
- DB query (p95): < 100ms
- Feed load: < 500ms
- Cache hit rate: > 80%
docker-compose -f docker-compose.yml build
# Tag for registry
docker tag instagram-clone-backend:latest <registry>/instagram-backend:latest
docker tag instagram-clone-frontend:latest <registry>/instagram-frontend:latest
# Push to registry
docker push <registry>/instagram-backend:latest
docker push <registry>/instagram-frontend:latest- Update all
.envfiles with production values - Ensure HTTPS/SSL is configured
- Set
NODE_ENV=production - Configure AWS credentials and S3 bucket
- Set strong JWT secrets
- Enable database SSL
- Configure CloudFront CDN
main: Production-ready codedevelop: Integration branchfeature/*: Feature brancheshotfix/*: Bug fixes
feat(scope): description
fix(scope): description
refactor(scope): description
test(scope): description
docs(scope): description
# Backend
cd backend && npm run lint
# Frontend
cd frontend && npm run lint
# Fix linting issues
cd backend && npm run lint:fix
cd frontend && npm run lint:fixBoth backend and frontend use TypeScript with strict mode enabled.
# Ensure PostgreSQL is running
# Check DB credentials in .env
# Verify database exists
psql -U postgres -d postgres -c "SELECT 1"# Ensure Redis is running
# Check Redis host/port in .env
# Test connection
redis-cli ping# Find and kill process using port
lsof -i :5000 # backend
lsof -i :3000 # frontend
lsof -i :5432 # postgres- Create feature branch:
git checkout -b feature/feature-name - Commit changes:
git commit -am 'feat(scope): description' - Push branch:
git push origin feature/feature-name - Submit pull request
MIT
For issues and questions, please create an issue in the repository.