Conversation
Signed-off-by: Shubham Jain <shubhamkjain@outlook.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR introduces a Go-based e-commerce microservices stack (user/product/order + API gateway) with Kafka support and Keploy artifacts for recording/replay, along with Docker Compose and Kubernetes (Kind) deployment resources.
Changes:
- Added Go implementations for user_service, product_service, and apigateway (Gin + MySQL/sqlx + JWT middleware).
- Added Kafka producer/consumer utilities and Docker Compose wiring for Kafka/ZooKeeper + topic initialization.
- Added Keploy configs and recorded HTTP test fixtures, plus K8s/Kind manifests and helper scripts.
Reviewed changes
Copilot reviewed 92 out of 95 changed files in this pull request and generated 19 comments.
Show a summary per file
| File | Description |
|---|---|
| go-services/user_service/main.go | User auth + user/address CRUD service (Gin + MySQL) |
| go-services/user_service/keploy.yml | Keploy config for user_service |
| go-services/user_service/db.sql | user_db schema (users, addresses) |
| go-services/user_service/Dockerfile | Container build/runtime for user_service |
| go-services/product_service/main.go | Product catalog + stock reserve/release service |
| go-services/product_service/keploy.yml | Keploy config for product_service |
| go-services/product_service/db.sql | product_db schema + seed inserts |
| go-services/product_service/Dockerfile | Container build/runtime for product_service |
| go-services/apigateway/main.go | Simple reverse-proxy API gateway for the services |
| go-services/apigateway/keploy.yml | Keploy config for apigateway |
| go-services/apigateway/Dockerfile | Container build/runtime for apigateway |
| go-services/internal/config/config.go | Shared env-based configuration (incl. Kafka broker parsing) |
| go-services/internal/db/mysql.go | MySQL connection helper w/ retry + pool settings |
| go-services/internal/auth/jwt.go | JWT generation/validation helpers |
| go-services/internal/middleware/auth.go | Gin JWT auth middleware |
| go-services/internal/kafka/producer.go | Kafka producer wrapper (kafka-go) |
| go-services/internal/kafka/consumer.go | Kafka consumer wrapper (kafka-go) |
| go-services/docker-compose.yml | Local stack: MySQLs + Kafka/ZK + services + topic init |
| go-services/scripts/create-kafka-topics.sh | Helper script to create Kafka topics |
| go-services/test_order_service.sh | Test driver script to exercise order flows for Keploy recording |
| go-services/script.sh | Local curl-based end-to-end script (Postman-like) |
| go-services/port-forward.sh | Convenience port-forwarding script for K8s deployments |
| go-services/order_service/Dockerfile | Order service container build (incl. Keploy faketime/CA setup) |
| go-services/order_service/entrypoint.sh | Entry point to install CA then run order-service |
| go-services/order_service/db.sql | order_db schema (orders, order_items) |
| go-services/order_service/keploy.yml | Keploy config for order_service |
| go-services/order_service/keploy/.gitignore | Ignores Keploy reports output |
| go-services/order_service/keploy/freezeTime/tests/test-1.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-2.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-3.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-4.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-5.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-6.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-7.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-8.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-9.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-10.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-11.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-12.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-13.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-14.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-15.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-16.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-17.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-18.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-19.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-20.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-21.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-22.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/freezeTime/tests/test-23.yaml | Keploy recorded HTTP test fixture (freezeTime) |
| go-services/order_service/keploy/dedup/tests/test-1.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-2.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-3.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-4.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-5.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-6.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-7.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-8.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-9.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-10.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-11.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-12.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-13.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-14.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-15.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-16.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-17.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-18.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-19.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-20.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-21.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-22.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/order_service/keploy/dedup/tests/test-23.yaml | Keploy recorded HTTP test fixture (dedup) |
| go-services/k8s/user-service.yaml | K8s Service/Deployment for user-service |
| go-services/k8s/product-service.yaml | K8s Service/Deployment for product-service |
| go-services/k8s/order-service.yaml | K8s Service/Deployment for order-service |
| go-services/k8s/order-service-standalone.yaml | Standalone order-service + Keploy agent pod spec |
| go-services/k8s/mysql-users.yaml | K8s MySQL deployment for user_db |
| go-services/k8s/mysql-products.yaml | K8s MySQL deployment for product_db |
| go-services/k8s/mysql-orders.yaml | K8s MySQL deployment for order_db |
| go-services/k8s/localstack.yaml | Localstack SQS init + service/deployment |
| go-services/k8s/apigateway.yaml | K8s Service/Deployment for apigateway |
| go-services/k8s/README.md | K8s/Kind deployment instructions |
| go-services/kind-config.yaml | Kind cluster config (port mapping) |
| go-services/keploy.yml | Root Keploy config for go-services |
| go-services/go.mod | Go module definition + dependencies |
| go-services/guide.md | Keploy workflow notes (local + K8s) |
| go-services/README.md | Main documentation for running/testing stack + Kafka verification |
| go-services/.gitignore | Ignores script/ directory |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| tx, _ := database.Beginx() | ||
| _, err := tx.Exec( | ||
| "INSERT INTO addresses (id, user_id, line1, line2, city, state, postal_code, country, phone, is_default) VALUES (?,?,?,?,?,?,?,?,?,?)", | ||
| addrID, userID, req.Line1, line2, req.City, req.State, req.PostalCode, req.Country, phone, isDefault, |
There was a problem hiding this comment.
database.Beginx() errors are ignored (tx, _ := ...). If Beginx fails, tx will be nil and tx.Exec(...) will panic. Handle the Beginx error and return an appropriate 500 response.
| if desc, ok := req["description"]; ok { | ||
| sets = append(sets, "description=?") | ||
| args = append(args, desc) | ||
| } |
There was a problem hiding this comment.
description is accepted as an untyped interface{} and forwarded directly to SQL. If a client sends a non-string JSON value (object/array/number), this will fail at runtime. Restrict description to string or null (validate type and return 400 on invalid input).
| until kafka-topics --bootstrap-server localhost:9092 --list >/dev/null 2>&1; do | ||
| sleep 1 | ||
| done |
There was a problem hiding this comment.
This script uses --bootstrap-server localhost:9092, but in docker-compose.yml Kafka is exposed on the host as localhost:29092 (and 9092 is only inside the Kafka container/network). If this script is meant to run on the host, it should use localhost:29092 (or accept the bootstrap server as an argument/env var).
| if err != nil { | ||
| c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("Failed to create user: %v", err)}) | ||
| return |
There was a problem hiding this comment.
This error response includes the raw DB error (%v), which can leak internal details (schema/driver messages) to clients. Return a generic message (and log the detailed error server-side) instead.
| if isDefault == 1 { | ||
| tx.Exec("UPDATE addresses SET is_default=0 WHERE user_id=? AND id<>?", userID, addrID) | ||
| } | ||
| tx.Commit() | ||
|
|
||
| c.JSON(http.StatusCreated, gin.H{"id": addrID}) |
There was a problem hiding this comment.
Commit() is called without checking its return value. If the commit fails (e.g., connection drop), the handler still returns 201 Created. Check the tx.Commit() error and return 500 on failure (and rollback where appropriate).
| fields := []string{"line1", "line2", "city", "state", "postal_code", "country", "phone"} | ||
| for _, f := range fields { | ||
| if val, ok := req[f]; ok { | ||
| sets = append(sets, f+"=?") | ||
| args = append(args, val) | ||
| } |
There was a problem hiding this comment.
This dynamic update accepts any JSON type for line1/line2/city/... values and passes them directly to SQL args. Non-string values (objects/arrays) will cause SQL/driver errors at runtime. Validate/coerce expected types for each field (and reject invalid types with 400).
| if [ -z "$JWT" ]; then | ||
| echo "ERROR: Failed to get JWT token. Trying to create user first..." | ||
|
|
||
| # Try to create user first (might need admin token or no auth) | ||
| echo "Creating user..." | ||
| CREATE_USER_RESPONSE=$(curl -s -X POST "${USER_BASE}/users" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d "{ | ||
| \"username\": \"${USERNAME}\", | ||
| \"email\": \"${EMAIL}\", | ||
| \"password\": \"${PASSWORD}\" | ||
| }") |
There was a problem hiding this comment.
This script attempts to create a user without an Authorization header when login fails, but the user_service implementation protects POST /api/v1/users with JWT auth. As written, this fallback path will always fail (and the script exits). Either obtain an admin token first and use it for user creation, or make user creation a public endpoint if that’s intended.
| hashedPwd, _ := bcrypt.GenerateFromPassword([]byte(cfg.AdminPassword), bcrypt.DefaultCost) | ||
|
|
There was a problem hiding this comment.
bcrypt.GenerateFromPassword errors are ignored here, which could lead to inserting/updating an empty/invalid hash (and masking configuration issues). Handle the returned error and abort seeding (or log and return) if hashing fails.
| database.Select(&addresses, "SELECT id, line1, line2, city, state, postal_code, country, phone, is_default FROM addresses WHERE user_id=? ORDER BY is_default DESC, created_at DESC", userID) | ||
|
|
||
| c.JSON(http.StatusOK, addresses) |
There was a problem hiding this comment.
The addresses list query error is ignored. If database.Select fails, this returns 200 with an empty list, hiding DB issues. Handle the error and return 500 when the query fails.
| - name: keploy-data | ||
| hostPath: | ||
| path: /home/ashish/asish_workspace/flipkart-jan/ecommerce_sample_app/go-services/order_service/keploy | ||
| type: Directory |
There was a problem hiding this comment.
This manifest hardcodes a developer-specific absolute hostPath (/home/ashish/...). This will not work on other machines/CI and is unsafe to commit as-is. Use a PVC, emptyDir, or a configurable path (and document how to mount Keploy data) instead of an absolute workstation path.
Kafka integration