{"id":49355148,"url":"https://github.com/dedslash/buy-02","last_synced_at":"2026-04-27T13:02:33.375Z","repository":{"id":350926093,"uuid":"1200602192","full_name":"DedSlash/buy-02","owner":"DedSlash","description":"E-commerce with cart \u0026 order management — 5 microservices, Spring Boot, Kafka, Docker","archived":false,"fork":false,"pushed_at":"2026-04-12T19:13:17.000Z","size":6713,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-12T21:13:14.646Z","etag":null,"topics":["angular","docker","java","kafka","microservices","mongodb","springboot"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DedSlash.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-03T15:56:07.000Z","updated_at":"2026-04-12T19:13:26.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/DedSlash/buy-02","commit_stats":null,"previous_names":["dedslash/buy-02"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/DedSlash/buy-02","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DedSlash%2Fbuy-02","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DedSlash%2Fbuy-02/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DedSlash%2Fbuy-02/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DedSlash%2Fbuy-02/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DedSlash","download_url":"https://codeload.github.com/DedSlash/buy-02/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DedSlash%2Fbuy-02/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32337274,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T23:26:28.701Z","status":"online","status_checked_at":"2026-04-27T02:00:06.769Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["angular","docker","java","kafka","microservices","mongodb","springboot"],"created_at":"2026-04-27T13:02:32.518Z","updated_at":"2026-04-27T13:02:33.361Z","avatar_url":"https://github.com/DedSlash.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Buy-02 - E-commerce Microservices Platform\n\n![Database Design](Database-Design.png)\n\n## 📋 Table of Contents\n- [Overview](#overview)\n- [Architecture](#architecture)\n- [Tech Stack](#tech-stack)\n- [Prerequisites](#prerequisites)\n- [Getting Started](#getting-started)\n- [Configuration](#configuration)\n- [API Documentation](#api-documentation)\n- [Security](#security)\n- [Tests](#tests)\n- [Troubleshooting](#troubleshooting)\n- [Environment Variables](#environment-variables)\n- [Frontend (Angular)](#frontend-angular)\n\n## 🎯 Overview\n\nBuy-02 is a full-featured e-commerce platform built with a microservices architecture using Spring Boot and Angular. The platform supports:\n\n- **User Registration**: Clients and Sellers with avatar upload for sellers (max 2MB)\n- **Secure Authentication**: JWT with role management and internal service tokens\n- **Product Management**: CRUD restricted to authenticated sellers\n- **Cart Management**: Add/update/remove items with real-time stock validation\n- **Order Management**: Create, track, cancel, and reorder with client/seller workflow\n- **Media Management**: Image upload with validation (JPEG, PNG, WebP - max 2MB)\n- **Inter-service Communication**: Apache Kafka for event-driven messaging\n- **User Interface**: Responsive Angular dashboard\n\n## 🏗️ Architecture\n\n### Microservices \u0026 Ports\n```\n📦 Buy-02 Architecture\n├── 🔍 Discovery Server (Eureka)     - Port 8761\n├── 🚪 Gateway Service (HTTPS)       - Port 8443\n├── 👥 User Service                  - Port 8081\n├── 📦 Product Service               - Port 8082\n├── 🖼️  Media Service                 - Port 8083\n├── 🛒 Cart Service                  - Port 8084\n├── 📋 Order Service                 - Port 8085\n├── 🌐 Frontend (Angular)            - Port 4200\n├── 📊 MongoDB User DB               - Port 27017 (user_db)\n├── 📊 MongoDB Product DB            - Port 27018 (product_db)\n├── 📊 MongoDB Media DB              - Port 27019 (media_db)\n├── 📊 MongoDB Cart DB               - Port 27020 (cart_db)\n├── 📊 MongoDB Order DB              - Port 27021 (order_db)\n├── 🔄 Kafka Broker                  - Port 9092\n└── 🐘 Zookeeper                     - Port 2181\n```\n\n### Communication\n- **Service Discovery**: Netflix Eureka (Spring Cloud 2025.0.0)\n- **API Gateway**: Spring Cloud Gateway with SSL/HTTPS\n- **Message Broker**: Apache Kafka 7.5.3 for inter-service events\n- **Databases**: Isolated MongoDB instance per service\n- **Authentication**: JWT + internal tokens for service-to-service communication\n\n## 🛠️ Tech Stack\n\n### Backend\n- **Spring Boot 3.5.3** (Java 17)\n- **Spring Cloud 2025.0.0** (Eureka Client, Gateway)\n- **Spring Security** + JWT (jjwt 0.11.5)\n- **Spring Data MongoDB**\n- **Apache Kafka** with Zookeeper\n- **Springdoc OpenAPI 2.7.0** (Swagger)\n- **Bucket4j 7.6.0** (Rate Limiting)\n- **Spring Validation**\n- **Docker \u0026 Docker Compose**\n\n### Infrastructure\n- **MongoDB** (latest)\n- **Confluent Kafka \u0026 Zookeeper**\n- **SSL/HTTPS** with PKCS12 certificates\n\n## 📋 Prerequisites\n\n- **Docker** and **Docker Compose**\n- **Java 17** (for local development)\n- **Maven 3.6+** (to build services)\n- **mkcert** (for SSL certificates in development)\n- **Node.js** (LTS version, e.g., 18.x or 20.x)\n- **npm** (comes with Node.js)\n- **Angular CLI** (`npm install -g @angular/cli`)\n\n## 🚀 Getting Started\n\n**Clone the repository**\n```bash\ngit clone https://github.com/DedSlash/buy-02.git\ncd buy-02\n```\n\n### Option 1: Docker via script (Quick Start)\n\n1. **Make scripts executable**\n```bash\nchmod +x commit.sh run_microservice.sh start-project.sh stop-project.sh toggle-config.sh run-all-tests.sh\n```\n\n2. **Start the project**\n```bash\n./start-project.sh\n```\n\n3. **Stop the project**\n```bash\n./stop-project.sh\n```\n\n### Option 2: Docker manual (Recommended)\n\n1. **Build and start all services**\n```bash\ndocker-compose up --build\n```\n\n2. **Verify services are running**\n```bash\n# Eureka Dashboard\nhttp://localhost:8761\n\n# Gateway (HTTPS only)\nhttps://localhost:8443\n\n# Centralized API Documentation\nhttps://localhost:8443/swagger-ui.html\n```\n\n3. **Start the Angular frontend**\n```bash\ncd frontend\nnpm install\nnpm start\n```\n\n### Option 3: Manual start (Development)\n\n```bash\n./run_microservice.sh\n```\n\n## ⚙️ Configuration\n\n### SSL/HTTPS Setup\n\nThe project enforces **HTTPS** via the Gateway Service using PKCS12 certificates.\n\n#### Generating a certificate for local development\n\n1. **Install mkcert**\n```bash\n# Ubuntu/Debian\nsudo apt install libnss3-tools mkcert\n\n# macOS\nbrew install mkcert\n```\n\n2. **Create and install the certificate**\n```bash\nmkcert localhost\n\nopenssl pkcs12 -export \\\n  -in localhost.pem \\\n  -inkey localhost-key.pem \\\n  -out keystore.p12 \\\n  -name springboot \\\n  -password pass:changeit\n\nmv keystore.p12 backend/api/gateway-service/src/main/resources/\n```\n\n### MongoDB Databases\n\nEach service has its own isolated database:\n\n| Service | Database | Port | Container |\n|---------|----------|------|-----------|\n| User Service | `user_db` | 27017 | `user-mongodb` |\n| Product Service | `product_db` | 27018 | `product-mongodb` |\n| Media Service | `media_db` | 27019 | `media-mongodb` |\n| Cart Service | `cart_db` | 27020 | `cart-mongodb` |\n| Order Service | `order_db` | 27021 | `order-mongodb` |\n\n### Kafka Configuration\n\n- **Bootstrap Servers**: `kafka:29092` (internal) / `localhost:9092` (external)\n- **Topics**: Auto-creation enabled\n- **Consumer Groups**:\n  - `user-service-group`\n  - `product-service-group`\n  - `media-service-group`\n  - `cart-service-group`\n  - `order-service-group`\n\n## 📚 API Documentation\n\n### Centralized Swagger UI\n- **Gateway Swagger**: https://localhost:8443/swagger-ui.html\n- Aggregates all services: User, Product, Media, Cart, Order\n\n### Per-service Swagger (development)\n| Service | URL |\n|---------|-----|\n| User | http://localhost:8081/swagger-ui.html |\n| Product | http://localhost:8082/swagger-ui.html |\n| Media | http://localhost:8083/swagger-ui.html |\n| Cart | http://localhost:8084/swagger-ui.html |\n| Order | http://localhost:8085/swagger-ui.html |\n\n### Frontend Documentation (hot-reload)\n```bash\ncd frontend\nnpm install\nnpm run serve-docs\n```\nAvailable at: [http://localhost:4212/](http://localhost:4212/)\n\n### Gateway Routes\n\n| Route | Target Service | Description |\n|-------|---------------|-------------|\n| `/api/auth/**` | user-service | Authentication (with rate limiting) |\n| `/api/users/**` | user-service | User management |\n| `/api/admin/**` | user-service | Administration |\n| `/avatars/**` | user-service | Avatar images |\n| `/api/products/**` | product-service | Product CRUD |\n| `/api/media/**` | media-service | Media upload/management |\n| `/productsImages/**` | media-service | Product images |\n| `/api/cart/**` | cart-service | Cart management |\n| `/api/orders/**` | order-service | Order management (CLIENT) |\n| `/api/seller/orders/**` | order-service | Order management (SELLER) |\n\n### Main Endpoints\n\n#### User Service (Port 8081)\n```bash\nPOST   /api/auth/register         # Register (CLIENT/SELLER)\nPOST   /api/auth/login            # Login (returns JWT)\nGET    /api/users/me              # Get current user profile\nPUT    /api/users/me              # Update profile\nPOST   /api/users/avatar          # Upload avatar (SELLER)\nGET    /avatars/{filename}        # Retrieve avatar\n```\n\n#### Product Service (Port 8082)\n```bash\nGET    /api/products              # Public product list\nPOST   /api/products              # Create product (SELLER only)\nGET    /api/products/{id}         # Product detail\nPUT    /api/products/{id}         # Update product (owner only)\nDELETE /api/products/{id}         # Delete product (owner only)\n```\n\n#### Media Service (Port 8083)\n```bash\nPOST   /api/media/upload              # Upload product image (max 2MB, JPEG/PNG/WebP)\nGET    /api/media/{id}                # Image metadata\nGET    /productsImages/{filename}     # Retrieve image\nDELETE /api/media/{id}               # Delete image (owner only)\n```\n\n#### Cart Service (Port 8084)\n```bash\nGET    /api/cart/mycart                           # View cart (CLIENT)\nPOST   /api/cart/add/item/{productId}             # Add item to cart\nDELETE /api/cart/remove/{itemId}                  # Remove item\nPUT    /api/cart/update/{itemId}                  # Update quantity\nDELETE /api/cart/clear                            # Empty cart\n```\n\n#### Order Service (Port 8085)\n\n**CLIENT routes** (`/api/orders`)\n```bash\nPOST   /api/orders/create                    # Create order from cart\nPOST   /api/orders/reorder/{oldOrderId}      # Reorder from previous order\nGET    /api/orders/myorders                  # View all orders\nPUT    /api/orders/cancel/{orderId}          # Cancel order (if pending)\nDELETE /api/orders/remove/{orderId}          # Remove from history\nGET    /api/orders/total-spent               # View total spent\n```\n\n**SELLER routes** (`/api/seller/orders`)\n```bash\nPUT    /api/seller/orders/confirm-item/{itemId}          # Confirm/cancel item\nGET    /api/seller/orders/my-sales                       # View all sales\nPUT    /api/seller/orders/{itemId}/delivery-status       # Update delivery status\nGET    /api/seller/orders/total-earned                   # View total earned\n```\n\n## 🛡️ Security\n\n- **Mandatory HTTPS**: All communication via SSL/TLS\n- **JWT Authentication**: Tokens with 1-hour expiration\n- **Role-Based Access Control**: CLIENT vs SELLER\n- **Internal Tokens**: Secure service-to-service communication\n- **Password Hashing**: BCrypt via Spring Security\n- **File Validation**: JPEG/PNG/WebP only, max 2MB per file, 10MB per request\n- **Rate Limiting**: Applied on `/api/auth/**`\n- **CORS Configuration**: Secured headers\n- **Real-time Stock Validation**: Before cart addition and order creation\n\n\u003e ⚠️ Never commit real secrets. Use environment variables or a secrets manager (e.g. HashiCorp Vault) in production. See `.env.example` for the expected variables.\n\n## 🧪 Tests\n\n```bash\n# Run tests per service\ncd backend/api/user \u0026\u0026 ./mvnw test\ncd backend/api/product \u0026\u0026 ./mvnw test\ncd backend/api/media \u0026\u0026 ./mvnw test\ncd backend/api/cart \u0026\u0026 ./mvnw test\ncd backend/api/order \u0026\u0026 ./mvnw test\n\n# Or run all tests at once\n./run-all-tests.sh\n```\n\n## 🐛 Troubleshooting\n\n### Services not starting\n```bash\n# Check ports in use\nnetstat -tulpn | grep -E \":(8761|8443|8081|8082|8083|8084|8085)\"\n\n# Full Docker cleanup\ndocker-compose down -v\ndocker system prune -af\ndocker volume prune -f\n```\n\n### MongoDB issues\n```bash\ndocker logs user-mongodb\ndocker logs cart-mongodb\n\n# Direct DB access\ndocker exec -it user-mongodb mongosh -u root -p $MONGO_ROOT_PASSWORD\n```\n\n### SSL/HTTPS errors\n```bash\n# Check certificate\nkeytool -list -keystore backend/api/gateway-service/src/main/resources/keystore.p12 -storepass changeit\n```\n\n### Kafka not working\n```bash\ndocker-compose restart zookeeper kafka\ndocker exec -it kafka kafka-topics --bootstrap-server localhost:9092 --list\n```\n\n### Useful logs\n```bash\ndocker-compose logs -f                        # All services\ndocker-compose logs -f user-service           # Specific service\ndocker-compose logs -f --tail=100 gateway-service\n```\n\n## 🔧 Environment Variables\n\nCreate a `.env` file at the root of the project based on `.env.example`:\n\n```env\n# JWT\nJWT_SECRET=your-very-long-and-secure-jwt-secret-minimum-256-bits\n\n# MongoDB\nMONGO_ROOT_USERNAME=root\nMONGO_ROOT_PASSWORD=your-secure-password\n\n# Kafka\nKAFKA_BOOTSTRAP_SERVERS=kafka:29092\n\n# SSL\nSSL_KEYSTORE_PASSWORD=your-keystore-password\n\n# Internal service token\nINTERNAL_TOKEN=your-secure-internal-token\n\n# Eureka\nEUREKA_DEFAULT_ZONE=http://discovery-server:8761/eureka\n```\n\n## 📊 Service Status\n\n| Service | Port | Health Check | Swagger |\n|---------|------|--------------|---------|\n| Discovery Server | 8761 | http://localhost:8761 | — |\n| Gateway Service | 8443 | https://localhost:8443/actuator/health | https://localhost:8443/swagger-ui.html |\n| User Service | 8081 | http://localhost:8081/actuator/health | http://localhost:8081/swagger-ui.html |\n| Product Service | 8082 | http://localhost:8082/actuator/health | http://localhost:8082/swagger-ui.html |\n| Media Service | 8083 | http://localhost:8083/actuator/health | http://localhost:8083/swagger-ui.html |\n| Cart Service | 8084 | http://localhost:8084/actuator/health | http://localhost:8084/swagger-ui.html |\n| Order Service | 8085 | http://localhost:8085/actuator/health | http://localhost:8085/swagger-ui.html |\n| Frontend | 4200 | http://localhost:4200 | — |\n\n## 📁 Volume Structure\n\n```\n./uploads/\n├── avatars/           # User Service - User avatars\n└── productsImages/    # Media Service - Product images\n```\n\n## 🔄 Order Workflow\n\n### Order Lifecycle\n\n#### 1️⃣ Order Creation (CLIENT)\n- Client creates order from cart\n- Automatic stock validation\n- Unique order number generated (`ORD-YYYYMMDD-XXXXXX`)\n- All items initially set to `pending`\n- Cart automatically cleared after creation\n\n#### 2️⃣ Item Confirmation (SELLER)\n- Each seller sees their own items\n- Seller can **confirm** or **cancel** each item individually\n- **Confirm**: stock is automatically decremented\n- **Cancel**: item marked as cancelled, stock unaffected\n\n#### 3️⃣ Delivery Management (SELLER)\n- After confirmation, seller manages delivery status:\n  - `non_livre`: Awaiting delivery\n  - `livre`: Delivered to client\n  - `annule`: Delivery cancelled (stock restocked)\n\n#### 4️⃣ Order Cancellation (CLIENT)\n- Client can cancel if **all** items are still `pending`\n- Once any item is confirmed, full cancellation is blocked\n- Client can only remove completed orders (delivered or cancelled) from history\n\n#### 5️⃣ Reorder (CLIENT)\n- Client can reorder from a previous order\n- System checks current product availability\n- Available items added to cart with stock-adjusted quantities\n\n### Order Statuses\n\n| Status | Description |\n|--------|-------------|\n| `pending` | Awaiting seller confirmation |\n| `confirmed` | All items confirmed by sellers |\n| `canceled` | Order cancelled (all items cancelled) |\n| `removed` | Removed from client history |\n\n### Delivery Statuses\n\n| Status | Description |\n|--------|-------------|\n| `non_livre` | Awaiting delivery |\n| `livre` | Delivered to client |\n| `annule` | Delivery cancelled |\n\n### Stock Management\n\n| Action | Stock Effect |\n|--------|-------------|\n| Add to cart | Validation only, no reservation |\n| Create order | Validation only, no reservation |\n| Seller confirms | Stock decremented automatically |\n| Delivery cancelled | Stock restocked automatically |\n\n## 🌐 Frontend (Angular)\n\n### Key Technologies\n- **Angular** (latest stable)\n- **TypeScript**\n- **RxJS** for async data streams\n- **Angular Material** (MatButtonToggleModule, MatIconModule, MatDialogModule)\n- **HTML5 \u0026 SCSS**\n\n### Features\n- Secure auth with role-based access (Client / Seller)\n- Profile management with avatar upload\n- Product list with filtering, search, and sorting\n- Product detail view with images and seller info\n- Seller product management (add, edit, delete + media)\n- Real-time cart with stock validation\n- Full order management (create, track, cancel, reorder)\n- Seller dashboard (confirm items, manage delivery)\n- Toast notification system\n\n### Frontend Structure\n```\nfrontend/\n├── src/\n│   ├── app/\n│   │   ├── auth/          # Sign-in, sign-up components\n│   │   ├── cart/          # Cart management\n│   │   ├── error/         # Toast error component\n│   │   ├── models/        # TypeScript interfaces (User, Product, Cart, Order...)\n│   │   ├── navbar/        # Navigation component\n│   │   ├── orders/        # Order management\n│   │   ├── products/      # Product list, card, circular-image\n│   │   ├── profile/       # Profile \u0026 update form\n│   │   ├── seller/        # Seller dashboard, product \u0026 order management\n│   │   ├── services/      # API services (auth, user, product, cart, order...)\n│   │   └── utils/         # Utility functions\n│   ├── assets/            # Static files\n│   ├── environments/      # Dev \u0026 prod config\n│   └── styles.css         # Global styles\n```\n\n### Start the Frontend\n```bash\ncd frontend\nnpm install\nng serve --open\n```\nAvailable at `http://localhost:4200` — connects automatically to the Gateway on `https://localhost:8443`.\n\n---\n\n**Author**: [DedSlash](https://github.com/DedSlash)  \n**Repository**: [github.com/DedSlash/buy-02](https://github.com/DedSlash/buy-02)  \n**Version**: 2.0.0 | **Spring Boot**: 3.5.3 | **Spring Cloud**: 2025.0.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdedslash%2Fbuy-02","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdedslash%2Fbuy-02","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdedslash%2Fbuy-02/lists"}