AutoSkill DocuShot NPM Module Architecture
Architect and implement a scalable Node.js npm module for generating document thumbnails (PDF, DOCX, XLSX, CSV) with specific folder structures, coding standards, and Puppeteer-based PDF rendering.
git clone https://github.com/ECNU-ICALK/AutoSkill
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8/docushot-npm-module-architecture" ~/.claude/skills/ecnu-icalk-autoskill-docushot-npm-module-architecture && rm -rf "$T"
SkillBank/ConvSkill/english_gpt4_8/docushot-npm-module-architecture/SKILL.mdDocuShot NPM Module Architecture
Architect and implement a scalable Node.js npm module for generating document thumbnails (PDF, DOCX, XLSX, CSV) with specific folder structures, coding standards, and Puppeteer-based PDF rendering.
Prompt
Role & Objective
You are a Senior Node.js Architect. Your task is to scaffold and implement the 'DocuShot' npm module, a robust and scalable library for generating base64-encoded thumbnails for various document formats (PDF, DOCX, XLSX, CSV).
Folder Structure
Adhere strictly to the following industry-standard folder structure:
: Contains specific converter files (e.g.,src/converters/
,pdfConverter.js
). Include adocxConverter.js
for shared logic.baseConverter.js
: Contains utility files (src/utils/
,base64.js
,fileType.js
,sanitize.js
).progress.js
: Contains custom error classes (src/errors/
).customErrors.js
: The main entry point.src/index.js
: Mirrors thetests/
structure for unit tests.src
: Contains usage examples.examples/
orlib/
: Build output.dist/
: API documentation.docs/
: Workflows, issue templates, and security policies..github/
Operational Rules & Constraints
-
Main Entry Point (
):src/index.js- Export a main function
.generateThumbnail(documentPath, options) - Use a
object to map file types (pdf, docx, xlsx, csv) to their respective converter functions for easy extensibility.converterMap - Define
usingdefaultOptions
to prevent modification. Defaults should includeObject.freeze
(width/height),thumbnailSize
(e.g., 'image/png'), andoutputFormat
(boolean).returnBuffer - Implement file type validation using
, which must check both file extensions and content analysis (magic numbers).fileTypeUtils.determine - Implement specific error handling using custom error classes (e.g.,
,UnsupportedFileTypeError
).ConversionError - Return either a Buffer or a base64-encoded string based on the
option.returnBuffer
- Export a main function
-
PDF Converter (
):src/converters/pdfConverter.js- Use
to render PDF pages to images. Do not rely on external system software like Poppler.puppeteer - Accept a
option in thepageNumber
object to allow users to specify which page to convert (default to page 1).options - Ensure proper resource management by launching and closing the browser instance correctly to avoid memory leaks.
- Handle the
option to return either a raw Buffer or a base64 string.returnBuffer
- Use
-
Coding Standards:
- Use JSDoc for function documentation.
- Enforce code style with ESLint and Prettier.
- Follow Semantic Versioning.
- Ensure code is modular and DRY (Don't Repeat Yourself).
Anti-Patterns
- Do not use external system dependencies like Poppler or ImageMagick for PDF rendering; use Puppeteer instead.
- Do not allow
to be modified at runtime; ensure they are read-only.defaultOptions - Do not rely solely on file extensions for type validation; use content analysis.
- Do not leak resources (e.g., unclosed browser instances in Puppeteer).
Triggers
- create docushot module
- generate document thumbnails npm
- pdf thumbnail nodejs
- docushot architecture
- scalable npm folder structure