This directory contains all API services for the "the-space" architecture. Each subdirectory is a standalone service or engine.
- control-center/: Main backend API for admin, modules, and orchestration.
- frontend-engine/: API for user-facing frontend and dashboard.
- system-engine/: System-level API for workflows and automation.
- mcp_adapter.py: Model Context Protocol adapter for AI model and tool interoperability.
The API can be deployed using Docker and Docker Compose with the included deploy.sh script:
# Basic deployment
./deploy.sh
# Deploy and run MCP endpoint tests
./deploy.sh --test-endpointsThe deployment script performs these steps:
- Checks for dependencies (Docker, Docker Compose)
- Verifies port availability (PostgreSQL, Redis, API)
- Builds and starts the containers
- Initializes the database
- Verifies MCP adapter health
- Runs internal functionality tests
- Optionally runs HTTP endpoint tests (with --test-endpoints)
Testing the API is straightforward using the provided scripts:
- MCP Adapter Testing:
scripts/test_mcp_direct.py- Test core MCP functionality directlyscripts/test_mcp_endpoints.sh- Test MCP HTTP endpointsscripts/model_manager.py- Example integrations with the MCP adapter
For detailed instructions, see MCP Adapter Documentation.
- Ensure each submodule has an up-to-date README and implementation guide.
- Pending: Review and update all API documentation to reflect only current and pending endpoints and features.
This document provides an overview of the SpaceNew API, including pluginized apps, admin/control-center endpoints, and guidance for plugin authors. All endpoints are discoverable via OpenAPI/Swagger and the /api/plugins discovery endpoints.
The MCP adapter (/api/mcp/*) provides standardized endpoints for AI model interoperability, tool invocation, and context management following the Model Context Protocol pattern. See MCP Adapter Documentation for details.
Key features:
- Context creation and management
- Tool invocation with standardized interfaces
- Model registration and prediction
- Structured context passing between components
Each plugin is self-contained with its own manifest and API routes. Below is a summary of available plugins and their endpoints.
- Manifest:
/api/plugins/financial_business/plugin_manifest.py - Routes:
/api/plugins/financial_business/routes.py - Description: Provides business account management, transfers, and admin user APIs.
| Method | Path | Summary |
|---|---|---|
| GET | /api/plugins/financial_business/account |
Get account summary |
| POST | /api/plugins/financial_business/transfer |
Transfer funds |
| GET | /api/plugins/financial_business/admin/users |
List admin users |
-
Summary: Get the current user's business account summary.
-
Parameters: None
-
Response Example:
{ "account_id": "123", "balance": 1000.0, "currency": "USD" } -
Error Responses:
- 401: Unauthorized
- 404: Account not found
-
Summary: Transfer funds between accounts.
-
Parameters:
from_account_id: string — Source account IDto_account_id: string — Destination account IDamount: number — Amount to transfercurrency: string — Currency code
-
Request Example:
{ "from_account_id": "123", "to_account_id": "456", "amount": 100.0, "currency": "USD" } -
Response Example:
{ "success": true, "transaction_id": "abc-789" } -
Error Responses:
- 400: Invalid request (e.g., insufficient funds)
- 401: Unauthorized
- 404: Account not found
-
Summary: List all admin users for the business.
-
Parameters: None
-
Response Example:
[ {"user_id": "1", "name": "Alice"}, {"user_id": "2", "name": "Bob"} ] -
Error Responses:
- 401: Unauthorized
- 403: Forbidden
- Plugin Management:
GET /api/control-center/plugins— List installed pluginsPOST /api/control-center/plugins/install— Install a pluginPOST /api/control-center/plugins/enable— Enable a pluginPOST /api/control-center/plugins/disable— Disable a pluginDELETE /api/control-center/plugins/uninstall— Uninstall a plugin
- Monitoring & Workflows:
GET /api/control-center/events— List recent eventsGET /api/control-center/workflows— List workflows
GET /api/plugins— List all available pluginsGET /api/plugins/{plugin}/endpoints— List all endpoints for a plugin
All endpoints return errors in the following format:
{
"error": "Description of the error.",
"code": 400
}Documented error codes:
- 400: Bad Request
- 401: Unauthorized
- 403: Forbidden
- 404: Not Found
- 500: Internal Server Error
- Each plugin must provide a manifest and register its API routes.
- All endpoints must be documented in this README and in OpenAPI/Swagger.
- Use descriptive summaries, parameter/response schemas, and error codes.
- Provide example requests and responses for each endpoint.
- All plugins and core endpoints are auto-documented and discoverable via OpenAPI/Swagger at
/api/docs(or your deployment's equivalent). - To add or update endpoint documentation, use FastAPI's
@routerand@appdecorators with docstrings and Pydantic response/request models in your route files. - After adding or changing endpoints, verify the OpenAPI spec is up-to-date by visiting
/api/docs. - All plugin endpoints must be registered so they appear in the OpenAPI spec and are discoverable via the
/api/plugins/{plugin}/endpointsendpoint.
- Use
GET /api/pluginsto list all available plugins and their metadata. - Use
GET /api/plugins/{plugin}/endpointsto list all endpoints for a specific plugin, including method, path, and summary. - These discovery endpoints are auto-updated as plugins are installed, enabled, or removed.
- Each plugin must provide Alembic-compatible migration scripts for any database tables or changes it introduces.
- Migration scripts should be located in the plugin's directory (e.g.,
/api/plugins/your_plugin/migrations/). - All database models must be integrated with the platform's main database (PostgreSQL) and follow the core data access conventions.
- All core services and plugins should expose a health check endpoint (e.g.,
/healthor/status). - The control center aggregates service health and status for monitoring and alerting.
- See
/api/control-center/routes/plugin_admin.pyfor service registry and monitoring endpoints.
- Each plugin and core service should include integration tests covering all endpoints and workflows.
- Data catalog and automated data management scripts should be provided for any new data models or tables.
- See
/tests/and/data/for examples and templates.
- See PLUGIN_AUTHORING.md for onboarding, plugin structure, manifest, API docs, migration, and workflow/event integration.
-
UI components/pages for plugin management and workflow orchestration are registered in
/core/plugin_system/ui_registry.py. -
Example:
UI_REGISTRY = { "financial_business": { "settingsPage": "/client/admin/FinancialBusinessSettings.tsx", "dashboardWidget": "/client/admin/BusinessAccountOverview.tsx" } }
-
See
/client/README.mdfor consuming the UI registry in the admin dashboard.
-
Plugin events and actions are registered in
/core/plugin_system/workflow_engine.py. -
Example:
EventBus.register_event("funds_transferred", {"params": ["from_account", "to_account", "amount", "currency"]})
-
See plugin manifests (e.g.,
plugin_manifest.py) for declared events.
| Plugin | Endpoint | Status | Notes |
|---|---|---|---|
| Financial Business | /account |
Mocked | Needs DB/service integration |
/transfer |
Mocked | Needs DB/service integration | |
/admin/users |
Mocked | Needs DB/service integration | |
/health |
Implemented | Health endpoint present | |
| Human Simulator | /admissions |
Mocked | Needs real backend logic |
/calendar |
Mocked | Needs real backend logic | |
| MirrorCore | /sessions |
Implemented | Real logic, integrated with DB/NLP |
/metrics |
Implemented | Real logic, advanced NLP | |
| ... | ... | ... | ... |
-
Migration Scripts:
/api/plugins/financial_business/migrations/(Alembic-compatible) -
Health Endpoint:
/api/plugins/financial_business/healthExample response:
{ "status": "ok", "uptime": 12345 } -
Integration Tests:
/tests/plugins/financial_business/(run withpytest)
- Migration Scripts:
/api/plugins/human_simulator/migrations/ - Health Endpoint:
/api/plugins/human_simulator/health - Integration Tests:
/tests/plugins/human_simulator/
- Migration Scripts:
/services/mirrorcore/migrations/ - Health Endpoint:
/services/mirrorcore/health - Integration Tests:
/tests/services/mirrorcore/
- Migration scripts exist in
/api/plugins/<plugin>/migrations/(e.g., financial_business, human_simulator). - Scripts create/update all DB tables/models used by the plugin.
- Models are integrated with PostgreSQL DB using SQLAlchemy.
- Usage:
alembic upgrade headto apply migrations.
-
Health endpoints are implemented for plugins and core services.
-
Returns JSON with status and uptime information.
-
Includes endpoint implementation status tracking in the core health endpoint.
-
Example implementation:
@router.get("/health") async def health(): # Basic health info health_data = {"status": "ok", "uptime": get_uptime()} # Add endpoint implementation status try: from core.endpoint_tracking.registry import get_registry registry = get_registry() health_data["endpoint_implementation_status"] = registry.get_summary() except Exception as e: health_data["endpoint_implementation_status"] = {"error": str(e)} return health_data
- Integration tests exist in
/tests/plugins/<plugin>/. - Tests cover API endpoints, DB operations, and workflow integration.
- Run with:
pytest tests/plugins/financial_business/
- Data catalog schema defined in
/data/schemas/catalog.json. - Example catalog implemented in
/data/catalog/main_catalog.json. - Import/export scripts available in
/data/scripts/. - Data management documentation in
/data/README.md.
- Plugin authoring guide created at
/docs/PLUGIN_AUTHORING.md. - Documentation includes plugin structure, manifest format, API routes, migrations, and UI integration.
- UI components registered in
/core/plugin_system/ui_registry.py. - Registry supports dynamic component loading for plugins.
- Example components for financial_business, human_simulator, and mirror_core plugins.
- Workflow engine implemented in
/core/plugin_system/workflow_engine.py. - Standard events registered for common platform operations.
- Plugin-specific events registered (e.g., funds_transferred, human_simulator.session_started).
- Example workflows defined in the registry.
- Status tracking table maintained in this README.
- Includes plugin name, endpoint, implementation status, and notes.
- Allows for tracking progress of features across plugins.
| Field | Description |
|---|---|
| Manifest | Path to manifest file |
| Routes | Path to routes file |
| Endpoints | Table of endpoints (method, path, summary) |
| Migration Scripts | Path to migration scripts |
| Health Endpoint | Path to health/status endpoint |
| Integration Tests | Path to integration tests |
| Data Catalog | Path to data schemas/catalog |
| Admin UI Integration | UI components/pages for admin/workflows |
| Workflow Integration | Event/workflow definitions and demos |
| Status | Implementation status (done, mocked, pending) |
- Manifest and routes file paths listed
- All endpoints listed in a table
- Each endpoint has summary, parameters, request/response examples, and error codes
- OpenAPI/Swagger spec is up-to-date and endpoints are visible at
/api/docs - Endpoints are discoverable via
/api/plugins/{plugin}/endpoints - Migration scripts and DB integration provided
- Health check endpoint implemented
- Integration tests included
- Data catalog and management scripts provided
- Onboarding and authoring docs referenced
- Admin UI integration documented
- Workflow/event integration documented
- Endpoint implementation status tracked - See
/docs/ENDPOINT_STATUS_TRACKING.mdfor comprehensive documentation
The API Gateway provides centralized routing, authentication, event-driven integration, and real-time WebSocket support for the Space-0.2 platform. It is production-optimized with structured logging, error handling, OpenAPI docs, configuration management, and rate limiting.
- Route:
/api/v1/gateway/{path:path} - Methods: GET, POST, PUT, DELETE
- Auth: JWT Bearer required
- Rate Limiting:
- Admin: 1000/min
- User: 100/min
- Guest: 20/min
- Headers:
Authorization: Bearer <token>X-Session-Id,X-Request-Id(optional, for tracing)
curl -H "Authorization: Bearer <token>" http://localhost:8000/api/v1/gateway/echo- Route:
/api/v1/ws - Auth: JWT Bearer required (query param
tokenorAuthorizationheader) - CSRF Protection:
- If
csrf_tokenis provided, must matchcsrftokencookie
- If
- Channel Authorization:
- Messages of type
join_channelare checked for user/channel permissions
- Messages of type
- Ping/Pong:
- Server sends
pingevery 30s of inactivity; client should respond withpong
- Server sends
import websockets
import asyncio
async def main():
uri = "ws://localhost:8000/api/v1/ws?token=<jwt>"
async with websockets.connect(uri) as ws:
await ws.send('{"type": "ping"}')
print(await ws.recv())
asyncio.run(main())- Route:
/api/v1/gateway/llm/generate - Method: POST
- Payload:
{
"prompt": "Write a poem about the sea.",
"model": "local-llama-3-8b",
"temperature": 0.7
}- Response:
{
"result": "The sea is vast..."
}- Route:
/api/v1/gateway/mcp/agent - Method: POST
- Payload:
{
"agent_id": "my-agent",
"input": "Summarize this document.",
"context": {"user_id": "abc123"}
}- Response:
{
"output": "This document is about..."
}- Plugin Example:
curl -H "Authorization: Bearer <token>" -X POST \
-d '{"action": "simulate", "params": {"scenario": "login"}}' \
http://localhost:8000/api/v1/gateway/plugin/human-simulator- MIS Example:
curl -H "Authorization: Bearer <token>" -X POST \
-d '{"code": "INV123", "pin": "4567"}' \
http://localhost:8000/api/frontend/membership/validate-invitation- Monitoring Example:
curl -H "Authorization: Bearer <token>" http://localhost:8000/api/control-center/monitoring/deep-health- Join Channel:
{"type": "join_channel", "channel_id": "general"}- Error Handling:
{"type": "error", "error": "Not authorized for this channel."}- CSRF Failure:
- If CSRF token is invalid, connection closes with code 4401.
- JWT authentication for all endpoints
- CSRF protection for WebSocket
- Channel-specific authorization (stub, extend as needed)
- Rate limiting per user/role
- Structured logging and error handling
- Human Simulator Plugin:
- Integrated via plugin routes; supports create/update/delete and backend sync.
- Membership Initiation System (MIS):
- Endpoints proxy to MIS backend with authentication, retry, and caching.
- Monitoring:
/api/control-center/monitoring/healthfor health/api/control-center/monitoring/deep-healthfor deep checks/api/control-center/monitoring/business-metricsfor business metrics
- MCP/LLM:
- Use
/api/v1/gateway/mcp/agentfor agent orchestration - Use
/api/v1/gateway/llm/generatefor local LLM completions
- Use
- See
tests/test_gateway.pyfor example API and WebSocket tests. - Use
pytestto run the test suite.
- Implement real DB checks in
is_user_authorized_for_channelfor production. - Add more business metrics and plugin usage stats as needed.