Create governance-service foundation
- Created governance-service application structure - Added pyproject.toml with FastAPI, SQLModel, asyncpg, and aitbc-core dependencies - Implemented main.py with basic governance service structure - Created systemd service file for governance-service (port 8105) - Added README.md with installation and configuration instructions This starts Phase 4.6: Extract Governance Service (foundation created)
This commit is contained in:
57
apps/governance-service/README.md
Normal file
57
apps/governance-service/README.md
Normal file
@@ -0,0 +1,57 @@
|
||||
# AITBC Governance Service
|
||||
|
||||
Manages governance operations.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
cd /opt/aitbc
|
||||
poetry install --with governance-service
|
||||
```
|
||||
|
||||
## Database Setup
|
||||
|
||||
Create a separate database for the governance service:
|
||||
|
||||
```sql
|
||||
CREATE DATABASE aitbc_governance;
|
||||
CREATE USER aitbc_governance WITH PASSWORD 'password';
|
||||
GRANT ALL PRIVILEGES ON DATABASE aitbc_governance TO aitbc_governance;
|
||||
```
|
||||
|
||||
## Running
|
||||
|
||||
```bash
|
||||
# Development
|
||||
python -m governance_service.main
|
||||
|
||||
# Production (systemd)
|
||||
sudo systemctl start governance-service
|
||||
sudo systemctl enable governance-service
|
||||
```
|
||||
|
||||
## Endpoints
|
||||
|
||||
- `GET /health` - Health check
|
||||
- `GET /governance/status` - Get governance status
|
||||
|
||||
## Migration Status
|
||||
|
||||
**Foundation Created:**
|
||||
- Application structure (pyproject.toml, main.py)
|
||||
- Systemd service configuration
|
||||
- Basic health and status endpoints
|
||||
|
||||
**Remaining:**
|
||||
- Extract governance domain models from coordinator-api
|
||||
- Extract governance services from coordinator-api
|
||||
- Extract governance routers from coordinator-api
|
||||
- Setup separate database session management
|
||||
- Update coordinator-api to remove governance code
|
||||
- End-to-end testing with gateway
|
||||
|
||||
## Service Configuration
|
||||
|
||||
- Port: 8105
|
||||
- Database: aitbc_governance
|
||||
- Gateway route: /governance/*
|
||||
17
apps/governance-service/governance-service.service
Normal file
17
apps/governance-service/governance-service.service
Normal file
@@ -0,0 +1,17 @@
|
||||
[Unit]
|
||||
Description=AITBC Governance Service
|
||||
After=network.target postgresql.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=aitbc
|
||||
WorkingDirectory=/opt/aitbc/apps/governance-service
|
||||
Environment="PATH=/opt/aitbc/venv/bin"
|
||||
Environment="PYTHONPATH=/opt/aitbc/packages/py/aitbc-core/src:/opt/aitbc/apps/governance-service/src:/opt/aitbc"
|
||||
Environment="DATABASE_URL=postgresql+asyncpg://aitbc_governance:password@localhost:5432/aitbc_governance"
|
||||
ExecStart=/opt/aitbc/venv/bin/python -m governance_service.main
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
24
apps/governance-service/pyproject.toml
Normal file
24
apps/governance-service/pyproject.toml
Normal file
@@ -0,0 +1,24 @@
|
||||
[project]
|
||||
name = "governance-service"
|
||||
version = "0.1.0"
|
||||
description = "AITBC Governance Service for governance operations"
|
||||
authors = [
|
||||
{name = "AITBC Team", email = "team@aitbc.dev"}
|
||||
]
|
||||
requires-python = ">=3.13"
|
||||
dependencies = [
|
||||
"fastapi>=0.104.0",
|
||||
"uvicorn>=0.24.0",
|
||||
"sqlmodel>=0.0.14",
|
||||
"asyncpg>=0.30.0",
|
||||
"aitbc-core",
|
||||
]
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
||||
[tool.poetry]
|
||||
packages = [
|
||||
{ include = "governance_service", from = "src" }
|
||||
]
|
||||
@@ -0,0 +1,6 @@
|
||||
"""
|
||||
AITBC Governance Service
|
||||
Manages governance operations
|
||||
"""
|
||||
|
||||
__version__ = "0.1.0"
|
||||
72
apps/governance-service/src/governance_service/main.py
Normal file
72
apps/governance-service/src/governance_service/main.py
Normal file
@@ -0,0 +1,72 @@
|
||||
"""
|
||||
Governance Service main application
|
||||
Manages governance operations
|
||||
"""
|
||||
|
||||
from contextlib import asynccontextmanager
|
||||
from typing import AsyncIterator
|
||||
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
|
||||
from aitbc import (
|
||||
configure_logging,
|
||||
get_logger,
|
||||
RequestIDMiddleware,
|
||||
PerformanceLoggingMiddleware,
|
||||
RequestValidationMiddleware,
|
||||
ErrorHandlerMiddleware,
|
||||
)
|
||||
|
||||
# Configure structured logging
|
||||
configure_logging(level="INFO")
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
||||
"""Lifecycle events for the Governance Service."""
|
||||
logger.info("Starting Governance Service")
|
||||
yield
|
||||
logger.info("Shutting down Governance Service")
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
title="AITBC Governance Service",
|
||||
description="Manages governance operations",
|
||||
version="0.1.0",
|
||||
lifespan=lifespan,
|
||||
)
|
||||
|
||||
# Add middleware
|
||||
app.add_middleware(RequestIDMiddleware)
|
||||
app.add_middleware(PerformanceLoggingMiddleware)
|
||||
app.add_middleware(RequestValidationMiddleware, max_request_size=10*1024*1024)
|
||||
app.add_middleware(ErrorHandlerMiddleware)
|
||||
|
||||
|
||||
class HealthResponse(BaseModel):
|
||||
"""Health check response"""
|
||||
status: str
|
||||
service: str
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
async def health() -> HealthResponse:
|
||||
"""Health check endpoint"""
|
||||
return HealthResponse(status="healthy", service="governance-service")
|
||||
|
||||
|
||||
@app.get("/governance/status")
|
||||
async def governance_status() -> dict[str, str]:
|
||||
"""Get governance status"""
|
||||
return {
|
||||
"status": "operational",
|
||||
"service": "governance-service",
|
||||
"message": "Governance service is running",
|
||||
}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run(app, host="0.0.0.0", port=8105)
|
||||
Reference in New Issue
Block a user