Skip to content

Swift Codebase analyzer / Developer Onboarding on Swift Project / Statistics report for your codebase

License

Notifications You must be signed in to change notification settings

Exey/SwiftCodeContext

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” SwiftCodeContext

Native macOS CLI tool for Swift codebase intelligence β€” find critical files, generate dependency graphs, learning paths, and AI-powered insights.

Built 100% in Swift using Apple-native technologies


⚑ Generate Report in 10 Seconds

cd SwiftCodeContext
swift run codecontext analyze ~/path/to/your/project --open

That's it. swift run builds automatically if needed, then opens the HTML report in Safari. No separate swift build step required.

Based on https://github.com/TelegramMessenger/Telegram-iOS

What the Report Contains

The generated HTML report includes:

  1. πŸ“Š Summary β€” total files, lines of code, declarations by type (structs, classes, enums, protocols, actors), and package count

  2. πŸ‘₯ Team Contribution Map β€” developer activity tracking with files modified, commit counts, and first/last change dates

  3. πŸ“š Dependencies & Imports β€” comprehensive classification into Apple frameworks, external dependencies, and local Swift packages with interactive tag clouds

  4. πŸ”₯ Knowledge Hotspots β€” files with the highest PageRank scores, identifying the most connected and architecturally significant code. Each entry includes clickable module badges for quick navigation and inline documentation previews where available

  5. πŸ“‹ Module Insights β€” package penetration analysis showing which modules are imported by the most other packages (foundational dependencies), plus quality metrics including top modules by TODO/FIXME density and technical debt indicators

  6. πŸ“ Longest Functions β€” ranked list of functions with the highest line counts, featuring clickable module badges for context and quick navigation to potential refactoring candidates

  7. πŸ“¦ Packages & Modules β€” detailed breakdown of each local Swift package with:

    • Complete file inventory sorted by lines of code
    • Declaration statistics by type (classes, structs, enums, protocols, actors, extensions)
    • Interactive force-directed dependency graph per package, colored by declaration type (πŸ”΅ classes, 🟒 structs, 🟑 enums, πŸ”΄ actors)
    • File-level annotations showing code intent through inline documentation previews
    • Precise line counts and declaration tags for every file
    • Package-level metrics including total files, lines of code, and declaration distribution

πŸš€ Quick Start

cd SwiftCodeContext

# Build
swift build

# Analyze a Swift project
swift run codecontext analyze /path/to/your/swift/project

# See all commands
swift run codecontext --help

πŸ—οΈ How to Build & Install

Option 1: Swift CLI (Recommended)

cd SwiftCodeContext

# Debug build (fast compilation)
swift build

# Run directly
swift run codecontext analyze ~/Projects/MyApp

# Release build (optimized, ~3x faster runtime)
swift build -c release

# The binary is at:
.build/release/codecontext

Option 2: Install System-Wide

swift build -c release
sudo cp .build/release/codecontext /usr/local/bin/

# Now use from anywhere:
codecontext analyze ~/Projects/MyApp
codecontext evolution --months 12
codecontext ask "Where is the networking layer?"

Option 3: One-Line Install Script

swift build -c release && sudo cp .build/release/codecontext /usr/local/bin/ && echo "βœ… installed"

Option 4: Xcode (for Development / Debugging)

# Open as Swift Package (Xcode 15+)
open Package.swift

In Xcode:

  1. Select the codecontext scheme
  2. Edit Scheme β†’ Run β†’ Arguments β†’ add: analyze /path/to/your/project
  3. ⌘R to build and run

πŸ“– Usage

Analyze a Codebase

# Analyze current directory
codecontext analyze

# Analyze specific path
codecontext analyze ~/Projects/MyApp

# With options
codecontext analyze ~/Projects/MyApp --no-cache --verbose --open

# --open automatically opens the HTML report in Safari

View Codebase Evolution

# Default: 6 months back, 30-day intervals
codecontext evolution

# Custom range
codecontext evolution --months 12 --interval 7

Ask AI Questions

# Requires AI config in .codecontext.json
codecontext ask "Where is the authentication logic?"
codecontext ask "What would break if I refactored UserService?"

