npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

create-preact-storybook-template

v1.0.4

Published

A modern Preact template with Storybook, TypeScript, Tailwind CSS, Vitest, and TypeDoc

Readme

create-preact-storybook-template

A modern Preact application template with TypeScript, Tailwind CSS, Storybook, comprehensive testing, and documentation setup.

Features

  • 🚀 Preact - Fast 3kB alternative to React with modern hooks
  • 📝 TypeScript - Full type safety and excellent developer experience
  • 🎨 Tailwind CSS - Utility-first CSS framework for rapid UI development
  • 📚 Storybook - Component development environment and documentation
  • 🧪 Vitest - Lightning-fast unit testing with coverage reports
  • 📖 TypeDoc - Automatic API documentation generation from JSDoc
  • Vite - Next-generation build tool with HMR
  • 🏗️ Modern Architecture - Strict separation of presentation and business logic

Quick Start

Create a new Preact app with one command:

npm create preact-storybook-template my-app
cd my-app
npm install
npm run dev

Or with yarn:

yarn create preact-storybook-template my-app
cd my-app
yarn install
yarn dev

Or with pnpm:

pnpm create preact-storybook-template my-app
cd my-app
pnpm install
pnpm dev

What's Included

📦 Dependencies

  • Preact - Modern React alternative with hooks support
  • TypeScript - Type safety and IntelliSense
  • Tailwind CSS - Utility-first styling
  • Vite - Fast build tool and dev server

🧪 Development & Testing

  • Vitest - Unit testing framework
  • @testing-library/preact - Testing utilities
  • @vitest/coverage-v8 - Coverage reporting
  • @vitest/ui - Testing interface

📚 Documentation & Stories

  • Storybook - Component documentation and development
  • TypeDoc - API documentation generation
  • @microsoft/tsdoc - TSDoc support

🏗️ Architecture Guidelines

  • Strict separation of concerns - UI components vs business logic
  • Component-driven development - Build and test components in isolation
  • Type-safe - Comprehensive TypeScript coverage
  • Test-driven - 100% test coverage requirement
  • Documentation-first - Storybook stories for every component

Available Scripts

Your new project will include these npm scripts:

# Development
npm run dev          # Start development server
npm run build        # Build for production
npm run preview      # Preview production build

# Testing
npm run test         # Run tests in watch mode
npm run test:run     # Run tests once
npm run test:ui      # Run tests with UI
npm run test:coverage # Generate coverage report

# Documentation
npm run storybook    # Start Storybook dev server
npm run docs:api     # Generate TypeDoc documentation
npm run docs:all     # Generate all documentation

# Code Quality
npm run type-check   # TypeScript type checking
npm run lint         # Lint and type check
npm run clean        # Clean build artifacts

Project Structure

my-app/
├── src/
│   ├── components/     # UI components (.tsx) - presentation only
│   │   ├── Button.tsx
│   │   ├── Card.tsx
│   │   └── index.ts
│   ├── hooks/         # Custom hooks (.ts) - state logic
│   ├── services/      # Business logic (.ts) - API calls
│   ├── utils/         # Pure utility functions (.ts)
│   ├── stories/       # Storybook stories (.stories.tsx)
│   ├── test/          # Test files (.test.ts/.test.tsx)
│   ├── assets/        # Static assets
│   ├── app.tsx        # Main app component
│   └── main.tsx       # Application entry point
├── public/            # Static public files
├── docs/              # Generated documentation
└── package.json       # Project configuration

Architecture Principles

This template enforces clean architecture with strict separation:

🎨 Presentation Layer (Components)

  • .tsx files in src/components/
  • Only UI rendering and user interactions
  • Import business logic from services/hooks
  • Comprehensive Storybook stories

🧠 Business Logic Layer

  • .ts files in src/services/, src/hooks/, src/utils/
  • API calls, data transformations, state management
  • Pure functions and custom hooks
  • 100% test coverage required

📝 Documentation Layer

  • Storybook - Component playground and documentation
  • TypeDoc - API documentation from JSDoc comments
  • Test Coverage - Detailed coverage reports

Best Practices

✅ Do's

  • Keep components small and focused
  • Write comprehensive tests for all business logic
  • Document all public APIs with JSDoc
  • Create Storybook stories for all components
  • Use TypeScript strictly (no any types)
  • Follow the separation of concerns principle

❌ Don'ts

  • Put business logic directly in components
  • Skip writing tests for .ts files
  • Hardcode API endpoints or configuration
  • Ignore TypeScript warnings
  • Create components without stories

Examples

Component with Business Logic Separation

// ❌ Bad: Logic mixed with presentation
export function UserProfile({ userId }: { userId: string }) {
  const [user, setUser] = useState(null);
  
  useEffect(() => {
    fetch(`/api/users/${userId}`)
      .then(res => res.json())
      .then(setUser);
  }, [userId]);
  
  return <div>{user?.name}</div>;
}

// ✅ Good: Separated concerns
// services/userService.ts
export const fetchUser = (id: string) => fetch(`/api/users/${id}`).then(r => r.json());

// hooks/useUser.ts  
export const useUser = (id: string) => {
  const [user, setUser] = useState(null);
  useEffect(() => {
    fetchUser(id).then(setUser);
  }, [id]);
  return user;
};

// components/UserProfile.tsx
export function UserProfile({ userId }: { userId: string }) {
  const user = useUser(userId);
  return <div>{user?.name}</div>;
}

Contributing

This template is designed to be a starting point. Feel free to:

  • Add more components and utilities
  • Extend the testing setup
  • Customize the build configuration
  • Add more Storybook addons

Learn More

License

MIT