Skip to content

Commit 8b2a862

Browse files
committed
Implement recursive gitignore handling and add rule-based filtering architecture
- Enhance GitIgnore to support nested .gitignore files with proper precedence - Add support for .jj (Jujutsu) directories in system detection - Create smart rules-based filtering architecture in rules.rs - Add comprehensive project type detection with context-aware rules - Update DEVELOPMENT_PLAN.md with details of rule system design - Create ARCHITECTURE.md with system component documentation - Update README with new filtering capabilities - Add backward compatibility for tests and legacy APIs
1 parent 928a4af commit 8b2a862

File tree

10 files changed

+1380
-85
lines changed

10 files changed

+1380
-85
lines changed

ARCHITECTURE.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Smart Tree Architecture
2+
3+
This document describes the high-level architecture of the Smart Tree application, focusing on the core components and their interactions.
4+
5+
## Component Overview
6+
7+
Smart Tree is organized into several key modules:
8+
9+
```
10+
smart-tree/
11+
├── src/
12+
│ ├── main.rs # Entry point and CLI parsing
13+
│ ├── lib.rs # Public API and re-exports
14+
│ ├── scanner.rs # Directory traversal and metadata collection
15+
│ ├── gitignore.rs # Gitignore pattern handling
16+
│ ├── rules.rs # Smart filtering rules system
17+
│ ├── types.rs # Core data structures
18+
│ ├── display/ # Display formatting and visualization
19+
│ │ ├── mod.rs
20+
│ │ ├── colors.rs
21+
│ │ ├── state.rs # Display state management
22+
│ │ ├── utils.rs
23+
│ │ └── tests.rs
24+
│ └── tests/ # Integration tests
25+
└── test_data/ # Sample data for examples and tests
26+
```
27+
28+
## Core Components
29+
30+
### 1. Directory Scanning (scanner.rs)
31+
32+
The scanning subsystem is responsible for traversing the directory structure, collecting metadata, and building the tree representation. Key responsibilities:
33+
34+
- Efficient directory traversal with depth limiting
35+
- Metadata collection (size, timestamps, file counts)
36+
- Applying .gitignore rules during traversal
37+
- Handling errors for inaccessible files/directories
38+
39+
### 2. Gitignore Implementation (gitignore.rs)
40+
41+
The gitignore subsystem handles pattern matching for ignored files and directories:
42+
43+
- Parse .gitignore patterns from files
44+
- Apply pattern matching rules
45+
- Support for nested .gitignore files
46+
- Handle system directories and special patterns
47+
48+
### 3. Smart Filtering Rules (rules.rs)
49+
50+
The rules engine provides context-aware filtering based on project types and content:
51+
52+
- Project type detection (Rust, Node.js, etc.)
53+
- Pluggable rule system for extensibility
54+
- Contextual evaluation of directories and files
55+
- Weighted scoring for complex decisions
56+
57+
### 4. Display System (display/)
58+
59+
The display subsystem handles the visual formatting of the tree structure:
60+
61+
- Intelligent line allocation with budget management
62+
- Head/tail display patterns for large listings
63+
- Color and emoji support for visual enhancement
64+
- Formatting of metadata and tree structure
65+
66+
## Data Flow
67+
68+
1. **Input Processing**:
69+
- Command-line arguments are parsed in `main.rs`
70+
- Configuration objects are created
71+
72+
2. **Directory Scanning**:
73+
- `scanner.rs` traverses the specified directory
74+
- Applies gitignore rules during traversal
75+
- Builds a `DirectoryEntry` tree structure
76+
77+
3. **Smart Filtering**:
78+
- Rules engine analyzes paths and context
79+
- Determines what to show and what to fold
80+
- Applies project-specific intelligence
81+
82+
4. **Tree Rendering**:
83+
- Display state allocates line budget
84+
- Rendering logic applies folding decisions
85+
- Formatting with colors and metadata
86+
- Output to terminal
87+
88+
## Extensibility Points
89+
90+
Smart Tree is designed with several extensibility mechanisms:
91+
92+
1. **Filtering Rules**:
93+
- Custom rules can be added to the `FilterRegistry`
94+
- Rules implement the `FilterRule` trait
95+
- Project-specific filtering based on detected context
96+
97+
2. **Display Formats**:
98+
- The formatting system is modular
99+
- Support for different output types (terminal, JSON, HTML)
100+
- Customizable metadata formatting
101+
102+
3. **Configuration**:
103+
- User-defined configuration via `.smart-tree.toml`
104+
- Runtime configuration through CLI options
105+
- Project-specific configurations
106+
107+
## Design Principles
108+
109+
1. **Intelligent Display**:
110+
The core value proposition is making smart decisions about what to show, not just showing everything.
111+
112+
2. **Context Awareness**:
113+
Understanding project types and patterns to make better filtering decisions.
114+
115+
3. **Progressive Disclosure**:
116+
Show important information first, with options to reveal more detail.
117+
118+
4. **Visual Clarity**:
119+
Use color, spacing, and symbols to enhance readability and information density.
120+
121+
5. **Performance**:
122+
Fast scanning even for large directories, with optimizations for common cases.

0 commit comments

Comments
 (0)