Skip to content

SuperInstance/cosmic-web

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

🌌 cosmic-web

The cosmic web as fleet architecture.

Map your dependency ecosystem onto the large-scale structure of the universe. Filaments of repos connected by imports. Voids where no repos exist. Clusters of tightly-coupled modules. Hub nodes as critical infrastructure.

         ╭─ ★ cluster-core ──★──★ cluster-utils ─╮
        ╱                    │                    ╲
  ·  ·  ·  ·  ·  ·  ·  ·  ★ hub-node  ·  ·  ·  ·  ·  ·  VOID
        ╲                    │                    ╱
         ╰─ ★ filament-b ───★──★ filament-c ───★─── filament-d ─── ·  ·
                                  │
                             ★ cluster-deep
                              ╱   │   ╲
                             ★    ★    ★

The Metaphor

In cosmology, the cosmic web is the largest known structure in the universe — a network of filaments, clusters, and voids stretching across billions of light-years. Matter isn't uniformly distributed; it clumps along filaments, accumulates at nodes, and leaves vast empty voids in between.

Your dependency ecosystem is the same:

Cosmology Fleet Architecture
Filaments Chains of repos linked by imports — deep supply chains
Voids Gaps in dependency-space — untapped niches, missing abstractions
Clusters Tightly-coupled repo groups — should probably be one repo
Nodes Critical hubs — single points of failure in the ecosystem
Density field Smoothed map of where repos concentrate
LSS statistics Correlation functions, power spectra — scaling relations of code

Modules

filament — Dependency Filaments

Detect chains of repos connected by imports using Minimum Spanning Tree (MST) of the dependency graph. Long filaments = deep supply chains = fragile infrastructure.

use cosmic_web::{DependencyGraph, FilamentDetector};

let mut graph = DependencyGraph::new();
graph.add_edge("serde", "serde_json", 1.0);
graph.add_edge("serde_json", "my-api", 0.8);
graph.add_edge("my-api", "my-app", 0.6);

let detector = FilamentDetector::new(2);
let filaments = detector.detect(&graph);

for f in &filaments {
    println!("Filament: {} repos, length={:.2}, strength={:.2}",
        f.repos.len(), f.length, f.strength);
}

void — Void Detection

Find empty regions of dependency-space using a watershed algorithm on a density field. Voids represent untapped niche space — no repos exist there yet.

use cosmic_web::{DependencyGraph, VoidDetector};

let graph = build_ecosystem_graph();
let detector = VoidDetector::new(50, 0.1);
let voids = detector.detect(&graph);

for v in &voids {
    println!("Void: radius={:.2}, volume={:.2}, nearby={} repos",
        v.radius, v.volume, v.nearby_repos);
}

cluster — Repo Clusters

Detect groups of tightly-coupled repos with the friends-of-friends (FoF) algorithm. Clusters suggest modules that should be merged or refactored.

use cosmic_web::{DependencyGraph, ClusterDetector};

let graph = build_ecosystem_graph();
let detector = ClusterDetector::new(0.5);
let clusters = detector.detect(&graph);

for c in &clusters {
    println!("Cluster: {} repos, mass={:.2}", c.repos.len(), c.mass);
}

// Cluster mass function (like the halo mass function!)
let (centers, counts) = ClusterDetector::mass_function(&clusters, 10);

node — Critical Hub Nodes

Identify repos depended on by many others using betweenness, degree, and eigenvector centrality. These are your single points of failure.

use cosmic_web::{DependencyGraph, HubDetector};

let graph = build_ecosystem_graph();
let detector = HubDetector::new(2);
let hubs = detector.detect(&graph);

for h in &hubs {
    println!("Hub: {} — betweenness={:.3}, degree={}, eigenvector={:.3}",
        h.repo, h.betweenness, h.degree, h.eigenvector_centrality);
}

density — Density Field

Kernel density estimation (KDE) on repo positions. Overdense regions are clusters, underdense are voids. Produces a smoothed density map of your ecosystem.

use cosmic_web::{DependencyGraph, DensityEstimator};

let mut graph = build_ecosystem_graph();
graph.compute_positions(100); // spring layout

let estimator = DensityEstimator::new(50, 0.3);
let field = estimator.estimate(graph.positions.as_ref().unwrap());

println!("Density contrast: {:.2}", field.contrast());
println!("Overdense cells: {}", field.overdense_cells(2.0).len());

large_scale — Large-Scale Structure Statistics

Compute two-point correlation functions, power spectra, and correlation lengths. Fit scaling relations and compare to cosmological values (γ ≈ 1.8, r₀ ≈ 5 h⁻¹ Mpc).

use cosmic_web::{DependencyGraph, LSSAnalyzer};

let graph = build_ecosystem_graph();
let analyzer = LSSAnalyzer::new(20);
let stats = analyzer.analyze(&graph);

println!("Correlation length: {:.2}", stats.correlation_length);
println!("Clusters: {}, Voids: {}, Filaments: {}",
    stats.n_clusters, stats.n_voids, stats.n_filaments);

// Compare to cosmological scaling
let positions = graph.positions.unwrap();
let cf = analyzer.correlation_function(&positions);
let (gamma, r0) = analyzer.fit_scaling_relation(&cf);
println!("Scaling: ξ(r) ∝ (r/{:.2})^{:.2}", r0, gamma);