Initialize Config

codecontext init
# Creates .codecontext.json with sensible defaults

βš™οΈ Configuration

Create .codecontext.json in your project root (or run codecontext init):

{
    "excludePaths": [".git", ".build", "DerivedData", "Pods", "Carthage"],
    "maxFilesAnalyze": 5000,
    "gitCommitLimit": 1000,
    "enableCache": true,
    "enableParallel": true,
    "hotspotCount": 15,
    "fileExtensions": ["swift"],
    "ai": {
        "enabled": false,
        "provider": "anthropic",
        "apiKey": "",
        "model": "claude-sonnet-4-20250514"
    }
}

Supported AI Providers

Provider provider Model examples
Anthropic Claude "anthropic" claude-sonnet-4-20250514
Google Gemini "gemini" gemini-2.5-flash

πŸ“ Project Structure

SwiftCodeContext/
β”œβ”€β”€ Package.swift
β”œβ”€β”€ Sources/CodeContext/
β”‚   β”œβ”€β”€ CLI/
β”‚   β”‚   β”œβ”€β”€ CodeContextCLI.swift           # @main entry point
β”‚   β”‚   β”œβ”€β”€ AnalyzeCommand.swift           # Main analysis command
β”‚   β”‚   β”œβ”€β”€ AskCommand.swift               # AI Q&A command
β”‚   β”‚   β”œβ”€β”€ EvolutionCommand.swift         # Temporal analysis
β”‚   β”‚   └── InitCommand.swift              # Config initialization
β”‚   β”œβ”€β”€ Core/
β”‚   β”‚   β”œβ”€β”€ AnalysisPipeline.swift         # Shared pipeline logic
β”‚   β”‚   β”œβ”€β”€ Config/
β”‚   β”‚   β”‚   └── CodeContextConfig.swift    # Config models + loader
β”‚   β”‚   β”œβ”€β”€ Cache/
β”‚   β”‚   β”‚   └── CacheManager.swift         # Actor-based file cache
β”‚   β”‚   β”œβ”€β”€ Parser/
β”‚   β”‚   β”‚   β”œβ”€β”€ ParsedFile.swift           # Models + protocol
β”‚   β”‚   β”‚   β”œβ”€β”€ SwiftParser.swift          # Swift source parser
β”‚   β”‚   β”‚   β”œβ”€β”€ ObjCParser.swift           # ObjC header parser
β”‚   β”‚   β”‚   β”œβ”€β”€ ParserFactory.swift        # Parser dispatch
β”‚   β”‚   β”‚   └── ParallelParser.swift       # Concurrent parsing
β”‚   β”‚   β”œβ”€β”€ Scanner/
β”‚   β”‚   β”‚   β”œβ”€β”€ RepositoryScanner.swift    # Directory walker
β”‚   β”‚   β”‚   └── GitAnalyzer.swift          # Git history via Process
β”‚   β”‚   β”œβ”€β”€ Graph/
β”‚   β”‚   β”‚   └── DependencyGraph.swift      # Graph + PageRank
β”‚   β”‚   β”œβ”€β”€ Generator/
β”‚   β”‚   β”‚   └── LearningPathGenerator.swift
β”‚   β”‚   β”œβ”€β”€ Temporal/
β”‚   β”‚   β”‚   └── TemporalAnalyzer.swift     # Evolution tracking
β”‚   β”‚   β”œβ”€β”€ AI/
β”‚   β”‚   β”‚   └── AICodeAnalyzer.swift       # URLSession-based AI
β”‚   β”‚   └── Exceptions/
β”‚   β”‚       └── CodeContextError.swift
β”‚   └── Output/
β”‚       └── ReportGenerator.swift          # HTML report
└── Tests/CodeContextTests/
    └── CodeContextTests.swift

πŸ§ͺ Run Tests

swift test

Requirements

  • macOS 13+ (Ventura or later)
  • Xcode 15+ / Swift 5.9+
  • git (comes with Xcode Command Line Tools)

About

Swift Codebase analyzer / Developer Onboarding on Swift Project / Statistics report for your codebase

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages