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>
94 lines
2.8 KiB
Python
94 lines
2.8 KiB
Python
from datetime import datetime
|
|
from typing import Optional, Dict, Any
|
|
from pydantic import BaseModel, Field, ConfigDict
|
|
|
|
|
|
class ServiceCreate(BaseModel):
|
|
"""Schema for creating a new service"""
|
|
name: str = Field(..., min_length=1, max_length=100)
|
|
description: Optional[str] = Field(default=None, max_length=500)
|
|
service_type: str = Field(default="backend")
|
|
url: str = Field(..., min_length=1)
|
|
health_endpoint: Optional[str] = Field(default="/health")
|
|
metadata: Dict[str, Any] = Field(default_factory=dict)
|
|
|
|
model_config = ConfigDict(
|
|
json_schema_extra={
|
|
"example": {
|
|
"name": "News API",
|
|
"description": "News generation and management API",
|
|
"service_type": "backend",
|
|
"url": "http://news-api:8050",
|
|
"health_endpoint": "/health",
|
|
"metadata": {
|
|
"version": "1.0.0",
|
|
"port": 8050
|
|
}
|
|
}
|
|
}
|
|
)
|
|
|
|
|
|
class ServiceUpdate(BaseModel):
|
|
"""Schema for updating a service"""
|
|
name: Optional[str] = Field(default=None, min_length=1, max_length=100)
|
|
description: Optional[str] = Field(default=None, max_length=500)
|
|
service_type: Optional[str] = None
|
|
url: Optional[str] = Field(default=None, min_length=1)
|
|
health_endpoint: Optional[str] = None
|
|
metadata: Optional[Dict[str, Any]] = None
|
|
|
|
model_config = ConfigDict(
|
|
json_schema_extra={
|
|
"example": {
|
|
"description": "Updated description",
|
|
"metadata": {
|
|
"version": "1.1.0"
|
|
}
|
|
}
|
|
}
|
|
)
|
|
|
|
|
|
class ServiceResponse(BaseModel):
|
|
"""Schema for service response"""
|
|
id: str = Field(alias="_id")
|
|
name: str
|
|
description: Optional[str] = None
|
|
service_type: str
|
|
url: str
|
|
health_endpoint: Optional[str] = None
|
|
status: str
|
|
last_health_check: Optional[datetime] = None
|
|
response_time_ms: Optional[float] = None
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
metadata: Dict[str, Any] = Field(default_factory=dict)
|
|
|
|
model_config = ConfigDict(
|
|
populate_by_name=True,
|
|
from_attributes=True
|
|
)
|
|
|
|
|
|
class ServiceHealthCheck(BaseModel):
|
|
"""Schema for health check result"""
|
|
service_id: str
|
|
service_name: str
|
|
status: str
|
|
response_time_ms: Optional[float] = None
|
|
checked_at: datetime
|
|
error_message: Optional[str] = None
|
|
|
|
model_config = ConfigDict(
|
|
json_schema_extra={
|
|
"example": {
|
|
"service_id": "507f1f77bcf86cd799439011",
|
|
"service_name": "News API",
|
|
"status": "healthy",
|
|
"response_time_ms": 45.2,
|
|
"checked_at": "2025-10-28T10:00:00Z"
|
|
}
|
|
}
|
|
)
|