diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7fb867d..93fcd64 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: Student Service CI/CD +name: User Service CI/CD on: push: diff --git a/Dockerfile b/Dockerfile index 88baa63..7cd7335 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,13 +15,13 @@ RUN go install github.com/swaggo/swag/cmd/swag@latest && \ swag init # build static binary -RUN go build -ldflags="-s -w" -o /app/student-service . +RUN go build -ldflags="-s -w" -o /app/user-service . FROM alpine:3.18 RUN apk add --no-cache ca-certificates WORKDIR /app -COPY --from=builder /app/student-service /app/student-service +COPY --from=builder /app/user-service /app/user-service # Include API docs and optional .env from the build context so the runtime image can serve /docs COPY --from=builder /src/docs /app/docs @@ -34,4 +34,4 @@ USER 1000:1000 HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:${SERVER_PORT}/health || exit 1 -CMD ["/app/student-service"] +CMD ["/app/user-service"] diff --git a/INTEGRATION.md b/INTEGRATION.md index 5c08315..a2dce9e 100644 --- a/INTEGRATION.md +++ b/INTEGRATION.md @@ -2,19 +2,19 @@ ## Overview -The Student Service demonstrates microservice integration by calling the Enrollment Service to fetch student enrollment data. This demonstrates how microservices communicate and share data across service boundaries in a distributed architecture. +The User Service demonstrates microservice integration by calling the Enrollment Service to fetch student enrollment data. This demonstrates how microservices communicate and share data across service boundaries in a distributed architecture. ## Architecture ``` ┌─────────────────────────────────────────────────────────────────┐ │ API Gateway (Port 8080) │ -│ Routes requests to Student Service │ +│ Routes requests to User Service │ └────────────────────────────┬────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────┐ -│ Student Service (Port 5001) │ +│ User Service (Port 5001) │ ├─────────────────────────────────────────────────────────────────┤ │ Storage: MongoDB (student data) │ │ Endpoints: │ diff --git a/MONGODB_GUIDE.md b/MONGODB_GUIDE.md index 571a3dd..d2f4f16 100644 --- a/MONGODB_GUIDE.md +++ b/MONGODB_GUIDE.md @@ -25,7 +25,7 @@ brew services start mongodb-community Create a `.env` file in the project root: ```env MONGODB_URI=mongodb://localhost:27017 -MONGODB_DB=student_service +MONGODB_DB=userdb SERVER_PORT=8080 SERVER_ENV=development ``` @@ -33,7 +33,7 @@ SERVER_ENV=development **For MongoDB Atlas (Cloud):** ```env MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/?retryWrites=true&w=majority -MONGODB_DB=student_service +MONGODB_DB=userdb ``` ### 3. Run the Server @@ -99,7 +99,7 @@ Each student document in the `students` collection contains: ### Using MongoDB Shell ```bash mongosh -use student_service +use user-service db.students.find() ``` diff --git a/Makefile b/Makefile index dc10e46..592b8d8 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .PHONY: help install run swagger clean help: - @echo "Student Service API - Available Commands" + @echo "User Service API - Available Commands" @echo "" @echo " make install - Download Go dependencies" @echo " make run - Run the server" diff --git a/README.md b/README.md index 13d91d8..84cf1ba 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Student Service 🎓 +# User Service 🎓 A production-ready Go microservice for student management with comprehensive security features, JWT authentication, and comprehensive testing. @@ -42,7 +42,7 @@ A production-ready Go microservice for student management with comprehensive sec │ ▼ ┌─────────────────────────────────────────────────┐ -│ Student Service (Port 5001) │ +│ User Service (Port 5001) │ ├─────────────────────────────────────────────────┤ │ Routes: │ │ POST /auth/register → registerH │ @@ -61,7 +61,7 @@ A production-ready Go microservice for student management with comprehensive sec └────────────────┘ └────────────────────┘ ``` -**Microservice Integration:** The Student Service calls the Enrollment Service via HTTP to fetch enrollments for the `/students/{id}/enrollments` endpoint. +**Microservice Integration:** The User Service calls the Enrollment Service via HTTP to fetch enrollments for the `/students/{id}/enrollments` endpoint. ## 📋 Requirements @@ -290,7 +290,7 @@ Response: 200 OK ## 🔗 Microservice Integration -The Student Service integrates with the **Enrollment Service** to provide comprehensive student information including course enrollments. +The User Service integrates with the **Enrollment Service** to provide comprehensive student information including course enrollments. **Key Features:** - ✅ Synchronous HTTP/REST calls to Enrollment Service @@ -443,9 +443,9 @@ Client API Gateway (Port 8080) ├─ Validates JWT ├─ Adds X-User-ID header - ├─ Routes to Student Service + ├─ Routes to User Service ↓ -Student Service (Port 5001) +User Service (Port 5001) ├─ Receives X-User-ID ├─ Processes request ├─ Returns response @@ -455,7 +455,7 @@ API Gateway (returns to client) **Environment:** ```bash -STUDENT_SERVICE_URL=http://localhost:5001 +USER_SERVICE_URL=http://localhost:5001 ``` diff --git a/README_API.md b/README_API.md index 8670a83..592c82b 100644 --- a/README_API.md +++ b/README_API.md @@ -1,4 +1,4 @@ -# Student Service API +# User Service API A simple student management API built with Go. diff --git a/main.go b/main.go index a20a34e..c755456 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,7 @@ import ( "golang.org/x/time/rate" ) -// @title Student Service API +// @title User Service API // @version 1.0 // @description A simple student management API with MongoDB // @BasePath / @@ -973,8 +973,8 @@ func registerHandler(w http.ResponseWriter, r *http.Request) { } // loginHandler godoc -// @Summary Login a student -// @Description Authenticate a student with email and password, return JWT token +// @Summary Login +// @Description Authenticate a USER with email and password, return JWT token // @Tags Auth // @Accept json // @Produce json diff --git a/test/README.md b/test/README.md index bd08000..e487516 100644 --- a/test/README.md +++ b/test/README.md @@ -1,6 +1,6 @@ # Rate Limiter Test Suite -This folder contains comprehensive tests for the rate limiting functionality of the Student Service. +This folder contains comprehensive tests for the rate limiting functionality of the User Service. ## Test Files @@ -163,7 +163,7 @@ chmod +x test/test_rate_limiter.sh ## Rate Limiter Configuration -Current configuration in the Student Service: +Current configuration in the User Service: - **Rate:** 5 requests per minute per IP - **Burst:** 1 (allows 1 immediate request) @@ -179,7 +179,7 @@ This means: ## Troubleshooting ### Problem: "Connection refused" -**Solution:** Make sure the Student Service is running +**Solution:** Make sure the User Service is running ```bash cd /workspaces/user-service go run main.go diff --git a/test_auth.sh b/test_auth.sh index a437693..42bfcaa 100755 --- a/test_auth.sh +++ b/test_auth.sh @@ -49,12 +49,12 @@ echo "----------------------------------------------" # Check if service is running if ! curl -s -f "$BASE_URL/" > /dev/null 2>&1; then - echo -e "${RED}❌ Student Service is not running on $BASE_URL${NC}" + echo -e "${RED}❌ User Service is not running on $BASE_URL${NC}" echo "Start with: go run main.go" exit 1 fi -echo -e "${GREEN}✅ Student Service is running${NC}" +echo -e "${GREEN}✅ User Service is running${NC}" echo "" # Test data diff --git a/test_enrollment_connection.sh b/test_enrollment_connection.sh index 5004055..80a3aa2 100755 --- a/test_enrollment_connection.sh +++ b/test_enrollment_connection.sh @@ -1,9 +1,9 @@ #!/bin/bash -# test_enrollment_connection.sh - Test enrollment service connection from student service +# test_enrollment_connection.sh - Test enrollment service connection from user service echo "==============================================" echo "Enrollment Service Connection Test" -echo "Student Service ↔ Enrollment Service (Cloud)" +echo "User Service ↔ Enrollment Service (Cloud)" echo "==============================================" echo "" @@ -13,7 +13,7 @@ if [ -f .env ]; then fi # Configuration -STUDENT_SERVICE="http://localhost:${SERVER_PORT:-5001}" +USER_SERVICE="http://localhost:${SERVER_PORT:-5001}" ENROLLMENT_SERVICE_URL="${ENROLLMENT_SERVICE_URL}" # Check if ENROLLMENT_SERVICE_URL is set @@ -52,14 +52,14 @@ info() { echo "📋 Step 1: Check Service Connectivity" echo "----------------------------------------------" -# Check Student Service -echo -n "Checking Student Service (localhost:5001)... " -if curl -s -f "$STUDENT_SERVICE/" > /dev/null 2>&1; then +# Check User Service +echo -n "Checking User Service (localhost:5001)... " +if curl -s -f "$USER_SERVICE/" > /dev/null 2>&1; then echo -e "${GREEN}✅${NC}" - pass "Student Service is running" + pass "User Service is running" else echo -e "${RED}❌${NC}" - fail "Student Service is not running" + fail "User Service is not running" exit 1 fi @@ -85,7 +85,7 @@ TEST_PHONE="555-$(printf '%04d' $((RANDOM % 10000)))" info "Registering student: $TEST_EMAIL" -REGISTER_RESPONSE=$(curl -s -X POST "$STUDENT_SERVICE/auth/register" \ +REGISTER_RESPONSE=$(curl -s -X POST "$USER_SERVICE/auth/register" \ -H "Content-Type: application/json" \ -d "{ \"email\": \"$TEST_EMAIL\", @@ -111,7 +111,7 @@ echo "----------------------------------------------" info "Logging in with email: $TEST_EMAIL" -LOGIN_RESPONSE=$(curl -s -X POST "$STUDENT_SERVICE/auth/login" \ +LOGIN_RESPONSE=$(curl -s -X POST "$USER_SERVICE/auth/login" \ -H "Content-Type: application/json" \ -d "{ \"email\": \"$TEST_EMAIL\", @@ -138,7 +138,7 @@ echo "" ENROLLMENT_RESPONSE=$(curl -s -w "\n%{http_code}" \ -H "Authorization: Bearer $TOKEN" \ - "$STUDENT_SERVICE/students/$STUDENT_ID/enrollments") + "$USER_SERVICE/students/$STUDENT_ID/enrollments") HTTP_CODE=$(echo "$ENROLLMENT_RESPONSE" | tail -n1) RESPONSE_BODY=$(echo "$ENROLLMENT_RESPONSE" | sed '$d') @@ -206,8 +206,8 @@ echo "" echo "🔍 Step 6: Connection Details" echo "----------------------------------------------" -info "Student Service Configuration:" -echo " - Base URL: $STUDENT_SERVICE" +info "User Service Configuration:" +echo " - Base URL: $USER_SERVICE" echo " - Port: 5001" echo " - Status: Running" echo "" @@ -237,11 +237,11 @@ if [ $TESTS_FAILED -eq 0 ]; then echo -e "${GREEN}✅ All tests passed!${NC}" echo "" echo "🎯 Results:" - echo " - Student Service ✅ Working" + echo " - User Service ✅ Working" echo " - Enrollment Service ✅ Reachable" echo " - Microservice Integration ✅ Successful" echo "" - echo "The Student Service successfully connects to the Enrollment Service" + echo "The User Service successfully connects to the Enrollment Service" echo "at $ENROLLMENT_SERVICE_URL" exit 0 else diff --git a/test_integration.sh b/test_integration.sh index e8c5196..f15006e 100755 --- a/test_integration.sh +++ b/test_integration.sh @@ -1,12 +1,12 @@ #!/bin/bash # test_integration.sh - Test script for Student-Enrollment microservice integration -# This script demonstrates how the Student Service calls the Enrollment Service +# This script demonstrates how the User Service calls the Enrollment Service set -e # Exit on errors echo "==============================================" echo "Microservice Integration Test" -echo "Student Service ↔ Enrollment Service" +echo "User Service ↔ Enrollment Service" echo "==============================================" echo "" @@ -16,16 +16,16 @@ if [ -f .env ]; then fi # Configuration (defaults for local development) -STUDENT_SERVICE="http://localhost:${SERVER_PORT:-5001}" +USER_SERVICE="http://localhost:${SERVER_PORT:-5001}" ENROLLMENT_SERVICE="${ENROLLMENT_SERVICE_URL:-http://localhost:5003}" API_GATEWAY="http://localhost:8080" echo "📋 Prerequisites Check" echo "----------------------------------------------" -# Check if Student Service is running -echo -n "Checking Student Service (port 5001)... " -if curl -s -f "$STUDENT_SERVICE/" > /dev/null 2>&1; then +# Check if User Service is running +echo -n "Checking User Service (port 5001)... " +if curl -s -f "$USER_SERVICE/" > /dev/null 2>&1; then echo "✅ Running" else echo "❌ Not running" @@ -46,7 +46,7 @@ echo "" echo "🔐 Step 1: Register Test Student" echo "----------------------------------------------" -REGISTER_RESPONSE=$(curl -s -X POST "$STUDENT_SERVICE/auth/register" \ +REGISTER_RESPONSE=$(curl -s -X POST "$USER_SERVICE/auth/register" \ -H "Content-Type: application/json" \ -d '{ "email": "testuser_'$(date +%s)'@university.edu", @@ -71,7 +71,7 @@ echo "" echo "🔑 Step 2: Login to Get JWT Token" echo "----------------------------------------------" -LOGIN_RESPONSE=$(curl -s -X POST "$STUDENT_SERVICE/auth/login" \ +LOGIN_RESPONSE=$(curl -s -X POST "$USER_SERVICE/auth/login" \ -H "Content-Type: application/json" \ -d '{ "email": "'$(echo "$REGISTER_RESPONSE" | jq -r '.email')'", @@ -137,7 +137,7 @@ echo "GET /students/$STUDENT_ID/enrollments" echo "" INTEGRATION_RESPONSE=$(curl -s -H "Authorization: Bearer $TOKEN" \ - "$STUDENT_SERVICE/students/$STUDENT_ID/enrollments") + "$USER_SERVICE/students/$STUDENT_ID/enrollments") echo "$INTEGRATION_RESPONSE" | jq '.' @@ -180,13 +180,13 @@ echo "✅ Integration Test Complete!" echo "==============================================" echo "" echo "📋 Summary:" -echo " - Student Service: Working" +echo " - User Service: Working" echo " - Enrollment Service: $([ -z "$ENROLLMENT_DOWN" ] && echo "Working" || echo "Down (graceful degradation tested)")" echo " - Microservice Integration: ✅ Successful" echo " - Student ID: $STUDENT_ID" echo " - Enrollments: $ENROLLMENT_COUNT" echo "" echo "🔗 Integration demonstrated:" -echo " Student Service → HTTP Call → Enrollment Service" +echo " User Service → HTTP Call → Enrollment Service" echo " Response combines data from both services" echo ""