TypeScript Project Template

October 16, 2025 ยท View on GitHub

CI Coverage Node.js Version License

A production-ready TypeScript template repository with comprehensive linting, formatting, testing, and build configuration. Perfect for quickly bootstrapping new TypeScript projects with industry best practices built-in.

๐ŸŽฏ Why Use This Template?

Starting a new TypeScript project often means hours of configuration setup. This template provides:

  • โœ… Zero Configuration Needed: All tooling pre-configured and ready to use
  • โœ… Industry Best Practices: Battle-tested configurations for linting, formatting, and testing
  • โœ… Immediate Productivity: Start writing code, not configuring tools
  • โœ… Consistent Code Quality: Enforced standards across your entire project
  • โœ… CI/CD Ready: GitHub Actions workflows included
  • โœ… Fully Documented: Clear examples and comprehensive documentation

โœจ Features

  • ๐Ÿ“ฆ Modern TypeScript: Full TypeScript 5.7+ configuration with strict type checking
  • ๐Ÿ” Code Quality: ESLint with SonarJS static analysis, complexity limits, and import sorting
  • ๐ŸŽจ Code Formatting: Prettier integration with automatic formatting on save
  • ๐Ÿงช Comprehensive Testing: Jest testing framework with coverage reporting and badges
  • โšก Optimized Build: Rollup bundling with Terser minification for optimal output
  • ๐Ÿ—๏ธ Modular Architecture: Example project structure with dependency injection patterns
  • ๐Ÿ“Š Quality Gates: Duplicate code detection, circular dependency checking
  • ๐Ÿ›ก๏ธ Security: SonarJS security patterns and vulnerability detection
  • ๐Ÿ”ง Developer Experience: EditorConfig, Visual Studio Code settings, and development container support
  • ๐Ÿ“‹ CI/CD Ready: Pre-configured GitHub Actions workflows with automated quality checks
  • ๐ŸŽ“ Learning Resource: Well-documented examples of TypeScript best practices

๐Ÿš€ Quick Start

Using This Template

  1. Click "Use this template" button at the top of this repository

  2. Create your new repository from the template

  3. Clone your new repository:

    git clone https://github.com/YOUR_USERNAME/YOUR_REPO_NAME.git
    cd YOUR_REPO_NAME
    
  4. Enable Corepack (if not already enabled):

    corepack enable
    
  5. Install dependencies:

    yarn install
    
  6. Start coding! The template includes example code you can replace with your own.

First Steps After Setup

  1. Update package.json:

    • Change name, description, author
    • Update repository, bugs, and homepage URLs
    • Modify keywords to match your project
  2. Update readme:

    • Replace this readme with your project's documentation
    • Update badges with your repository information
  3. Configure licensing:

    • Review and update LICENSE file if needed
    • Update copyright headers in source files (or run yarn copyright)
  4. Customize CODEOWNERS:

    • Update .github/CODEOWNERS with your team's information

๐Ÿ“ Project Structure

