Crate ggen_core

Crate ggen_core 

Source
Expand description

§ggen-core - Core graph-aware code generation engine

This crate provides the core functionality for RDF-based code generation, including template processing, RDF handling, and deterministic output generation.

§Overview

ggen-core is the foundational crate for the ggen code generation system. It provides:

  • Template Processing: Parse, render, and generate code from templates with RDF integration
  • RDF Graph Management: Load, query, and manipulate RDF data using SPARQL
  • Project Generation: Scaffold complete projects from templates
  • Registry Integration: Discover and install template packs from the registry
  • Lifecycle Management: Orchestrate build, test, and deployment phases
  • Deterministic Output: Ensure reproducible code generation

§Key Modules

§Template System

  • template - Core template parsing and rendering
  • templates - File tree generation from templates
  • pipeline - Template processing pipeline
  • generator - High-level generation engine

§RDF Integration

  • graph - RDF graph management with SPARQL caching
  • rdf - Template metadata and validation
  • delta - Delta-driven projection for graph changes

§Project Management

§Registry and Packs

  • registry - Registry client for pack discovery
  • cache - Local cache manager for downloaded packs
  • lockfile - Dependency lockfile management
  • resolver - Template resolution from packs
  • gpack - Gpack manifest structure and file discovery

§Utilities

  • inject - File injection utilities
  • merge - Three-way merge for delta-driven projection
  • snapshot - Snapshot management for baselines
  • preprocessor - Template preprocessor pipeline
  • register - Tera filter and function registration
  • tera_env - Tera template engine environment utilities

§Security (Week 4 Hardening)

  • security - Security hardening module (command injection prevention, input validation)

§Quick Start

§Basic Template Generation

use ggen_core::{Generator, GenContext, Pipeline};
use std::collections::BTreeMap;
use std::path::PathBuf;

let pipeline = Pipeline::new()?;
let mut vars = BTreeMap::new();
vars.insert("name".to_string(), "MyApp".to_string());

let ctx = GenContext::new(
    PathBuf::from("template.tmpl"),
    PathBuf::from("output")
).with_vars(vars);

let mut generator = Generator::new(pipeline, ctx);
let output_path = generator.generate()?;
println!("Generated: {:?}", output_path);

§Using RDF Graph

use ggen_core::Graph;

