231 lines
5.9 KiB
Markdown
231 lines
5.9 KiB
Markdown
# Microservices Architecture Deployment Guide
|
|
|
|
## **Architecture Overview**
|
|
|
|
```
|
|
Frontend (Next.js) → API Gateway (Express) → Git Integration Service (Node.js)
|
|
Port 3001 Port 8000 Port 8012
|
|
```
|
|
|
|
## **✅ Changes Applied**
|
|
|
|
### **1. Frontend Fixes**
|
|
- ✅ Replaced `fetch()` calls with `authApiClient` in `DiffViewerContext.tsx`
|
|
- ✅ Replaced `fetch()` calls with `authApiClient` in `diff-viewer/page.tsx`
|
|
- ✅ All API calls now go through API Gateway (port 8000) instead of frontend (port 3001)
|
|
|
|
### **2. Backend Enhancements**
|
|
- ✅ Added missing `/api/github/repository/:id/resolve-path` endpoint
|
|
- ✅ Enhanced path resolution with case-insensitive file matching
|
|
- ✅ All existing endpoints remain functional
|
|
|
|
### **3. API Gateway Routing**
|
|
- ✅ Added `/api/diffs` route to API Gateway
|
|
- ✅ Configured proper proxy forwarding to Git Integration Service
|
|
- ✅ Added authentication middleware for diff operations
|
|
- ✅ Set appropriate timeouts for diff operations (120 seconds)
|
|
|
|
## **🚀 Deployment Steps**
|
|
|
|
### **1. Start All Services**
|
|
|
|
```bash
|
|
# Navigate to backend directory
|
|
cd /home/tech4biz/Documents/merge/codenuk-backend-live
|
|
|
|
# Start all services with Docker Compose
|
|
docker-compose up -d
|
|
|
|
# Check service status
|
|
docker-compose ps
|
|
```
|
|
|
|
### **2. Start Frontend**
|
|
|
|
```bash
|
|
# Navigate to frontend directory
|
|
cd /home/tech4biz/Documents/merge/codenuk-frontend-live
|
|
|
|
# Install dependencies (if not already done)
|
|
npm install
|
|
|
|
# Start frontend development server
|
|
npm run dev
|
|
```
|
|
|
|
### **3. Verify Architecture**
|
|
|
|
```bash
|
|
# Run the architecture test
|
|
cd /home/tech4biz/Documents/merge/codenuk-backend-live
|
|
node test-microservices-architecture.js
|
|
```
|
|
|
|
## **🔍 Service Endpoints**
|
|
|
|
### **Frontend (Port 3001)**
|
|
- **URL**: http://localhost:3001
|
|
- **Purpose**: Next.js React application
|
|
- **API Calls**: All go through API Gateway (port 8000)
|
|
|
|
### **API Gateway (Port 8000)**
|
|
- **URL**: http://localhost:8000
|
|
- **Purpose**: Single entry point for all backend services
|
|
- **Routes**:
|
|
- `/api/github/*` → Git Integration Service
|
|
- `/api/diffs/*` → Git Integration Service
|
|
- `/api/vcs/*` → Git Integration Service
|
|
- `/api/ai/*` → Git Integration Service
|
|
|
|
### **Git Integration Service (Port 8012)**
|
|
- **URL**: http://localhost:8012
|
|
- **Purpose**: Handles all Git operations
|
|
- **Routes**:
|
|
- `/api/github/*` - GitHub integration
|
|
- `/api/diffs/*` - Diff viewer operations
|
|
- `/api/vcs/*` - Multi-provider VCS support
|
|
- `/api/ai/*` - AI streaming operations
|
|
|
|
## **🧪 Testing the Architecture**
|
|
|
|
### **1. Test Service Health**
|
|
|
|
```bash
|
|
# Test API Gateway
|
|
curl http://localhost:8000/health
|
|
|
|
# Test Git Integration Service
|
|
curl http://localhost:8012/health
|
|
|
|
# Test Frontend
|
|
curl http://localhost:3001
|
|
```
|
|
|
|
### **2. Test API Routing**
|
|
|
|
```bash
|
|
# Test GitHub endpoints through gateway
|
|
curl http://localhost:8000/api/github/health
|
|
|
|
# Test diff endpoints through gateway
|
|
curl http://localhost:8000/api/diffs/repositories
|
|
|
|
# Test direct service call (should work)
|
|
curl http://localhost:8012/api/github/health
|
|
```
|
|
|
|
### **3. Test Frontend Integration**
|
|
|
|
1. Open http://localhost:3001
|
|
2. Navigate to GitHub repositories page
|
|
3. Navigate to diff viewer page
|
|
4. Check browser network tab - all API calls should go to port 8000
|
|
|
|
## **🔧 Configuration**
|
|
|
|
### **Environment Variables**
|
|
|
|
#### **Frontend (.env.local)**
|
|
```env
|
|
NEXT_PUBLIC_API_URL=http://localhost:8000
|
|
```
|
|
|
|
#### **API Gateway (.env)**
|
|
```env
|
|
GIT_INTEGRATION_URL=http://git-integration:8012
|
|
PORT=8000
|
|
```
|
|
|
|
#### **Git Integration Service (.env)**
|
|
```env
|
|
PORT=8012
|
|
DATABASE_URL=postgresql://user:password@postgres:5432/codenuk
|
|
```
|
|
|
|
## **🐛 Troubleshooting**
|
|
|
|
### **Common Issues**
|
|
|
|
#### **1. Frontend calls port 3001 instead of 8000**
|
|
- **Cause**: Using `fetch()` instead of `authApiClient`
|
|
- **Fix**: Replace all `fetch('/api/...')` with `authApiClient.get('/api/...')`
|
|
|
|
#### **2. API Gateway returns 502 errors**
|
|
- **Cause**: Git Integration Service not running
|
|
- **Fix**: Check `docker-compose ps` and restart services
|
|
|
|
#### **3. CORS errors in browser**
|
|
- **Cause**: Frontend trying to call different ports
|
|
- **Fix**: Ensure all API calls go through port 8000
|
|
|
|
#### **4. Authentication errors**
|
|
- **Cause**: Missing or invalid JWT tokens
|
|
- **Fix**: Check authentication flow and token refresh
|
|
|
|
### **Debug Commands**
|
|
|
|
```bash
|
|
# Check service logs
|
|
docker-compose logs git-integration
|
|
docker-compose logs api-gateway
|
|
|
|
# Check service connectivity
|
|
docker-compose exec api-gateway curl http://git-integration:8012/health
|
|
|
|
# Test specific endpoints
|
|
curl -H "Authorization: Bearer <token>" http://localhost:8000/api/github/user/repositories
|
|
```
|
|
|
|
## **📊 Monitoring**
|
|
|
|
### **Service Health Checks**
|
|
|
|
```bash
|
|
# API Gateway health
|
|
curl http://localhost:8000/health
|
|
|
|
# Git Integration health
|
|
curl http://localhost:8012/health
|
|
|
|
# Frontend health
|
|
curl http://localhost:3001
|
|
```
|
|
|
|
### **Log Monitoring**
|
|
|
|
```bash
|
|
# Follow all logs
|
|
docker-compose logs -f
|
|
|
|
# Follow specific service logs
|
|
docker-compose logs -f git-integration
|
|
docker-compose logs -f api-gateway
|
|
```
|
|
|
|
## **🎯 Success Criteria**
|
|
|
|
✅ **Frontend (3001)** - All API calls go to port 8000
|
|
✅ **API Gateway (8000)** - Routes requests to appropriate services
|
|
✅ **Git Integration (8012)** - Handles all Git operations
|
|
✅ **Authentication** - JWT tokens properly forwarded
|
|
✅ **Error Handling** - Proper error responses and timeouts
|
|
✅ **CORS** - No cross-origin issues
|
|
|
|
## **📈 Performance Considerations**
|
|
|
|
- **API Gateway**: 200 requests/minute limit for diff operations
|
|
- **Git Integration**: 120-second timeout for large operations
|
|
- **Frontend**: 10-second timeout for API calls
|
|
- **Database**: Connection pooling enabled
|
|
|
|
## **🔒 Security**
|
|
|
|
- **Authentication**: JWT tokens required for write operations
|
|
- **Authorization**: User context forwarded to services
|
|
- **Rate Limiting**: Applied at API Gateway level
|
|
- **CORS**: Configured for frontend domain only
|
|
|
|
---
|
|
|
|
**✅ Architecture is now properly configured for microservices deployment!**
|