super-solid-system 1.0.0__tar.gz → 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: super-solid-system
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Summary: A lightweight, type-safe microkernel & plug-and-play framework for Python.
5
5
  License-Expression: Apache-2.0
6
6
  License-File: LICENSE
@@ -18,15 +18,13 @@ Classifier: Programming Language :: Python :: 3.13
18
18
  Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
19
19
  Classifier: Typing :: Typed
20
20
  Requires-Dist: pydantic (>=2.0.0)
21
- Project-URL: Homepage, https://github.com/Doth-J/super-solid-system
22
- Project-URL: Issues, https://github.com/Doth-J/super-solid-system/issues
23
- Project-URL: Repository, https://github.com/Doth-J/super-solid-system
21
+ Project-URL: Homepage, https://github.com/super-solid-framework/super-solid-system
22
+ Project-URL: Issues, https://github.com/super-solid-framework/super-solid-system/issues
23
+ Project-URL: Repository, https://github.com/super-solid-framework/super-solid-system
24
24
  Description-Content-Type: text/markdown
25
25
 
26
- # Super-Solid System (`supersolid`)
27
-
28
26
  <p align="center">
29
- <img src="docs/logo.png" alt="Super-Solid" width="250"/>
27
+ <img src="https://raw.githubusercontent.com/super-solid-framework/super-solid-system/main/docs/logo.png" alt="Super-Solid" width="250"/>
30
28
  </p>
31
29
 
32
30
  <h1 align="center">Super-Solid System</h1>
@@ -40,7 +38,7 @@ Description-Content-Type: text/markdown
40
38
  <img alt="License" src="https://img.shields.io/badge/license-Apache%202.0-green"/>
41
39
  <img alt="Tests" src="https://img.shields.io/badge/tests-43%2F43%20passing-brightgreen"/>
42
40
  <img alt="Coverage" src="https://img.shields.io/badge/coverage-100%25-brightgreen"/>
43
- <img alt="Status" src="https://img.shields.io/badge/status-v1.0.0-brightgreen"/>
41
+ <img alt="Status" src="https://img.shields.io/badge/status-v1.0.1-brightgreen"/>
44
42
  </p>
45
43
 
46
44
  > A lightweight, type-safe microkernel & plug-and-play framework for Python.
@@ -490,5 +488,5 @@ TOTAL 438 0 100%
490
488
 
491
489
  ## License
492
490
 
