simple-text-analyzer / web_app /README_MODULES.md
egumasa's picture
initialize app
a543e33

Refactored Modular Architecture

This document describes the new modular architecture for the text analysis application, designed for better maintainability and code organization.

Architecture Overview

The application has been refactored into separate modules, each with a specific responsibility:

frontend/
β”œβ”€β”€ app.py                    # Main application entry point
β”œβ”€β”€ session_manager.py        # Session state management
β”œβ”€β”€ ui_components.py          # Reusable UI components
β”œβ”€β”€ analysis_handlers.py      # Analysis workflow handlers
β”œβ”€β”€ reference_manager.py      # Reference list management
β”œβ”€β”€ config_manager.py         # Configuration management
β”œβ”€β”€ pos_handlers.py          # POS analysis handlers
└── comparison_functions.py   # Text comparison functions (unchanged)

Module Responsibilities

1. app.py - Main Application

  • Entry point for the Streamlit application
  • Handles routing between different interfaces
  • Minimal, clean structure that orchestrates other modules

2. session_manager.py - Session State Management

  • Centralized session state initialization and management
  • Handles language changes and analyzer clearing
  • Provides utilities for managing reference lists in session state

3. ui_components.py - Reusable UI Components

  • Reusable UI components (selectors, inputs, displays)
  • Consistent styling and behavior across the application
  • Reduces code duplication

4. analysis_handlers.py - Analysis Workflows

  • Handles different types of analysis (single text, batch, comparison)
  • Manages analyzer and parser instances
  • Contains result display logic

5. reference_manager.py - Reference List Management

  • Manages both default and custom reference lists
  • Handles reference list configuration and validation
  • Provides utilities for reference list operations

6. config_manager.py - Configuration Management

  • Handles file processing and configuration
  • Manages uploaded file configurations
  • Provides validation and configuration utilities

7. pos_handlers.py - POS Analysis

  • Specialized handlers for POS and dependency parsing
  • Handles both single text and batch POS analysis
  • Manages POS-specific result display

Key Benefits

1. Separation of Concerns

  • Each module has a single, well-defined responsibility
  • Easier to understand and modify individual components
  • Reduced coupling between different parts of the application

2. Maintainability

  • Easier to locate and fix bugs
  • Simpler to add new features
  • Better code organization and readability

3. Testability

  • Individual modules can be tested in isolation
  • Easier to write unit tests for specific functionality
  • Better error handling and debugging

4. Reusability

  • UI components can be reused across different interfaces
  • Configuration logic can be shared between different analysis types
  • Common patterns are centralized

5. Scalability

  • Easy to add new analysis types or features
  • Modular structure supports future expansion
  • Clear interfaces between modules

Usage

Running the Application

The application runs the same way as before:

streamlit run app.py

Adding New Features

Adding a New Analysis Type

  1. Create handler methods in analysis_handlers.py
  2. Add UI components in ui_components.py if needed
  3. Add routing logic in app.py

Adding New UI Components

  1. Add reusable components to ui_components.py
  2. Use consistent parameter patterns
  3. Document component usage

Modifying Configuration

  1. Update config_manager.py for new configuration types
  2. Add validation logic as needed
  3. Update reference_manager.py if reference lists are affected

Migration Notes

Backward Compatibility

  • All existing functionality is preserved
  • UI and user experience remain unchanged
  • Configuration files and data formats are unchanged

Code Changes

  • Removed code duplication (~40% reduction in main app.py)
  • Improved error handling and validation
  • Better separation of concerns
  • More consistent code patterns

Testing

  • All existing functionality should work identically
  • Run through complete user workflows to verify
  • Check edge cases and error conditions

Future Improvements

Potential Enhancements

  1. Configuration Persistence: Save and load analysis configurations
  2. Plugin System: Support for third-party analysis plugins
  3. API Integration: REST API for programmatic access
  4. Advanced Validation: More sophisticated configuration validation
  5. Performance Monitoring: Built-in performance tracking

Technical Debt Reduction

  1. Type Hints: Add comprehensive type hints throughout
  2. Documentation: Add detailed docstrings for all methods
  3. Testing: Implement comprehensive test suite
  4. Error Handling: Improve error messages and recovery
  5. Logging: Add structured logging for debugging

Troubleshooting

Common Issues

  1. Import Errors: Ensure all modules are in the same directory
  2. Session State Issues: Check session_manager.py for state management
  3. UI Component Issues: Check ui_components.py for component logic
  4. Configuration Issues: Check config_manager.py for validation logic

Debug Mode

Enable debug mode by setting environment variable:

export STREAMLIT_DEBUG=true
streamlit run app.py

This will provide additional debugging information and error details.