API Reference
Project Mapper can be used programmatically in your Node.js applications. This reference covers the available functions and their parameters.
Main Functions
generateProjectMap(inputDir, options)
Analyzes a project directory and generates a knowledge transfer document.
Parameters:
inputDir(string): Path to the project directoryoptions(object): Configuration optionstemplate(string): Template to use ('standard', 'minimal', 'detailed')format(string): Output format ('markdown', 'json')includeGuide(boolean): Whether to include the LLM guideignore(string[]): Glob patterns to ignoredepth(number): Maximum directory depth to analyze
Returns:
Promise<object>: Object containinganalysisandknowledgeTransfer
Example:
import { generateProjectMap } from 'project-mapper';
async function analyzeMyProject() {
const result = await generateProjectMap('./my-project', {
template: 'detailed',
includeGuide: true
});
console.log(result.knowledgeTransfer);
// Access raw analysis data
const rawAnalysis = result.analysis;
// Do something with the data
const componentCount = rawAnalysis.overview.totalFiles;
console.log(`Project has ${componentCount} files`);
}
analyzeMyProject();
analyzeProject(inputDir, options)
Analyzes a project directory without generating a knowledge transfer document.
Parameters:
inputDir(string): Path to the project directoryoptions(object): Configuration optionsignorePaths(string[]): Glob patterns to ignoremaxDepth(number): Maximum directory depth to analyzeverbose(boolean): Enable verbose output
Returns:
Promise<object>: Detailed analysis of the project
Example:
import { analyzeProject } from 'project-mapper';
async function getProjectAnalysis() {
const analysis = await analyzeProject('./my-project', {
ignorePaths: ['node_modules/**', 'dist/**'],
maxDepth: 5
});
console.log(`Found ${analysis.overview.totalFiles} files`);
console.log(`Found ${analysis.overview.totalDirectories} directories`);
// Access important files
for (const file of analysis.structure.importantFiles) {
console.log(`Important file: ${file.path} (score: ${file.score})`);
}
}
generateKnowledgeTransfer(analysis, options)
Generates a knowledge transfer document from an existing analysis.
Parameters:
analysis(object): Project analysis objectoptions(object): Configuration optionsprojectName(string): Name to use for the projecttemplate(string): Template to use ('standard', 'minimal', 'detailed')format(string): Output format ('markdown', 'json')includeGuide(boolean): Whether to include the LLM guide
Returns:
Promise<string|object>: Knowledge transfer document in the specified format
Example:
import { analyzeProject, generateKnowledgeTransfer } from 'project-mapper';
async function generateCustomDocument() {
// First analyze the project
const analysis = await analyzeProject('./my-project');
// Then generate a knowledge transfer document
const document = await generateKnowledgeTransfer(analysis, {
projectName: 'My Amazing Project',
template: 'minimal',
format: 'markdown'
});
console.log(document);
}
analyzeProjectSemantics(projectDir, options)
Performs semantic analysis on a project directory to extract domain concepts and terminology.
Parameters:
projectDir(string): Path to the project directoryoptions(object): Configuration optionsignorePaths(string[]): Glob patterns to ignoreincludeComments(boolean): Include code comments in analysisincludeDocs(boolean): Include documentation files in analysisincludeIdentifiers(boolean): Include code identifiers in analysisminTermFrequency(number): Minimum frequency for a term to be includedmaxTerms(number): Maximum number of terms to include
Returns:
Promise<object>: Semantic analysis results
Example:
import { analyzeProjectSemantics } from 'project-mapper';
async function getSemanticAnalysis() {
const semantics = await analyzeProjectSemantics('./my-project', {
minTermFrequency: 2,
maxTerms: 50
});
console.log('Domain concepts:');
for (const concept of semantics.domainConcepts) {
console.log(`- ${concept.name} (frequency: ${concept.frequency})`);
}
console.log('Domain glossary:');
for (const entry of semantics.domainGlossary) {
console.log(`- ${entry.term}: ${entry.definition}`);
}
}
enhancedKnowledgeTransfer(analysis, options)
Generates an enhanced knowledge transfer document that includes semantic information.
Parameters:
analysis(object): Project analysis object, optionally including semantics dataoptions(object): Configuration options (same as generateKnowledgeTransfer)projectDir(string): Path to project directory (needed if semantics not included)
Returns:
Promise<string|object>: Enhanced knowledge transfer document
Example:
import { analyzeProject, analyzeProjectSemantics, enhancedKnowledgeTransfer } from 'project-mapper';
async function generateEnhancedDocument() {
// Analyze the project
const analysis = await analyzeProject('./my-project');
// Add semantic analysis
analysis.semantics = await analyzeProjectSemantics('./my-project');
// Generate enhanced document
const document = await enhancedKnowledgeTransfer(analysis, {
projectName: 'My Project',
template: 'standard'
});
console.log(document);
}
generateContextQuestionnaire(analysis)
Generates a context questionnaire based on project analysis to gather additional information.
Parameters:
analysis(object): Project analysis object with semantics data
Returns:
- object: Questionnaire object with title, description, and questions
Example:
import { analyzeProject, analyzeProjectSemantics, generateContextQuestionnaire } from 'project-mapper';
import fs from 'fs';
async function createQuestionnaire() {
// Analyze the project
const analysis = await analyzeProject('./my-project');
// Add semantic analysis
analysis.semantics = await analyzeProjectSemantics('./my-project');
// Generate questionnaire
const questionnaire = generateContextQuestionnaire(analysis);
// Format as markdown
let markdown = `# ${questionnaire.title}\n\n${questionnaire.description}\n\n`;
for (const q of questionnaire.questions) {
markdown += `## ${q.question}\n\n*${q.context}*\n\n`;
markdown += `Your answer: *(fill in here)*\n\n---\n\n`;
}
// Save to file
fs.writeFileSync('questionnaire.md', markdown);
console.log('Questionnaire created: questionnaire.md');
}
Visualization Functions
Project Mapper also includes functions for visualizing project concepts and relationships:
generateConceptNetworkVisualization(semantics, options)
Generates an SVG visualization of the concept network.
generateMermaidConceptDiagram(semantics, options)
Generates a Mermaid.js diagram of the concept network.
exportInteractiveConceptNetwork(semantics, outputPath)
Creates an interactive HTML visualization of the concept network using D3.js.
generateConceptDistributionHeatmap(semantics, options)
Generates an HTML table visualization showing concept distribution across files.
Type Definitions
For TypeScript users, here are the main types used in the API:
interface AnalysisOptions {
ignorePaths?: string[];
maxDepth?: number;
verbose?: boolean;
}
interface KnowledgeTransferOptions {
projectName?: string;
template?: 'standard' | 'minimal' | 'detailed';
format?: 'markdown' | 'json';
includeGuide?: boolean;
}
interface ProjectMapOptions extends AnalysisOptions, KnowledgeTransferOptions {
ignore?: string[];
depth?: number;
}
interface SemanticAnalysisOptions {
ignorePaths?: string[];
includeComments?: boolean;
includeDocs?: boolean;
includeIdentifiers?: boolean;
minTermFrequency?: number;
maxTerms?: number;
}
interface EnhancedKnowledgeTransferOptions extends KnowledgeTransferOptions {
projectDir?: string;
}