Skip to main content

Crate what_stack

Crate what_stack 

Source
Expand description

Detect project roots and technology stacks from generic process metadata.

what-stack is a small standalone library. It does not depend on Docker, socket collection, async runtimes, logging, serialization, CLI parsing, or any application-specific types. Callers pass ordinary strings and paths: image names, project directories, process names, executable paths, working directories, and command-line arguments.

§Detection Model

The crate exposes focused single-purpose functions plus StackDetector for repeated lookups with caching:

Every detected StackLabel carries a StackKind (runtime, framework, tool, database, or service).

High-level stack detection in StackDetector::detect_stack uses this priority:

  1. Image label.
  2. Process label, when it is final (framework, database, or service).
  3. Project config label.
  4. Process label (runtime or tool).

Config labels are guarded: a project config is used only when the process is a known runtime or tool, or when the process is unknown but its executable belongs to the project. This keeps a postgres or nginx process started from a Next.js folder labeled as itself, and keeps unrelated helper shells from inheriting a project’s framework label just because their working directory happens to be inside that project.

Config labels are also ecosystem-aware: a known runtime or tool accepts only config labels from its own ecosystem. In a Laravel project with vite.config.js, php is Laravel and node is Vite; a python process in a Next.js folder stays Python.

§Scope

This crate only detects labels. It does not discover running processes, inspect network ports, query container engines, kill processes, read custom rule files, or format user-facing output.

§Examples

Direct image and process detection:

use what_stack::{StackKind, detect_from_image, detect_from_process};

let nginx = detect_from_image("ghcr.io/org/nginx:latest").expect("known image");
assert_eq!(nginx, "Nginx");
assert_eq!(nginx.kind(), StackKind::Service);
assert_eq!(detect_from_process("node.exe").expect("known process"), "Node.js");

Cached high-level detection:

use what_stack::{StackDetector, StackInput};

let mut detector = StackDetector::new();
let label = detector.detect_stack(StackInput::new("").image("redis:7-alpine"));

assert_eq!(label.expect("known image"), "Redis");

Structs§

ProjectInput
Process-like path inputs used to resolve a project root.
StackDetector
Cache-owning detector for repeated stack and project lookups.
StackInput
Inputs used by StackDetector to resolve a stack.
StackLabel
Human-readable application, framework, runtime, or service label.

Enums§

StackKind
Broad category of a detected StackLabel.

Constants§

MAX_WALK_DEPTH
Maximum number of directories tested during one upward project walk.

Functions§

detect_from_config
Detect a stack label from configuration files in a project root.
detect_from_image
Detect a stack label from a container or artifact image name.
detect_from_process
Detect a stack label from a process executable name.
detect_from_process_names
Detect a stack label from a process name, falling back to an executable name.
find_project_root
Walk upward from start looking for project marker files.
home_dir
Return the current user’s home directory, when it can be determined.
project_name
Return the display name for a project root path.
resolve_project_root
Resolve a project root from process-like path inputs without caching.