UNPKG

@bodheesh/create-bodhi-node-app

Version:

Create a production-ready Node.js REST API with zero configuration

132 lines (107 loc) • 3.5 kB
# @bodhi/crud-api-generator A powerful CLI tool that generates Express.js REST APIs or GraphQL endpoints from a simple JSON schema. ## Features - šŸš€ Instant API generation from JSON schema - šŸ’¾ Support for MongoDB, PostgreSQL, and Firebase - šŸ”„ Auto-generated CRUD operations - šŸ“š Swagger documentation generation - ⚔ GraphQL support - šŸŽÆ Clean and maintainable code generation ## Installation ```bash npm install -g @bodhi/crud-api-generator ``` ## Usage 1. Create a JSON schema file (e.g., `schema.json`): ```json { "name": "User", "fields": { "name": { "type": "String", "required": true }, "email": { "type": "String", "required": true, "unique": true }, "age": { "type": "Number" } } } ``` 2. Generate the API: ```bash bodhi-crud generate -s schema.json -d mongodb -t rest ``` Options: - `-s, --schema`: Path to JSON schema file (required) - `-d, --database`: Database type (mongodb, postgres, firebase) (default: mongodb) - `-t, --type`: API type (rest, graphql) (default: rest) - `-o, --output`: Output directory (default: ./generated) ## Generated Structure The tool will generate the following files: ``` generated/ ā”œā”€ā”€ models/ │ └── user.model.js ā”œā”€ā”€ controllers/ │ └── user.controller.js ā”œā”€ā”€ routes/ │ └── user.routes.js └── swagger.json ``` ## Database Support ### MongoDB - Uses Mongoose for schema definition and validation - Generates complete CRUD operations - Includes pagination and filtering ### PostgreSQL (Coming Soon) - Sequelize ORM integration - Migration generation - Complex queries support ### Firebase (Coming Soon) - Firestore integration - Real-time updates - Security rules generation ## Contributing Contributions are welcome! Please feel free to submit a Pull Request. ## License MIT šŸ“¦ rest-api ┣ šŸ“‚ src ā”ƒ ┣ šŸ“‚ config ā”ƒ ā”ƒ ┣ šŸ“„ index.js # Central configuration ā”ƒ ā”ƒ ā”— šŸ“„ swagger.js # Swagger/OpenAPI configuration ā”ƒ ┣ šŸ“‚ controllers ā”ƒ ā”ƒ ┣ šŸ“‚ auth ā”ƒ ā”ƒ ā”ƒ ā”— šŸ“„ auth.controller.js # Authentication controller ā”ƒ ā”ƒ ā”— šŸ“‚ user ā”ƒ ā”ƒ ā”— šŸ“„ user.controller.js # User management controller ā”ƒ ┣ šŸ“‚ middleware ā”ƒ ā”ƒ ┣ šŸ“„ error.middleware.js # Global error handler ā”ƒ ā”ƒ ā”— šŸ“‚ validation ā”ƒ ā”ƒ ┣ šŸ“„ auth.middleware.js # JWT authentication ā”ƒ ā”ƒ ┣ šŸ“„ auth.validation.js # Auth input validation ā”ƒ ā”ƒ ┣ šŸ“„ role.middleware.js # Role-based access control ā”ƒ ā”ƒ ā”— šŸ“„ user.validation.js # User input validation ā”ƒ ┣ šŸ“‚ models ā”ƒ ā”ƒ ā”— šŸ“„ user.model.js # User model schema ā”ƒ ┣ šŸ“‚ routes ā”ƒ ā”ƒ ┣ šŸ“‚ auth ā”ƒ ā”ƒ ā”ƒ ā”— šŸ“„ auth.routes.js # Auth routes ā”ƒ ā”ƒ ā”— šŸ“‚ user ā”ƒ ā”ƒ ā”— šŸ“„ user.routes.js # User routes ā”ƒ ┣ šŸ“‚ utils ā”ƒ ā”ƒ ┣ šŸ“„ db.util.js # Database utilities ā”ƒ ā”ƒ ┣ šŸ“„ error.util.js # Error classes ā”ƒ ā”ƒ ┣ šŸ“„ logger.util.js # Logging utility ā”ƒ ā”ƒ ā”— šŸ“„ response.util.js # Response formatter ā”ƒ ā”— šŸ“„ index.js # Application entry point ┣ šŸ“‚ logs # Log files directory ┣ šŸ“„ .env.example # Environment variables example ┣ šŸ“„ .gitignore # Git ignore file ┣ šŸ“„ package.json # Project dependencies ā”— šŸ“„ README.md # Project documentation