|
| 1 | +# Module Structure |
| 2 | + |
| 3 | +## Overview |
| 4 | +Organizing the codebase into logical modules for better maintainability and clarity. |
| 5 | + |
| 6 | +## Proposed Structure |
| 7 | + |
| 8 | +``` |
| 9 | +src/ |
| 10 | +├── lib.rs # Public API exports |
| 11 | +├── main.rs # Binary entry point |
| 12 | +│ |
| 13 | +├── core/ # Core business logic |
| 14 | +│ ├── mod.rs |
| 15 | +│ ├── app_state_container.rs |
| 16 | +│ ├── buffer_manager.rs |
| 17 | +│ ├── service_container.rs |
| 18 | +│ └── global_state.rs |
| 19 | +│ |
| 20 | +├── data/ # Data layer (DataTable/DataView) |
| 21 | +│ ├── mod.rs |
| 22 | +│ ├── provider.rs # DataProvider traits |
| 23 | +│ ├── table.rs # DataTable implementation |
| 24 | +│ ├── view.rs # DataView implementation |
| 25 | +│ ├── adapters/ # Adapters for existing data sources |
| 26 | +│ │ ├── mod.rs |
| 27 | +│ │ ├── buffer_adapter.rs |
| 28 | +│ │ ├── csv_adapter.rs |
| 29 | +│ │ └── api_adapter.rs |
| 30 | +│ └── converters/ # Data format converters |
| 31 | +│ ├── mod.rs |
| 32 | +│ ├── csv_converter.rs |
| 33 | +│ └── json_converter.rs |
| 34 | +│ |
| 35 | +├── ui/ # UI layer |
| 36 | +│ ├── mod.rs |
| 37 | +│ ├── enhanced_tui.rs # Main TUI application |
| 38 | +│ ├── classic_cli.rs # Classic CLI mode |
| 39 | +│ ├── key_dispatcher.rs # Key event handling |
| 40 | +│ └── renderer.rs # Rendering logic |
| 41 | +│ |
| 42 | +├── widgets/ # UI widgets |
| 43 | +│ ├── mod.rs |
| 44 | +│ ├── debug_widget.rs |
| 45 | +│ ├── editor_widget.rs |
| 46 | +│ ├── help_widget.rs |
| 47 | +│ ├── stats_widget.rs |
| 48 | +│ ├── search_modes_widget.rs |
| 49 | +│ ├── history_widget.rs |
| 50 | +│ └── table_widget.rs |
| 51 | +│ |
| 52 | +├── state/ # State management |
| 53 | +│ ├── mod.rs |
| 54 | +│ ├── selection_state.rs |
| 55 | +│ ├── filter_state.rs |
| 56 | +│ ├── sort_state.rs |
| 57 | +│ ├── search_state.rs |
| 58 | +│ ├── column_search_state.rs |
| 59 | +│ ├── clipboard_state.rs |
| 60 | +│ ├── chord_state.rs |
| 61 | +│ └── undo_redo_state.rs |
| 62 | +│ |
| 63 | +├── sql/ # SQL parsing and execution |
| 64 | +│ ├── mod.rs |
| 65 | +│ ├── parser.rs |
| 66 | +│ ├── executor.rs |
| 67 | +│ ├── optimizer.rs |
| 68 | +│ └── cache.rs |
| 69 | +│ |
| 70 | +├── api/ # External API interactions |
| 71 | +│ ├── mod.rs |
| 72 | +│ ├── client.rs |
| 73 | +│ ├── models.rs |
| 74 | +│ └── endpoints.rs |
| 75 | +│ |
| 76 | +├── utils/ # Utility functions |
| 77 | +│ ├── mod.rs |
| 78 | +│ ├── debouncer.rs |
| 79 | +│ ├── formatter.rs |
| 80 | +│ ├── logger.rs |
| 81 | +│ └── paths.rs |
| 82 | +│ |
| 83 | +├── config/ # Configuration |
| 84 | +│ ├── mod.rs |
| 85 | +│ ├── settings.rs |
| 86 | +│ ├── themes.rs |
| 87 | +│ └── keybindings.rs |
| 88 | +│ |
| 89 | +└── tests/ # Integration tests |
| 90 | + ├── mod.rs |
| 91 | + └── ... |
| 92 | +``` |
| 93 | + |
| 94 | +## Migration Strategy |
| 95 | + |
| 96 | +### Phase 1: Create Directory Structure (V35) |
| 97 | +- Create directories |
| 98 | +- Add mod.rs files with re-exports |
| 99 | +- No code moves yet |
| 100 | + |
| 101 | +### Phase 2: Move Widgets (V36) |
| 102 | +- Move all *_widget.rs files to widgets/ |
| 103 | +- Update imports |
| 104 | + |
| 105 | +### Phase 3: Move Data Layer (V37) |
| 106 | +- Move DataProvider trait to data/provider.rs |
| 107 | +- Move datatable* files to data/ |
| 108 | +- Move converters and adapters |
| 109 | + |
| 110 | +### Phase 4: Move State Components (V38) |
| 111 | +- Extract state structs from app_state_container.rs |
| 112 | +- Create separate files in state/ |
| 113 | +- Keep AppStateContainer as orchestrator |
| 114 | + |
| 115 | +### Phase 5: Move UI Components (V39) |
| 116 | +- Move enhanced_tui.rs to ui/ |
| 117 | +- Move classic_cli.rs to ui/ |
| 118 | +- Move key_dispatcher.rs to ui/ |
| 119 | + |
| 120 | +### Phase 6: Move SQL Components (V40) |
| 121 | +- Move SQL-related files to sql/ |
| 122 | +- Organize parser, executor, cache |
| 123 | + |
| 124 | +### Phase 7: Move Utils and Config (V41) |
| 125 | +- Move utility files to utils/ |
| 126 | +- Move config files to config/ |
| 127 | + |
| 128 | +## Benefits |
| 129 | + |
| 130 | +1. **Clearer Organization**: Related files grouped together |
| 131 | +2. **Easier Navigation**: Find files by functionality |
| 132 | +3. **Better Encapsulation**: Modules can have private internals |
| 133 | +4. **Scalability**: Easy to add new features in appropriate modules |
| 134 | +5. **Testing**: Can test modules in isolation |
| 135 | +6. **Documentation**: Each module can have its own README |
| 136 | + |
| 137 | +## Module Visibility Rules |
| 138 | + |
| 139 | +- Each module has a `mod.rs` that controls what's public |
| 140 | +- Internal implementation details stay private |
| 141 | +- Public API is explicitly exported |
| 142 | +- Cross-module dependencies are minimized |
| 143 | + |
| 144 | +## Example: widgets/mod.rs |
| 145 | + |
| 146 | +```rust |
| 147 | +// Re-export public widgets |
| 148 | +pub mod debug_widget; |
| 149 | +pub mod editor_widget; |
| 150 | +pub mod help_widget; |
| 151 | +pub mod stats_widget; |
| 152 | + |
| 153 | +// Common widget traits (if any) |
| 154 | +pub trait Widget { |
| 155 | + fn render(&self, area: Rect, buf: &mut Buffer); |
| 156 | +} |
| 157 | + |
| 158 | +// Widget utilities |
| 159 | +mod utils; // Private to widgets module |
| 160 | +``` |
| 161 | + |
| 162 | +## Example: data/mod.rs |
| 163 | + |
| 164 | +```rust |
| 165 | +// Public API for data layer |
| 166 | +pub mod provider; |
| 167 | +pub use provider::{DataProvider, DataViewProvider}; |
| 168 | + |
| 169 | +// DataTable and DataView will be public |
| 170 | +pub mod table; |
| 171 | +pub mod view; |
| 172 | + |
| 173 | +// Adapters are public for gradual migration |
| 174 | +pub mod adapters; |
| 175 | + |
| 176 | +// Internal converters |
| 177 | +mod converters; |
| 178 | +``` |
| 179 | + |
| 180 | +## Gradual Migration |
| 181 | + |
| 182 | +Each phase is a separate PR that: |
| 183 | +1. Moves specific files |
| 184 | +2. Updates imports |
| 185 | +3. Ensures tests pass |
| 186 | +4. Maintains backward compatibility |
| 187 | + |
| 188 | +No breaking changes - just reorganization! |
0 commit comments