palesi v0.0.2
Pales - Prisma API Layer Scaffolding
š Introduction
Pales is a CLI tool designed to automate the generation of modular API layers for Node.js applications using Prisma and Zod. It streamlines the creation of models, validation schemas, and API endpoints based on a Prisma schema, reducing development overhead and ensuring consistency.
š Features
- š Automatic Module Generation: Generates route handlers, validation schemas, and controllers from your Prisma schema.
- š Zod Integration: Automatically converts Prisma types to Zod validation schemas.
- š Modular Structure: Organizes your API into modular components within
src/app/modules/
. - ā” Efficient Development: Save time by scaffolding essential files in seconds.
š Prerequisites
Ensure you have the following installed:
š¦ Installation
You can install pales
globally using npm:
npm install -g pales
Alternatively, you can install it locally within your project:
npm install --save-dev pales
šÆ Usage
Once installed, navigate to your project root (where schema.prisma
exists) and run:
pales
This will:
- Parse your
schema.prisma
file. - Extract all models.
- Generate corresponding API modules with routes and validation.
š Project Structure
After running pales
, your project structure will look like this:
š src/
āāā š app/
ā āāā š modules/
ā ā āāā user/
ā ā ā āāā user.controller.ts
ā ā ā āāā user.routes.ts
ā ā ā āāā user.validation.ts
ā ā ā āāā user.service.ts
ā ā āāā post/
ā ā ā āāā post.controller.ts
ā ā ā āāā post.routes.ts
ā ā ā āāā post.validation.ts
ā ā ā āāā post.service.ts
ā āāā š routes/
ā ā āāā index.ts
ā āāā š lib/
ā ā āāā utils.ts
ā ā āāā generate-constants.sh
ā ā āāā process-model.sh
ā ā āāā zod-generator.sh
ā ā āāā update-routes.sh
š„ Example
If your schema.prisma
contains:
model User {
id String @id @default(uuid())
name String
email String @unique
createdAt DateTime @default(now())
}
Running pales
will generate:
- Routes (**
user.routes.ts
**): Defines API endpoints for theUser
model. - Controller (**
user.controller.ts
**): Handles incoming requests. - Validation (**
user.validation.ts
**): Ensures request data matches the model schema. - Service (**
user.service.ts
**): Business logic layer for theUser
model.
š Commands
Command | Description |
---|---|
pales-generate | Generates API modules from Prisma schema. |
pales-create `| Creates Application Starter. | |
pales --clean | Deletes previously generated modules. |
pales --debug | Runs in debug mode to log errors. |
š Troubleshooting
- If you see
schema.prisma not found
, ensure you are runningpales
in the correct directory. - If
schema.pi
is missing, try manually copyingschema.prisma
toschema.pi
. - If
TYPE_MAP
errors occur, ensure you're usingbash
with associative array support.
š License
MIT License
š¤ Contributing
Contributions are welcome! Feel free to open an issue or submit a pull request.
š Happy coding!