493
- [Apache-2.0](LICENSE)
491
+ [Apache-2.0](https://github.com/super-solid-framework/super-solid-system/blob/main/LICENSE)
494
492
 
@@ -1,468 +1,466 @@
1
- # Super-Solid System (`supersolid`)
2
-
3
- <p align="center">
4
- <img src="docs/logo.png" alt="Super-Solid" width="250"/>
5
- </p>
6
-
7
- <h1 align="center">Super-Solid System</h1>
8
-
9
- <p align="center">
10
- <strong>A robust, generic infrastructure for building modular software systems with plug-and-play engines, dynamic plugin discovery, thread-safe component registries, and fault-tolerant system lifecycle management.</strong><br/>
11
- </p>
12
-
13
- <p align="center">
14
- <img alt="Python" src="https://img.shields.io/badge/python-%3E%3D3.10-blue?logo=python&logoColor=white"/>
15
- <img alt="License" src="https://img.shields.io/badge/license-Apache%202.0-green"/>
16
- <img alt="Tests" src="https://img.shields.io/badge/tests-43%2F43%20passing-brightgreen"/>
17
- <img alt="Coverage" src="https://img.shields.io/badge/coverage-100%25-brightgreen"/>
18
- <img alt="Status" src="https://img.shields.io/badge/status-v1.0.0-brightgreen"/>
19
- </p>
20
-
21
- > A lightweight, type-safe microkernel & plug-and-play framework for Python.
22
-
23
- ## What is Super-Solid System?
24
-
25
- Super-Solid System (`S³`) gives you a small set of building blocks for assembling modular applications:
26
-
27
- - **Registries** hold your components type-checked, thread-safe, and cached.
28
- - **Engines** group registries together and handle boot/shutdown logic.
29
- - **Systems** orchestrate engines in dependency order with automatic rollback.
30
- - **Events** let everything talk to each other through a reactive signal bus.
31
- - **Security** controls who can load what and from where.
32
- - **Health** provides a standard way for components to report their status.
33
-
34
- No magic, no hidden state, no framework lock-in. Just clean abstractions you subclass and wire up.
35
-
36
- ## Architecture
37
-
38
- ```mermaid
39
- graph TD
40
- S["SuperSolidSystem"]
41
- EB["SuperSolidEventBus"]
42
- E1["SuperSolidEngine A"]
43
- E2["SuperSolidEngine B"]
44
- R1["SuperSolidRegistry 1"]
45
- R2["SuperSolidRegistry 2"]
46
- R3["SuperSolidRegistry 3"]
47
- D["DiscoveryStrategy Chain"]
48
- SP["SecurityPolicy"]
49
- H["HealthCheckable"]
50
-
51
- S -->|starts / stops| E1
52
- S -->|starts / stops| E2
53
- S -->|publishes signals| EB
54
- E1 -->|routes loads to| R1
55
- E1 -->|routes loads to| R2
56
- E2 -->|routes loads to| R3
57
- R1 -->|discovers plugins via| D
58
- R1 -.->|enforced by| SP
59
- R2 -.->|enforced by| SP
60
- E1 -.->|implements| H
61
- E2 -.->|implements| H
62
- ```
63
-
64
- The core loop is simple:
65
-
66
- 1. **Register** component classes into typed registries (or let discovery find them).
67
- 2. **Load** components on demand — the registry instantiates, caches, and returns them.
68
- 3. **Wire** registries into engines, engines into a system, and call `start()`.
69
-
70
- ## Installation
71
-
72
- ### Pip (editable, for development)
73
-
74
- ```bash
75
- pip install -e /path/to/super-solid-system
76
- ```
77
-
78
- ### Poetry (as a local dependency)
79
-
80
- ```bash
81
- poetry add --editable /path/to/super-solid-system
82
- ```
83
-
84
- ### Docker (Multi-stage build)
85
-
86
- ```bash
87
- # Build the production Docker image
88
- docker build -t super-solid-system:latest .
89
-
90
- # Run container & verify installation
91
- docker run --rm super-solid-system:latest
92
- ```
93
-
94
- ## Quickstart
95
-
96
- ### 1. Define a base interface and a registry
97
-
98
- ```python
99
- from abc import ABC, abstractmethod
100
- from supersolid.core import super_solid_registry, SuperSolidRegistry
101
-
102
- class BaseAdapter(ABC):
103
- @abstractmethod
104
- def connect(self) -> None: ...
105
-
106
- # [QUICK] Create a typed component registry using super_solid_registry
107
- Adapters = super_solid_registry(name="adapters", component_class=BaseAdapter)
108
-
109
- # [ALTERNATIVE] Create a class component registry by subclassing SuperSolidRegistry
110
- class AdapterRegistry(SuperSolidRegistry[BaseAdapter]):
111
- def __init__(self):
112
- super().__init__(name="adapters", component_class=BaseAdapter)
113
-
114
- Adapters = AdapterRegistry()
115
- ```
116
-
117
- `SuperSolidRegistry` is generic — it enforces that only `BaseAdapter` subclasses can be registered here. Anything else raises a `TypeError` at registration time.
118
-
119
- ### 2. Register components
120
-
121
- You can register manually:
122
-
123
- ```python
124
- Adapters.register("database", "sqlite", SqliteAdapter)
125
- ```
126
-
127
- Or use the `@super_solid_component` decorator for a more declarative style:
128
-
129
- ```python
130
- from supersolid.core import super_solid_component
131
-
132
- @super_solid_component(Adapters, namespace="database", name="postgres", version="1.0.0")
133
- class PostgresAdapter(BaseAdapter):
134
- def __init__(self, dsn: str = "postgresql://localhost/db"):
135
- self.dsn = dsn
136
-
137
- def connect(self) -> None:
138
- print(f"Connected to {self.dsn}")
139
-
140
- def disconnect(self) -> None:
141
- print("Disconnected.")
142
- ```
143
-
144
- The decorator registers the class and attaches a `ComponentMetadata` model you can inspect later:
145
-
146
- ```python
147
- PostgresAdapter._metadata.version # "1.0.0"
148
- PostgresAdapter._metadata.namespace # "database"
149
- ```
150
-
151
- ### 3. Load components
152
-
153
- ```python
154
- db = Adapters.load("database", "postgres", dsn="postgresql://prod/mydb")
155
- db.connect() # Connected to postgresql://prod/mydb
156
- ```
157
-
158
- What happens under the hood:
159
-
160
- 1. Checks the cache if already loaded with the same parameters, returns the cached instance.
161
- 2. If not registered, runs the **discovery chain** (more on that below).
162
- 3. Introspects the constructor signature and filters keyword arguments automatically.
163
- 4. Calls lifecycle hooks (`initialize()` or `boot()`) if the component defines them.
164
- 5. Caches and returns the instance.
165
-
166
- When you're done:
167
-
168
- ```python
169
- Adapters.unload("database", "postgres")
170
- # Calls disconnect() or stop() automatically if the component defines them
171
- ```
172
-
173
- ### 4. Build an engine
174
-
175
- A `SuperSolidEngine` groups registries and provides a unified loading interface:
176
-
177
- ```python
178
- from supersolid.core import SuperSolidEngine
179
-
180
- class CoreEngine(SuperSolidEngine):
181
- def __init__(self):
182
- super().__init__()
183
- self.connect(Adapters) # attach registries
184
-
185
- def boot(self, **kwargs) -> None:
186
- self._running = True
187
- db = self.load("adapters", "database", "postgres")
188
- db.connect()
189
-
190
- def mount(self, app, **kwargs) -> None:
191
- pass # hook for attaching to a web framework, etc.
192
-
193
- def shutdown(self, **kwargs) -> None:
194
- self._running = False
195
- ```
196
-
197
- Need async? Subclass `SuperSolidAsyncEngine` instead — it provides `boot_async()`, `mount_async()`, and `shutdown_async()` that automatically bridge to the sync interface via `asyncio.run()`.
198
-
199
- ### 5. Orchestrate with a system
200
-
201
- ```python
202
- from supersolid.core import SuperSolidSystem
203
-
204
- class MyApp(SuperSolidSystem):
205
- pass
206
-
207
- app = MyApp()
208
- app.add_engine("core", CoreEngine())
209
- app.start() # boots engines in dependency order
210
- # ... your app runs ...
211
- app.stop() # shuts down in reverse order
212
- ```
213
-
214
- If any engine fails during `start()`, all previously booted engines are shut down in reverse (LIFO) order automatically.
215
-
216
- ## Engine Dependencies (Dependency Resolution)
217
-
218
- Engines can declare dependencies on other engines:
219
-
220
- ```python
221
- class ConsensusEngine(SuperSolidEngine):
222
- depends_on = ["network"] # boot network engine first
223
- # ...
224
-
225
- class NetworkEngine(SuperSolidEngine):
226
- depends_on = []
227
- # ...
228
-
229
- system = MyApp()
230
- system.add_engine("consensus", ConsensusEngine())
231
- system.add_engine("network", NetworkEngine())
232
- system.start()
233
- # Boot order: network → consensus (resolved via topological sort)
234
- ```
235
-
236
- The system uses the internal `graphlibs` `TopologicalSorter` so circular dependencies raise a `CycleError` immediately.
237
-
238
- ## Events
239
-
240
- `SuperSolidSystem` comes with a built-in `SuperSolidEventBus` that publishes lifecycle signals automatically:
241
-
242
- | Event | When it fires |
243
- | :-------------------- | :--------------------------------- |
244
- | `EngineBootingEvent` | Right before an engine boots |
245
- | `EngineBootedEvent` | After an engine boots successfully |
246
- | `EngineShutdownEvent` | After an engine shuts down |
247
- | `SystemErrorEvent` | On boot failure or shutdown error |
248
- | `PluginLoadedEvent` | When a plugin is loaded |
249
-
250
- ### Subscribing to events
251
-
252
- ```python
253
- from supersolid.core import SuperSolidEventBus, EngineBootedEvent, super_solid_subscriber
254
-
255
- bus = SuperSolidEventBus()
256
-
257
- @super_solid_subscriber(bus)
258
- def on_boot(event: EngineBootedEvent):
259
- print(f"Engine '{event.engine_name}' is up!")
260
- ```
261
-
262
- The decorator infers the event type from the parameter annotation. You can also be explicit:
263
-
264
- ```python
265
- @super_solid_subscriber(bus, event_type=EngineBootedEvent)
266
- def on_boot(event):
267
- print(f"Engine '{event.engine_name}' is up!")
268
- ```
269
-
270
- ### Publishing events
271
-
272
- The `@super_solid_publisher` decorator auto-publishes a function's return value if it's a `SystemEvent`:
273
-
274
- ```python
275
- from supersolid.core import super_solid_publisher, EngineBootedEvent
276
-
277
- @super_solid_publisher(bus)
278
- def finish_boot(name: str) -> EngineBootedEvent:
279
- # ... do boot work ...
280
- return EngineBootedEvent(engine_name=name)
281
-
282
- finish_boot("consensus") # automatically published to bus
283
- ```
284
-
285
- Works with both sync and async functions.
286
-
287
- ### Custom events
288
-
289
- All events are Pydantic models with `extra = "allow"`, so you can add any fields:
290
-
291
- ```python
292
- from supersolid.core import SystemEvent
293
-
294
- class NodeSyncEvent(SystemEvent):
295
- node_id: str
296
- epoch: int
297
-
298
- # Extra fields work too — they serialize to JSON just fine
299
- event = NodeSyncEvent(node_id="node_01", epoch=42, custom_field="whatever")
300
- event.model_dump_json()
301
- ```
302
-
303
- ## Plugin Discovery
304
-
305
- When you call `registry.load()` for something that isn't registered yet, the registry runs a **discovery chain** to try to find it automatically. The default chain has three strategies:
306
-
307
- ```mermaid
308
- graph LR
309
- A["InternalLib"] -->|not found| B["EntryPoints"]
310
- B -->|not found| C["PluginDirectory"]
311
- style A fill:#4a9,stroke:#333,color:#fff
312
- style B fill:#49a,stroke:#333,color:#fff
313
- style C fill:#a94,stroke:#333,color:#fff
314
- ```
315
-
316
- | Strategy | Where it looks |
317
- | :---------------- | :------------------------------------------------------------------------ |
318
- | `InternalLib` | `{root_pkg}.lib.{registry_name}.{namespace}_{name}` (trusted imports) |
319
- | `EntryPoints` | Setuptools entry points in group `{root_pkg}.{registry_name}.{namespace}` |
320
- | `PluginDirectory` | `plugins.{registry_name}.{namespace}_{name}` (local files) |
321
-
322
- ### Writing a custom discovery strategy
323
-
324
- ```python
325
- from supersolid.core import DiscoveryStrategy
326
-
327
- class RemoteDiscovery(DiscoveryStrategy):
328
- def discover(self, registry, item_namespace, item_name) -> bool:
329
- # fetch plugin from remote source, register it
330
- return registry.is_registered(item_namespace, item_name)
331
-
332
- Adapters.add_discovery(RemoteDiscovery())
333
- ```
334
-
335
- ## Security
336
-
337
- ### SecurityPolicy
338
-
339
- Attach a `SecurityPolicy` to any registry to control access:
340
-
341
- ```python
342
- from supersolid.core import SecurityPolicy
343
-
344
- policy = SecurityPolicy(
345
- allowed_namespaces={"database", "cache"}, # only these namespaces can be loaded
346
- allowed_callers={"core_engine"}, # only these caller IDs are authorized
347
- allow_internal_lib=True, # trusted internal imports still work
348
- allow_dynamic_discovery=False, # block external plugins (EntryPoints, PluginDirectory)
349
- )
350
-
351
- Adapters.set_policy(policy)
352
- ```
353
-
354
- Now `Adapters.load("auth", "oauth")` raises `PermissionError` because `"auth"` isn't in the allowed set. And external discovery strategies are skipped entirely, while `InternalLib` still runs as a trusted fallback.
355
-
356
- ### Plugin verification
357
-
358
- Before importing a plugin file, you can verify its checksum:
359
-
360
- ```python
361
- from supersolid.core import PluginVerifier
362
-
363
- if PluginVerifier.verify_sha256("plugins/consensus/my_plugin.py", expected_hash):
364
- import plugins.consensus.my_plugin
365
- ```
366
-
367
- ## Health Checks
368
-
369
- Any component can implement health reporting by defining a `health_check()` method:
370
-
371
- ```python
372
- from supersolid.core import HealthStatus, HealthState, HealthCheckable
373
-
374
- class DatabaseAdapter:
375
- def health_check(self) -> HealthStatus:
376
- return HealthStatus(
377
- state=HealthState.HEALTHY,
378
- details={"connections": 42, "pool_size": 100}
379
- )
380
-
381
- db = DatabaseAdapter()
382
- isinstance(db, HealthCheckable) # True structural typing via Protocol
383
- db.health_check().model_dump_json()
384
- # {"state": "healthy", "details": {"connections": 42, "pool_size": 100}, "timestamp": ...}
385
- ```
386
-
387
- `HealthCheckable` is a `@runtime_checkable` Protocol no need to inherit from anything.
388
-
389
- The three states are `HEALTHY`, `DEGRADED`, and `UNHEALTHY`.
390
-
391
- ## Project Structure
392
-
393
- ```
394
- super-solid-system/
395
- ├── supersolid/
396
- └── core/
397
- │ ├── __init__.py # Public API exports
398
- │ ├── registry.py # SuperSolidRegistry, super_solid_component, ComponentMetadata
399
- │ ├── engine.py # SuperSolidEngine, AsyncSuperSolidEngine
400
- │ ├── system.py # SuperSolidSystem (orchestrator)
401
- │ ├── events.py # SuperSolidEventBus, SystemEvent, super_solid_subscriber, super_solid_publisher
402
- ├── discovery.py # DiscoveryStrategy, InternalLib, EntryPoints, PluginDirectory
403
- ├── security.py # SecurityPolicy, PluginVerifier
404
- └── health.py # HealthStatus, HealthState, HealthCheckable
405
- ├── tests/
406
- │ ├── test_registry.py # Registration, loading, type enforcement, thread safety, unload
407
- │ ├── test_events.py # Event bus pub/sub, @open_subscriber, @open_publisher
408
- ├── test_security.py # Namespace ACL, caller auth, discovery fallbacks, SHA-256
409
- ├── test_health.py # Health models, Protocol duck typing
410
- │ └── test_system.py # DAG resolution, start/stop, rollback on failure
411
- ├── pyproject.toml
412
- ├── LICENSE
413
- └── README.md
414
- ```
415
-
416
- ---
417
-
418
- ## API Reference
419
-
420
- | Export | Module | What it does |
421
- | :----------------------- | :--------------- | :----------------------------------------------------------------------------------------------- |
422
- | `SuperSolidSystem` | `core.system` | Orchestrator boots/stops engines in dependency order (`SolidSystem`, `OpenSystem`) |
423
- | `SuperSolidEngine` | `core.engine` | Domain hubgroups registries, handles boot/mount/shutdown (`SolidEngine`, `OpenEngine`) |
424
- | `SuperSolidAsyncEngine` | `core.engine` | Async variant supporting `boot_async()`, `mount_async()` (`SolidAsyncEngine`, `AsyncOpenEngine`) |
425
- | `SuperSolidRegistry` | `core.registry` | Generic registry type checks, caching, discovery (`SolidRegistry`, `OpenRegistry`) |
426
- | `super_solid_registry` | `core.registry` | Factory functioninstantiates a `SuperSolidRegistry` (`solid_registry`, `open_registry`) |
427
- | `super_solid_component` | `core.registry` | Decorator registers a class with metadata (`solid_component`, `open_component`) |
428
- | `ComponentMetadata` | `core.registry` | Pydantic model — name, namespace, version, and extras |
429
- | `SuperSolidEventBus` | `core.events` | In-memory pub/sub signal bus (`SolidEventBus`, `OpenEventBus`) |
430
- | `SystemEvent` | `core.events` | Base event model (Pydantic, extra fields allowed) |
431
- | `super_solid_subscriber` | `core.events` | Decoratorsubscribes handler with type inference (`solid_subscriber`, `open_subscriber`) |
432
- | `super_solid_publisher` | `core.events` | Decoratorauto-publishes return values (`solid_publisher`, `open_publisher`) |
433
- | `DiscoveryStrategy` | `core.discovery` | Abstract base subclass to write custom plugin discovery |
434
- | `SecurityPolicy` | `core.security` | Pydantic model — namespace/caller ACL, discovery toggles |
435
- | `PluginVerifier` | `core.security` | SHA-256 file checksum verification |
436
- | `HealthStatus` | `core.health` | Pydantic model state, details, timestamp |
437
- | `HealthState` | `core.health` | Enum — `HEALTHY`, `DEGRADED`, `UNHEALTHY` |
438
- | `HealthCheckable` | `core.health` | Protocol — any class with `health_check()` satisfies it |
439
-
440
- ## Running Tests
441
-
442
- Run the test suite with coverage report:
443
-
444
- ```bash
445
- poetry run python -m pytest --cov=supersolid --cov-report=term-missing
446
- ```
447
-
448
- ```text
449
- Name Stmts Miss Cover
450
- --------------------------------------------------
451
- supersolid/__init__.py 2 0 100%
452
- supersolid/core/__init__.py 8 0 100%
453
- supersolid/core/discovery.py 43 0 100%
454
- supersolid/core/engine.py 49 0 100%
455
- supersolid/core/events.py 85 0 100%
456
- supersolid/core/health.py 14 0 100%
457
- supersolid/core/registry.py 154 0 100%
458
- supersolid/core/security.py 24 0 100%
459
- supersolid/core/system.py 59 0 100%
460
- --------------------------------------------------
461
- TOTAL 438 0 100%
462
-
463
- ============================= 43 passed in 1.12s ==============================
464
- ```
465
-
466
- ## License
467
-
468
- [Apache-2.0](LICENSE)
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/super-solid-framework/super-solid-system/main/docs/logo.png" alt="Super-Solid" width="250"/>
3
+ </p>
4
+
5
+ <h1 align="center">Super-Solid System</h1>
6
+
7
+ <p align="center">
8
+ <strong>A robust, generic infrastructure for building modular software systems with plug-and-play engines, dynamic plugin discovery, thread-safe component registries, and fault-tolerant system lifecycle management.</strong><br/>
9
+ </p>
10
+
11
+ <p align="center">
12
+ <img alt="Python" src="https://img.shields.io/badge/python-%3E%3D3.10-blue?logo=python&logoColor=white"/>
13
+ <img alt="License" src="https://img.shields.io/badge/license-Apache%202.0-green"/>
14
+ <img alt="Tests" src="https://img.shields.io/badge/tests-43%2F43%20passing-brightgreen"/>
15
+ <img alt="Coverage" src="https://img.shields.io/badge/coverage-100%25-brightgreen"/>
16
+ <img alt="Status" src="https://img.shields.io/badge/status-v1.0.1-brightgreen"/>
17
+ </p>
18
+
19
+ > A lightweight, type-safe microkernel & plug-and-play framework for Python.
20
+
21
+ ## What is Super-Solid System?
22
+
23
+ Super-Solid System (`S³`) gives you a small set of building blocks for assembling modular applications:
24
+
25
+ - **Registries** hold your components type-checked, thread-safe, and cached.
26
+ - **Engines** group registries together and handle boot/shutdown logic.
27
+ - **Systems** orchestrate engines in dependency order with automatic rollback.
28
+ - **Events** let everything talk to each other through a reactive signal bus.
29
+ - **Security** controls who can load what and from where.
30
+ - **Health** provides a standard way for components to report their status.
31
+
32
+ No magic, no hidden state, no framework lock-in. Just clean abstractions you subclass and wire up.
33
+
34
+ ## Architecture
35
+
36
+ ```mermaid
37
+ graph TD
38
+ S["SuperSolidSystem"]
39
+ EB["SuperSolidEventBus"]
40
+ E1["SuperSolidEngine A"]
41
+ E2["SuperSolidEngine B"]
42
+ R1["SuperSolidRegistry 1"]
43
+ R2["SuperSolidRegistry 2"]
44
+ R3["SuperSolidRegistry 3"]
45
+ D["DiscoveryStrategy Chain"]
46
+ SP["SecurityPolicy"]
47
+ H["HealthCheckable"]
48
+
49
+ S -->|starts / stops| E1
50
+ S -->|starts / stops| E2
51
+ S -->|publishes signals| EB
52
+ E1 -->|routes loads to| R1
53
+ E1 -->|routes loads to| R2
54
+ E2 -->|routes loads to| R3
55
+ R1 -->|discovers plugins via| D
56
+ R1 -.->|enforced by| SP
57
+ R2 -.->|enforced by| SP
58
+ E1 -.->|implements| H
59
+ E2 -.->|implements| H
60
+ ```
61
+
62
+ The core loop is simple:
63
+
64
+ 1. **Register** component classes into typed registries (or let discovery find them).
65
+ 2. **Load** components on demand — the registry instantiates, caches, and returns them.
66
+ 3. **Wire** registries into engines, engines into a system, and call `start()`.
67
+
68
+ ## Installation
69
+
70
+ ### Pip (editable, for development)
71
+
72
+ ```bash
73
+ pip install -e /path/to/super-solid-system
74
+ ```
75
+
76
+ ### Poetry (as a local dependency)
77
+
78
+ ```bash
79
+ poetry add --editable /path/to/super-solid-system
80
+ ```
81
+
82
+ ### Docker (Multi-stage build)
83
+
84
+ ```bash
85
+ # Build the production Docker image
86
+ docker build -t super-solid-system:latest .
87
+
88
+ # Run container & verify installation
89
+ docker run --rm super-solid-system:latest
90
+ ```
91
+
92
+ ## Quickstart
93
+
94
+ ### 1. Define a base interface and a registry
95
+
96
+ ```python
97
+ from abc import ABC, abstractmethod
98
+ from supersolid.core import super_solid_registry, SuperSolidRegistry
99
+
100
+ class BaseAdapter(ABC):
101
+ @abstractmethod
102
+ def connect(self) -> None: ...
103
+
104
+ # [QUICK] Create a typed component registry using super_solid_registry
105
+ Adapters = super_solid_registry(name="adapters", component_class=BaseAdapter)
106
+
107
+ # [ALTERNATIVE] Create a class component registry by subclassing SuperSolidRegistry
108
+ class AdapterRegistry(SuperSolidRegistry[BaseAdapter]):
109
+ def __init__(self):
110
+ super().__init__(name="adapters", component_class=BaseAdapter)
111
+
112
+ Adapters = AdapterRegistry()
113
+ ```
114
+
115
+ `SuperSolidRegistry` is generic — it enforces that only `BaseAdapter` subclasses can be registered here. Anything else raises a `TypeError` at registration time.
116
+
117
+ ### 2. Register components
118
+
119
+ You can register manually:
120
+
121
+ ```python
122
+ Adapters.register("database", "sqlite", SqliteAdapter)
123
+ ```
124
+
125
+ Or use the `@super_solid_component` decorator for a more declarative style:
126
+
127
+ ```python
128
+ from supersolid.core import super_solid_component
129
+
130
+ @super_solid_component(Adapters, namespace="database", name="postgres", version="1.0.0")
131
+ class PostgresAdapter(BaseAdapter):
132
+ def __init__(self, dsn: str = "postgresql://localhost/db"):
133
+ self.dsn = dsn
134
+
135
+ def connect(self) -> None:
136
+ print(f"Connected to {self.dsn}")
137
+
138
+ def disconnect(self) -> None:
139
+ print("Disconnected.")
140
+ ```
141
+
142
+ The decorator registers the class and attaches a `ComponentMetadata` model you can inspect later:
143
+
144
+ ```python
145
+ PostgresAdapter._metadata.version # "1.0.0"
146
+ PostgresAdapter._metadata.namespace # "database"
147
+ ```
148
+
149
+ ### 3. Load components
150
+
151
+ ```python
152
+ db = Adapters.load("database", "postgres", dsn="postgresql://prod/mydb")
153
+ db.connect() # Connected to postgresql://prod/mydb
154
+ ```
155
+
156
+ What happens under the hood:
157
+
158
+ 1. Checks the cache — if already loaded with the same parameters, returns the cached instance.
159
+ 2. If not registered, runs the **discovery chain** (more on that below).
160
+ 3. Introspects the constructor signature and filters keyword arguments automatically.
161
+ 4. Calls lifecycle hooks (`initialize()` or `boot()`) if the component defines them.
162
+ 5. Caches and returns the instance.
163
+
164
+ When you're done:
165
+
166
+ ```python
167
+ Adapters.unload("database", "postgres")
168
+ # Calls disconnect() or stop() automatically if the component defines them
169
+ ```
170
+
171
+ ### 4. Build an engine
172
+
173
+ A `SuperSolidEngine` groups registries and provides a unified loading interface:
174
+
175
+ ```python
176
+ from supersolid.core import SuperSolidEngine
177
+
178
+ class CoreEngine(SuperSolidEngine):
179
+ def __init__(self):
180
+ super().__init__()
181
+ self.connect(Adapters) # attach registries
182
+
183
+ def boot(self, **kwargs) -> None:
184
+ self._running = True
185
+ db = self.load("adapters", "database", "postgres")
186
+ db.connect()
187
+
188
+ def mount(self, app, **kwargs) -> None:
189
+ pass # hook for attaching to a web framework, etc.
190
+
191
+ def shutdown(self, **kwargs) -> None:
192
+ self._running = False
193
+ ```
194
+
195
+ Need async? Subclass `SuperSolidAsyncEngine` instead — it provides `boot_async()`, `mount_async()`, and `shutdown_async()` that automatically bridge to the sync interface via `asyncio.run()`.
196
+
197
+ ### 5. Orchestrate with a system
198
+
199
+ ```python
200
+ from supersolid.core import SuperSolidSystem
201
+
202
+ class MyApp(SuperSolidSystem):
203
+ pass
204
+
205
+ app = MyApp()
206
+ app.add_engine("core", CoreEngine())
207
+ app.start() # boots engines in dependency order
208
+ # ... your app runs ...
209
+ app.stop() # shuts down in reverse order
210
+ ```
211
+
212
+ If any engine fails during `start()`, all previously booted engines are shut down in reverse (LIFO) order automatically.
213
+
214
+ ## Engine Dependencies (Dependency Resolution)
215
+
216
+ Engines can declare dependencies on other engines:
217
+
218
+ ```python
219
+ class ConsensusEngine(SuperSolidEngine):
220
+ depends_on = ["network"] # boot network engine first
221
+ # ...
222
+
223
+ class NetworkEngine(SuperSolidEngine):
224
+ depends_on = []
225
+ # ...
226
+
227
+ system = MyApp()
228
+ system.add_engine("consensus", ConsensusEngine())
229
+ system.add_engine("network", NetworkEngine())
230
+ system.start()
231
+ # Boot order: network → consensus (resolved via topological sort)
232
+ ```
233
+
234
+ The system uses the internal `graphlibs` `TopologicalSorter` so circular dependencies raise a `CycleError` immediately.
235
+
236
+ ## Events
237
+
238
+ `SuperSolidSystem` comes with a built-in `SuperSolidEventBus` that publishes lifecycle signals automatically:
239
+
240
+ | Event | When it fires |
241
+ | :-------------------- | :--------------------------------- |
242
+ | `EngineBootingEvent` | Right before an engine boots |
243
+ | `EngineBootedEvent` | After an engine boots successfully |
244
+ | `EngineShutdownEvent` | After an engine shuts down |
245
+ | `SystemErrorEvent` | On boot failure or shutdown error |
246
+ | `PluginLoadedEvent` | When a plugin is loaded |
247
+
248
+ ### Subscribing to events
249
+
250
+ ```python
251
+ from supersolid.core import SuperSolidEventBus, EngineBootedEvent, super_solid_subscriber
252
+
253
+ bus = SuperSolidEventBus()
254
+
255
+ @super_solid_subscriber(bus)
256
+ def on_boot(event: EngineBootedEvent):
257
+ print(f"Engine '{event.engine_name}' is up!")
258
+ ```
259
+
260
+ The decorator infers the event type from the parameter annotation. You can also be explicit:
261
+
262
+ ```python
263
+ @super_solid_subscriber(bus, event_type=EngineBootedEvent)
264
+ def on_boot(event):
265
+ print(f"Engine '{event.engine_name}' is up!")
266
+ ```
267
+
268
+ ### Publishing events
269
+
270
+ The `@super_solid_publisher` decorator auto-publishes a function's return value if it's a `SystemEvent`:
271
+
272
+ ```python
273
+ from supersolid.core import super_solid_publisher, EngineBootedEvent
274
+
275
+ @super_solid_publisher(bus)
276
+ def finish_boot(name: str) -> EngineBootedEvent:
277
+ # ... do boot work ...
278
+ return EngineBootedEvent(engine_name=name)
279
+
280
+ finish_boot("consensus") # automatically published to bus
281
+ ```
282
+
283
+ Works with both sync and async functions.
284
+
285
+ ### Custom events
286
+
287
+ All events are Pydantic models with `extra = "allow"`, so you can add any fields:
288
+
289
+ ```python
290
+ from supersolid.core import SystemEvent
291
+
292
+ class NodeSyncEvent(SystemEvent):
293
+ node_id: str
294
+ epoch: int
295
+
296
+ # Extra fields work too — they serialize to JSON just fine
297
+ event = NodeSyncEvent(node_id="node_01", epoch=42, custom_field="whatever")
298
+ event.model_dump_json()
299
+ ```
300
+
301
+ ## Plugin Discovery
302
+
303
+ When you call `registry.load()` for something that isn't registered yet, the registry runs a **discovery chain** to try to find it automatically. The default chain has three strategies:
304
+
305
+ ```mermaid
306
+ graph LR
307
+ A["InternalLib"] -->|not found| B["EntryPoints"]
308
+ B -->|not found| C["PluginDirectory"]
309
+ style A fill:#4a9,stroke:#333,color:#fff
310
+ style B fill:#49a,stroke:#333,color:#fff
311
+ style C fill:#a94,stroke:#333,color:#fff
312
+ ```
313
+
314
+ | Strategy | Where it looks |
315
+ | :---------------- | :------------------------------------------------------------------------ |
316
+ | `InternalLib` | `{root_pkg}.lib.{registry_name}.{namespace}_{name}` (trusted imports) |
317
+ | `EntryPoints` | Setuptools entry points in group `{root_pkg}.{registry_name}.{namespace}` |
318
+ | `PluginDirectory` | `plugins.{registry_name}.{namespace}_{name}` (local files) |
319
+
320
+ ### Writing a custom discovery strategy
321
+
322
+ ```python
323
+ from supersolid.core import DiscoveryStrategy
324
+
325
+ class RemoteDiscovery(DiscoveryStrategy):
326
+ def discover(self, registry, item_namespace, item_name) -> bool:
327
+ # fetch plugin from remote source, register it
328
+ return registry.is_registered(item_namespace, item_name)
329
+
330
+ Adapters.add_discovery(RemoteDiscovery())
331
+ ```
332
+
333
+ ## Security
334
+
335
+ ### SecurityPolicy
336
+
337
+ Attach a `SecurityPolicy` to any registry to control access:
338
+
339
+ ```python
340
+ from supersolid.core import SecurityPolicy
341
+
342
+ policy = SecurityPolicy(
343
+ allowed_namespaces={"database", "cache"}, # only these namespaces can be loaded
344
+ allowed_callers={"core_engine"}, # only these caller IDs are authorized
345
+ allow_internal_lib=True, # trusted internal imports still work
346
+ allow_dynamic_discovery=False, # block external plugins (EntryPoints, PluginDirectory)
347
+ )
348
+
349
+ Adapters.set_policy(policy)
350
+ ```
351
+
352
+ Now `Adapters.load("auth", "oauth")` raises `PermissionError` because `"auth"` isn't in the allowed set. And external discovery strategies are skipped entirely, while `InternalLib` still runs as a trusted fallback.
353
+
354
+ ### Plugin verification
355
+
356
+ Before importing a plugin file, you can verify its checksum:
357
+
358
+ ```python
359
+ from supersolid.core import PluginVerifier
360
+
361
+ if PluginVerifier.verify_sha256("plugins/consensus/my_plugin.py", expected_hash):
362
+ import plugins.consensus.my_plugin
363
+ ```
364
+
365
+ ## Health Checks
366
+
367
+ Any component can implement health reporting by defining a `health_check()` method:
368
+
369
+ ```python
370
+ from supersolid.core import HealthStatus, HealthState, HealthCheckable
371
+
372
+ class DatabaseAdapter:
373
+ def health_check(self) -> HealthStatus:
374
+ return HealthStatus(
375
+ state=HealthState.HEALTHY,
376
+ details={"connections": 42, "pool_size": 100}
377
+ )
378
+
379
+ db = DatabaseAdapter()
380
+ isinstance(db, HealthCheckable) # True — structural typing via Protocol
381
+ db.health_check().model_dump_json()
382
+ # {"state": "healthy", "details": {"connections": 42, "pool_size": 100}, "timestamp": ...}
383
+ ```
384
+
385
+ `HealthCheckable` is a `@runtime_checkable` Protocol — no need to inherit from anything.
386
+
387
+ The three states are `HEALTHY`, `DEGRADED`, and `UNHEALTHY`.
388
+
389
+ ## Project Structure
390
+
391
+ ```
392
+ super-solid-system/
393
+ ├── supersolid/
394
+ │ └── core/
395
+ ├── __init__.py # Public API exports
396
+ ├── registry.py # SuperSolidRegistry, super_solid_component, ComponentMetadata
397
+ │ ├── engine.py # SuperSolidEngine, AsyncSuperSolidEngine
398
+ │ ├── system.py # SuperSolidSystem (orchestrator)
399
+ │ ├── events.py # SuperSolidEventBus, SystemEvent, super_solid_subscriber, super_solid_publisher
400
+ │ ├── discovery.py # DiscoveryStrategy, InternalLib, EntryPoints, PluginDirectory
401
+ │ ├── security.py # SecurityPolicy, PluginVerifier
402
+ └── health.py # HealthStatus, HealthState, HealthCheckable
403
+ ├── tests/
404
+ ├── test_registry.py # Registration, loading, type enforcement, thread safety, unload
405
+ ├── test_events.py # Event bus pub/sub, @open_subscriber, @open_publisher
406
+ │ ├── test_security.py # Namespace ACL, caller auth, discovery fallbacks, SHA-256
407
+ │ ├── test_health.py # Health models, Protocol duck typing
408
+ └── test_system.py # DAG resolution, start/stop, rollback on failure
409
+ ├── pyproject.toml
410
+ ├── LICENSE
411
+ └── README.md
412
+ ```
413
+
414
+ ---
415
+
416
+ ## API Reference
417
+
418
+ | Export | Module | What it does |
419
+ | :----------------------- | :--------------- | :----------------------------------------------------------------------------------------------- |
420
+ | `SuperSolidSystem` | `core.system` | Orchestrator boots/stops engines in dependency order (`SolidSystem`, `OpenSystem`) |
421
+ | `SuperSolidEngine` | `core.engine` | Domain hub groups registries, handles boot/mount/shutdown (`SolidEngine`, `OpenEngine`) |
422
+ | `SuperSolidAsyncEngine` | `core.engine` | Async variant supporting `boot_async()`, `mount_async()` (`SolidAsyncEngine`, `AsyncOpenEngine`) |
423
+ | `SuperSolidRegistry` | `core.registry` | Generic registrytype checks, caching, discovery (`SolidRegistry`, `OpenRegistry`) |
424
+ | `super_solid_registry` | `core.registry` | Factory function instantiates a `SuperSolidRegistry` (`solid_registry`, `open_registry`) |
425
+ | `super_solid_component` | `core.registry` | Decoratorregisters a class with metadata (`solid_component`, `open_component`) |
426
+ | `ComponentMetadata` | `core.registry` | Pydantic modelname, namespace, version, and extras |
427
+ | `SuperSolidEventBus` | `core.events` | In-memory pub/sub signal bus (`SolidEventBus`, `OpenEventBus`) |
428
+ | `SystemEvent` | `core.events` | Base event model (Pydantic, extra fields allowed) |
429
+ | `super_solid_subscriber` | `core.events` | Decorator subscribes handler with type inference (`solid_subscriber`, `open_subscriber`) |
430
+ | `super_solid_publisher` | `core.events` | Decorator auto-publishes return values (`solid_publisher`, `open_publisher`) |
431
+ | `DiscoveryStrategy` | `core.discovery` | Abstract base subclass to write custom plugin discovery |
432
+ | `SecurityPolicy` | `core.security` | Pydantic model namespace/caller ACL, discovery toggles |
433
+ | `PluginVerifier` | `core.security` | SHA-256 file checksum verification |
434
+ | `HealthStatus` | `core.health` | Pydantic model — state, details, timestamp |
435
+ | `HealthState` | `core.health` | Enum `HEALTHY`, `DEGRADED`, `UNHEALTHY` |
436
+ | `HealthCheckable` | `core.health` | Protocolany class with `health_check()` satisfies it |
437
+
438
+ ## Running Tests
439
+
440
+ Run the test suite with coverage report:
441
+
442
+ ```bash
443
+ poetry run python -m pytest --cov=supersolid --cov-report=term-missing
444
+ ```
445
+
446
+ ```text
447
+ Name Stmts Miss Cover
448
+ --------------------------------------------------
449
+ supersolid/__init__.py 2 0 100%
450
+ supersolid/core/__init__.py 8 0 100%
451
+ supersolid/core/discovery.py 43 0 100%
452
+ supersolid/core/engine.py 49 0 100%
453
+ supersolid/core/events.py 85 0 100%
454
+ supersolid/core/health.py 14 0 100%
455
+ supersolid/core/registry.py 154 0 100%
456
+ supersolid/core/security.py 24 0 100%
457
+ supersolid/core/system.py 59 0 100%
458
+ --------------------------------------------------
459
+ TOTAL 438 0 100%
460
+
461
+ ============================= 43 passed in 1.12s ==============================
462
+ ```
463
+
464
+ ## License
465
+
466
+ [Apache-2.0](https://github.com/super-solid-framework/super-solid-system/blob/main/LICENSE)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "super-solid-system"
3
- version = "1.0.0"
3
+ version = "1.0.1"
4
4
  description = "A lightweight, type-safe microkernel & plug-and-play framework for Python."
5
5
  authors = [
6
6
  {name = "Doth-J", email = "theodjoan@gmail.com"}
@@ -33,9 +33,9 @@ dependencies = [
33
33
  ]
34
34
 
35
35
  [project.urls]
36
- Homepage = "https://github.com/Doth-J/super-solid-system"
37
- Repository = "https://github.com/Doth-J/super-solid-system"
38
- Issues = "https://github.com/Doth-J/super-solid-system/issues"
36
+ Homepage = "https://github.com/super-solid-framework/super-solid-system"
37
+ Repository = "https://github.com/super-solid-framework/super-solid-system"
38
+ Issues = "https://github.com/super-solid-framework/super-solid-system/issues"
39
39
 
40
40
  [tool.poetry]
41
41
  packages = [{include = "supersolid"}]