|
| 1 | +# Architecture Overview |
| 2 | + |
| 3 | +## High-Level Component Diagram |
| 4 | + |
| 5 | +```mermaid |
| 6 | +flowchart TD |
| 7 | + User[User] --> Terminal[Terminal Interface] |
| 8 | + Terminal --> App[Application Layer] |
| 9 | + App --> Storage[Storage Layer] |
| 10 | +
|
| 11 | + App --> Importers[Data Importers] |
| 12 | + App --> Preprocessing[Semantic Preprocessor] |
| 13 | + App --> Analyzers[Analyzer System] |
| 14 | +
|
| 15 | + Importers --> Parquet[(Parquet Files)] |
| 16 | + Preprocessing --> Parquet |
| 17 | + Analyzers --> Parquet |
| 18 | +
|
| 19 | + Analyzers --> Primary[Primary Analyzers] |
| 20 | + Analyzers --> Secondary[Secondary Analyzers] |
| 21 | + Analyzers --> WebPresenters[Web Presenters] |
| 22 | +
|
| 23 | + WebPresenters --> Dash[Dash Apps] |
| 24 | + WebPresenters --> Shiny[Shiny Apps] |
| 25 | +
|
| 26 | + Storage --> TinyDB[(TinyDB)] |
| 27 | + Storage --> FileSystem[(File System)] |
| 28 | +``` |
| 29 | + |
| 30 | +## Core Abstractions |
| 31 | + |
| 32 | +### Application Layer (`app/`) |
| 33 | + |
| 34 | +Central orchestration and workspace management |
| 35 | + |
| 36 | +Key Classes: |
| 37 | + |
| 38 | +- `App` - Main application controller, orchestrates all operations |
| 39 | +- `AppContext` - Dependency injection container for application-wide services |
| 40 | +- `ProjectContext` - Project-specific operations and column mapping |
| 41 | +- `AnalysisContext` - Analysis execution environment and progress tracking |
| 42 | +- `AnalysisOutputContext` - Handles analysis result management |
| 43 | +- `AnalysisWebServerContext` - Web server lifecycle management |
| 44 | +- `SettingsContext` - Configuration and user preferences |
| 45 | + |
| 46 | +### View Layer (`components/`) |
| 47 | + |
| 48 | +Terminal UI components using inquirer |
| 49 | + |
| 50 | +Key Components: |
| 51 | + |
| 52 | +- `ViewContext` - UI state management and terminal context |
| 53 | +- `main_menu()` - Application entry point menu |
| 54 | +- `splash()` - Application branding and welcome |
| 55 | +- Menu flows: project selection, analysis creation, parameter customization |
| 56 | +- Server management: web server lifecycle, export workflows |
| 57 | + |
| 58 | +### Model Layer (`storage/`) |
| 59 | + |
| 60 | +Data persistence and state management |
| 61 | + |
| 62 | +Key Classes: |
| 63 | + |
| 64 | +- `Storage` - Main storage controller, manages projects and analyses |
| 65 | +- `ProjectModel` - Project metadata and configuration |
| 66 | +- `AnalysisModel` - Analysis metadata, parameters, and state |
| 67 | +- `SettingsModel` - User preferences and application settings |
| 68 | +- `FileSelectionState` - File picker state management |
| 69 | +- `TableStats` - Data statistics and preview information |
| 70 | + |
| 71 | +## Data Flow Architecture |
| 72 | + |
| 73 | +### Import → Analysis → Export Pipeline |
| 74 | + |
| 75 | +```mermaid |
| 76 | +sequenceDiagram |
| 77 | + participant User |
| 78 | + participant Terminal |
| 79 | + participant App |
| 80 | + participant Importer |
| 81 | + participant Preprocessor |
| 82 | + participant Analyzer |
| 83 | + participant WebServer |
| 84 | +
|
| 85 | + User->>Terminal: Select data file |
| 86 | + Terminal->>App: Create project |
| 87 | + App->>Importer: Import CSV/Excel |
| 88 | + Importer->>App: Parquet file path |
| 89 | + App->>Preprocessor: Apply column semantics |
| 90 | + Preprocessor->>App: Processed data path |
| 91 | + User->>Terminal: Configure analysis |
| 92 | + Terminal->>App: Run analysis |
| 93 | + App->>Analyzer: Execute with context |
| 94 | + Analyzer->>App: Analysis results |
| 95 | + App->>WebServer: Start dashboard |
| 96 | + WebServer->>User: Interactive visualization |
| 97 | +``` |
| 98 | + |
| 99 | +### Context-Based Dependency Injection |
| 100 | + |
| 101 | +Each layer receives context objects containing exactly what it needs: |
| 102 | + |
| 103 | +```python |
| 104 | +# Analyzer Context Pattern |
| 105 | +class AnalysisContext: |
| 106 | + input_path: Path # Input parquet file |
| 107 | + output_path: Path # Where to write results |
| 108 | + preprocessing: Callable # Column mapping function |
| 109 | + progress_callback: Callable # Progress reporting |
| 110 | + parameters: dict # User-configured parameters |
| 111 | + |
| 112 | +class AnalysisWebServerContext: |
| 113 | + primary_output_path: Path |
| 114 | + secondary_output_paths: list[Path] |
| 115 | + dash_app: dash.Dash # For dashboard creation |
| 116 | + server_config: dict |
| 117 | +``` |
| 118 | + |
| 119 | +## Core Domain Patterns |
| 120 | + |
| 121 | +### Analyzer Interface System |
| 122 | + |
| 123 | +Declarative analysis definition |
| 124 | + |
| 125 | +```python |
| 126 | +# interface.py |
| 127 | +interface = AnalyzerInterface( |
| 128 | + input=AnalyzerInput( |
| 129 | + columns=[ |
| 130 | + AnalyzerInputColumn( |
| 131 | + name="author_id", |
| 132 | + semantic_type=ColumnSemantic.USER_ID, |
| 133 | + required=True |
| 134 | + ) |
| 135 | + ] |
| 136 | + ), |
| 137 | + outputs=[ |
| 138 | + AnalyzerOutput( |
| 139 | + name="hashtag_analysis", |
| 140 | + columns=[...], |
| 141 | + internal=False # User-consumable |
| 142 | + ) |
| 143 | + ], |
| 144 | + params=[ |
| 145 | + AnalyzerParam( |
| 146 | + name="time_window", |
| 147 | + param_type=ParamType.TIME_BINNING, |
| 148 | + default="1D" |
| 149 | + ) |
| 150 | + ] |
| 151 | +) |
| 152 | +``` |
| 153 | + |
| 154 | +### Three-Stage Analysis Pipeline |
| 155 | + |
| 156 | +1. **Primary Analyzers** - Raw data processing |
| 157 | + - Input: Preprocessed parquet files |
| 158 | + - Output: Normalized analysis results |
| 159 | + - Examples: hashtag extraction, n-gram generation, temporal aggregation |
| 160 | + |
| 161 | +2. **Secondary Analyzers** - Result transformation |
| 162 | + - Input: Primary analyzer outputs |
| 163 | + - Output: User-friendly reports and summaries |
| 164 | + - Examples: statistics calculation, trend analysis |
| 165 | + |
| 166 | +3. **Web Presenters** - Interactive visualization |
| 167 | + - Input: Primary + secondary outputs |
| 168 | + - Output: Dash/Shiny web applications |
| 169 | + - Examples: interactive charts, data exploration interfaces |
| 170 | + |
| 171 | +## Integration Points |
| 172 | + |
| 173 | +### External Data Sources |
| 174 | + |
| 175 | +- **CSV Importer**: Handles delimiter detection, encoding issues |
| 176 | +- **Excel Importer**: Multi-sheet support, data type inference |
| 177 | +- **File System**: Project directory structure, workspace management |
| 178 | + |
| 179 | +### Web Framework Integration |
| 180 | + |
| 181 | +- **Dash Integration**: Plotly-based interactive dashboards |
| 182 | +- **Shiny Integration**: Modern Python web UI framework |
| 183 | +- **Server Management**: Background process handling, port management |
| 184 | + |
| 185 | +### Export Capabilities |
| 186 | + |
| 187 | +- **XLSX Export**: Formatted Excel files with multiple sheets |
| 188 | +- **CSV Export**: Standard comma-separated values |
| 189 | +- **Parquet Export**: Native format for data interchange |
| 190 | + |
| 191 | +## Key Architectural Decisions |
| 192 | + |
| 193 | +### Parquet-Centric Data Flow |
| 194 | + |
| 195 | +- All analysis data stored as Parquet files |
| 196 | +- Enables efficient columnar operations with Polars |
| 197 | +- Provides schema validation and compression |
| 198 | +- Facilitates data sharing between analysis stages |
| 199 | + |
| 200 | +### Context Pattern for Decoupling |
| 201 | + |
| 202 | +- Eliminates direct dependencies between layers |
| 203 | +- Enables testing with mock contexts |
| 204 | +- Allows analyzer development without application knowledge |
| 205 | +- Supports different execution environments (CLI, web, testing) |
| 206 | + |
| 207 | +### Domain-Driven Module Organization |
| 208 | + |
| 209 | +- Clear boundaries between core, edge, and content domains |
| 210 | +- Enables independent development of analyzers |
| 211 | +- Supports plugin-like extensibility |
| 212 | +- Facilitates maintenance and testing |
| 213 | + |
| 214 | +### Semantic Type System |
| 215 | + |
| 216 | +- Guides users in column selection for analyses |
| 217 | +- Enables automatic data validation and preprocessing |
| 218 | +- Supports analyzer input requirements |
| 219 | +- Provides consistent UX across different data sources |
0 commit comments