TypeScript Project Template
October 16, 2025 ยท View on GitHub
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
-
Click "Use this template" button at the top of this repository
-
Create your new repository from the template
-
Clone your new repository:
git clone https://github.com/YOUR_USERNAME/YOUR_REPO_NAME.git cd YOUR_REPO_NAME -
Enable Corepack (if not already enabled):
corepack enable -
Install dependencies:
yarn install -
Start coding! The template includes example code you can replace with your own.
First Steps After Setup
-
Update
package.json:- Change
name,description,author - Update
repository,bugs, andhomepageURLs - Modify
keywordsto match your project
- Change
-
Update
readme:- Replace this readme with your project's documentation
- Update badges with your repository information
-
Configure licensing:
- Review and update
LICENSEfile if needed - Update copyright headers in source files (or run
yarn copyright)
- Review and update
-
Customize CODEOWNERS:
- Update
.github/CODEOWNERSwith your team's information
- Update
๐ 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
-
Use the correct Node.js version (if using nvm):
nvm use -
Enable Corepack (ships with Node.js 16.10+):
corepack enable -
Install dependencies:
yarn install -
Verify everything works:
yarn all
Yarn Scripts Reference
| Script | Description |
|---|---|
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
- Write your code in the
src/directory - Add tests in
src/__tests__/for your new features - Run tests frequently:
yarn test - Check code quality:
yarn quality - Fix issues automatically:
yarn lint:fix - 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
| File | Purpose |
|---|---|
.editorconfig | Consistent editor settings across IDEs |
.gitignore | Git ignore patterns for Node.js projects |
.jscpd.json | Code duplication detection (1% threshold) |
.markdown-lint.yml | Markdown linter rules |
.nvmrc | Node.js version specification (20) |
.prettierignore | Files to exclude from formatting |
.yaml-lint.yml | YAML file linter rules |
CODEOWNERS | Code 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!
- Fork the repository
- Create a feature branch:
git checkout -b feature/improvement - Make your changes following the existing patterns
- Add or update tests as needed
- Run the complete pipeline:
yarn all - Ensure all quality gates pass
- 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
- Template Setup Guide: Detailed setup instructions
- Template Checklist: Customization checklist
- Quick Reference: Command and configuration reference
- Contributing: How to contribute to this template
- Starter Templates: Example starting points
๏ฟฝ๐ฌ Support
- Issues: Report bugs or request features via GitHub Issues
- Discussions: Ask questions in GitHub Discussions
Happy coding! ๐ Start building your next TypeScript project with confidence.