let graph = Graph::new()?;
graph.insert_turtle(r#"
    @prefix ex: <http://example.org/> .
    ex:alice a ex:Person ;
             ex:name "Alice" .
"#)?;

let results = graph.query("SELECT ?s ?o WHERE { ?s ex:name ?o }")?;
assert!(!results.is_empty());

§Creating a New Project

use ggen_core::project_generator::{ProjectConfig, ProjectType, create_new_project};
use std::path::PathBuf;

let config = ProjectConfig {
    name: "my-cli".to_string(),
    project_type: ProjectType::RustCli,
    framework: None,
    path: PathBuf::from("."),
};

create_new_project(&config).await?;

Re-exports§

pub use lifecycle::Placeholder;
pub use lifecycle::PlaceholderProcessor;
pub use lifecycle::PlaceholderRegistry;
pub use lifecycle::ReadinessCategory;
pub use lifecycle::ReadinessReport;
pub use lifecycle::ReadinessRequirement;
pub use lifecycle::ReadinessStatus;
pub use lifecycle::ReadinessTracker;
pub use lifecycle::Closed;
pub use lifecycle::Counter;
pub use lifecycle::EmptyPathError;
pub use lifecycle::EmptyStringError;
pub use lifecycle::FileHandle;
pub use lifecycle::NonEmptyPath;
pub use lifecycle::NonEmptyString;
pub use lifecycle::Open;
pub use cache::CacheManager;
pub use cache::CachedPack;
pub use delta::DeltaType;
pub use delta::GraphDelta;
pub use delta::ImpactAnalyzer;
pub use delta::TemplateImpact;
pub use generator::GenContext;
pub use generator::Generator;
pub use github::GitHubClient;
pub use github::PagesConfig;
pub use github::RepoInfo;
pub use github::WorkflowRun;
pub use github::WorkflowRunsResponse;
pub use gpack::GpackManifest;
pub use graph::Graph;
pub use graph::GraphStore;
pub use lockfile::LockEntry;
pub use lockfile::Lockfile;
pub use lockfile::LockfileManager;
pub use merge::ConflictType;
pub use merge::MergeConflict;
pub use merge::MergeResult;
pub use merge::MergeStrategy;
pub use merge::RegionAwareMerger;
pub use merge::RegionUtils;
pub use merge::ThreeWayMerger;
pub use packs::LockedPack;
pub use packs::PackLockfile;
pub use packs::PackSource;
pub use pipeline::Pipeline;
pub use pipeline::PipelineBuilder;
pub use pqc::calculate_sha256;
pub use pqc::calculate_sha256_file;
pub use pqc::PqcSigner;
pub use pqc::PqcVerifier;
pub use rdf::GgenOntology;
pub use rdf::TemplateMetadata;
pub use rdf::TemplateMetadataStore;
pub use rdf::TemplateRelationship;
pub use rdf::TemplateVariable;
pub use rdf::ValidationReport;
pub use rdf::ValidationResult;
pub use rdf::Validator;
pub use rdf::GGEN_NAMESPACE;
pub use registry::RegistryClient;
pub use registry::RegistryIndex;
pub use registry::ResolvedPack;
pub use registry::SearchResult;
pub use resolver::TemplateResolver;
pub use resolver::TemplateSearchResult;
pub use resolver::TemplateSource;
pub use snapshot::FileSnapshot;
pub use snapshot::GraphSnapshot;
pub use snapshot::Region;
pub use snapshot::RegionType;
pub use snapshot::Snapshot;
pub use snapshot::SnapshotManager;
pub use snapshot::TemplateSnapshot;
pub use template::Template;
pub use templates::generate_file_tree;
pub use templates::FileTreeGenerator;
pub use templates::FileTreeNode;
pub use templates::FileTreeTemplate;
pub use templates::GenerationResult;
pub use templates::NodeType;
pub use templates::TemplateContext;
pub use templates::TemplateFormat;
pub use templates::TemplateParser;
pub use ontology_pack::Cardinality;
pub use ontology_pack::CodeGenTarget;
pub use ontology_pack::OntologyClass;
pub use ontology_pack::OntologyConfig;
pub use ontology_pack::OntologyDefinition;
pub use ontology_pack::OntologyFormat;
pub use ontology_pack::OntologyPackMetadata;
pub use ontology_pack::OntologyProperty;
pub use ontology_pack::OntologyRelationship;
pub use ontology_pack::OntologySchema;
pub use ontology_pack::PropertyRange;
pub use ontology_pack::RelationshipType;
pub use ontology::AtomicPromotionCheck;
pub use ontology::AtomicSnapshotPromoter;
pub use ontology::AutonomousControlLoop;
pub use ontology::CompositeValidator;
pub use ontology::Constitution;
pub use ontology::ConstitutionValidation;
pub use ontology::ControlLoopConfig;
pub use ontology::DeltaSigmaProposal;
pub use ontology::DeltaSigmaProposer;
pub use ontology::DynamicValidator;
pub use ontology::GuardSoundnessCheck;
pub use ontology::ImmutabilityCheck;
pub use ontology::Invariant;
pub use ontology::InvariantCheck;
pub use ontology::InvariantResult;
pub use ontology::IterationTelemetry;
pub use ontology::LoopState;
pub use ontology::MinerConfig;
pub use ontology::MockDynamicValidator;
pub use ontology::MockLLMProposer;
pub use ontology::MockPerformanceValidator;
pub use ontology::MockStaticValidator;
pub use ontology::NoRetrocausationCheck;
pub use ontology::Observation;
pub use ontology::ObservationSource;
pub use ontology::OntClass;
pub use ontology::OntProperty;
pub use ontology::OntologyError;
pub use ontology::OntologyExtractor;
pub use ontology::OntologyResult;
pub use ontology::OntologyStats;
pub use ontology::Pattern;
pub use ontology::PatternMiner;
pub use ontology::PatternType;
pub use ontology::PerformanceMetrics;
pub use ontology::PerformanceValidator;
pub use ontology::ProjectionDeterminismCheck;
pub use ontology::PromotionMetrics;
pub use ontology::PromotionResult;
pub use ontology::ProposedChange;
pub use ontology::ProposerConfig;
pub use ontology::RealLLMProposer;
pub use ontology::SLOPreservationCheck;
pub use ontology::SigmaOverlay;
pub use ontology::SigmaReceipt;
pub use ontology::SigmaRuntime;
pub use ontology::SigmaSnapshot;
pub use ontology::SigmaSnapshotId;
pub use ontology::SnapshotGuard;
pub use ontology::SnapshotMetadata;
pub use ontology::StaticValidator;
pub use ontology::TestResult;
pub use ontology::TypeSoundnessCheck;
pub use ontology::ValidationContext;
pub use ontology::ValidationEvidence;
pub use ontology::ValidatorResult;
pub use types::CodeownersGenerator;
pub use types::Detection;
pub use types::DomainProtectionStrategy;
pub use types::EnterpriseConfig;
pub use types::FailureModeEntry;
pub use types::FmeaConfig;
pub use types::FmeaValidationError;
pub use types::GenerationConfig;
pub use types::Occurrence;
pub use types::OwnerEntry;
pub use types::OwnersFile;
pub use types::PathProtectionConfig;
pub use types::PathProtectionError;
pub use types::PokaYokeConfig;
pub use types::ProtectedPath;
pub use types::RegeneratePath;
pub use types::RpnLevel;
pub use types::RpnScore;
pub use types::Severity;
pub use v6::AllowedVocabulary;
pub use v6::BuildReceipt;
pub use v6::CanonicalizationPass;
pub use v6::EmissionPass;
pub use v6::Epoch;
pub use v6::EpochId;
pub use v6::ExtractionPass;
pub use v6::ForbiddenVocabulary;
pub use v6::Guard;
pub use v6::GuardAction;
pub use v6::GuardViolation;
pub use v6::NormalizationPass;
pub use v6::OutputFile;
pub use v6::Pass;
pub use v6::PassContext;
pub use v6::PassExecution;
pub use v6::PassResult;
pub use v6::PassType;
pub use v6::PathGuard;
pub use v6::PipelineConfig;
pub use v6::ReceiptGenerationPass;
pub use v6::SecretGuard;
pub use v6::StagedPipeline;
pub use v6::VerifyMode;
pub use v6::VocabularyRegistry;

Modules§

audit
Audit trail module for tracking ggen sync execution
cache
Local cache manager for gpack templates
cli_generator
CLI Generator for 2026 best practices
codegen
Code generation module
config
Configuration management for ggen
delta
Delta-driven projection for detecting and analyzing RDF graph changes
generator
Template generation engine
github
GitHub API client for Pages and workflow operations
gpack
Gpack manifest structure and file discovery
graph
Comprehensive Oxigraph wrapper with full Store API coverage
inject
File injection utilities for template generation
lifecycle
Universal lifecycle system for ggen (80/20 Implementation)
lockfile
Lockfile manager for ggen.lock
lockfile_unified
Unified Lockfile Trait System for ggen v4.0
manifest
ggen.toml manifest parsing and validation module
merge
Three-way merge for delta-driven projection
ontology
ontology_pack
Ontology Pack Metadata and Core Data Structures
packs
Pack Installation System for ggen v4.0
parallel_generator
Parallel template generation for bulk operations
pipeline
Template processing pipeline with RDF/SPARQL integration
poc
Hygen-like POC with RDF support, prefixes, and inline RDF
poka_yoke
Poka-Yoke (Error-Proofing) mechanisms for ggen CLI.
pqc
Post-Quantum Cryptography (PQC) module for ggen
preprocessor
Template preprocessor pipeline for deterministic text transformations
prevention
Prevention Systems - Design for Lean Six Sigma (DfLSS)
project_generator
Project generator for scaffolding new projects
rdf
RDF metadata management for templates using Oxigraph
register
Tera template environment registration and text transformation helpers
registry
Registry client for fetching gpack metadata
resolver
Template resolver for gpack:template syntax
security
Security module for input validation, command execution safety, and error sanitization
simple_tracing
Simple tracing system for pipeline debugging
snapshot
Snapshot management for delta-driven projection
streaming_generator
Streaming file generator for memory-efficient template processing
telemetry
OpenTelemetry instrumentation for ggen
template
Template system: YAML frontmatter + Tera rendering + RDF/SPARQL integration
template_cache
Template caching system for performance optimization
templates
Template-to-file-tree generation system
tera_env
Tera template environment setup and configuration
types
Enterprise types for FMEA & Poka-Yoke marketplace framework.
v6
ggen v6: Fully-Rendered Libraries via Ontology-First Compilation
validation
SHACL validation module for ggen sync poka-yoke

Macros§

telemetry_context
Create a telemetry context with common attributes
time_operation
Macro for easy performance timing