Skip to content

Commit 504de90

Browse files
committed
Update RFCS
1 parent e1e1b94 commit 504de90

File tree

2 files changed

+167
-11
lines changed

2 files changed

+167
-11
lines changed

docs/rfcs/0-core-architecture-and-extensibility-model.md renamed to docs/rfcs/rfc-0001-core-architecture-and-extensibility-model.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
# RFC: Core Architecture & Extensibility Model
1+
# RFC-0001: Core Architecture & Extensibility Model
2+
3+
**Status:** Draft
4+
**Author:** Kasun B.
5+
**Created:** 2025-10-21
6+
**Target Version:** Sovereign v0.1
7+
**Tags:** Architecture, Extensibility, Plugin System, Multi-DB, RFC
8+
9+
---
210

311
## 1. Vision
412

5-
*Sovereign* aims to evolve into an **enterprise-grade software platform** built on a simple, modular, and self-sufficient architecture.
6-
The guiding philosophy is *"Simplicity is the ultimate sophistication."*
13+
_Sovereign_ aims to evolve into an **enterprise-grade software platform** built on a simple, modular, and self-sufficient architecture.
14+
The guiding philosophy is _"Simplicity is the ultimate sophistication."_
715

816
The platform's foundation must be strong, extendible, and maintainable — without unnecessary dependencies or over-engineering.
917

@@ -18,14 +26,14 @@ The platform's foundation must be strong, extendible, and maintainable — witho
1826

1927
## 3. Technology Stack
2028

21-
| Layer | Current | Future-Ready For |
22-
|-------------------|------------------------------------------------------------|---------------------------------------------------|
23-
| **Runtime** | Node.js (ESM `.mjs`) | Golang (optional replacement) |
24-
| **Web Framework** | Express.js + Handlebars + React/JSX SSR middleware | React/Vite standalone web app |
25-
| **ORM / DB Layer**| Prisma + SQLite | Prisma + PostgreSQL, multi-DB support |
26-
| **API Layer** | REST (core) | Optional GraphQL extension |
27-
| **CLI** | Node-based (`sv` tool) | Manage plugins, migrations, and tenants |
28-
| **Extensions** | `/plugins/*` structure | SDK + manifest-based plugin registration |
29+
| Layer | Current | Future-Ready For |
30+
| ------------------ | -------------------------------------------------- | ---------------------------------------- |
31+
| **Runtime** | Node.js (ESM `.mjs`) | Golang (optional replacement) |
32+
| **Web Framework** | Express.js + Handlebars + React/JSX SSR middleware | React/Vite standalone web app |
33+
| **ORM / DB Layer** | Prisma + SQLite | Prisma + PostgreSQL, multi-DB support |
34+
| **API Layer** | REST (core) | Optional GraphQL extension |
35+
| **CLI** | Node-based (`sv` tool) | Manage plugins, migrations, and tenants |
36+
| **Extensions** | `/plugins/*` structure | SDK + manifest-based plugin registration |
2937

