Skip to content

crafteraadarsh/codedna

Repository files navigation

CodeDna 🧬

Codebase intelligence engine and AI agent skill.

CI crates.io docs.rs Tests License Rust Platform

Point CodeDna at any local directory or remote Git URL. It scans the repository and produces a complete intelligence report β€” tech stack, architecture, LOC distribution, framework usage, infrastructure, dead code β€” in milliseconds. Output is both human-readable and machine-readable (JSON), making it the ideal first command for any AI coding agent.

codedna analyze .
codedna analyze https://github.com/vercel/next.js
codedna json . --compact

This repository is primarily a Rust CLI tool. It also ships agent integration files so CodeDna can be used cleanly from Codex, OpenCode, and Claude.


Table of Contents


Install CLI

From GitHub

cargo install --git https://github.com/crafteraadarsh/codedna

From Source

git clone https://github.com/crafteraadarsh/codedna
cd codedna
cargo install --path .

Requires Rust stable. Install Rust at rustup.rs.

Verify installation:

codedna --version

Agent Support

CodeDna integrates with agents using their native distribution paths:

  • Codex: packaged skill in skill/codedna/
  • OpenCode: native skill in .opencode/skills/codedna/
  • Claude: plugin marketplace at .claude-plugin/marketplace.json

Install Codex Skill

If you want Codex to use CodeDna as a real skill, use the dedicated package in skill/codedna/.

  • skill/codedna/SKILL.md contains the trigger description and workflow
  • skill/codedna/agents/openai.yaml contains Codex UI metadata

Install it with:

./scripts/install-codex-skill.sh

Package it as a distributable tarball with:

./scripts/package-codex-skill.sh

Bootstrap OpenCode And Claude

To copy the OpenCode skill into another repository and add Claude bootstrap guidance:

./scripts/bootstrap-agent-files.sh /path/to/target-repo opencode claude

To install the Codex skill and bootstrap OpenCode plus Claude in one go:

./scripts/bootstrap-agent-files.sh /path/to/target-repo codex opencode claude

Install OpenCode Skill

Install the OpenCode skill globally with:

./scripts/install-opencode-skill.sh

OpenCode also discovers project-local skills from:

.opencode/skills/codedna/SKILL.md

Install Claude Plugin

This repository now includes an official Claude plugin marketplace:

.claude-plugin/marketplace.json
plugins/codedna/.claude-plugin/plugin.json

In Claude Code, install it with:

/plugin marketplace add crafteraadarsh/codedna
/plugin install codedna@codedna-marketplace

Quick Start

# Full intelligence report (local)
codedna analyze .

# Full intelligence report (remote β€” auto-clones)
codedna analyze https://github.com/vercel/next.js

# JSON for AI agents
codedna json . --compact

# Tech stack only
codedna stack .

# Dead code detection
codedna deadcode https://github.com/user/repo

# Directory tree
codedna map . --depth 3

# Find files using a specific framework
codedna framework react .

Commands

All commands accept a local path or a Git URL.

Command Description
codedna analyze [path|url] Full intelligence report
codedna analyze [path|url] --time Report with elapsed time
codedna stack [path|url] Languages, frameworks, databases
codedna files [path|url] Per-file LOC breakdown
codedna framework <name> [path|url] Files importing a given framework
codedna deadcode [path|url] Unreachable / unused files
codedna map [path|url] Directory tree
codedna map [path|url] --depth N Directory tree limited to N levels
codedna scan [path|url] Raw scanned file list
codedna json [path|url] Full analysis as JSON
codedna json [path|url] --compact Single-line JSON
codedna json [path|url] --time JSON with elapsed time

Example Output

╔════════════════════════════════════════╗
β•‘                                        β•‘
β•‘      CodeDna Intelligence Report      β•‘
β•‘                                        β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

  Project Type
  ────────────
  Full-stack web application

  Stack
  ─────
  React  +  Vite  +  Express

  Databases
  ─────────
  PostgreSQL,  Redis

  Infrastructure
  ──────────────
  Docker  β€’  GitHub Actions

  Architecture
  ────────────
  Frontend β†’ API β†’ Database

  Languages
  ─────────
  TypeScript        β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘   78%     12,450 LOC
  JavaScript        β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘   13%      2,100 LOC
  CSS               β–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘    7%      1,100 LOC
  Markdown          β–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘    2%        130 LOC

  Top 5 Files by LOC
  ──────────────────
  1  src/server.ts                                       340 LOC   TypeScript
  2  src/controllers/user.ts                             290 LOC   TypeScript
  3  src/api/routes.ts                                   240 LOC   TypeScript
  4  src/components/Dashboard.tsx                        180 LOC   TypeScript
  5  src/utils/auth.ts                                   160 LOC   TypeScript

  Dead Code
  ─────────
  src/utils/oldHelper.ts
  src/components/LegacyNavbar.tsx

  Summary
  ───────
  Total LOC          15,780
  Languages          4
  Frameworks         3
  Databases          2
  Infrastructure     2
  Files scanned      148
  Dead files         2
  Dependency links   87

JSON Output

codedna json . produces structured JSON for programmatic consumption:

{
  "project_type": "Full-stack web application",
  "total_loc": 15780,
  "languages": {
    "TypeScript": 12450,
    "JavaScript": 2100,
    "CSS": 1100
  },
  "frameworks": ["React", "Vite", "Express"],
  "databases": ["PostgreSQL", "Redis"],
  "infrastructure": ["Docker", "GitHub Actions"],
  "architecture": "Frontend β†’ API β†’ Database",
  "dead_code": [
    "src/utils/oldHelper.ts",
    "src/components/LegacyNavbar.tsx"
  ],
  "dependency_graph": {
    "src/server.ts": ["src/api/routes.ts"],
    "src/api/routes.ts": ["src/controllers/user.ts"]
  },
  "file_breakdown": [
    { "file": "src/server.ts", "loc": 340, "language": "TypeScript" }
  ]
}

JSON Fields

Field Type Description
project_type string High-level project classification
total_loc number Total non-empty lines of code
languages object Language β†’ LOC map
frameworks string[] Detected frameworks
databases string[] Detected databases / ORMs
infrastructure string[] Detected DevOps tooling
architecture string Inferred architecture pattern
dead_code string[] Unreachable file paths
dependency_graph object File β†’ imported files map
file_breakdown object[] Per-file { file, loc, language }

jq Recipes

# Compact agent context
codedna json . --compact | jq -c '{project_type,frameworks,databases,infrastructure,architecture,total_loc}'

# All frameworks
codedna json . | jq '.frameworks[]'

# Languages sorted by LOC
codedna json . | jq '.languages | to_entries | sort_by(-.value)'

# Dead code files
codedna json . | jq '.dead_code[]'

# Top 5 largest files
codedna json . | jq '.file_breakdown[:5]'

# Check if Docker is used
codedna json . | jq '.infrastructure | contains(["Docker"])'

How It Works

Input (local path or Git URL)
    β”‚
    β–Ό
Git Handler                    β€” detect URL vs path; shallow-clone if remote
    β”‚
    β–Ό
Scanner                        β€” recursive file walk, skip ignored directories
    β”‚
    β”œβ”€β”€β–Ί Language Detector     β€” file extension β†’ language classification
    β”œβ”€β”€β–Ί LOC Counter           β€” count non-empty lines per file            (parallel)
    β”œβ”€β”€β–Ί Framework Detector    β€” parse manifests + per-file import scanning
    β”œβ”€β”€β–Ί Infra Detector        β€” detect Docker, CI, Kubernetes, Makefile
    β”œβ”€β”€β–Ί Dependency Graph      β€” parse import/require/mod statements       (parallel)
    └──► Dead Code Detector    β€” BFS from entry points over dependency graph
                β”‚
                β–Ό
          AnalysisResult
                β”‚
          β”Œβ”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”
          β–Ό           β–Ό
    CLI Report     JSON Output
                      β”‚
                      β–Ό
               Cleanup (delete temp dir if remote)

All file-level analysis runs in parallel via rayon.


Git URL Support

CodeDna accepts Git URLs directly. No manual cloning required.

Supported Formats

https://github.com/user/repo
https://gitlab.com/user/repo
http://github.com/user/repo
git@github.com:user/repo.git
git@gitlab.com:user/repo.git

Any input starting with http://, https://, or git@ is treated as a Git URL. Everything else is a local path.

What Happens

  1. URL detected β†’ shallow clone (--depth 1) into a temp directory
  2. Standard analysis pipeline runs on the cloned content
  3. Output paths are normalized (identical format to local analysis)
  4. Temp directory is deleted automatically

Error Handling

  • Repository not found β€” clear message for non-existent repos
  • Network failure β€” connectivity error with retry suggestion
  • Invalid URL β€” message indicating the URL is not a valid Git repository
  • Auth required β€” message for private repos needing authentication

Detection Coverage

Languages (22)

.rs .ts .tsx .js .jsx .mjs .py .go .sol .css .scss .sass .html .htm .toml .json .yml .yaml .md .sh .bash .zsh

Frameworks (46)

Ecosystem Frameworks
JS / TS React, Next.js, Vue, Nuxt, Svelte, Astro, Remix, Gatsby, Express, Vite, NestJS, Fastify, Koa, Hapi
Python FastAPI, Django, Flask, Starlette, Tornado, aiohttp, Pyramid, Sanic, Litestar
Rust Tokio, Axum, Actix-web, Rocket, Warp, Tonic, Poem, Hyper, Tauri, Leptos, Dioxus, Yew
Go Gin, Echo, Fiber, Gorilla Mux, Beego, Chi, Revel, Uber FX

Databases (26)

Source Databases
package.json PostgreSQL, MongoDB, MySQL, Redis, Prisma, SQLite, Sequelize, TypeORM, Drizzle ORM, Knex, Cassandra, Elasticsearch, DynamoDB
requirements.txt SQLAlchemy, PostgreSQL, MongoDB, Redis, MySQL, Tortoise ORM, Peewee
Cargo.toml SQLx, Diesel, SeaORM, PostgreSQL, MongoDB, Redis, SQLite, Sled, Elasticsearch

Infrastructure

