LostMind Analyzer Pro (LAP)
A Python application for code repository analysis, providing automated structure mapping and documentation generation to streamline project understanding.
The Problem
When examining unfamiliar code repositories, developers regularly encounter these challenges:
- Structure Confusion: Difficulty understanding project organization and file hierarchy
- Dependency Blindness: Struggling to identify what external packages and internal modules the codebase relies on
- Documentation Gap: Lack of up-to-date, consistent documentation for large projects
- Onboarding Inefficiency: Time wasted getting new team members up to speed on codebase architecture
These inefficiencies slow down development, cause integration challenges, and lead to inconsistent project knowledge across teams.
The Solution
LostMind Analyzer Pro addresses these challenges through automated code analysis:
- Project Structure Mapping: Creates hierarchical representations of the codebase organization
- Basic Dependency Detection: Identifies imports in Python files and requirements in package.json
- Documentation Generation: Outputs documentation in multiple formats (JSON, Markdown)
- AI-Friendly Formatting: Prepares analysis results in formats optimized for AI processing
- Intuitive GUI: Provides a user-friendly Tkinter interface for interactive project examination
Technical Implementation Details
The application is built using a clean, object-oriented architecture with error handling and pattern recognition.
Core Analyzer Class
The foundation of LAP is the ProjectAnalyzer
class, which implements several key features:
class ProjectAnalyzer:
"""Analyzes project directories and generates structured reports with Markdown export."""
IGNORE_DIRS = [
r'^__pycache__$',
r'^\.git$',
r'^\.venv$',
r'^venv$',
r'^\.env$',
r'^\.idea$',
r'^\.vs$',
r'^\.pytest_cache$',
r'^node_modules$',
r'^build$',
r'^dist$',
r'^myenv$',
r'^env$'
]
IGNORE_FILES = [
r'.*\.pyc$',
r'.*\.pyo$',
r'.*\.pyd$',
r'.*\.so$'
]
MAIN_FILE_PATTERNS = [
r'^main\.py$',
r'^app\.py$',
r'^run\.py$',
r'^server\.py$',
r'^wsgi\.py$',
r'^manage\.py$'
]
FILE_TYPES = [
".py", ".tsx", ".ts", ".jsx", ".js", ".html", ".css",
".json", ".yaml", ".yml", ".toml", ".ini", ".cfg", ".conf",
".sh", ".bash", ".zsh", ".md", ".txt", ".tpl", ".template"
]
Project Structure Analysis
The application performs directory traversal with filtering to map out project structure:
def analyze_project(self, root_path: str) -> dict:
project_info = {
'name': os.path.basename(root_path),
'path': root_path,
'files': [],
'main_files': [],
'structure': {}
}
for root, dirs, files in os.walk(root_path):
dirs[:] = [d for d in dirs if not self.is_ignored_dir(d)]
rel_path = os.path.relpath(root, root_path)
current_level = project_info['structure']
if rel_path != '.':
for part in rel_path.split(os.sep):
current_level = current_level.setdefault(part, {})
for file in files:
if self.is_ignored_file(file):
continue
filepath = os.path.join(root, file)
file_info = {
'name': file,
'path': os.path.relpath(filepath, root_path),
'size': os.path.getsize(filepath),
'modified': datetime.fromtimestamp(os.path.getmtime(filepath)).strftime('%Y-%m-%d %H:%M:%S'),
'is_main': self.is_main_file(file),
'content': self.extract_content(filepath, file.split('.')[-1]) if file.endswith(tuple(self.FILE_TYPES)) else None
}
project_info['files'].append(file_info)
if file_info['is_main']:
project_info['main_files'].append(file_info)
return project_info
Basic Dependency Detection
The tool identifies imports in Python files using the AST module and also extracts dependencies from package.json files:
def detect_dependencies(self, project_info: dict) -> list:
dependencies = set()
for file in project_info['files']:
if file['content']:
if file['name'].endswith(".py"):
try:
tree = ast.parse(file['content'])
for node in ast.walk(tree):
if isinstance(node, (ast.Import, ast.ImportFrom)):
for alias in node.names:
if isinstance(node, ast.ImportFrom):
dependencies.add(node.module)
else:
dependencies.add(alias.name)
except SyntaxError:
print(f"Syntax error in file {file['path']}, skipping dependency analysis")
elif file['name'].endswith((".js", ".jsx", ".ts", ".tsx")):
for line in file['content'].splitlines():
match = re.search(r"(import|require)\s+(?:[\w*{}\s,]+from\s+)?[\"']([^\"']+)[\"']", line)
if match:
dependencies.add(match.group(2))
elif file['name'] == "package.json":
try:
pkg_data = json.loads(file['content'])
if "dependencies" in pkg_data:
dependencies.update(pkg_data["dependencies"].keys())
if "devDependencies" in pkg_data:
dependencies.update(pkg_data["devDependencies"].keys())
except json.JSONDecodeError as e:
print(f"JSONDecodeError parsing package.json: {file['path']}, {e}")
return list(dependencies)
Documentation Generation
The application generates Markdown documentation from the analyzed project structure:
def generate_markdown(self, project_info: dict) -> str:
md_content = f"# Project Documentation: {project_info['name']}\n\n"
md_content += f"Path: `{project_info['path']}`\n\n"
md_content += "## Files\n\n"
for file in project_info['files']:
md_content += f"### {file['name']}\n"
md_content += f"- Path: `{file['path']}`\n"
md_content += f"- Size: {file['size']} bytes\n"
md_content += f"- Modified: {file['modified']}\n"
if file['content']:
md_content += f"{file['content']}\n"
return md_content
Simple User Interface
The application includes a tkinter-based GUI for ease of use:
class ProjectAnalyzerGUI:
def __init__(self):
self.analyzer = ProjectAnalyzer()
self.setup_gui()
def setup_gui(self):
self.root = tk.Tk()
self.root.title("Project Analyzer")
self.root.geometry("800x600")
ttk.Button(self.root, text="Select Project", command=self.select_project).pack(pady=5)
ttk.Button(self.root, text="Export JSON", command=self.export_json).pack(pady=5)
ttk.Button(self.root, text="Export Markdown", command=self.export_markdown).pack(pady=5)
ttk.Button(self.root, text="Analyze File", command=self.analyze_file).pack(pady=5)
ttk.Button(self.root, text="Export AI-Friendly", command=self.export_ai_friendly).pack(pady=5)
self.status_label = ttk.Label(self.root, text="Ready")
self.status_label.pack(pady=5)
self.output_frame = ttk.Frame(self.root)
self.output_frame.pack(fill="both", expand=True, padx=10, pady=10)
self.output_text = tk.Text(self.output_frame, wrap="word", state="disabled", font=("Arial", 10))
self.output_text.pack(fill="both", expand=True)
System Workflow
The application follows a straightforward process flow:
┌─────────────────────┐ ┌─────────────────────┐ ┌─────────────────────┐
│ │ │ │ │ │
│ User Interface │ │ Analysis Engine │ │ Output Formats │
│ │ │ │ │ │
└──────────┬──────────┘ └──────────┬──────────┘ └──────────┬──────────┘
│ │ │
│ │ │
▼ │ │
┌─────────────────────┐ │ │
│ Project Selection │ │ │
│ │ │ │
└──────────┬──────────┘ │ │
│ │ │
│ │ │
▼ ▼ │
┌─────────────────────┐ ┌─────────────────────┐ │
│ │ │ │ │
│ Directory Traversal │────▶│ Structure Mapping │ │
│ │ │ & File Analysis │ │
│ │ │ │ │
└─────────────────────┘ └──────────┬──────────┘ │
│ │
│ │
▼ │
┌─────────────────────┐ │
│ │ │
│ Dependency Analysis │ │
│ │ │
└──────────┬──────────┘ │
│ │
│ │
│ │
│ │
┌──────────────────────────────┬─────┴─────────────────┘
│ │
│ │
▼ ▼
┌─────────────────────┐ ┌─────────────────────┐
│ │ │ │
│ JSON Output │ │ Markdown Generation │
│ │ │ │
└─────────────────────┘ └─────────────────────┘
Learning Journey
Developing LAP has been a valuable learning experience covering several areas:
- File System Operations: Working with Python's
os
module for directory traversal and file management - AST Parsing: Using Python's Abstract Syntax Tree module to analyze code without execution
- Pattern Matching: Implementing regex-based pattern recognition for identifying key files and imports
- GUI Development: Building an intuitive interface with Tkinter
- Document Generation: Creating formatted outputs in JSON and Markdown
Implementation Challenges
Building this tool presented several interesting coding challenges:
1. Handling Large Projects
Challenge: Analyzing large projects with many files could be slow or memory-intensive.
Solution: Implemented selective file parsing and ignore patterns to focus on relevant files.
2. Cross-Language Support
Challenge: Different file types require different parsing approaches.
Solution: Created file type detection and specialized handling for Python files vs. JavaScript files.
3. Readable Documentation
Challenge: Converting raw file data into meaningful documentation.
Solution: Developed structured Markdown templates and organization schemes for the generated documentation.
Future Development Plans
As LAP continues to evolve, I'm planning several enhancements:
- Expanded Code Metrics: Adding complexity analysis and other quantitative measures
- Interactive Visualization: Adding graphical representations of project structure and dependencies
- More Language Support: Extending analysis to additional programming languages
- Enhanced AI Integration: Improving the AI-friendly output format for better machine processing
This project demonstrates my ability to create useful Python applications that combine core language features with practical development tools, all while maintaining clean code organization and proper error handling.