3038
## 4. Directory Structure (Root-level)
3139

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# RFC-0002: Plugin Manifest & Lifecycle
2+
3+
**Status:** Draft
4+
**Author:** Kasun B.
5+
**Created:** 2025-10-21
6+
**Target Version:** Sovereign v0.1
7+
**Tags:** Tags: Plugins, SDK, Manifest, Extensibility, Lifecycle
8+
9+
---
10+
11+
## 1. Purpose
12+
13+
This RFC defines the structure and behavior of the Sovereign Plugin Manifest and its associated lifecycle. It ensures all plugins follow a consistent, predictable format while remaining lightweight and isolated. Plugins extend the platform without modifying core code, interacting only through stable contracts and SDK APIs.
14+
15+
## 2. Design Goals
16+
17+
- Standardize plugin definition and metadata using a manifest file.
18+
- Provide clear lifecycle hooks for setup, enablement, and teardown.
19+
- Support backend, frontend, and hybrid (full-stack) plugins.
20+
- Allow plugin-specific database schemas, migrations, and configuration.
21+
- Maintain version and API compatibility across Sovereign releases.
22+
- Enable validation and integrity checks for plugins before activation.
23+
24+
## 3. Manifest File
25+
26+
_Example `plugin.json`_
27+
28+
```json
29+
{
30+
"name": "@sovereign/papertrail",
31+
"version": "1.0.0",
32+
"description": "Evidence and documentation board system for Sovereign.",
33+
"author": "CommonsEngine Team",
34+
"license": "AGPL-3.0",
35+
"sovereign": {
36+
"engine": ">=0.1.0 <2.0.0",
37+
"entry": "./index.mjs"
38+
},
39+
"capabilities": [
40+
"papertrail.board.read",
41+
"papertrail.board.write",
42+
"papertrail.board.update",
43+
"papertrail.board.delete"
44+
],
45+
"events": {
46+
"subscribe": ["board.created", "user.deleted"]
47+
},
48+
"schema": "./prisma/schema.prisma",
49+
"migrations": "./prisma/migrations",
50+
"config": {
51+
"PT_MAX_CARDS": { "type": "number", "default": 500 }
52+
}
53+
}
54+
```
55+
56+
## 4. Lifecycle Phases
57+
58+
The plugin passes through defined stages handled by the Extension Host.
59+
60+
**1. Discovery**
61+
62+
The extension host scans `/plugins/*/plugin.json` and validates manifests.
63+
Invalid or incompatible plugins are skipped with logged warnings.
64+
65+
**2. Validation**
66+
67+
Manifest is validated using a JSON schema (zod or ajv).
68+
Compatibility ranges for api and engine are checked.
69+
70+
**3. Initialization**
71+
72+
The backend entry module is imported in a sandboxed VM or worker.
73+
The module must export an object implementing the SovereignPlugin interface.
74+
75+
**4. Registration**
76+
77+
The plugin’s register() method is called with a scoped SDK context:
78+
79+
```
80+
{
81+
router, db, events, scheduler, config, caps, log
82+
}
83+
```
84+
85+
Plugins register routes, events, jobs, and declare capabilities here.
86+
87+
**5. Activation**
88+
89+
Optional hook: `onEnable(tenantId)`
90+
91+
Called when the plugin is enabled for a tenant. Used to seed data or initialize resources.
92+
93+
**6. Migration**
94+
95+
Optional hook: `onMigrate()`
96+
97+
Runs when the plugin schema version changes or after install. Executes plugin-provided migrations through the Prisma migration runner.
98+
99+
**7. Deactivation**
100+
101+
Optional hook: `onDisable(tenantId)`
102+
103+
Called when plugin is disabled or tenant deactivated. Used to clean temporary data or stop background jobs.
104+
105+
**8. Shutdown**
106+
107+
When Sovereign stops, the extension host calls `onShutdown()` if present, giving the plugin a chance to release resources gracefully.
108+
109+
## 5. UI Contributions
110+
111+
If the plugin includes a UI section, the manifest’s "ui" block declares routes and slot components. The front-end loader dynamically mounts these into the Handlebars/React SSR application. Slots allow plugins to inject UI fragments into predefined areas such as navbar, sidebar, or settings.
112+
113+
## 6. Migrations and Databases
114+
115+
Each plugin can ship its own Prisma schema and migrations directory. Migrations are applied per plugin, per tenant (if multi-tenancy enabled). The core migration runner maintains a migration registry table to ensure order and idempotency.
116+
117+
## 7. Security Model
118+
119+
- Plugins execute in isolated sandbox or worker contexts.
120+
- Only whitelisted SDK APIs are available.
121+
- Direct fs or network access is prohibited; storage and fetch go through provided service facades.
122+
- Plugin manifests can be signed or verified against an allow-list.
123+
- Capability declarations must match a known prefix (e.g., papertrail.\*).
124+
- Access checks enforced via caps.require() in backend routes.
125+
126+
## 8. Versioning and Compatibility
127+
128+
- The manifest’s `sovereign.api` and `sovereign.engine` define compatibility.
129+
- Deprecated fields remain supported for one minor version before removal.
130+
- Plugins should use semantic versioning and increment minor when changing interfaces.
131+
132+
## 9. CLI Integration
133+
134+
The CLI uses manifest metadata for management commands:
135+
136+
```
137+
sv plugins:list
138+
sv plugins:enable
139+
sv plugins:disable
140+
sv migrate:deploy –plugin
141+
sv plugin:info
142+
```
143+
144+
## 10. Error Handling and Logging
145+
146+
Each plugin receives a scoped logger instance with context `{ pluginId, tenantId }`.
147+
148+
Fatal errors during registration or migration disable the plugin and log diagnostics without halting the platform.

0 commit comments

Comments
 (0)