Development and Architecture
This document is for contributors and maintainers. It summarizes the package architecture, design decisions, and development workflow for Scientific Writer v2.7.0.
Architecture Overview
Package Structure
scientific_writer/
├── __init__.py # Public API exports, version
├── api.py # Async generate_paper() function
├── cli.py # CLI entrypoint (cli_main)
├── core.py # Core utilities (API keys, instructions, data processing)
├── models.py # Data models (ProgressUpdate, PaperResult, etc.)
└── utils.py # Helper functions (paper detection, file scanning)
Plugin Structure
claude-scientific-writer/
├── .claude-plugin/ # Plugin metadata
│ └── plugin.json
├── commands/ # Plugin commands
│ └── scientific-writer-init.md
├── skills/ # All 19+ skills
│ ├── citation-management/
│ ├── clinical-reports/
│ ├── research-lookup/
│ └── ... (16+ more)
├── templates/ # CLAUDE.md template
│ └── CLAUDE.scientific-writer.md
└── scientific_writer/ # Python package
Key Components
api.generate_paper: Async generator streaming progress and yielding a comprehensive result
cli.cli_main: CLI interface; 100% backward-compatible behavior
core: Shared logic for API key retrieval, instruction loading, output management, data handling
models: Typed dataclasses for API responses
utils: File scanning, paper detection, and helpers
- Plugin System: Commands, skills, and templates for Claude Code integration
Data Models
ProgressUpdate: real-time progress updates (stage, message, timestamp, details)
PaperResult: final result with status, files, metadata, citations, token_usage, and errors
PaperMetadata: title, created_at, topic, word_count
PaperFiles: all relevant paths (final, drafts, references, figures, data, logs)
TokenUsage: token consumption statistics (input_tokens, output_tokens, total_tokens, cache stats)
All models are fully typed and serializable to dictionaries.
API Design
- Async generator pattern for real-time updates and a final, comprehensive result
- Stateless operation per invocation
- Robust error handling with
success | partial | failed status
- Automatic paper directory detection and file scanning
Local Development
Setup
uv sync
Environment variables:
ANTHROPIC_API_KEY (required)
OPENROUTER_API_KEY (optional, for research lookup)
Run
# CLI
uv run scientific-writer
# Example API usage
uv run python example_api_usage.py
Testing and Quality
- Full type hints across the package
- Lint/format according to project defaults
- Validate imports and API signatures locally via example usage
Plugin Development
Testing Plugin Locally
For local plugin development and testing:
Create test marketplace (see TESTING_INSTRUCTIONS.md):
cd ..
mkdir -p test-marketplace/.claude-plugin
Configure marketplace with relative path to your local plugin:
{
"name": "test-marketplace",
"plugins": [{
"name": "claude-scientific-writer",
"source": "../claude-scientific-writer"
}]
}
Add marketplace in Claude Code:
/plugin marketplace add ../test-marketplace
Install plugin:
/plugin install claude-scientific-writer@test-marketplace
Test in a project:
/scientific-writer:init
Plugin Structure Requirements
.claude-plugin/plugin.json - Plugin metadata
commands/ - Command definitions (YAML frontmatter required)
skills/ - Skill definitions (each with SKILL.md + YAML frontmatter)
templates/ - Template files (CLAUDE.scientific-writer.md)
Adding New Skills
- Create directory in
skills/
- Add
SKILL.md with YAML frontmatter:---
name: skill-name
description: Brief description
allowed-tools: [read_file, write, etc.]
---
- Add references, scripts, assets as needed
- Test skill availability after plugin reinstall
Release Notes
v2.7.0 highlights:
- Claude Code Plugin Focus - Optimized for IDE integration
- Plugin installation with
/scientific-writer:init
- All 19+ skills accessible via plugin
- Streamlined IDE workflow
v2.0 highlights:
- Programmatic API via
generate_paper
- Progress streaming and comprehensive JSON results
- Modular package structure with entry points
- 100% CLI backward compatibility
See CHANGELOG.md for details.
Migration Guides
v1.x -> v2.0
- CLI remains identical (
scientific-writer)
- New package structure replaces single-file script
- For programmatic use, import from
scientific_writer
Example:
from scientific_writer import generate_paper
CLI/API -> Plugin (v2.7.0)
For best IDE experience:
- Install as Claude Code plugin (recommended)
- Use
/scientific-writer:init in your project
- Access all skills directly in IDE
- No CLI required for most workflows
Contributing
- Fork and create a feature branch
uv sync to install dependencies
- Make changes with clear commits
- Test locally (CLI, API, and plugin if applicable)
- Ensure all examples run
- Update documentation if needed
- Open a pull request with a concise description
Project Links
README.md — entry point and quick start
Docs/API.md — full API reference
Docs/TROUBLESHOOTING.md — troubleshooting
Docs/SKILLS.md — skills overview
CHANGELOG.md — release history
CLAUDE.md — system instructions (kept at root)
1---2name: 586-development-345145ee3description: Development and Architecture4---5# Development and Architecture67This document is for contributors and maintainers. It summarizes the package architecture, design decisions, and development workflow for Scientific Writer v2.7.0.89## Architecture Overview1011### Package Structure1213```14scientific_writer/15├── __init__.py # Public API exports, version16├── api.py # Async generate_paper() function17├── cli.py # CLI entrypoint (cli_main)18├── core.py # Core utilities (API keys, instructions, data processing)19├── models.py # Data models (ProgressUpdate, PaperResult, etc.)20└── utils.py # Helper functions (paper detection, file scanning)21```2223### Plugin Structure2425```26claude-scientific-writer/27├── .claude-plugin/ # Plugin metadata28│ └── plugin.json29├── commands/ # Plugin commands30│ └── scientific-writer-init.md31├── skills/ # All 19+ skills32│ ├── citation-management/33│ ├── clinical-reports/34│ ├── research-lookup/35│ └── ... (16+ more)36├── templates/ # CLAUDE.md template37│ └── CLAUDE.scientific-writer.md38└── scientific_writer/ # Python package39```4041### Key Components4243- `api.generate_paper`: Async generator streaming progress and yielding a comprehensive result44- `cli.cli_main`: CLI interface; 100% backward-compatible behavior45- `core`: Shared logic for API key retrieval, instruction loading, output management, data handling46- `models`: Typed dataclasses for API responses47- `utils`: File scanning, paper detection, and helpers48- **Plugin System**: Commands, skills, and templates for Claude Code integration4950## Data Models5152- `ProgressUpdate`: real-time progress updates (stage, message, timestamp, details)53- `PaperResult`: final result with status, files, metadata, citations, token_usage, and errors54- `PaperMetadata`: title, created_at, topic, word_count55- `PaperFiles`: all relevant paths (final, drafts, references, figures, data, logs)56- `TokenUsage`: token consumption statistics (input_tokens, output_tokens, total_tokens, cache stats)5758All models are fully typed and serializable to dictionaries.5960## API Design6162- Async generator pattern for real-time updates and a final, comprehensive result63- Stateless operation per invocation64- Robust error handling with `success | partial | failed` status65- Automatic paper directory detection and file scanning6667## Local Development6869### Setup7071```bash72uv sync73```7475Environment variables:7677- `ANTHROPIC_API_KEY` (required)78- `OPENROUTER_API_KEY` (optional, for research lookup)7980### Run8182```bash83# CLI84uv run scientific-writer8586# Example API usage87uv run python example_api_usage.py88```8990## Testing and Quality9192- Full type hints across the package93- Lint/format according to project defaults94- Validate imports and API signatures locally via example usage9596## Plugin Development9798### Testing Plugin Locally99100For local plugin development and testing:1011021. **Create test marketplace** (see `TESTING_INSTRUCTIONS.md`):103 ```bash104 cd ..105 mkdir -p test-marketplace/.claude-plugin106 ```1071082. **Configure marketplace** with relative path to your local plugin:109 ```json110 {111 "name": "test-marketplace",112 "plugins": [{113 "name": "claude-scientific-writer",114 "source": "../claude-scientific-writer"115 }]116 }117 ```1181193. **Add marketplace in Claude Code**:120 ```121 /plugin marketplace add ../test-marketplace122 ```1231244. **Install plugin**:125 ```126 /plugin install claude-scientific-writer@test-marketplace127 ```1281295. **Test in a project**:130 ```131 /scientific-writer:init132 ```133134### Plugin Structure Requirements135136- **`.claude-plugin/plugin.json`** - Plugin metadata137- **`commands/`** - Command definitions (YAML frontmatter required)138- **`skills/`** - Skill definitions (each with SKILL.md + YAML frontmatter)139- **`templates/`** - Template files (CLAUDE.scientific-writer.md)140141### Adding New Skills1421431. Create directory in `skills/`1442. Add `SKILL.md` with YAML frontmatter:145 ```yaml146 ---147 name: skill-name148 description: Brief description149 allowed-tools: [read_file, write, etc.]150 ---151 ```1523. Add references, scripts, assets as needed1534. Test skill availability after plugin reinstall154155## Release Notes156157v2.7.0 highlights:158159- **Claude Code Plugin Focus** - Optimized for IDE integration160- Plugin installation with `/scientific-writer:init`161- All 19+ skills accessible via plugin162- Streamlined IDE workflow163164v2.0 highlights:165166- Programmatic API via `generate_paper`167- Progress streaming and comprehensive JSON results168- Modular package structure with entry points169- 100% CLI backward compatibility170171See `CHANGELOG.md` for details.172173## Migration Guides174175### v1.x -> v2.0176177- CLI remains identical (`scientific-writer`)178- New package structure replaces single-file script179- For programmatic use, import from `scientific_writer`180181Example:182183```python184from scientific_writer import generate_paper185```186187### CLI/API -> Plugin (v2.7.0)188189For best IDE experience:190- Install as Claude Code plugin (recommended)191- Use `/scientific-writer:init` in your project192- Access all skills directly in IDE193- No CLI required for most workflows194195## Contributing1961971. Fork and create a feature branch1982. `uv sync` to install dependencies1993. Make changes with clear commits2004. Test locally (CLI, API, and plugin if applicable)2015. Ensure all examples run2026. Update documentation if needed2037. Open a pull request with a concise description204205## Project Links206207- `README.md` — entry point and quick start208- `Docs/API.md` — full API reference209- `Docs/TROUBLESHOOTING.md` — troubleshooting210- `Docs/SKILLS.md` — skills overview211- `CHANGELOG.md` — release history212- `CLAUDE.md` — system instructions (kept at root)213214