Automatically analyze codebases to generate comprehensive threat models with attack vectors, data flow diagrams, and security recommendations.
ThreatMapAI is an advanced tool that leverages large language models (LLMs) to automatically analyze code repositories and generate comprehensive security threat models. Using a combination of static code analysis, Retrieval Augmented Generation (RAG), and graph-based visualization, it identifies potential security vulnerabilities, maps data flows across security boundaries, and provides detailed security recommendations.
The tool is designed to be language-agnostic and can analyze repositories of any size through efficient embedding-based RAG techniques.
graph TD
A[Repository Source] --> B[Repository Analyzer]
B --> C[Code Structure Analysis]
B --> D[Data Flow Mapping]
B --> E[Security Boundary Detection]
C --> F[Embedding Store]
D --> F
E --> F
F --> G[LLM Processor]
G --> H[Code Analysis]
G --> I[Threat Detection]
G --> J[Security Recommendations]
H --> K[Threat Model]
I --> K
J --> K
K --> L[Visualizer]
L --> M[Class Diagrams]
L --> N[Data Flow Diagrams]
L --> O[Threat Relationship Diagrams]
L --> P[HTML Security Report]
# Clone the repository
git clone https://github.com/omaid/ThreatMapAI.git
cd ThreatMapAI
# Run the installer (automatically sets up a virtual environment)
chmod +x setup.sh
./setup.sh
This will:
venv directoryIf you prefer to set up manually:
# Create a virtual environment
python3 -m venv venv
# Activate it (on macOS/Linux)
source venv/bin/activate
# OR on Windows
# venv\Scripts\activate
pip install -r requirements.txt
python -m cli init
Some models require authentication with a Hugging Face token:
python -m cli set_token
The primary way to interact with ThreatMapAI is through its command-line interface:
# Initialize environment and download required models
python -m cli init
# Analyze a GitHub repository
python -m cli analyze https://github.com/username/repo
# Analyze a local repository
python -m cli analyze /path/to/local/repo --local
# Generate visualizations only
python -m cli visualize --output-dir output
# View diagrams in browser
python -m cli view
ThreatMapAI can also be used as an API service:
# Start the API server
python main.py
The API server provides endpoints for:
/analyze - Analyze a repository/health - Health checkfrom repository_analyzer.analyzer import RepositoryAnalyzer
from repository_analyzer.embedding_store import EmbeddingStore
from llm_processor.processor import LLMProcessor
from visualizer.visualizer import ThreatModelVisualizer
# Initialize components
embedding_store = EmbeddingStore()
analyzer = RepositoryAnalyzer(repo_path="temp_repo", embedding_store=embedding_store)
llm_processor = LLMProcessor(embedding_store)
visualizer = ThreatModelVisualizer()
# Clone and analyze repository
analyzer.clone_repository("https://github.com/username/repo")
analysis_results = analyzer.analyze_code()
# Generate threat model
threat_model = llm_processor.generate_threat_model(analysis_results)
# Generate visualizations and report
report_path = visualizer.generate_report(threat_model)
print(f"Report generated at: {report_path}")
All output is saved to the output directory (configurable):
analysis_results.json: Raw analysis datathreat_model.json: Generated threat modelclass_diagram.mmd: Class structure diagramflow_diagram.mmd: Data flow diagramthreat_diagram.mmd: Threat relationship diagramthreat_analysis_report.html: Comprehensive HTML reportThere are several ways to view the generated Mermaid diagrams:
Using the built-in viewer:
python -m cli view
Using Mermaid Live Editor:
Using GitHub:
Using VS Code:
ThreatMapAI can utilize GPU acceleration for faster processing:
# Configure GPU settings
python -m cli configure_gpu
# Check GPU information
python -m cli gpu_info --detailed
# Run benchmark
python -m cli gpu_info --benchmark
You can select different models for analysis:
# List available models
python -m cli select_model --list
# Select a specific model
python -m cli select_model CodeLlama-2-7b-Instruct --variant Q4_0 --download
Create a .env file to configure:
MODEL_PATH=/path/to/model
OUTPUT_DIR=output
HF_TOKEN=your_huggingface_token
Dependency conflicts:
pip install -r requirements.txt --no-depspip install -r requirements.txttree-sitter installation fails:
pip install tree-sitter-languagesModel download fails:
python -m cli set_token to set up your tokenOut of memory:
python -m cli analyze https://github.com/username/repo --memory-limit 4.0GPU issues:
python -m cli analyze URL --force-cpupython -m cli gpu_infoAnalysis taking too long:
Method 2: Set in your environment
# Add to your shell profile (.bashrc, .zshrc, etc.)
export HF_TOKEN=your_token_here
# OR set just for the current session
export HF_TOKEN=your_token_here
Method 3: Manually add to .env file
# Create or edit the .env file in your project directory
echo "HF_TOKEN=your_token_here" >> .env
Verify your token is set
# Run the initialization which will verify token access
python -m cli init
If you see authentication errors even after setting your token, try:
python -m cli set_token to save it in your .env file
Automatically analyze codebases to generate comprehensive threat models with attack vectors, data flow diagrams, and security recommendations.
ThreatMapAI is an advanced tool that leverages large language models (LLMs) to automatically analyze code repositories and generate comprehensive security threat models. Using a combination of static code analysis, Retrieval Augmented Generation (RAG), and graph-based visualization, it identifies potential security vulnerabilities, maps data flows across security boundaries, and provides detailed security recommendations.
The tool is designed to be language-agnostic and can analyze repositories of any size through efficient embedding-based RAG techniques.
graph TD
A[Repository Source] --> B[Repository Analyzer]
B --> C[Code Structure Analysis]
B --> D[Data Flow Mapping]
B --> E[Security Boundary Detection]
C --> F[Embedding Store]
D --> F
E --> F
F --> G[LLM Processor]
G --> H[Code Analysis]
G --> I[Threat Detection]
G --> J[Security Recommendations]
H --> K[Threat Model]
I --> K
J --> K
K --> L[Visualizer]
L --> M[Class Diagrams]
L --> N[Data Flow Diagrams]
L --> O[Threat Relationship Diagrams]
L --> P[HTML Security Report]
# Clone the repository
git clone https://github.com/omaid/ThreatMapAI.git
cd ThreatMapAI
# Run the installer (automatically sets up a virtual environment)
chmod +x setup.sh
./setup.sh
This will:
venv directoryIf you prefer to set up manually:
# Create a virtual environment
python3 -m venv venv
# Activate it (on macOS/Linux)
source venv/bin/activate
# OR on Windows
# venv\Scripts\activate
pip install -r requirements.txt
python -m cli init
Some models require authentication with a Hugging Face token:
python -m cli set_token
The primary way to interact with ThreatMapAI is through its command-line interface:
# Initialize environment and download required models
python -m cli init
# Analyze a GitHub repository
python -m cli analyze https://github.com/username/repo
# Analyze a local repository
python -m cli analyze /path/to/local/repo --local
# Generate visualizations only
python -m cli visualize --output-dir output
# View diagrams in browser
python -m cli view
ThreatMapAI can also be used as an API service:
# Start the API server
python main.py
The API server provides endpoints for:
/analyze - Analyze a repository/health - Health checkfrom repository_analyzer.analyzer import RepositoryAnalyzer
from repository_analyzer.embedding_store import EmbeddingStore
from llm_processor.processor import LLMProcessor
from visualizer.visualizer import ThreatModelVisualizer
# Initialize components
embedding_store = EmbeddingStore()
analyzer = RepositoryAnalyzer(repo_path="temp_repo", embedding_store=embedding_store)
llm_processor = LLMProcessor(embedding_store)
visualizer = ThreatModelVisualizer()
# Clone and analyze repository
analyzer.clone_repository("https://github.com/username/repo")
analysis_results = analyzer.analyze_code()
# Generate threat model
threat_model = llm_processor.generate_threat_model(analysis_results)
# Generate visualizations and report
report_path = visualizer.generate_report(threat_model)
print(f"Report generated at: {report_path}")
All output is saved to the output directory (configurable):
analysis_results.json: Raw analysis datathreat_model.json: Generated threat modelclass_diagram.mmd: Class structure diagramflow_diagram.mmd: Data flow diagramthreat_diagram.mmd: Threat relationship diagramthreat_analysis_report.html: Comprehensive HTML reportThere are several ways to view the generated Mermaid diagrams:
Using the built-in viewer:
python -m cli view
Using Mermaid Live Editor:
Using GitHub:
Using VS Code:
ThreatMapAI can utilize GPU acceleration for faster processing:
# Configure GPU settings
python -m cli configure_gpu
# Check GPU information
python -m cli gpu_info --detailed
# Run benchmark
python -m cli gpu_info --benchmark
You can select different models for analysis:
# List available models
python -m cli select_model --list
# Select a specific model
python -m cli select_model CodeLlama-2-7b-Instruct --variant Q4_0 --download
Create a .env file to configure:
MODEL_PATH=/path/to/model
OUTPUT_DIR=output
HF_TOKEN=your_huggingface_token
Dependency conflicts:
pip install -r requirements.txt --no-depspip install -r requirements.txttree-sitter installation fails:
pip install tree-sitter-languagesModel download fails:
python -m cli set_token to set up your tokenOut of memory:
python -m cli analyze https://github.com/username/repo --memory-limit 4.0GPU issues:
python -m cli analyze URL --force-cpupython -m cli gpu_infoAnalysis taking too long:
Method 2: Set in your environment
# Add to your shell profile (.bashrc, .zshrc, etc.)
export HF_TOKEN=your_token_here
# OR set just for the current session
export HF_TOKEN=your_token_here
Method 3: Manually add to .env file
# Create or edit the .env file in your project directory
echo "HF_TOKEN=your_token_here" >> .env
Verify your token is set
# Run the initialization which will verify token access
python -m cli init
If you see authentication errors even after setting your token, try:
python -m cli set_token to save it in your .env file