Skip to content

Anasnew99/Code-Orient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

code-orient

πŸš€ AI-free Codebase Explainer - A CLI tool that analyzes repositories and generates comprehensive documentation including architecture overviews, dependency graphs, and onboarding guides.

✨ Features

  • πŸ“Š Architecture Overview - Identifies layers, patterns, and tech stack
  • πŸ”— Dependency Graph - Visualizes module and file dependencies with Mermaid diagrams
  • πŸ“š Onboarding Guide - "Where to start" guide for new developers
  • ⚠️ Risky Files Detection - Identifies god objects and complex files
  • 🎨 Mermaid Diagrams - Generates visual dependency graphs
  • πŸ” AST-based Analysis - Uses ts-morph for accurate TypeScript/JavaScript parsing
  • 🚫 No AI Required - Deterministic analysis based on code structure

πŸ“¦ Installation

Global Installation

pnpm add -g code-orient

Using pnpm dlx (No Installation)

pnpm dlx code-orient ./my-repo

Using npx

npx code-orient ./my-repo

πŸš€ Quick Start

# Analyze a repository
code-orient ./path-to-repo

# Specify custom output directory
code-orient ./path-to-repo -o ./docs

# Skip diagram generation (faster)
code-orient ./path-to-repo --no-diagrams

πŸ“‹ Command Line Options

Usage: code-orient <repo-path> [options]

Options:
  -o, --output <dir>     Output directory for generated reports (default: "./code-orient-output")
  --no-diagrams          Skip generating diagrams
  -h, --help             Display help for command
  -V, --version          Display version number

πŸ“„ Generated Reports

The tool generates the following markdown files in the output directory:

File Description
README.md Overview and summary of the analysis
architecture.md Architecture layers, patterns, and tech stack
dependency-graph.md Module and file dependencies with Mermaid diagrams
onboarding-guide.md Step-by-step guide for new developers
risky-files.md Files that may need refactoring
dependency-graph.mmd Mermaid diagram source file (if diagrams enabled)

πŸ”§ How It Works

  1. AST Parsing - Uses ts-morph to parse TypeScript/JavaScript files
  2. Module Detection - Identifies modules based on directory structure
  3. Dependency Analysis - Tracks imports/exports to build dependency graph
  4. Complexity Metrics - Calculates cyclomatic complexity and identifies risky files
  5. Pattern Recognition - Detects common architectural patterns (hooks, services, components)
  6. Report Generation - Creates markdown reports with diagrams

πŸ“Š Example Output

Architecture Overview

## πŸ—οΈ Architecture Layers

### Presentation Layer
UI components, views, and user-facing elements

### Service Layer
Business logic, API clients, and external service integrations

### Data Layer
Data models, entities, type definitions, and schemas

Dependency Graph

graph TD
  components --> services
  services --> models
  hooks --> components
Loading

Onboarding Guide

The tool generates a comprehensive guide including:

  • Entry points to start reading
  • Key modules to understand
  • Learning path recommendations
  • Code organization patterns
  • Things to watch out for

πŸ› οΈ Development

Prerequisites

  • Node.js 18+
  • pnpm 8+

Setup

# Clone the repository
git clone <repo-url>
cd code-orient

# Install dependencies
pnpm install

# Build the project
pnpm build

# Run locally
pnpm dev ./path-to-repo

# Or run the built version
pnpm start ./path-to-repo

Project Structure

code-orient/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ cli.ts              # CLI entry point
β”‚   β”œβ”€β”€ analyzer.ts          # Main codebase analyzer
β”‚   β”œβ”€β”€ architecture.ts      # Architecture pattern detection
β”‚   β”œβ”€β”€ complexity.ts        # Complexity and risk analysis
β”‚   β”œβ”€β”€ report.ts            # Report generator
β”‚   β”œβ”€β”€ types.ts             # TypeScript type definitions
β”‚   └── reports/             # Individual report generators
β”‚       β”œβ”€β”€ architecture.ts
β”‚       β”œβ”€β”€ dependency.ts
β”‚       β”œβ”€β”€ onboarding.ts
β”‚       └── risky-files.ts
β”œβ”€β”€ dist/                    # Compiled JavaScript output
└── package.json

🎯 Use Cases

  • Onboarding New Developers - Quickly understand codebase structure
  • Code Reviews - Identify risky files and architectural issues
  • Documentation - Generate up-to-date architecture documentation
  • Refactoring - Find god objects and complex files that need attention
  • Dependency Analysis - Understand module dependencies and relationships

βš™οΈ Configuration

The tool automatically detects:

  • TypeScript/JavaScript files (.ts, .tsx, .js, .jsx)
  • Entry points (index.ts, main.ts, app.ts)
  • Architecture layers (components, services, models, etc.)
  • Tech stack (React, Node.js, Express, etc.)
  • Common patterns (hooks, services, components)

πŸ” What Gets Analyzed

  • Files: All TypeScript and JavaScript files
  • Exports: Named and default exports
  • Imports: Relative and absolute imports
  • Classes: Methods, properties, inheritance
  • Functions: Parameters, async/await, exports
  • Interfaces & Types: Type definitions
  • Complexity: Cyclomatic complexity metrics

⚠️ Risky Files Detection

Files are flagged as risky if they have:

  • High cyclomatic complexity (>50)
  • Large file size (>500 lines)
  • Too many dependencies (>20 imports)
  • Too many exports (>15) - potential god object
  • Multiple classes in one file (>5)
  • Large classes/functions (>200/100 lines)

🌟 Why It's Cool

  • βœ… Deterministic - No AI, just AST parsing and analysis
  • βœ… Fast - Analyzes codebases quickly
  • βœ… Accurate - Uses proper AST parsing, not regex
  • βœ… Developer-focused - Solves real onboarding pain points
  • βœ… Visual - Generates diagrams for better understanding
  • βœ… Zero Configuration - Works out of the box
  • βœ… Privacy-friendly - All analysis happens locally

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“ License

MIT

πŸ™ Acknowledgments

Built with:

About

Find out everything about codebases

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors