Files
openclaw-workspace-2026/Projects/site-survey-ai/TASK_STRUCTURE_IMPROVEMENT.md
T
JC Beasley cb5e26b561 Update memory service with working NocoDB configuration
- Set correct table ID: mx149yctebfwvys (ai_data_Memory)
- Updated type column with SingleSelect options
- Added all required columns for corrections, preferences, episodes, decisions, validation
- Fixed column options for type, severity, status fields
2026-07-04 17:02:40 -07:00

168 lines
5.4 KiB
Markdown

# Task: IT Site Survey AI Structure Improvement
## Description
Restructure the IT Site Survey AI application to follow professional Python project standards with clear separation of concerns, modular design, and improved maintainability.
## Current Issues
- Monolithic app.py file (792 lines) containing all application logic
- Mixed concerns (API, business logic, data models, utilities)
- Poor organization making code difficult to navigate
- Backup files cluttering the directory
- No clear separation between frontend and backend
- Missing comprehensive test suite
- Inconsistent with other applications on the server
## Requirements
### 1. Directory Structure
Implement the standardized structure defined in PROJECT_STRUCTURE_IMPROVEMENTS.md:
- src/ directory for Python source code
- Clear separation of models, API, services, and utilities
- Dedicated frontend directory for UI assets
- tests/ directory for comprehensive test suite
- docs/ directory for documentation
- requirements/ directory for dependency management
### 2. Code Modularization
Split the monolithic app.py into logical modules:
- models/ - Data models and database schemas
- api/ - API endpoints organized by resource
- services/ - Business logic separated from API layer
- utils/ - Utility functions and helpers
- config.py - Configuration management
### 3. Testing Implementation
Create comprehensive test suite:
- Unit tests for each module
- Integration tests for API endpoints
- Database integration tests
- Test configuration and fixtures
### 4. Documentation
Create detailed documentation:
- API documentation
- Architecture overview
- Deployment instructions
- Development setup guide
### 5. Development Tools
Set up professional development environment:
- Code linting with Flake8
- Code formatting with Black
- Makefile for common tasks
- Git configuration and .gitignore
## Technical Details
### Source Directory Structure
```
src/
├── __init__.py
├── app.py # Application entry point
├── config.py # Configuration management
├── models/
│ ├── __init__.py
│ ├── survey.py # Survey data model
│ └── response.py # Response data model
├── api/
│ ├── __init__.py
│ ├── surveys.py # Survey management endpoints
│ ├── responses.py # Response handling endpoints
│ └── analytics.py # AI analysis endpoints
├── services/
│ ├── __init__.py
│ ├── survey_service.py # Survey business logic
│ ├── response_service.py # Response business logic
│ ├── ai_service.py # AI integration logic
│ └── export_service.py # Export functionality
├── utils/
│ ├── __init__.py
│ ├── database.py # Database utilities
│ └── validation.py # Input validation
└── templates/ # HTML templates
```
### Frontend Directory Structure
```
frontend/
├── static/
│ ├── css/
│ │ └── styles.css # Main stylesheet
│ ├── js/
│ │ ├── app.js # Main JavaScript
│ │ └── dashboard.js # Dashboard JavaScript
│ └── images/ # Image assets
└── templates/
├── base.html # Base template
├── index.html # Main survey page
└── dashboard.html # Dashboard page
```
### Test Directory Structure
```
tests/
├── __init__.py
├── conftest.py # Test configuration
├── test_models.py # Model tests
├── test_api.py # API endpoint tests
├── test_services.py # Service layer tests
└── test_utils.py # Utility function tests
```
## Implementation Steps
### Phase 1: Directory Restructuring (2 days)
1. Create new directory structure
2. Move existing files to appropriate locations
3. Update import statements
4. Verify application functionality
### Phase 2: Code Modularization (3 days)
1. Split app.py into logical modules
2. Refactor API endpoints into separate files
3. Extract business logic into service layer
4. Create data models
5. Implement configuration management
### Phase 3: Testing Implementation (2 days)
1. Set up testing framework (pytest)
2. Create unit tests for each module
3. Implement integration tests
4. Add test configuration
### Phase 4: Documentation and Tools (1 day)
1. Create API documentation
2. Write architecture overview
3. Set up development tools (Flake8, Black)
4. Create Makefile for common tasks
## Acceptance Criteria
- [ ] Application runs identically to current version
- [ ] All existing API endpoints function correctly
- [ ] Code is organized in logical modules
- [ ] Comprehensive test suite with >80% coverage
- [ ] Documentation covers all major components
- [ ] Development tools configured and working
- [ ] No functionality lost during restructuring
- [ ] Backup of original structure maintained
- [ ] Clear migration path documented
## Dependencies
- Python 3.8+
- Flask
- SQLAlchemy (for future database integration)
- pytest (for testing)
- flake8, black (for code quality)
## Priority
High - Critical for long-term maintainability
## Estimated Effort
8 days (64 hours)
## Risk Mitigation
- Maintain backup of current structure
- Implement changes incrementally
- Test thoroughly at each phase
- Document rollback procedures
- Keep all API endpoints backward compatible