1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//! # Stigmergy: Emergent Coordination through Shared Data Structures
//!
//! Stigmergy is a biological concept describing how organisms coordinate their activities
//! through modifications to their shared environment. Ants building trails, termites
//! constructing mounds, and birds flocking all demonstrate stigmergic behavior - simple
//! local actions that produce complex global coordination without central control.
//!
//! This crate implements a stigmergic system for software, providing:
//!
//! - **Entity-Component Architecture**: Entities are unique identifiers that can have
//! multiple components attached, following ECS (Entity Component System) patterns
//! - **Schema Validation**: Components are validated against JSON schemas to ensure
//! data integrity and consistency
//! - **PostgreSQL Storage**: All entities and components are persisted in PostgreSQL
//! - **HTTP API**: RESTful endpoints for managing entities and components
//! - **Configuration Management**: System configuration through frontmatter-delimited files
//!
//! ## Core Concepts
//!
//! ### Entities
//! Entities are 32-byte identifiers encoded as URL-safe base64 strings with an "entity:"
//! prefix. They serve as unique handles in the system and can be randomly generated or
//! explicitly specified.
//!
//! ### Components
//! Components are typed data structures that can be attached to entities. Each component
//! has a Rust-style type path identifier (e.g., "Position", "std::collections::HashMap")
//! and JSON data that must conform to a predefined schema.
//!
//! ### Validation
//! All component data is validated against JSON schemas that support:
//! - Primitive types (null, boolean, integer, number, string)
//! - Complex types (arrays, objects)
//! - Enumerations and union types via `oneOf`
//! - Nested structures with full recursion
//!
//! ### Persistence
//! All entities, components, and their relationships are stored in PostgreSQL with
//! automatic timestamp tracking for creation and modification events.
//!
//! ## Architecture
//!
//! The system follows a layered architecture:
//!
//! ```text
//! ┌─────────────────────────────────────────┐
//! │ HTTP API Layer (Axum routes) │
//! ├─────────────────────────────────────────┤
//! │ Business Logic (Component operations) │
//! ├─────────────────────────────────────────┤
//! │ PostgreSQL Database (Persistent storage)│
//! └─────────────────────────────────────────┘
//! ```
//!
//! ## Usage Examples
//!
//! ### Creating and Managing Entities
//!
//! ```rust
//! # use stigmergy::Entity;
//! // Create a new entity with a specific ID
//! let entity = Entity::new([1u8; 32]);
//! let entity_str = entity.to_string(); // "entity:AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE"
//!
//! // Parse an entity from its string representation
//! let parsed: Entity = entity_str.parse().unwrap();
//! assert_eq!(entity, parsed);
//!
//! // Generate a random entity
//! let random_entity = Entity::random_url_safe().unwrap();
//! ```
//!
//! ### Component Schema Definition
//!
//! Component schemas can be created manually or automatically generated using the derive macro:
//!
//! ```rust
//! # use stigmergy::{Component, ComponentDefinition, JsonSchema};
//! # use serde_json::json;
//! // Manual schema definition
//! let component = Component::new("Position").unwrap();
//!
//! let schema = json!({
//! "type": "object",
//! "properties": {
//! "x": { "type": "number" },
//! "y": { "type": "number" },
//! "z": { "type": "number" }
//! },
//! "required": ["x", "y"]
//! });
//!
//! let definition = ComponentDefinition::new(component, schema);
//!
//! // Validate component data
//! let valid_data = json!({"x": 1.0, "y": 2.0, "z": 3.0});
//! assert!(definition.validate_component_data(&valid_data).is_ok());
//! ```
//!
//! ### Automatic Schema Generation
//!
//! Use the `JsonSchemaDerive` macro to automatically generate schemas for structs and enums:
//!
//! ```rust
//! # use stigmergy::JsonSchema;
//! # use serde_json::json;
//! // Define types with automatic schema generation
//! #[derive(stigmergy_derive::JsonSchema)]
//! struct Position {
//! x: f64,
//! y: f64,
//! z: Option<f64>,
//! }
//!
//! #[derive(stigmergy_derive::JsonSchema)]
//! enum Status {
//! Active,
//! Inactive,
//! Pending,
//! }
//!
//! #[derive(stigmergy_derive::JsonSchema)]
//! enum Shape {
//! Circle { radius: f64 },
//! Rectangle { width: f64, height: f64 },
//! }
//!
//! // Generate schemas automatically
//! let position_schema = Position::json_schema();
//! let status_schema = Status::json_schema();
//! let shape_schema = Shape::json_schema();
//!
//! // Unit enums become string enums
//! assert_eq!(status_schema["type"], "string");
//! assert!(status_schema["enum"].as_array().unwrap().len() == 3);
//!
//! // Complex enums use oneOf patterns
//! assert!(shape_schema["oneOf"].is_array());
//! ```
//!
// Public modules
/// PostgreSQL database operations for stigmergy.
///
/// This module provides functions for interacting with the PostgreSQL database,
/// including entity management with automatic timestamp tracking.
/// Command-line interface utilities for program termination and output formatting.
///
/// This module provides common CLI utilities for stigmergy binaries, including
/// error handling, formatted output, and program termination functions.
/// Component-specific utilities for validation and creation.
///
/// This module provides helper functions for working with components and component
/// definitions, including schema validation and error handling.
/// Command-line interface command handlers.
///
/// This module contains organized command handlers for the stigctl CLI application,
/// with each command type implemented in a dedicated submodule.
/// HTTP client utilities for interacting with stigmergy services.
///
/// This module provides a standardized HTTP client for communicating with
/// stigmergy HTTP APIs, handling requests, responses, and error conditions.
pub use ;
pub use ;
pub use ;
pub use ;
pub use DataStoreError;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;