Signal Technology
Dockerfile Docker
docker-compose.yml / .yaml Docker Compose
.github/workflows/*.yml GitHub Actions
k8s/ or kubernetes/ YAML files Kubernetes
Makefile Makefile

Architecture Inference

Signals Result
Frontend + Backend + Database Frontend β†’ API β†’ Database
Frontend + Backend Frontend β†’ API
Backend + Database API β†’ Database
Frontend only Frontend only
Backend only API only
None detected Monolithic / undetermined

Ignored Directories

node_modules/ .git/ target/ dist/ build/ coverage/


Performance

Metric Value
Local analysis (26 files) ~2.6 ms
Remote repos Shallow clone (--depth 1)
Parallelism rayon β€” all CPU cores
100k+ file repos < 5 seconds target
Memory Streaming per-file reads
Temp dir cleanup Automatic after analysis
# Build in release mode for best performance
cargo build --release
./target/release/codedna analyze .

AI Agent Skill

CodeDna is designed as the first command any AI agent runs on a new codebase.

Skill Architecture

codedna/
β”œβ”€β”€ .claude-plugin/
β”‚   └── marketplace.json         ← Claude plugin marketplace definition
β”œβ”€β”€ .opencode/
β”‚   └── skills/
β”‚       └── codedna/
β”‚           └── SKILL.md         ← native OpenCode skill
β”œβ”€β”€ skills/
β”‚   └── codedna-analyzer/
β”‚       β”œβ”€β”€ SKILL.md              ← full portable skill specification
β”‚       └── examples/
β”‚           β”œβ”€β”€ local-analysis.md
β”‚           └── remote-analysis.md
β”œβ”€β”€ skill/
β”‚   └── codedna/
β”‚       β”œβ”€β”€ SKILL.md              ← valid Codex skill package
β”‚       └── agents/openai.yaml    ← Codex skill metadata
β”œβ”€β”€ plugins/
β”‚   └── codedna/
β”‚       β”œβ”€β”€ .claude-plugin/plugin.json
β”‚       └── skills/codedna/SKILL.md
β”œβ”€β”€ templates/
β”‚   └── CLAUDE.md                 ← portable Claude template
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ install-codex-skill.sh
β”‚   β”œβ”€β”€ install-opencode-skill.sh
β”‚   β”œβ”€β”€ package-codex-skill.sh
β”‚   └── bootstrap-agent-files.sh
β”œβ”€β”€ AGENTS.md                     ← OpenCode / Codex CLI
β”œβ”€β”€ CLAUDE.md                     ← Claude Code
β”œβ”€β”€ GEMINI.md                     ← Gemini CLI
└── .cursorrules                  ← Cursor

The detailed, portable reference lives in skills/codedna-analyzer/SKILL.md. The valid Codex skill package lives in skill/codedna/.

Agent Files In This Repo

File Purpose
AGENTS.md Instructions for OpenCode and Codex-style repo guidance here
CLAUDE.md Claude Code bootstrap for this repository
GEMINI.md Gemini CLI bootstrap for this repository
.cursorrules Cursor guidance for this repository
.opencode/skills/codedna/SKILL.md Native OpenCode skill
.claude-plugin/marketplace.json Claude marketplace definition
plugins/codedna/.claude-plugin/plugin.json Claude plugin manifest
plugins/codedna/skills/codedna/SKILL.md Claude-packaged CodeDna skill
skill/codedna/SKILL.md Codex skill trigger and workflow
skill/codedna/agents/openai.yaml Codex UI metadata for the skill
templates/CLAUDE.md Portable Claude bootstrap template
scripts/install-opencode-skill.sh Installs the OpenCode skill globally
scripts/bootstrap-agent-files.sh Copies/install skills into a target repository

Each config file instructs the agent to run codedna json . --compact before any task and use the output to understand the project.

One-Liner for Any Agent

# Get compact context
codedna json . --compact | jq -c '{project_type,frameworks,databases,infrastructure,architecture,total_loc}'

# Or for a remote repo
codedna json https://github.com/user/repo --compact | jq -c '{project_type,frameworks,databases,infrastructure,architecture,total_loc}'

# Copy to clipboard (macOS)
codedna json . --compact | pbcopy

# Copy to clipboard (Linux)
codedna json . --compact | xclip -selection clipboard

Full Skill Specification

See skills/codedna-analyzer/SKILL.md for the complete skill definition β€” JSON schema, field reference, detection tables, architecture inference, jq recipes, and annotated examples.


Project Structure

src/
β”œβ”€β”€ main.rs                 β€” entry point, module declarations
β”œβ”€β”€ cli.rs                  β€” clap CLI definitions and command dispatch
β”œβ”€β”€ git_handler.rs          β€” Git URL detection, shallow clone, temp dir management
β”œβ”€β”€ analysis.rs             β€” analysis pipeline orchestration
β”œβ”€β”€ scanner.rs              β€” recursive file walker (walkdir)
β”œβ”€β”€ language_detector.rs    β€” file extension β†’ language mapping
β”œβ”€β”€ loc_counter.rs          β€” line counting with binary detection
β”œβ”€β”€ framework_detector.rs   β€” manifest parsing + per-file import scanning
β”œβ”€β”€ dependency_graph.rs     β€” import/require/mod statement parsing
β”œβ”€β”€ dead_code_detector.rs   β€” BFS reachability from entry points
β”œβ”€β”€ reporter.rs             β€” CLI report + JSON output formatting
└── repo_map.rs             β€” tree-style directory rendering

Dependencies

Crate Purpose
clap 4 CLI argument parsing (derive)
walkdir 2 Recursive directory traversal
serde + serde_json JSON serialization
rayon Parallel file processing
git2 0.19 Git operations (vendored OpenSSL)
tempfile 3 Temp directory management

CI

Cross-platform CI via GitHub Actions β€” runs on every push to main:

  • Clippy β€” lint-free (-D warnings)
  • Rustfmt β€” format check
  • Tests β€” Ubuntu, macOS, Windows (155 tests)
  • Release builds β€” Linux x86_64, macOS x86_64, macOS ARM64, Windows x86_64

Release binaries are uploaded as artifacts on every green build.


Contributing

Contributions welcome. See CONTRIBUTING.md for the full guide.

cargo test          # 155 tests must pass
cargo clippy        # must be warning-free
cargo fmt           # must be formatted

License

MIT β€” see LICENSE.


CodeDna β€” codebase intelligence for humans and AI agents 🧬

About

🧬 Rust-powered codebase intelligence engine β€” reveals tech stack, architecture, LOC distribution, dead code, and more. Agent-friendly JSON output.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors