# `arcella-inspect`
> **Static code introspection for Rust โ structured, machine-readable metadata for AI agents, architecture tools, and automated analysis.**
`arcella-inspect` is a Rust library and CLI tool that parses Rust source code and extracts rich structural metadata โ functions, structs, calls, attributes, documentation โ into a clean, hierarchical **YAML 1.2** format. Designed for integration with AI-driven code understanding, dependency mapping, documentation generation, and architectural audits.
[](https://crates.io/crates/arcella-inspect)
[](https://docs.rs/arcella-inspect)
[](https://github.com/ArcellaTeam/arcella-rust-inspect)
Part of the [**Arcella**](https://github.com/ArcellaTeam) ecosystem.
---
## ๐ Features
- โ
**Accurate AST-based analysis** using `syn`
- โ
**Full function signatures**: parameters, return types, attributes (`pub`, `async`, `unsafe`, etc.)
- โ
**Call graph extraction** with internal/external call distinction
- โ
**Documentation strings** from `///` and `#[doc = "..."]`
- โ
**Cargo workspace support** โ each crate analyzed as a subproject
- โ
**YAML 1.2 output** โ human-readable and AI-friendly
- โ
**Extensible format** designed for future enrichment (AI tags, performance hints, etc.)
---
## ๐ฆ Installation
### As a CLI tool
```bash
cargo install arcella-inspect
```
### As a library (in your `Cargo.toml`)
```toml
[dependencies]
arcella-inspect = "0.1"
```
---
## โถ๏ธ Usage
### CLI: Analyze a project and output YAML
```bash
# Analyze current directory
arc-inspect
# Analyze specific project
arc-inspect ./my-rust-project
# Pipe to file
arc-inspect > architecture.yaml
```
### Library: Use in your own tool
```rust
use arcella_inspect::{analyze_project, analysis_to_yaml};
let root = std::path::Path::new("./my-project");
let analysis = analyze_project(root)?;
let yaml = analysis_to_yaml(&analysis, root)?;
println!("{}", yaml);
```
---
## ๐ Output Format (Simplified)
```yaml
version: "1.0"
subprojects:
- name: "auth-service"
root: "crates/auth"
functions:
- name: "validate_token"
file: "src/validator.rs"
line: 34
returns: "Result<Claims, AuthError>"
parameters:
- "token: &str"
- "secret: &[u8]"
attributes: ["pub", "async"]
docstring: "Validates a JWT token using the provided secret."
calls:
- name: "jsonwebtoken::decode"
external: true
- name: "metrics::record_auth_attempt"
file: "src/metrics.rs"
line: 12
```
๐ See the full [**output format specification**](../FORMAT.md) for details.
---
## ๐ Use Cases
- **AI code agents**: feed structured Rust metadata to LLMs for reasoning
- **Architecture visualization**: generate call graphs and module maps
- **Documentation automation**: extract public APIs with docs and signatures
- **Security & compliance**: audit for unsafe code, external dependencies, or missing docs
- **Refactoring assistance**: identify dead code, tight coupling, or complex call chains
---
## ๐งช Example
Given `src/lib.rs`:
```rust
/// Adds two numbers.
pub fn add(a: i32, b: i32) -> i32 {
a + b
}
```
Running `arc-inspect` produces:
```yaml
version: "1.0"
subprojects:
- name: "my-crate"
root: "."
functions:
- name: "add"
file: "src/lib.rs"
line: 2
returns: "i32"
parameters:
- "a: i32"
- "b: i32"
docstring: "Adds two numbers."
attributes: ["pub"]
calls: []
```
---
## ๐ Documentation
- [Output Format (English)](../FORMAT.md)
- [Output Format (Russian)](../FORMAT-ru.md)
---
## ๐ License
Dual-licensed under **MIT** or **Apache 2.0** โ your choice.
---
## ๐ค Contributing
Contributions are welcome! Please open an issue or PR on [GitHub](https://github.com/ArcellaTeam/arcella-rust-inspect).
Planned improvements:
- Support for enums, traits, and constants
- Performance optimizations for large codebases
- JSON and NDJSON output formats
- Integration with `rust-analyzer` LSP for real-time analysis
---