โ”œโ”€โ”€ .devcontainer/          # Dev container for consistent development environment
โ”œโ”€โ”€ .github/
โ”‚   โ”œโ”€โ”€ workflows/          # GitHub Actions CI/CD workflows
โ”‚   โ”‚   โ””โ”€โ”€ ci.yml          # Main CI pipeline (lint, test, build)
โ”‚   โ”œโ”€โ”€ FUNDING.yml         # GitHub funding/sponsor configuration
โ”‚   โ””โ”€โ”€ pull_request_template.md
โ”œโ”€โ”€ .vscode/                # VS Code workspace settings and extensions
โ”œโ”€โ”€ __mocks__/              # Jest test mocks
โ”œโ”€โ”€ badges/                 # Generated coverage badges
โ”œโ”€โ”€ coverage/               # Test coverage reports (generated)
โ”œโ”€โ”€ dist/                   # Build output (generated)
โ”œโ”€โ”€ script/                 # Utility scripts
โ”‚   โ””โ”€โ”€ release.sh          # Release automation
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ index.ts            # Main entry point
โ”‚   โ”œโ”€โ”€ core/               # Core business logic
โ”‚   โ”œโ”€โ”€ logging/            # Modular logging system (example architecture)
โ”‚   โ”‚   โ”œโ”€โ”€ loggers/        # Logger implementations
โ”‚   โ”‚   โ”œโ”€โ”€ pino/           # Pino logger integration
โ”‚   โ”‚   โ”œโ”€โ”€ filters/        # Log filtering system
โ”‚   โ”‚   โ””โ”€โ”€ types.ts        # Type definitions
โ”‚   โ””โ”€โ”€ __tests__/          # Comprehensive test suite
โ”‚       โ”œโ”€โ”€ jest.setup.ts   # Jest globals setup for ESM
โ”‚       โ””โ”€โ”€ loggers/        # Logger implementation tests
โ”œโ”€โ”€ .editorconfig           # Editor configuration for consistent coding styles
โ”œโ”€โ”€ .gitignore              # Git ignore patterns
โ”œโ”€โ”€ .gitattributes          # Git attributes
โ”œโ”€โ”€ .jscpd.json            # Code duplication detection configuration
โ”œโ”€โ”€ .markdown-lint.yml      # Markdown linter rules
โ”œโ”€โ”€ .npmignore              # NPM publish ignore patterns
โ”œโ”€โ”€ .nvmrc                  # Node.js version specification
โ”œโ”€โ”€ .prettierignore         # Prettier ignore patterns
โ”œโ”€โ”€ .prettierrc.yml         # Prettier code formatting configuration
โ”œโ”€โ”€ .yaml-lint.yml          # YAML file linter rules                   |
โ”œโ”€โ”€ CODEOWNERS              # Code ownership and review assignments
โ”œโ”€โ”€ eslint.config.mjs       # Modern ESLint flat configuration
โ”œโ”€โ”€ jest.config.cjs         # Jest testing configuration
โ”œโ”€โ”€ package.json            # Project dependencies and scripts
โ”œโ”€โ”€ rollup.config.js        # Rollup bundling configuration
โ”œโ”€โ”€ tsconfig.json           # Production TypeScript configuration
โ”œโ”€โ”€ tsconfig.test.json      # Test environment TypeScript configuration
โ””โ”€โ”€ README.md               # This file

๐Ÿ’ป Development

Prerequisites

  • Node.js 20+ (specified in .nvmrc)
  • Yarn 4.5.3 (managed via Corepack)

Setup Your Development Environment

  1. Use the correct Node.js version (if using nvm):

    nvm use
    
  2. Enable Corepack (ships with Node.js 16.10+):

    corepack enable
    
  3. Install dependencies:

    yarn install
    
  4. Verify everything works:

    yarn all
    

Yarn Scripts Reference

ScriptDescription
yarn all๐Ÿš€ Complete pipeline: lint:fix โ†’ quality โ†’ test โ†’ package
yarn typecheck๐Ÿ“‹ TypeScript type checking without emit
yarn lint๐Ÿ” Run Prettier and ESLint validation
yarn lint:fix๐ŸŽจ autoformat and fix code issues
yarn quality๐Ÿ“Š Run quality gates: lint + duplication + circular deps
yarn test๐Ÿงช Run Jest tests with coverage reporting
yarn coverage๐Ÿ“ˆ Generate coverage badge
yarn duplication๐Ÿ“Š Analyze code duplication (1% threshold)
yarn madge๐Ÿ”„ Detect circular dependencies
yarn package๐Ÿ“ฆ Create production build
yarn package:watch๐Ÿ‘€ Build in watch mode for development
yarn copyrightยฉ๏ธ Update copyright headers in source files

Day-to-Day Development Workflow

  1. Write your code in the src/ directory
  2. Add tests in src/__tests__/ for your new features
  3. Run tests frequently: yarn test
  4. Check code quality: yarn quality
  5. Fix issues automatically: yarn lint:fix
  6. Build for production: yarn package

Testing

Run the test suite:

yarn test

This will:

  • Execute all Jest tests
  • Generate coverage reports in coverage/
  • Create a coverage badge in badges/coverage.svg

Code Quality Checks

The template includes multiple quality gates:

Check for code duplication:

yarn duplication

Check for circular dependencies:

yarn madge

Run all quality checks:

yarn quality

Building

Create an optimized production build:

yarn package

This uses Rollup to create an optimized bundle in dist/.

๐Ÿ”„ CI/CD

The repository includes a comprehensive CI/CD workflow:

  • CI Pipeline (.github/workflows/ci.yml):
    • Runs on Node.js 20 with Ubuntu latest
    • Executes linting, type checking, and tests
    • Generates coverage reports
    • Builds production bundles
    • Validates code quality gates

Customizing CI/CD

Edit .github/workflows/ci.yml to adjust:

  • Node.js version (currently set to 20)
  • Additional build steps
  • Deployment configurations
  • Quality gate thresholds

