aj-rest-api-generator
Version:
š„ A powerful and interactive CLI tool to scaffold REST API boilerplates in seconds.
195 lines (145 loc) ⢠5.79 kB
Markdown
# AJ REST API Generator š
[](https://npmjs.com/package/aj-rest-api-generator)
[](https://opensource.org/licenses/MIT)
[](https://github.com/Aj3322/aj-rest-api-generator/actions/workflows/npm-publish.yml)
A CLI tool to instantly scaffold production-ready Node.js REST APIs with either CommonJS or ES Modules support.
<img src="https://github.com/user-attachments/assets/3cda5952-8970-43fa-97b9-34a968d2e5e3" />
## Features āØ
- ā”ļø Instant REST API scaffolding
- š Supports both CommonJS and ES Modules
- š Organized folder structure
- š Built-in best practices
- š ļø Configurable options
- š¦ Ready-to-use with Express.js
## Installation š¦
### Global Installation (Recommended)
```bash
npm install -g aj-rest-api-generator
```
### Local Installation
```bash
npm install aj-rest-api-generator --save-dev
```
## Usage š
### Interactive Mode
```bash
aj create
```
### With ES Modules
```bash
aj create rest --name my-api --module
```
### With CommonJS (default)
```bash
aj create rest --name my-api --commonjs
```
## Options āļø
| Option | Description | Default |
|-----------------------|--------------------------------------------------|-------------|
| `-n, --name <name>` | Set project name | `rest-api` |
| `--module` | Use ES Modules format | `false` |
| `--commonjs` | Use CommonJS format (default) | `true` |
| `-f, --force` | Overwrite existing directory without prompting | `false` |
| `-y, --yes` | Skip all prompts using default values | `false` |
| `-v, --version` | Show package version | - |
| `-h, --help` | Display help information | - |
### Behavior Notes:
- When neither `--module` nor `--commonjs` is specified:
- In interactive mode: Prompts for selection
- With `--yes`: Defaults to CommonJS
- `--force` will delete existing directories without confirmation
- `--yes` will use these defaults:
- Project name: `rest-api`
- Module system: CommonJS
- No directory overwriting (unless combined with `--force`)
## Project Structure š
Generated projects include:
```
project-root/
|āā src/
| āāā config/ # Configuration files
| āāā controllers/ # Route controllers
| āāā models/ # Database models
| āāā routes/ # Route definitions
| āāā middlewares/ # Custom express middlewares
| āāā services/ # Business logic services
| āāā utils/ # Utility classes and functions
| āāā validations/ # Request validation schemas
| āāā constants/ # Constants definitions
|āā tests/ # Test files
|āā docs/ # API documentation files
|āā logs/ # Log files
|āā public/ # Public assets
|āā uploads/ # File uploads
|āā .env.example # Example environment variables
āāā .env # Environment variables
āāā .gitignore # Git ignore file
āāā .eslintrc.js # ESLint configuration
āāā .prettierrc # Prettier configuration
```
#Example Endpoint
---
### 𩺠Health Check
| Method | URL | Uses |
|--------|-----|------|
| `GET` | `/api/health` | Check if the server is alive |
---
### š„ User Management
| Method | URL | Uses |
|--------|-----|------|
| `POST` | `/api/users` | Create user |
| `GET` | `/api/users` | List all users |
| `GET` | `/api/users/:id` | Get user by ID |
| `PUT` | `/api/users/:id` | Update user |
| `DELETE` | `/api/users/:id` | Delete user |
---
### š Authentication
| Method | URL | Uses |
|--------|-----|------|
| `POST` | `/api/auth/register` | User registration |
| `POST` | `/api/auth/login` | User login |
| `POST` | `/api/auth/refresh` | Refresh token |
| `POST` | `/api/auth/logout` | User logout |
---
### š Metrics
| Method | URL | Uses |
|--------|-----|------|
| `GET` | `/api/metrics` | System metrics |
| `GET` | `/api/metrics/requests` | Request statistics |
---
### š Documentation
| Method | URL | Uses |
|--------|-----|------|
| `GET` | `/api/docs` | API documentation (Swagger/OpenAPI) |
| `GET` | `/api/docs/json` | OpenAPI spec (JSON) |
| `GET` | `/api/docs/yaml` | OpenAPI spec (YAML) |
---
## Development š ļø
1. Clone the repo:
```bash
git clone https://github.com/yourusername/aj-rest-api-generator.git
```
2. Install dependencies:
```bash
npm install
```
3. Link for local development:
```bash
npm link
```
4. Test your changes:
```bash
npm test
```
## Contributing š¤
Contributions are welcome! Please follow these steps:
1. Fork the project
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request
## License š
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Support š
If you find this project useful, please consider starring ā the repository or buying me a coffee ā:
[](https://www.buymeacoffee.com/yourusername)