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

https://github.com/samchon/nestia-start

Nestia template project installed by "npx nestia start"
https://github.com/samchon/nestia-start

Last synced: 8 months ago
JSON representation

Nestia template project installed by "npx nestia start"

Awesome Lists containing this project

README

          

# Nestia Template
## Outline
[![Build Status](https://github.com/samchon/nestia-start/workflows/build/badge.svg)](https://github.com/samchon/nestia-start/actions?query=workflow%3Abuild)

A template repository for backend projects using [nestia](https://github.com/samchon/nestia).

You can create a new project from this boilerplate by running below command:

```bash
npx nestia start
```

For reference, this is a minimal boilerplate project concentrating only on [nestia](https://github.com/samchon/nestia) SDK generation.

If you wanna much detailed boilerplate project, visit [`@samchon/backend`](https://github.com/samchon/backend).

## Directories and Files
This template project has categorized directories like below.

As you can see from the below, all of the Backend source files are placed into the [src](src/) directory. When you build the TypeScript source files, compiled files would be placed into the `lib` directory following the [tsconfig.json](tsconfig.json) configuration. Otherwise you build client [SDK](#32-sdk) library for npm publishing and their compiled files would be placed into the [packages](packages) directory.

- [packages/api/](packages/api): SDK module built by `npm run build:api`
- [src/](src): Backend source directory
- [src/api/](src/api/): Client SDK that would be published to the `@ORGANIZATION/PROJECT-api`
- [**src/api/functional/**](src/api/functional/): API functions generated by the [`nestia`](https://github.com/samchon/nestia)
- [**src/api/structures/**](src/api/structures/): DTO structures
- [src/controllers/](src/controllers/): Controller classes of the Main Program
- [**test/**](test): Test Automation Program
- [nestia.config.ts](nestia.config.ts): Configuration file of [`nestia`](https://github.com/samchon/nestia)
- [package.json](package.json): NPM configuration
- [tsconfig.json](tsconfig.json): TypeScript configuration for the main program

## NPM Run Commands
List of the run commands defined in the [package.json](package.json) are like below:

- Test
- **`test`**: Run test automation program
- `benchmark`: Run performance benchmark program
- Build
- `build`: Build everything
- `build:main`: Build main program (`src` directory)
- `build:test` Build test automation program (`test` directory)
- `build:sdk`: Build SDK into main program only
- `build:swagger`: Build Swagger Documents
- **`dev`**: Incremental build for development (test program)
- Deploy
- `package:api`: Build and deploy the SDK library to the NPM
- `start`: Start the backend server
- `start:dev`: Start the backend server with incremental build and reload
- Webpack
- `webpack`: Run webpack bundler
- `webpack:start`: Start the backend server built by webpack
- `webpack:test`: Run test program to the webpack built

## Specialization
Transform this template project to be yours.

When you've created a new backend project through this template project, you can specialize it to be suitable for you by changing some words. Replace below words through IDE specific function like `Edit > Replace in Files` (*Ctrl + Shift + H*), who've been supported by the VSCode.

| Before | After
|-----------------|----------------------------------------
| ORGANIZATION | Your account or corporation name
| PROJECT | Your own project name
| AUTHOR | Author name
| https://github.com/samchon/nestia-start | Your repository URL

## Test Driven Development
With [nestia](https://github.com/samchon/nestia) helps to accomplish TDD (Test Driven Development).

Just define DTOs and API controllers' methods (only declarations) first. After the definitions, and build SDK (Software Development Kit) through [nestia](https://github.com/samchon/nestia) (`npm run build:sdk`). After buildling those SDK, develop test automation program using the SDK, following use-case scenarios in the framework of client side.

During the test automation program development, you can find that which API is miss-designed or which requirement analysis is not exact. Development of the main program must be the last step after such validation process during TDD.

> Visit the [samchon/backend](https://github.com/samchon/backend), then you may find much detailed story about this TDD.
>
> 1. Definitions
> 2. SDK
> 3. Test Automation Program
> 4. Main Program

```typescript
import {
ArrayUtil,
GaffComparator,
RandomGenerator,
TestValidator,
} from "@nestia/e2e";

import api from "@ORGANIZATION/PROJECT-api/lib/index";
import { IBbsArticle } from "@ORGANIZATION/PROJECT-api/lib/structures/bbs/IBbsArticle";
import { IPage } from "@ORGANIZATION/PROJECT-api/lib/structures/common/IPage";

export async function test_api_bbs_article_index_sort(
connection: api.IConnection,
): Promise {
// GENERATE 100 ARTICLES
const section: string = "general";
await ArrayUtil.asyncRepeat(100, () =>
api.functional.bbs.articles.create(connection, {
section,
body: {
writer: RandomGenerator.name(),
title: RandomGenerator.paragraph(),
body: RandomGenerator.content(),
format: "txt",
files: [],
password: RandomGenerator.alphabets(8),
},
}),
);

// PREPARE VALIDATOR
const validator = TestValidator.sort(
"BbsArticleProvider.index()",
async (sort: IPage.Sort) => {
const page: IPage =
await api.functional.bbs.articles.index(connection, {
section,
body: {
limit: 100,
sort,
},
});
return page.data;
},
);

// DO VALIDATE
const components = [
validator("created_at")(GaffComparator.dates((x) => x.created_at)),
validator("updated_at")(GaffComparator.dates((x) => x.updated_at)),
validator("title")(GaffComparator.strings((x) => x.title)),
validator("writer")(GaffComparator.strings((x) => x.writer)),
validator(
"writer",
"title",
)(GaffComparator.strings((x) => [x.writer, x.title])),
];
for (const comp of components) {
await comp("+", false);
await comp("-", false);
}
}
```

For reference, if you run `npm run benchmark` command, your test functions defined in the [test/features/api](test/features/api) directory would be utilized for performance benchmarking. If you want to see the performance bench result earlier, visit below link please:

- [docs/benchmarks/AMD Ryzen 9 7940HS w Radeon 780M Graphics.md](https://github.com/samchon/nestia-start/blob/master/docs/benchmarks/AMD%20Ryzen%209%207940HS%20w%20Radeon%20780M%20Graphics.md)