hermes-web-cli/MODULE_DEVELOPMENT_SPEC_UPDATE.md
yumoqing 9a5158d09a fix: Simplify init.py according to correct module development rules
- Update init.py to only expose variables/functions for web scripts (no routing)
- Remove api.py (routing is automatic for wwwroot files)
- Add MODULE_DEVELOPMENT_SPEC_UPDATE.md with clarified rules
- Follow proper module development specification
2026-04-21 14:43:26 +08:00

47 lines
1.9 KiB
Markdown

# Module Development Specification (Updated)
## Directory Structure
```
module-name/
├── module_name/ # Python package (underscore format)
│ ├── __init__.py # Required for Python package
│ └── init.py # Exposes variables/functions for web scripts
├── wwwroot/ # Web resources (auto-routed)
│ ├── *.ui # Bricks framework UI files
│ └── *.dspy # DSPy workflow files
├── models/ # Database table definitions (JSON)
├── json/ # CRUD operation definitions (JSON)
├── init/ # Initial data (JSON)
├── pyproject.toml # Package configuration for pip install
└── build.sh # Build script (optional)
```
## Key Rules
### 1. Automatic Routing
- Files in `wwwroot/` are automatically accessible via `/{module_name}/filename.ext`
- No need to register routes manually with ServerEnv
- Supported extensions: `.ui`, `.dspy`
### 2. init.py Purpose
- **Primary role**: Expose variables and functions for use by other modules and web scripts
- **Not for**: Route registration, ServerEnv configuration, complex initialization
- **Should contain**:
- Module constants and configuration
- Helper functions callable from .ui/.dspy scripts
- Variables needed by other Python modules
### 3. Python Package Naming
- Directory: `module-name/` (hyphen format for repository)
- Python package: `module_name/` (underscore format for import)
- PyPI package name: `module-name` (hyphen format)
### 4. Installation
- Must include `pyproject.toml` or `setup.py`
- Must be installable via `pip install .`
- Should declare dependencies properly
### 5. Web Script Integration
- .ui and .dspy files can import/use functions from init.py
- Use standard Python import syntax in web scripts
- Keep init.py lightweight and focused on exposure