@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
Maintainers
Readme
Create Stack Fastify
π 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 apiUsage
@machize/machize/create-stack-fastify-name> api [--module=module-name]Parameters:
project-name: The name of your new projectapi: 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=ordersInteractive 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
β― GraphQLAvailable 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
- HTTP Server: Fastify-based HTTP server with type safety and enhanced content parsing
- Authentication System: JWT-based authentication with RSA key support and middleware
- Database Integration: Ready-to-use database connections with migration support
- API Documentation: Auto-generated Swagger documentation with interactive UI
- Error Handling: Centralized error handling with proper HTTP responses and GraphQL redirects
- Logging: Structured logging with different levels and request tracking
- Environment Configuration: Environment-based configuration management with .env support
- RSA Key Management: Automatic RSA key generation and configuration scripts
- Content-Type Detection: Smart content parsing for different media types
- 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:
Navigate to your project:
cd my-projectInstall dependencies (automatically done during creation):
yarn install # or npm installConfigure your environment:
cp .env.example .env # Edit .env with your configurationSet up your database:
- For TypeORM: Configure
src/config/typeorm.connection.ts - For Prisma: Edit
prisma/schema.prisma
- For TypeORM: Configure
Run database migrations (if applicable):
# For TypeORM yarn typeorm migration:run # For Prisma yarn prisma migrate devStart the development server:
yarn dev # or npm run devAccess 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)
- API:
π 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.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π¨βπ» Author
MΓ‘rcio Zebedeu
- GitHub: @zebedeu
- Email: [email protected]
π 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
- Fastify - Fast and low overhead web framework
- TypeScript - Typed superset of JavaScript
- TypeORM - Amazing ORM for TypeScript
- Prisma - Next-generation ORM
- Swagger - API documentation tools
- GraphQL - Query language for APIs
π 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