โš™๏ธ Configuration

TypeScript Configuration

The template includes two TypeScript configurations:

  • tsconfig.json: Production configuration for building

    • Strict type checking enabled
    • ECMAScript 2022 target and module format
    • Path aliases supported (@/* โ†’ src/*)
  • tsconfig.test.json: Test environment configuration

    • Extends base configuration
    • Includes test files and mocks
    • Jest type definitions

ESLint Configuration

Modern ESLint flat configuration (eslint.config.mjs) with:

  • TypeScript Integration: Full type-aware linting with strict rules
  • SonarJS Static Analysis: Comprehensive static code analysis with security patterns, extremely low complexity limits, and code quality rules
  • Import Organization: Automatic import sorting and organization
  • Complexity Monitoring: Extremely low cyclomatic complexity limits (fails at >5) and cognitive complexity (fails at >8)
  • Jest Support: Test-specific rules and globals
  • Prettier Integration: Seamless code formatting

Prettier Configuration

Code formatting with Prettier (.prettierrc.yml):

  • 2-space indentation
  • Single quotes
  • Semicolons
  • 80 character line width
  • Arrow parens always
  • Trailing commas: none

Jest Configuration

Testing framework setup (jest.config.cjs):

  • TypeScript support via ts-jest
  • ESM module support with experimental VM modules
  • Jest globals injection via setup file (src/__tests__/jest.setup.ts)
  • Coverage thresholds and reporting
  • Module path mapping
  • Test environment: Node.js

Rollup Configuration

Production bundling (rollup.config.js):

  • ES Module output
  • TypeScript compilation
  • Terser minification
  • External dependency handling
  • Declaration file generation

Additional Configuration Files

FilePurpose
.editorconfigConsistent editor settings across IDEs
.gitignoreGit ignore patterns for Node.js projects
.jscpd.jsonCode duplication detection (1% threshold)
.markdown-lint.ymlMarkdown linter rules
.nvmrcNode.js version specification (20)
.prettierignoreFiles to exclude from formatting
.yaml-lint.ymlYAML file linter rules
CODEOWNERSCode ownership and review assignments

๐Ÿ—๏ธ Architecture

The template includes an example modular architecture with:

Logging System

A comprehensive logging abstraction with multiple implementations:

  • CoreLogger: Console logger (example implementation)
  • PinoLogger: Structured logging with Pino
  • FilteredLogger: Conditional logging based on filters
  • CompositeLogger: Multi-logger orchestration
  • MetricsLogger: Performance and metrics tracking
  • MockLogger: Testing and development
  • NoopLogger: Disabled logging

This demonstrates:

  • Dependency Injection: Loosely coupled components
  • Interface Segregation: Clean abstractions
  • Factory Pattern: Logger creation and configuration
  • Composition: Building complex behavior from simple parts

Example Usage

The template includes example code that you can:

  • Learn from: See TypeScript best practices in action
  • Modify: Adapt the structure to your needs
  • Replace: Remove entirely and start fresh
  • Extend: Build upon the existing patterns

๐Ÿ“š What's Included?

Development Tools

  • TypeScript 5.7+: Latest TypeScript with strict mode
  • ESLint 9: Modern flat config with comprehensive rules
  • Prettier 3: Opinionated code formatting
  • Jest 29: Testing framework with coverage
  • Rollup 4: Production bundling and optimization

Quality Tools

  • SonarJS: Comprehensive static code analysis with security patterns, extremely low complexity limits, and code quality rules
  • JSCPD: Code duplication detection
  • Madge: Circular dependency checking
  • make-coverage-badge: Automatic coverage badges

Visual Studio Code Integration

  • Workspace settings for consistent development
  • Recommended extensions
  • Debug configurations
  • Task definitions

Dev Container Support

Fully configured development container for consistent environments across teams.

๐Ÿค Contributing to This Template

Contributions to improve this template are welcome!

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/improvement
  3. Make your changes following the existing patterns
  4. Add or update tests as needed
  5. Run the complete pipeline: yarn all
  6. Ensure all quality gates pass
  7. Submit a pull request with a clear description

๐Ÿ“„ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

This template incorporates best practices from:

  • TypeScript team's recommendations
  • ESLint and Prettier communities
  • Jest testing patterns
  • Modern JavaScript development practices

๏ฟฝ Additional Documentation

๏ฟฝ๐Ÿ’ฌ Support


Happy coding! ๐Ÿš€ Start building your next TypeScript project with confidence.