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

@machize/create-stack-fastify

v1.0.22

Published

πŸš€ A powerful CLI tool for generating production-ready Fastify projects with TypeScript, Clean Architecture, and Domain-Driven Design

Downloads

66

Readme

Create Stack Fastify

npm version License: MIT

πŸš€ A powerful CLI tool for generating production-ready Fastify projects with TypeScript, following Clean Architecture and Domain-Driven Design principles.

🌟 Features

  • ⚑ Fast Setup: Generate a complete project structure in seconds
  • πŸ—οΈ Clean Architecture: Follows Clean Architecture and DDD patterns
  • πŸ”§ TypeScript First: Full TypeScript support with type safety
  • πŸš€ Fastify Framework: Built on top of the fastest Node.js web framework
  • πŸ“Š Database Support: Choose between TypeORM or Prisma ORM
  • πŸ“š API Documentation: Automatic Swagger/OpenAPI documentation generation
  • πŸ” GraphQL Ready: Optional GraphQL support with schema generation
  • πŸ” Authentication: Built-in JWT authentication system with RSA key support
  • πŸ“§ Email Service: Integrated email service with template support
  • πŸ§ͺ Testing Ready: Pre-configured testing environment with Jest
  • πŸ“¦ Module System: Modular architecture for better code organization
  • 🌐 Internationalization: Full English language support with comprehensive documentation
  • πŸ”§ Content-Type Handling: Enhanced request parsing with automatic Content-Type detection
  • πŸ› οΈ Error Handling: Improved GraphQL error handling with automatic redirects
  • 🀝 Open Source: MIT licensed and open for contributions

πŸ“‹ Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (version 16 or higher)
  • npm or yarn package manager

πŸš€ Quick Start

Installation

