{"id":28739711,"url":"https://github.com/abshar777/test-ec2","last_synced_at":"2025-06-16T06:10:40.416Z","repository":{"id":291442315,"uuid":"977485918","full_name":"Abshar777/test-ec2","owner":"Abshar777","description":null,"archived":false,"fork":false,"pushed_at":"2025-05-04T16:52:21.000Z","size":2343,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-04T17:39:00.239Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Abshar777.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-04T10:18:32.000Z","updated_at":"2025-05-04T16:52:24.000Z","dependencies_parsed_at":"2025-05-04T17:49:12.521Z","dependency_job_id":null,"html_url":"https://github.com/Abshar777/test-ec2","commit_stats":null,"previous_names":["abshar777/test-ec2"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Abshar777/test-ec2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Abshar777%2Ftest-ec2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Abshar777%2Ftest-ec2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Abshar777%2Ftest-ec2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Abshar777%2Ftest-ec2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Abshar777","download_url":"https://codeload.github.com/Abshar777/test-ec2/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Abshar777%2Ftest-ec2/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260109606,"owners_count":22960037,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-16T06:10:32.993Z","updated_at":"2025-06-16T06:10:40.408Z","avatar_url":"https://github.com/Abshar777.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🛒 Shop-Co\n\n**Shop-Co** is a modern, full-stack e-commerce platform featuring real-time order tracking, role-based authentication (Client, Delivery Boy, Admin), and a clean scalable architecture. Built with **Next.js**, **Node.js**, **Express**, **TypeScript**, **MongoDB**, **Redis**, and **WebSockets**, it offers a powerful and responsive shopping experience.\n\n---\n\n## 📌 Project Overview\n\n- **Frontend**: Next.js (React) + React Query\n- **Backend**: Node.js, Express.js, TypeScript\n- **Architecture**: Clean Architecture\n- **Authentication**: Role-based (Client, Delivery Boy, Admin)\n- **Real-time**: WebSocket (Socket.io) with Redis Pub/Sub\n- **Database**: MongoDB\n- **Caching**: Redis\n- **Deployment**: Self-hosted on EC2 (Frontend + Backend + Redis + MongoDB)\n\n---\n\n## 🧱 System Architecture Diagram\n\n```plaintext\n+----------------+       +----------------+       +----------------+\n|   Client App   | \u003c---\u003e |   API Server   | \u003c---\u003e |    MongoDB     |\n|  (Next.js)     |       | (Express.js)   |       |                |\n+----------------+       +----------------+       +----------------+\n        |                        |\n        |                        v\n        |                +----------------+\n        |                |     Redis      |\n        |                |  (Pub/Sub \u0026    |\n        |                |   Caching)     |\n        |                +----------------+\n        |                        ^\n        |                        |\n        v                        v\n+----------------+       +----------------+\n| WebSockets via |\u003c-----\u003e| Delivery App   |\n|   Socket.io    |       | (Real-time)    |\n+----------------+       +----------------+\n```\n\n\n## ⚙️ Stack Used\n\n- **Frontend**: Next.js, React, TypeScript, React Query  \n- **Backend**: Node.js, Express.js, TypeScript  \n- **Database**: MongoDB  \n- **Cache \u0026 Messaging**: Redis (with Pub/Sub)  \n- **Real-time**: Socket.io  \n- **Deployment**: Docker, Docker Compose, EC2 Instance (self-hosted)  \n\n---\n\n## 📁 Folder Structure\n\n```plaintext\nshop-co/\n├── frontend/ # Next.js frontend application\n├── backend/ # Express.js backend API\n├── admin/ # Admin dashboard \n└── docker-compose.yml # Docker Compose file\n```\n## 🚀 Setup Instructions\n\n### 🔐 SSH Login (for EC2 Hosting)\n\n```bash\nssh -i \"shop-co3.pem\" ubuntu@ec2-3-109-142-4.ap-south-1.compute.amazonaws.com\n```\n\n### 📥 Clone Repository\n\n```bash\ngit clone https://github.com/Abshar777/shop-co.git\ncd shop-co\n```\n\n### 🐳 Docker Compose Setup\n```bash\ndocker-compose up --build\n```\n\nThis command builds and starts the following services:\n\n- **Frontend**: Next.js application\n- **Backend**: Node.js + Express API\n- **Redis**: For caching and WebSocket message brokering\n- **MongoDB**: NoSQL database for storing user, product, and order data\n\n---\n\n### 🌍 Environment Variables\n\nEnsure the following `.env` files are created for proper configuration.\n\n#### Backend (`/backend/.env`)\n\n```env\nPORT=5000\nMONGO_URI=mongodb://mongo:27017/shopco\nJWT_SECRET=_jwt_secret\nREDIS_HOST=redis\nREDIS_PORT=6379\n```\n#### Frontend (/frontend/.env)\n\n```env\nNEXT_PUBLIC_BACKEND_URL=https://api.studioivory.art\n\nNEXTAUTH_SECRET= _next_auth_SCRETE\n\nNEXT_PUBLIC_FRONTEND_URL=https://studioivory.art\n```\n\n\n#### Admin (/admin/.env)\n\n```env\nNEXT_PUBLIC_BACKEND_URL=https://api.studioivory.art\n\nNEXTAUTH_SECRET= _next_auth_SCRETE\n\nNEXT_PUBLIC_FRONTEND_URL=https://studioivory.art\n```\n\n## 🌐 Hosting \u0026 Deployment Steps (on EC2)\n\n1. SSH into your EC2 instance:\n   - `ssh -i path-to-your-key.pem ubuntu@your-ec2-ip`\n\n2. Install Docker \u0026 Docker Compose (if not already installed):\n   - `sudo apt update`\n   - `sudo apt install docker.io docker-compose -y`\n\n3. Clone the repository:\n   - `git clone https://github.com/Abshar777/shop-co.git`\n   - `cd shop-co`\n\n4. Add your `.env` files in `frontend/` and `backend/`.\n\n5. Start the services:\n   - `docker-compose up -d`\n\n6. (Optional) Set up **NGINX** reverse proxy and **SSL** using **Certbot** for secure HTTPS connections.\n\n7. Ensure that the EC2 security group allows access to the following ports:\n   - **Port `80`** (HTTP)\n   - **Port `443`** (HTTPS)\n   - **Port `5000`** (Backend API - optional if using reverse proxy)\n\n---\n\n## 📡 WebSocket Flow Explanation\n\n- When a user places or updates an order, the backend emits a WebSocket event using `Socket.IO`.\n- The backend publishes the event message to **Redis** using **Pub/Sub**.\n- Redis broadcasts the message to all subscribed backend instances.\n- **Clients** (users, admins) and **delivery agents** receive the updates in real-time.\n\nThe WebSocket flow ensures that all relevant parties get the updates instantly:\n- The **user** sees the real-time order status.\n- The **admin** sees the real-time status of all orders.\n- The **delivery agent** is notified of any new deliveries or updates in their queue.\n\n---\n\n## 📈 Scaling Plan\n\n### 🔁 Redis for WebSocket Scaling\n\n- The current setup uses **Redis Pub/Sub** to manage real-time communication.\n- Redis Pub/Sub ensures that any message sent through WebSockets is broadcast across all backend instances.\n- This allows the system to scale horizontally by adding more backend instances without losing real-time data synchronization.\n\n### 🧱 Horizontal Scaling via Load Balancer\n\n- Deploy multiple backend containers using **Docker Swarm** or **Kubernetes**.\n- Use **NGINX** or **AWS ALB (Application Load Balancer)** to distribute traffic across multiple backend containers.\n- For session management, consider storing session tokens and user data in **Redis** for shared access.\n\n---\n\n## 🔮 Future Improvements (Optional)\n\n- **Payment gateway integration**: Add payment options like Stripe or Razorpay for processing payments.\n- **Order analytics dashboard**: Provide an admin panel to analyze order trends, delivery times, and more.\n- **Push notifications**: Implement push notifications for delivery agents, admins, and customers.\n- **Two-factor authentication (2FA)**: Implement multi-factor authentication for enhanced security.\n- **Improved logging \u0026 monitoring**: Integrate tools like **Prometheus** and **Grafana** to monitor system health and performance.\n- **Mobile application**: Develop a mobile app using **React Native** for users and delivery agents.\n- **CI/CD pipelines**: Set up **CI/CD pipelines** using GitHub Actions, GitLab CI, or Jenkins to automate builds and deployments.\n\n---\n\n## 📝 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabshar777%2Ftest-ec2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabshar777%2Ftest-ec2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabshar777%2Ftest-ec2/lists"}