myex-cli
v1.0.0
Published
Opinionated Express.js framework with CLI tools
Maintainers
Readme
MYX - Opinionated Express.js Framework with CLI
A modern, opinionated Express.js framework with CLI tools for rapid development. Build robust, scalable, and maintainable Node.js applications with best practices baked in.
Features
- ES6 Modules: Modern JavaScript syntax with import/export
- MongoDB Integration: Database integration with Mongoose
- Authentication: JWT-based authentication with Passport.js
- Security: Best practices with Helmet, CORS, and rate limiting
- Logging: Comprehensive logging with Winston
- Process Management: PM2 for clustering and performance
- Containerization: Docker and Kubernetes support
- Testing: Jest and Supertest for API testing
- API Documentation: Swagger/OpenAPI integration
Prerequisites
- Node.js (>= 18.0.0)
- MongoDB (>= 6.0)
- Docker and Docker Compose (optional)
- Kubernetes (optional)
Getting Started
Installation
As a Development Tool
Install MYX CLI globally:
npm install -g myx-cliThis will give you access to the myx command for creating and managing MYX applications.
Creating a New Project
Create a new MYX project:
myx new my-project
cd my-projectThis will scaffold a new MYX application in the my-project directory.
Options:
--no-git: Skip git initialization--no-install: Skip npm install--db <database>: Choose database (mongodb, postgres, mysql)--auth <auth>: Choose authentication (jwt, passport, oauth)
Generating Code
MYX CLI provides several generators to speed up development:
Generate a Complete Feature
myx generate feature user --fields name:String:true email:String:true:null:null password:String:true role:String:false:user:nullThis will generate:
- Model:
src/models/user.model.js - Service:
src/services/user.service.js - Controller:
src/controllers/user.controller.js - Routes:
src/routes/user.routes.js
And update routes/index.js to include the new routes.
Generate Individual Components
You can also generate components individually:
# Generate a model
myx generate model product --fields name:String:true price:Number:true category:String:false
# Generate a controller
myx generate controller product --model product
# Generate a service
myx generate service product --model product
# Generate a route
myx generate route product --controller product
# Generate a middleware
myx generate middleware authRunning the Application
Development Mode
npm run devThis will start the application with Nodemon for automatic restarts on file changes.
Production Mode
npm startWith PM2
npm run pm2:startTo stop the PM2 processes:
npm run pm2:stopDocker Deployment
Build and Run with Docker
npm run docker:build
npm run docker:runUsing Docker Compose
docker-compose -f deploy/docker-compose.yml up -dKubernetes Deployment
Update the Kubernetes manifests in the
deploy/k8sdirectory with your configuration.Apply the manifests:
kubectl apply -f deploy/k8s/
Project Structure
/myx
├── /src # Source code
│ ├── /config # Environment configurations
│ ├── /controllers # Request handlers
│ ├── /middlewares # Custom middleware
│ ├── /models # MongoDB schemas
│ ├── /routes # API routes
│ ├── /security # Security configurations
│ ├── /services # Business logic
│ ├── /db # Database connection
│ ├── /utils # Utility functions
│ └── app.js # Express app setup
├── /deploy # Deployment configurations
│ ├── Dockerfile # Docker configuration
│ ├── docker-compose.yml # Docker Compose config
│ └── /k8s # Kubernetes manifests
├── /test # Tests
├── /docs # Documentation
├── .env # Environment variables
├── package.json # Dependencies and scripts
└── pm2.config.js # PM2 configurationAPI Documentation
API documentation is available via Swagger UI at /api-docs when the application is running. The documentation includes:
- Detailed information about all endpoints
- Request and response schemas
- Authentication requirements
- Example requests and responses
You can also access the raw Swagger/OpenAPI specification at /swagger.json.
Main Endpoints
Authentication
POST /api/auth/register: Register a new userPOST /api/auth/login: Login a userPOST /api/auth/refresh-token: Refresh access tokenPOST /api/auth/logout: Logout a userPOST /api/auth/forgot-password: Request password resetPOST /api/auth/reset-password: Reset password
User Management
GET /api/users/me: Get current user profileGET /api/users/:id: Get user by IDPUT /api/users/:id: Update userDELETE /api/users/:id: Delete user (admin only)
System
GET /health: API health checkGET /api: API informationGET /api-docs: Swagger documentation
Testing
Run tests with:
npm testDocumentation
Additional documentation is available in the /docs directory:
License
MIT
Contributing
- Fork the repository
- Create your feature branch:
git checkout -b feature/my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin feature/my-new-feature - Submit a pull request
