Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/arifszn/velvet

๐Ÿฅข The simplest way to create REST API with Node.js, Express.js, and TypeORM.
https://github.com/arifszn/velvet

backend-api boilerplate boilerplate-template nodejs nodejs-boilerplate nodejs-server starter starter-kit starter-project starter-template starterkit

Last synced: 2 months ago
JSON representation

๐Ÿฅข The simplest way to create REST API with Node.js, Express.js, and TypeORM.

Awesome Lists containing this project

README

        




๐Ÿ“ฆ REST API Starter Kit/Boilerplate powered by Node.js, Express.js, and TypeORM.









API Docs
ยท
Report Bug
ยท
Request Feature




Preview

**Velvet** is a modern, customized, minimal API starter kit to kickstart your next REST API backend. This project provides a robust foundation for building modern, scalable, and maintainable web applications using Node.js, Express, TypeScript, and various other tools and libraries.

## Features

- **Dockerized Environment:** Easily set up and manage your development environment using Docker.
- **CLI for Resource Generation:** Quickly generate resource files (controller, service, repository, DTO, entity, and route) using the CLI tool.
- **Service Repository Pattern:** Maintain a clean and modular codebase with a well-structured service repository pattern.
- **Authentication and Authorization:** Secure your API with JWT-based authentication and role-based access control.
- **Zod Validation:** Ensure data integrity with schema-based validation using Zod.
- **Class Transformer DTOs:** Clean and transform your data with Class Transformer.
- **Swagger UI and Redoc UI:** Automatically generate and visualize your API documentation.
- **ESLint and Prettier:** Enforce coding standards and ensure a consistent code style.
- **Winston Logging:** Centralized and customizable logging using Winston.
- **Advanced searching:** Searching capabilities with sorting, filtering, and keyword search.
- **GitHub Actions:** CI/CD workflows for testing and linting.

CLI Preview

## Getting Started

### Installation

### Copy the environment file

```bash
cp .env.example .env
```

### Build and run the Docker containers

```bash
docker compose up
```

This will start the application along with any other services defined in the docker-compose.yml file.

### Access the application

The application should now be running at [`http://localhost:3000`](http://localhost:3000) (or the port specified in your docker-compose.yml).

### Running Migrations

To run the migrations, you can use the following commands inside the Docker container:

#### Generate Migration

```bash
npm run migration:generate --name=CreateUsers
```

Replace _`CreateUsers`_ with name of the migration.

#### Run Migration

```bash
npm run migration:run
```

#### Revert Migration

```bash
npm run migration:revert
```

## Generating Resources

One of the key features of this starter kit is the ability to quickly generate new resources (e.g., controllers, services, repositories, DTOs, entities, and routes) using the CLI tool.

### Generate a new resource

- Run the generate command:

```bash
npm run generate
```

- Follow the prompts to enter the resource name and select the file types to generate.

### Example

To generate a new resource called `Article`, run the command and follow the prompts:

```bash
npm run generate
```

- Enter the resource name: `Article`
- Select the files to generate: `entity`, `repository`, `service`, `controller`, `route`, `dto`

This will generate the following files:

- `src/entities/article.entity.ts`
- `src/repositories/article.repository.ts`
- `src/services/article.service.ts`
- `src/controllers/article.controller.ts`
- `src/routes/articles.ts`
- `src/dtos/article.dto.ts`

The generated files will be pre-configured and ready for use, allowing you to focus on implementing your business logic.

Remember to create a migration for the new entity and add the route to the index route (src/routes/index.ts).

## API Documentation

This starter kit comes with integrated API documentation tools. You can access the Swagger UI and Redoc UI for your API documentation.

- Swagger UI: [`http://localhost:3000/swagger`](http://localhost:3000/swagger)
- Redoc UI: [`http://localhost:3000/redoc`](http://localhost:3000/redoc)

You can also access the online API documentation [here](https://redocly.github.io/redoc/?url=https://raw.githubusercontent.com/arifszn/velvet/main/src/api-docs.json).

## Folder Structure

The project follows a modular folder structure:

```css
src/
โ”œโ”€โ”€ configs/ # Application configurations
โ”œโ”€โ”€ constants/ # Application constants
โ”œโ”€โ”€ controllers/ # Route controllers
โ”œโ”€โ”€ dtos/ # Data Transfer Objects
โ”œโ”€โ”€ entities/ # TypeORM entities
โ”œโ”€โ”€ exceptions/ # Custom exceptions
โ”œโ”€โ”€ interfaces/ # TypeScript interfaces
โ”œโ”€โ”€ middlewares/ # App middlewares
โ”œโ”€โ”€ migrations/ # Database migrations
โ”œโ”€โ”€ repositories/ # Data access layer
โ”œโ”€โ”€ routes/ # API routes
โ”œโ”€โ”€ services/ # Business logic layer
โ”œโ”€โ”€ utils/ # Utility functions
โ”œโ”€โ”€ app.ts # Application setup
.env # Environment variables
docker-compose.yml # Docker Compose configuration
Dockerfile # Docker configuration
tsconfig.json # TypeScript configuration
.eslintrc.js # ESLint configuration
.prettierrc # Prettier configuration
```

## Admin Routes

To access the admin routes, the authenticated user's `isAdmin` column must be set to `true` in the database. You can update the `isAdmin` field using Adminer, a database management tool accessible at [`http://localhost:8080`](http://localhost:8080).

## Support

You can show your support by starring this project.



Github Star

## Contribute

To contribute, see the [contributing guide](https://github.com/arifszn/velvet/blob/main/CONTRIBUTING.md).

## License

[MIT License](https://github.com/arifszn/velvet/blob/main/LICENSE)