The Shared Layer contains pure types with zero dependencies on other SystemPrompt crates. These crates define the foundation that all other layers build upon.

Characteristics

  • No database access - Pure types only
  • No side effects - Deterministic behavior
  • No external I/O - No network calls
  • Serializable - All types implement Serialize/Deserialize
  • Compile-time only - No runtime state

Crates

Crate Purpose
systemprompt-models Domain models, API types, DTOs
systemprompt-traits Core trait definitions
systemprompt-identifiers Typed IDs with compile-time safety
systemprompt-extension Extension framework
systemprompt-provider-contracts LLM and tool provider traits
systemprompt-client Generic HTTP client
systemprompt-template-provider Template loading abstractions

Dependency Rules

Shared layer crates:

  • Can depend on external crates (serde, uuid, etc.)
  • Can depend on each other within the layer
  • Cannot depend on Infrastructure, Domain, Application, or Entry crates

Common Patterns

Typed Identifiers

use systemprompt_identifiers::{UserId, TenantId, ContentId};

// Type-safe - compiler prevents mixing ID types
fn get_content(tenant: TenantId, content: ContentId) -> Result<Content> {
    // ...
}

// This would fail to compile:
// get_content(user_id, content_id)  // UserId is not TenantId

Extension Registration

use systemprompt_extension::{Extension, register_extension};

struct MyExtension;

impl Extension for MyExtension {
    fn id(&self) -> &'static str { "my-extension" }
    fn name(&self) -> &'static str { "My Extension" }
    fn version(&self) -> &'static str { "1.0.0" }
    fn dependencies(&self) -> Vec<&'static str> { vec![] }
}

register_extension!(MyExtension);

Provider Contracts

use systemprompt_provider_contracts::{LlmProvider, LlmRequest, LlmResponse};

#[async_trait]
impl LlmProvider for MyProvider {
    fn id(&self) -> &'static str { "my-provider" }

    async fn complete(&self, request: LlmRequest) -> Result<LlmResponse> {
        // Implementation
    }
}

Layer Diagram

┌────────────────────────────────────────────────────────────┐
│                      SHARED LAYER                          │
│                                                            │
│  ┌──────────┐  ┌──────────┐  ┌─────────────┐              │
│  │  models  │  │  traits  │  │ identifiers │              │
│  └──────────┘  └──────────┘  └─────────────┘              │
│                                                            │
│  ┌───────────┐  ┌───────────────────┐  ┌────────┐        │
│  │ extension │  │ provider-contracts │  │ client │        │
│  └───────────┘  └───────────────────┘  └────────┘        │
│                                                            │
│  ┌───────────────────┐                                    │
│  │ template-provider │                                    │
│  └───────────────────┘                                    │
└────────────────────────────────────────────────────────────┘