From e4cf030bcc913aeeac8696e32814a88f9e3e7009 Mon Sep 17 00:00:00 2001 From: Chandini Date: Wed, 3 Sep 2025 13:58:10 +0530 Subject: [PATCH] backend changes --- .env.backup | 65 ++++++++++++ docker-compose.yml | 116 ++++++++++++---------- services/api-gateway/src/server.js | 10 +- services/user-auth/src/config/database.js | 5 +- 4 files changed, 135 insertions(+), 61 deletions(-) create mode 100644 .env.backup diff --git a/.env.backup b/.env.backup new file mode 100644 index 0000000..4e5b20c --- /dev/null +++ b/.env.backup @@ -0,0 +1,65 @@ +# Database Configuration +POSTGRES_HOST=localhost +POSTGRES_PORT=5432 +POSTGRES_DB=dev_pipeline +POSTGRES_USER=pipeline_admin +POSTGRES_PASSWORD=secure_pipeline_2024 + +# Redis Configuration +REDIS_PASSWORD=redis_secure_2024 + +# MongoDB Configuration +MONGO_INITDB_ROOT_USERNAME=pipeline_admin +MONGO_INITDB_ROOT_PASSWORD=mongo_secure_2024 + +# RabbitMQ Configuration +RABBITMQ_DEFAULT_USER=pipeline_admin +RABBITMQ_DEFAULT_PASS=rabbit_secure_2024 + +# n8n Configuration +N8N_BASIC_AUTH_USER=admin +N8N_BASIC_AUTH_PASSWORD=admin_n8n_2024 +N8N_ENCRYPTION_KEY=very_secure_encryption_key_2024 + +# Jenkins Configuration +JENKINS_ADMIN_ID=admin +JENKINS_ADMIN_PASSWORD=jenkins_secure_2024 + +# Gitea Configuration +GITEA_ADMIN_USER=admin +GITEA_ADMIN_PASSWORD=gitea_secure_2024 + +# API Keys (add your actual keys later) +CLAUDE_API_KEY=your_claude_api_key_here +OPENAI_API_KEY=your_openai_api_key_here +CLOUDTOPIAA_API_KEY=your_cloudtopiaa_api_key_here +CLOUDTOPIAA_API_URL=https://api.cloudtopiaa.com + +# JWT Configuration +JWT_SECRET=ultra_secure_jwt_secret_2024 + +# Environment +ENVIRONMENT=development +NODE_ENV=development +PYTHONPATH=/app/src + +# Monitoring +GRAFANA_ADMIN_USER=admin +GRAFANA_ADMIN_PASSWORD=grafana_secure_2024 +RABBITMQ_PASSWORD=rabbit_secure_2024 +MONGODB_PASSWORD=pipeline_password +MONGODB_PASSWORD=pipeline_password +CLAUDE_API_KEY=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 +CLAUDE_API_KEY=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 + +# SMTP Configuration (Option 1) +SMTP_HOST=smtp.gmail.com +SMTP_PORT=587 +SMTP_SECURE=false +SMTP_USER=frontendtechbiz@gmail.com +SMTP_PASS=oidhhjeasgzbqptq +SMTP_FROM=frontendtechbiz@gmail.com + +# Gmail Configuration (Option 2 - Alternative to SMTP) +GMAIL_USER=frontendtechbiz@gmail.com +GMAIL_APP_PASSWORD=oidhhjeasgzbqptq \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index cf68178..00398e7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,22 +23,22 @@ services: retries: 5 start_period: 60s -# redis: -# image: redis:7-alpine -# container_name: pipeline_redis -# command: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD} -# volumes: -# - redis_data:/data -# ports: -# - "6379:6379" -# networks: -# - pipeline_network -# healthcheck: -# test: ["CMD", "redis-cli", "--raw", "incr", "ping"] -# interval: 30s -# timeout: 10s -# retries: 5 -# start_period: 30s + redis: + image: redis:7-alpine + container_name: pipeline_redis + command: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD} + volumes: + - redis_data:/data + ports: + - "6379:6379" + networks: + - pipeline_network + healthcheck: + test: ["CMD", "redis-cli", "--raw", "incr", "ping"] + interval: 30s + timeout: 10s + retries: 5 + start_period: 30s # mongodb: # image: mongo:7 @@ -366,23 +366,23 @@ services: # networks: # - pipeline_network - redis: - image: redis:7-alpine - container_name: pipeline_redis - environment: - REDIS_PASSWORD: redis123 - REDIS_USER: redisuser - ports: - - "6380:6379" - volumes: - - redis_data:/data - command: redis-server --requirepass redis123 - healthcheck: - test: ["CMD", "redis-cli", "--raw", "incr", "ping"] - interval: 30s - timeout: 10s - retries: 3 - start_period: 40s + # redis: + # image: redis:7-alpine + # container_name: pipeline_redis + # environment: + # REDIS_PASSWORD: redis123 + # REDIS_USER: redisuser + # ports: + # - "6380:6379" + # volumes: + # - redis_data:/data + # command: redis-server --requirepass redis123 + # healthcheck: + # test: ["CMD", "redis-cli", "--raw", "incr", "ping"] + # interval: 30s + # timeout: 10s + # retries: 3 + # start_period: 40s mongodb: image: mongo:7 @@ -543,22 +543,25 @@ services: environment: - NODE_ENV=development - PORT=8000 - - REDIS_HOST=redis - - REDIS_PORT=6379 - - REDIS_PASSWORD=redis123 + - HOST=0.0.0.0 + # Database connections - POSTGRES_HOST=postgres - POSTGRES_PORT=5432 - POSTGRES_DB=dev_pipeline - POSTGRES_USER=pipeline_admin - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + # Cache and message queue + - REDIS_HOST=redis + - REDIS_PORT=6379 + - REDIS_PASSWORD=${REDIS_PASSWORD} - RABBITMQ_HOST=rabbitmq - RABBITMQ_PORT=5672 - RABBITMQ_USER=pipeline_admin - RABBITMQ_PASSWORD=${RABBITMQ_PASSWORD} - # JWT Configuration (must match user-auth service) + # JWT configuration - JWT_ACCESS_SECRET=access-secret-key-2024-tech4biz-${POSTGRES_PASSWORD} - JWT_REFRESH_SECRET=refresh-secret-key-2024-tech4biz-${POSTGRES_PASSWORD} - # Internal service URLs for proxying (Docker network names) + # Service URLs - USER_AUTH_URL=http://user-auth:8011 - TEMPLATE_MANAGER_URL=http://template-manager:8009 - REQUIREMENT_PROCESSOR_URL=http://requirement-processor:8001 @@ -569,6 +572,9 @@ services: - DEPLOYMENT_MANAGER_URL=http://deployment-manager:8006 - DASHBOARD_URL=http://dashboard:8008 - SELF_IMPROVING_GENERATOR_URL=http://self-improving-generator:8007 + volumes: + - api_gateway_logs:/app/logs # Add persistent volume for logs + user: "node" # Run as node user instead of root networks: - pipeline_network depends_on: @@ -578,6 +584,13 @@ services: condition: service_healthy rabbitmq: condition: service_healthy + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8000/health"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s + restart: unless-stopped requirement-processor: build: ./services/requirement-processor @@ -592,7 +605,7 @@ services: - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} - REDIS_HOST=redis - REDIS_PORT=6379 - - REDIS_PASSWORD=redis123 + - REDIS_PASSWORD=${REDIS_PASSWORD} - MONGODB_HOST=mongodb - MONGODB_PORT=27017 - NEO4J_URI=bolt://neo4j:7687 @@ -600,7 +613,7 @@ services: - NEO4J_PASSWORD=password - CHROMA_HOST=chromadb - CHROMA_PORT=8000 - - REDIS_URL=redis://:redis123@redis:6379 + - REDIS_URL=redis://redis:6379 networks: - pipeline_network depends_on: @@ -624,7 +637,7 @@ services: - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} - REDIS_HOST=redis - REDIS_PORT=6379 - - REDIS_PASSWORD=redis123 + - REDIS_PASSWORD=${REDIS_PASSWORD} networks: - pipeline_network depends_on: @@ -680,7 +693,7 @@ services: - MONGODB_PORT=27017 - REDIS_HOST=redis - REDIS_PORT=6379 - - REDIS_PASSWORD=redis123 + - REDIS_PASSWORD=${REDIS_PASSWORD} - CLAUDE_API_KEY=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 - OPENAI_API_KEY=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 # - NEO4J_URI=bolt://neo4j:7687 @@ -725,7 +738,7 @@ services: - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} - REDIS_HOST=redis - REDIS_PORT=6379 - - REDIS_PASSWORD=redis123 + - REDIS_PASSWORD=${REDIS_PASSWORD} networks: - pipeline_network depends_on: @@ -777,7 +790,7 @@ services: - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} - REDIS_HOST=redis - REDIS_PORT=6379 - - REDIS_PASSWORD=redis123 + - REDIS_PASSWORD=${REDIS_PASSWORD} - JWT_ACCESS_SECRET=access-secret-key-2024-tech4biz-${POSTGRES_PASSWORD} - JWT_REFRESH_SECRET=refresh-secret-key-2024-tech4biz-${POSTGRES_PASSWORD} - JWT_ACCESS_EXPIRY=15m @@ -892,15 +905,7 @@ services: - NODE_ENV=production - PORT=8008 - DATABASE_URL=postgresql://pipeline_admin:${POSTGRES_PASSWORD}@postgres:5432/dev_pipeline - - POSTGRES_HOST=postgres - - POSTGRES_PORT=5432 - - POSTGRES_DB=dev_pipeline - - POSTGRES_USER=pipeline_admin - - POSTGRES_PASSWORD=secure_pipeline_2024 - - REDIS_URL=redis://:redis123@redis:6379 - - REDIS_HOST=redis - - REDIS_PORT=6379 - - REDIS_PASSWORD=redis123 + - REDIS_URL=redis://pipeline_redis:6379 - API_GATEWAY_URL=http://pipeline_api_gateway:8000 - CODE_GENERATOR_URL=http://pipeline_code_generator:8004 - SELF_IMPROVING_URL=http://pipeline_self_improving_generator:8007 @@ -992,6 +997,8 @@ volumes: driver: local chromadb_data: driver: local + api_gateway_logs: + driver: local # ===================================== # Networks @@ -1007,5 +1014,4 @@ networks: # ===================================== # Self-Improving Code Generator # ===================================== - - + diff --git a/services/api-gateway/src/server.js b/services/api-gateway/src/server.js index 1557278..575ad29 100644 --- a/services/api-gateway/src/server.js +++ b/services/api-gateway/src/server.js @@ -157,7 +157,8 @@ const websocketHandlers = websocketAuth(io); // Auth Service - Fixed proxy with proper connection handling console.log('🔧 Registering /api/auth proxy route...'); app.use('/api/auth', (req, res, next) => { - console.log(`🔥 [AUTH PROXY] ${req.method} ${req.originalUrl} → http://localhost:8011${req.originalUrl}`); + const authServiceUrl = serviceTargets.USER_AUTH_URL; + console.log(`🔥 [AUTH PROXY] ${req.method} ${req.originalUrl} → ${authServiceUrl}${req.originalUrl}`); // Set response timeout to prevent hanging res.setTimeout(15000, () => { @@ -169,7 +170,7 @@ app.use('/api/auth', (req, res, next) => { const options = { method: req.method, - url: `http://localhost:8011${req.originalUrl}`, + url: `${authServiceUrl}${req.originalUrl}`, headers: { 'Content-Type': 'application/json', 'User-Agent': 'API-Gateway/1.0', @@ -222,7 +223,8 @@ app.use('/api/templates', authMiddleware.verifyToken, authMiddleware.forwardUserContext, (req, res, next) => { - console.log(`🔥 [TEMPLATE PROXY] ${req.method} ${req.originalUrl} → http://localhost:8009${req.originalUrl}`); + const templateServiceUrl = serviceTargets.TEMPLATE_MANAGER_URL; + console.log(`🔥 [TEMPLATE PROXY] ${req.method} ${req.originalUrl} → ${templateServiceUrl}${req.originalUrl}`); // Set response timeout to prevent hanging res.setTimeout(15000, () => { @@ -234,7 +236,7 @@ app.use('/api/templates', const options = { method: req.method, - url: `http://localhost:8009${req.originalUrl}`, + url: `${templateServiceUrl}${req.originalUrl}`, headers: { 'Content-Type': 'application/json', 'User-Agent': 'API-Gateway/1.0', diff --git a/services/user-auth/src/config/database.js b/services/user-auth/src/config/database.js index 4f54ce1..3ebdb60 100644 --- a/services/user-auth/src/config/database.js +++ b/services/user-auth/src/config/database.js @@ -10,7 +10,7 @@ class Database { password: process.env.POSTGRES_PASSWORD || 'secure_pipeline_2024', max: 20, idleTimeoutMillis: 30000, - connectionTimeoutMillis: 2000, + connectionTimeoutMillis: 10000, }); // Test connection on startup @@ -24,7 +24,8 @@ class Database { client.release(); } catch (err) { console.error('❌ User Auth Database connection failed:', err.message); - process.exit(1); + // Don't exit the process, just log the error + // The service can still start and retry connections later } }