Architecture

    ╭──────────────────────────────────────────────────────────╮
    │                    cosmic-web                            │
    │                                                          │
    │  ┌──────────┐  ┌──────────┐  ┌──────────┐              │
    │  │ filament  │  │  void_   │  │ cluster  │              │
    │  │  (MST)    │  │(watershed)│  │  (FoF)   │              │
    │  └────┬─────┘  └────┬─────┘  └────┬─────┘              │
    │       │              │              │                     │
    │       └──────────────┼──────────────┘                    │
    │                      │                                   │
    │              ┌───────┴────────┐                          │
    │              │    density     │                          │
    │              │     (KDE)      │                          │
    │              └───────┬────────┘                          │
    │                      │                                   │
    │              ┌───────┴────────┐                          │
    │              │  large_scale   │                          │
    │              │  (ξ, P(k), r₀) │                          │
    │              └────────────────┘                          │
    │                                                          │
    │  ┌──────────┐  ┌──────────────────────────────┐         │
    │  │   node   │  │     DependencyGraph           │         │
    │  │(centrality)│ │  (repos, edges, positions)   │         │
    │  └──────────┘  └──────────────────────────────┘         │
    ╰──────────────────────────────────────────────────────────╯

ASCII Visualization

A dependency ecosystem mapped to the cosmic web:

    VOID                    ·  ·  ·  ·  ·  ·  ·  ·  VOID
       ·  ·  ·  ·  ·  ·                 ·  ·  ·  ·  ·  ·
                     ╭─★─★─★─╮
    ·  ·  ·  ·  ·   │CLUSTER │   ·  ·  ·  ·  ·  ·  ·  ·
                     │  A     │
    ·  ·  ·  ·  ·   ╰───★────╯   ·  ·  ·  ·  ·  ·  ·  ·
                         │
    ·  ·  ·  ·  ·    ★ HUB ★    ·  ·  ·  ·  ·  ·  ·  ·
                      ╱  │  ╲
    ·  ·  ·     ╭─★──★──★──★──★─╮    ·  ·  FILAMENT  ·  ·
                │   FILAMENT B    │
    ·  ·  ·    ╰──────★──────────╯   ·  ·  ·  ·  ·  ·  ·
                        │
    ·  ·  ·  ·  ·   ╭──★──╮    ·  ·  ·  ·  ·  ·  ·  ·  ·
                     │CLUST│
    ·  ·  ·  ·  ·   │ ER C │   ·  ·  ·  ·  ·  ·  ·  ·  ·
                     ╰─★─★─╯
    VOID          ·  ·  ·  ·  ·  ·  ·  ·              VOID

Legend:

  • = repo node
  • CLUSTER = tightly-coupled group
  • FILAMENT = dependency chain
  • HUB = critical node (high centrality)
  • VOID = empty region (no repos)

Installation

[dependencies]
cosmic-web = "0.1"

Core Types

struct Filament {
    repos: Vec<String>,     // Repos in the chain
    length: f64,            // Total filament length
    strength: f64,          // Total edge weight
}

struct Void {
    center: Vec<f64>,       // Center of the void
    radius: f64,            // Effective radius
    volume: f64,            // Effective volume
    nearby_repos: usize,    // Repos near the boundary
}

struct Cluster {
    repos: Vec<String>,     // Member repos
    mass: f64,              // Total internal edge weight
    centroid: Vec<f64>,     // Center of mass
    radius: f64,            // Max distance from centroid
}

struct HubNode {
    repo: String,           // Repository name
    betweenness: f64,       // Betweenness centrality
    degree: usize,          // Connection count
    eigenvector_centrality: f64,  // Influence score
}

struct DensityField {
    grid: Vec<Vec<f64>>,    // 2D density grid
    resolution: usize,      // Grid resolution
    bounds: (f64, f64),     // Spatial bounds
}

struct LSSStats {
    correlation_length: f64,    // Scale where ξ(r) = 1
    power_spectrum: Vec<f64>,   // P(k) values
    n_clusters: usize,          // Cluster count
    n_voids: usize,             // Void count
    n_filaments: usize,         // Filament count
}

Algorithms

Component Algorithm Cosmological Analog
Filament detection Kruskal's MST Cosmic filament tracing
Void detection Watershed on density field Watershed void finder
Cluster detection Friends-of-friends (FoF) Halo finder
Hub identification Brandes' betweenness + power iteration Cluster centrality
Density estimation Gaussian KDE Galaxy density maps
LSS statistics Two-point correlation, DFT ξ(r), P(k) analysis

The Physics

In real cosmology:

  • Filaments connect galaxy clusters, forming the backbone of the cosmic web
  • Voids occupy ~80% of volume but contain <10% of matter
  • Clusters sit at filament intersections — the most massive gravitationally bound objects
  • The two-point correlation function ξ(r) ∝ (r/r₀)^(-γ) with γ ≈ 1.8
  • The power spectrum P(k) encodes all clustering information

In your codebase, the same structures emerge naturally from dependency patterns. Deep filaments mean fragile supply chains. Large voids mean missed opportunities. Overweighted hubs mean bus factor = 1.

Map your universe. Find your structure.

License

MIT

About

Fleet as cosmic web: dependency filaments, empty voids, repo clusters, hub nodes with centrality measures, and large-scale structure statistics

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages