feat: Phase 2 - Service Management CRUD API (Backend)

Backend Implementation:
- Service model with comprehensive fields (name, url, type, status, health_endpoint)
- Complete CRUD API endpoints for service management
- Health check mechanism with httpx and response time tracking
- Service status tracking (healthy/unhealthy/unknown)
- Service type categorization (backend, frontend, database, cache, etc.)

API Endpoints:
- GET /api/services - Get all services
- POST /api/services - Create new service
- GET /api/services/{id} - Get service by ID
- PUT /api/services/{id} - Update service
- DELETE /api/services/{id} - Delete service
- POST /api/services/{id}/health-check - Check specific service health
- POST /api/services/health-check/all - Check all services health

Frontend Preparation:
- TypeScript type definitions for Service
- Service API client with full CRUD methods
- Health check client methods

Files Added:
- backend/app/models/service.py - Service data model
- backend/app/schemas/service.py - Request/response schemas
- backend/app/services/service_service.py - Business logic
- backend/app/routes/services.py - API route handlers
- frontend/src/types/service.ts - TypeScript types
- frontend/src/api/service.ts - API client

Updated:
- backend/app/main.py - Added services router
- docs/PROGRESS.md - Added Phase 2 status

Next: Frontend UI implementation (Services list page, Add/Edit modal, Health monitoring)

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
jungwoo choi
2025-10-28 16:44:33 +09:00
parent f4b75b96a5
commit e60e531cdc
8 changed files with 642 additions and 3 deletions

View File

@ -0,0 +1,45 @@
import api from './auth';
import type { Service, ServiceCreate, ServiceUpdate, ServiceHealthCheck } from '../types/service';
export const serviceAPI = {
// Get all services
getAll: async (): Promise<Service[]> => {
const { data } = await api.get<Service[]>('/api/services');
return data;
},
// Get service by ID
getById: async (id: string): Promise<Service> => {
const { data } = await api.get<Service>(`/api/services/${id}`);
return data;
},
// Create new service
create: async (serviceData: ServiceCreate): Promise<Service> => {
const { data } = await api.post<Service>('/api/services', serviceData);
return data;
},
// Update service
update: async (id: string, serviceData: ServiceUpdate): Promise<Service> => {
const { data} = await api.put<Service>(`/api/services/${id}`, serviceData);
return data;
},
// Delete service
delete: async (id: string): Promise<void> => {
await api.delete(`/api/services/${id}`);
},
// Check service health
checkHealth: async (id: string): Promise<ServiceHealthCheck> => {
const { data } = await api.post<ServiceHealthCheck>(`/api/services/${id}/health-check`);
return data;
},
// Check all services health
checkAllHealth: async (): Promise<ServiceHealthCheck[]> => {
const { data } = await api.post<ServiceHealthCheck[]>('/api/services/health-check/all');
return data;
},
};

View File

@ -0,0 +1,56 @@
export interface Service {
_id: string;
name: string;
description?: string;
service_type: ServiceType;
url: string;
health_endpoint?: string;
status: ServiceStatus;
last_health_check?: string;
response_time_ms?: number;
created_at: string;
updated_at: string;
metadata: Record<string, any>;
}
export enum ServiceType {
BACKEND = 'backend',
FRONTEND = 'frontend',
DATABASE = 'database',
CACHE = 'cache',
MESSAGE_QUEUE = 'message_queue',
OTHER = 'other',
}
export enum ServiceStatus {
HEALTHY = 'healthy',
UNHEALTHY = 'unhealthy',
UNKNOWN = 'unknown',
}
export interface ServiceCreate {
name: string;
description?: string;
service_type: ServiceType;
url: string;
health_endpoint?: string;
metadata?: Record<string, any>;
}
export interface ServiceUpdate {
name?: string;
description?: string;
service_type?: ServiceType;
url?: string;
health_endpoint?: string;
metadata?: Record<string, any>;
}
export interface ServiceHealthCheck {
service_id: string;
service_name: string;
status: ServiceStatus;
response_time_ms?: number;
checked_at: string;
error_message?: string;
}