You can use `@machize/machize/create-stack-fastifyy with npm/yarn without global installation:

# Using npm
npx @machize/machize/create-stack-fastifyct api

# Using yarn
yarn create @machize/machize/create-stack-fastifyct api

Usage

@machize/machize/create-stack-fastify-name> api [--module=module-name]

Parameters:

  • project-name: The name of your new project
  • api: Command to create a Fastify API project
  • --module (optional): Add additional modules to your project

Examples:

# Creates project with default 'users' module (includes TypeScript files)
npx @machize/machize/create-stack-fastifye-api api

# Creates project with 'users' + 'products' modules
npx @machize/machize/create-stack-fastifye-api api --module=products

# Add new module to existing project
npx @machize/machize/create-stack-fastify-project --module=orders

Interactive Setup

During project creation, you'll be prompted to choose the tools you want to include:

? Which tools would you like to use?
❯ β—― TypeORM
  β—― Prisma
  β—― Swagger
  β—― GraphQL

Available Options:

  • TypeORM: Object-Relational Mapping with decorators
  • Prisma: Modern database toolkit with type-safe client
  • Swagger: Automatic API documentation generation
  • GraphQL: GraphQL API with schema-first approach

πŸ“ Project Structure

The generated project follows a clean, modular architecture based on Clean Architecture and DDD principles:

my-project/
β”œβ”€β”€ .husky/                   # Git hooks configuration
β”œβ”€β”€ prisma/                  # Prisma schema and migrations (if selected)
β”‚   └── schema.prisma        # Database schema definition
β”œβ”€β”€ tests/                   # Test files and utilities
β”œβ”€β”€ uploads/                 # File upload directory
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ config/              # Application configuration
β”‚   β”‚   β”œβ”€β”€ client/          # External service clients
β”‚   β”‚   β”œβ”€β”€ swaggers/        # Swagger documentation files
β”‚   β”‚   β”‚   β”œβ”€β”€ components/  # Swagger components
β”‚   β”‚   β”‚   └── specification/ # API specifications
β”‚   β”‚   β”œβ”€β”€ column.ts        # Database column configurations
β”‚   β”‚   β”œβ”€β”€ constants.ts     # Application constants
β”‚   β”‚   β”œβ”€β”€ graphql.config.ts # GraphQL configuration (if selected)
β”‚   β”‚   └── typeorm.connection.ts # TypeORM config (if selected)
β”‚   β”œβ”€β”€ shared/              # Shared utilities and types
β”‚   β”‚   β”œβ”€β”€ common/          # Common utilities
β”‚   β”‚   β”œβ”€β”€ domain/          # Domain-specific shared code
β”‚   β”‚   β”œβ”€β”€ interfaces/      # Shared interfaces
β”‚   β”‚   β”œβ”€β”€ types/           # Type definitions
β”‚   β”‚   └── utils/           # Utility functions
β”‚   └── core/                # Core business logic
β”‚       β”œβ”€β”€ infra/           # Shared infrastructure layer
β”‚       β”‚   β”œβ”€β”€ adapter/     # External service adapters
β”‚       β”‚   β”‚   β”œβ”€β”€ adapterFastify.ts    # Fastify adapter
β”‚       β”‚   β”‚   └── httpResponse.ts      # HTTP response utilities
β”‚       β”‚   β”œβ”€β”€ graphql/     # GraphQL infrastructure (if selected)
β”‚       β”‚   β”‚   β”œβ”€β”€ schema/      # GraphQL schema files
β”‚       β”‚   β”‚   └── resolvers.ts # Main resolvers file
β”‚       β”‚   β”œβ”€β”€ http/        # HTTP infrastructure
β”‚       β”‚   β”‚   β”œβ”€β”€ handlers/    # Route handlers
β”‚       β”‚   β”‚   β”œβ”€β”€ middlewares/ # Custom middlewares
β”‚       β”‚   β”‚   β”œβ”€β”€ v1/routers/  # API route definitions
β”‚       β”‚   β”‚   β”œβ”€β”€ app.ts       # Fastify application setup
β”‚       β”‚   β”‚   β”œβ”€β”€ httpServer.ts # HTTP server configuration
β”‚       β”‚   β”‚   β”œβ”€β”€ server.ts    # Main server entry point
β”‚       β”‚   β”‚   β”œβ”€β”€ swagger.ts   # Swagger setup (if selected)
β”‚       β”‚   β”‚   └── openapidocs.ts # OpenAPI documentation
β”‚       β”‚   β”œβ”€β”€ plugins/     # Infrastructure plugins
β”‚       β”‚   β”‚   β”œβ”€β”€ swagger.plugins.ts   # Swagger plugin
β”‚       β”‚   β”‚   └── mercurius.plugins.ts # GraphQL plugin
β”‚       β”‚   β”œβ”€β”€ prisma/      # Prisma client (if selected)
β”‚       β”‚   β”‚   └── prisma-client.ts
β”‚       β”‚   └── typeorm/     # TypeORM entities (if selected)
β”‚       β”‚       └── entities/
β”‚       └── [module-name]/   # Domain modules (e.g., users, orders)
β”‚           β”œβ”€β”€ application/ # Application layer
β”‚           β”‚   β”œβ”€β”€ services/    # Application services
β”‚           β”‚   β”‚   β”œβ”€β”€ auth/    # Authentication services
β”‚           β”‚   β”‚   β”œβ”€β”€ mail/    # Mail services
β”‚           β”‚   β”‚   └── user/    # User services
β”‚           β”‚   └── usecases/    # Use cases/interactors
β”‚           β”‚       β”œβ”€β”€ auth/    # Authentication use cases
β”‚           β”‚       └── user/    # User use cases
β”‚           β”œβ”€β”€ domain/      # Domain layer
β”‚           β”‚   β”œβ”€β”€ auth/        # Auth domain entities and DTOs
β”‚           β”‚   └── user/        # User domain entities and DTOs
β”‚           β”œβ”€β”€ mappers/     # Data transformation mappers
β”‚           β”œβ”€β”€ model/       # Data models
β”‚           β”œβ”€β”€ module/      # Module configuration and DI
β”‚           β”œβ”€β”€ plugins/     # Module-specific plugins
β”‚           β”œβ”€β”€ repositories/ # Data access repositories
β”‚           β”œβ”€β”€ service/     # Domain services
β”‚           └── [module].resolver.ts # GraphQL resolver (if GraphQL enabled)
β”œβ”€β”€ .env                     # Environment variables
β”œβ”€β”€ package.json             # Project dependencies and scripts
β”œβ”€β”€ tsconfig.json            # TypeScript configuration
β”œβ”€β”€ README.md                # Project documentation
β”œβ”€β”€ GRAPHQL_EXAMPLES.md      # GraphQL usage examples (if selected)
β”œβ”€β”€ SWAGGER_TYPEORM_EXAMPLES.md # Swagger + TypeORM examples (if selected)
└── LIBRARIES_EXAMPLES.md    # Library usage examples

πŸ”§ Generated Files and Features

Core Features

  1. HTTP Server: Fastify-based HTTP server with type safety and enhanced content parsing
  2. Authentication System: JWT-based authentication with RSA key support and middleware
  3. Database Integration: Ready-to-use database connections with migration support
  4. API Documentation: Auto-generated Swagger documentation with interactive UI
  5. Error Handling: Centralized error handling with proper HTTP responses and GraphQL redirects
  6. Logging: Structured logging with different levels and request tracking
  7. Environment Configuration: Environment-based configuration management with .env support
  8. RSA Key Management: Automatic RSA key generation and configuration scripts
  9. Content-Type Detection: Smart content parsing for different media types
  10. International Support: Full English documentation and comments

Authentication System

The generated project includes a complete authentication system:

  • JWT Token Management: Secure token generation and validation
  • User Registration: Sign-up with email validation
  • User Login: Secure authentication endpoint
  • Protected Routes: Middleware for route protection
  • Password Hashing: Bcrypt-based password security

Database Support

TypeORM Integration

  • Entity definitions with decorators
  • Repository pattern implementation
  • Migration system support
  • Connection pooling and configuration

Prisma Integration

  • Schema-first database modeling
  • Type-safe database client
  • Automatic migration generation
  • Intuitive query interface

API Documentation

When Swagger is enabled, the project includes:

  • Automatic OpenAPI schema generation
  • Interactive API documentation at /docs
  • JSON schema endpoint at /docs/json
  • Request/response validation
  • Authentication documentation

GraphQL Support

When GraphQL is enabled, you get:

  • GraphQL schema definition
  • Resolver implementation templates
  • GraphiQL playground at /graphiql
  • Type-safe GraphQL operations
  • Integration with your chosen ORM

πŸƒβ€β™‚οΈ Getting Started with Your Project

After creating your project:

  1. Navigate to your project:

    cd my-project
  2. Install dependencies (automatically done during creation):

    yarn install
    # or
    npm install
  3. Configure your environment:

    cp .env.example .env
    # Edit .env with your configuration
  4. Set up your database:

    • For TypeORM: Configure src/config/typeorm.connection.ts
    • For Prisma: Edit prisma/schema.prisma
  5. Run database migrations (if applicable):

    # For TypeORM
    yarn typeorm migration:run
       
    # For Prisma
    yarn prisma migrate dev
  6. Start the development server:

    yarn dev
    # or
    npm run dev
  7. Access your application:

    • API: http://localhost:3021
    • Health Check: http://localhost:3021/healthcheck
    • Swagger UI: http://localhost:3021/docs (if enabled)
    • GraphiQL: http://localhost:3021/graphiql (if enabled)

πŸ“š Available Scripts

The generated project includes these npm scripts:

# Development
yarn dev          # Start development server with hot reload
yarn build        # Build the project for production
yarn start        # Start production server

# Testing
yarn test         # Run test suite
yarn test:watch   # Run tests in watch mode
yarn test:coverage # Run tests with coverage report

# Linting and Formatting
yarn lint         # Run ESLint
yarn lint:fix     # Fix ESLint issues automatically
yarn format       # Format code with Prettier

# Database (varies by ORM choice)
yarn typeorm      # TypeORM CLI commands
yarn prisma       # Prisma CLI commands

πŸ” Environment Configuration

The project uses environment variables for configuration. Create a .env file in your project root:

# Server Configuration
PORT=3021
NODE_ENV=development

# Database Configuration
DATABASE_URL="postgresql://username:password@localhost:5432/database"

# JWT Configuration
JWT_SECRET="your-super-secret-jwt-key"
JWT_EXPIRES_IN="7d"

# Email Configuration (if using email service)
SMTP_HOST="smtp.gmail.com"
SMTP_PORT=587
SMTP_USER="[email protected]"
SMTP_PASS="your-app-password"

# External Services
REDIS_URL="redis://localhost:6379"

πŸ§ͺ Testing

The project is set up for testing with Jest and includes:

  • Unit test examples
  • Integration test templates
  • Test utilities and helpers
  • Coverage reporting
  • Mock implementations

πŸ“– API Examples

REST API Examples

// GET /api/v1/users
// Response: List of users

// POST /api/v1/auth/signup
{
  "email": "[email protected]",
  "password": "securePassword123",
  "name": "John Doe"
}

// POST /api/v1/auth/signin
{
  "email": "[email protected]",
  "password": "securePassword123"
}

GraphQL Examples (if enabled)

# Query: Get all users
query GetUsers {
  users {
    id
    email
    name
    createdAt
  }
}

# Mutation: Create user
mutation CreateUser {
  createUser(input: {
    email: "[email protected]"
    name: "John Doe"
    password: "securePassword123"
  }) {
    id
    email
    name
  }
}

🀝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

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

πŸ‘¨β€πŸ’» Author

MΓ‘rcio Zebedeu

πŸ“ Recent Updates

v1.0.3 - Internationalization and Enhanced Features

  • βœ… Full English Translation: All Portuguese text translated to English
  • βœ… Enhanced Documentation: Comprehensive RSA key setup guide
  • βœ… Improved Error Handling: Better GraphQL error responses with automatic redirects
  • βœ… Content-Type Enhancement: Smart parsing for requests without Content-Type headers
  • βœ… Code Comments: All code comments translated to English for better accessibility
  • βœ… Template Updates: All template files now use English documentation

πŸ™ Acknowledgments

πŸ“Š Project Stats

  • Language: TypeScript
  • Framework: Fastify
  • Architecture: Clean Architecture + DDD
  • Package Manager: Yarn/NPM
  • Minimum Node.js: v16+

⭐ Star this project if you find it helpful!

πŸ“’ Follow the project for updates and new features