Giter Club home page Giter Club logo

bbs-backend's Introduction

Backend of Bullet-in Board System

1. Outline

Nestia Logo

GitHub license npm version Build Status Guide Documents

Example backend server of Bullet-in Board System for education.

@samchon/bbs-backend is an example backend project of NestJS and Prisma stack. It has been developed to educate how to adapt functional programming in the NestJS development. Therefore, it is not the actual bullet-in board service, and implementation of most functions is different from the actual bullet-in board service and may be meaningless.

Also, @samchon/bbs-backend guides how to utilize those 3rd party libraries (what I've developed) in the production, and demonostrates how they are powerful for the productivity. Especially, I have ideally implemented TDD (Test Driven Development) through below libaries. I hope this repo would be helpful for your learning.

  • typia: Superfast runtime validator
  • nestia: NestJS helper libaries like SDK generation
  • prisma-markdown: Markdown generator of Prisma, including ERD and descriptions

2. Installation

2.1. NodeJS

This backend server has implemented through TypeScript and it runs on the NodeJS. Therefore, to mount this backend server on your local machine, you've to install the NodeJS.

2.2. PostgreSQL

bash postgres.sh

If you've installed Docker, then run the script above.

Otherwise, visit below PostgreSQL official site and install it manually.

https://www.enterprisedb.com/downloads/postgres-postgresql-downloads

After that, run the npm run schema <root-account> <password> command.

Database schema for BBS backend system would be automatically constructed.

npm run schema postgres root

2.3. Repository

From now on, you can start the backend server development, right now.

Just download this project through the git clone command and install dependencies by the npm install command. After those preparations, you can start the development by typing the npm run dev command.

# CLONE REPOSITORY
git clone https://github.com/samchon/bbs-backend
cd bbs-backend

# INSTALL DEPENDENCIES
npm install

# START DEVELOPMENT
npm run dev

3. Development

  • A. Definition only
    • Design prisma schema file
    • Build and Share ERD document with your companions
    • Write DTO structures
    • Declare controller method only
  • B. Software Development Kit
    • Build SDK from the declaration only controller files
    • SDK supports mockup simulator, boosting up frontend development
    • SDK is type safe, so development be much safer
  • C. Test Automation Program
    • Build test program earlier than main program development
    • Utilize SDK library in the test program development
    • This is the TDD (Test Driven Development)
  • D. Main Program Development

3.1. Definition

ERD

Before developing the main program, define it before.

At first, design the DB architecture on the Prisma Schema file (prisma/schema.prisma).

Writing the schema definitions, don't forget to write the detailed descriptions on each tables and properties. After that, build ERD (Enterprise Relationship Diagram) document through npm run build:prisma command. The ERD document will be generated on the docs/ERD.md path. If you share the ERD document with your companions, your team can enjoy increased productivity by standardizing words and entities.

At second, write DTO structures under the src/api/structures directory and declare API endpoint specs under the src/controllers directory. Note that, do not implement the function body of the controller. Just write declaration only. Below code is never pseudo code, but actual code for current step.

@Controlleer("bbs/articles")
export class BbsArticleController {
  @TypedRoute.Patch()
  public async index(
    @TypedBody() input: IBbsArticle.IRequest
  ): Promise<IPage<IBbsArticle.ISummary>> {
    input;
    return null!;
  }
}

3.2. Software Development Kit

nestia-sdk-demo

@samchon/bbs-backend provides SDK (Software Development Kit) for convenience.

SDK library means a collection of fetch functions with proper types, automatically generated by nestia. As you can see from the above gif image, SDK library boosts up client developments, by providing type hints and auto completions.

Furthermore, the SDK library supports Mockup Simulator.

If client developer configures simulate option to be true, the SDK library will not send HTTP request to your backend server, but simulate the API endpoints by itself. With that feature, frontend developers can directly start the interaction development, even when the main program development has not started.

# BUILD SDK IN LOCAL
npm run build:sdk

# BUILD SDK AND PUBLISH IT TO THE NPM
npm run package:api

3.3. Test Automation Program

TDD (Test Driven Development)

After the Definition and client SDK generation, you've to design the use-case scenarios and implement a test automation program who represents those use-case scenarios and guarantees the Main Program.

To add a new test function in the Test Automation Program, create a new TS file under the test/features directory following the below category and implement the test scenario function with representative function name and export symbol.

Note that, the Test Automation Program resets the local DB schema whenever being run. Therefore, you've to be careful if import data has been stored in the local DB server. To avoid the resetting the local DB, configure the reset option like below.

Also, the Test Automation Program runs all of the test functions placed into the test/features directory. However, those full testing may consume too much time. Therefore, if you want to reduce the testing time by specializing some test functions, use the include option like below.

  • supported options
    • include: test only restricted functions who is containing the special keyword.
    • exclude: exclude some functions who is containing the special keyword.
    • reset: do not reset the DB
# test without db reset
npm run test -- --reset false

# include or exclude some features
npm run test -- --include something
npm run test -- --include cart order issue
npm run test -- --include cart order issue --exclude index deposit

3.4. Main Program

After Definition, client SDK building and Test Automation Program are all prepared, finally you can develop the Main Program. Also, when you complete the Main Program implementation, it would better to validate the implementation through the pre-built SDK and Test Automation Program.

However, do not commit a mistake that writing source codes only in the controller classes. The API Controller must have a role that only intermediation. The main source code should be write down separately following the directory categorizing. For example, source code about DB I/O should be written into the src/providers directory.

4. Appendix

4.1. NPM Run Commands

List of the run commands defined in the package.json are like below:

  • Test
  • Build
    • build: Build every below programs
    • build:sdk: Build SDK library, but only for local
    • build:test: Build Test Automation Program
    • build:main: Build main program
    • dev: Incremental builder of the Test Automation Program
    • eslint: EsLint validator runner
    • pretter: Adjust prettier to every source codes
    • webpack: Run webpack bundler
  • Deploy
    • package:api: Build and deploy the SDK library to the NPM
    • schema: Create DB, users and schemas on local database
    • start: Start the backend server
  • Webpack
    • webpack: Run webpack bundler
    • webpack:start: Start the backend server built by webpack
    • webpack:test: Run test program to the webpack built

4.2. Directories

bbs-backend's People

Contributors

dependabot[bot] avatar samchon avatar switch1220 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bbs-backend's Issues

Prisma 선택의 이유가 궁금합니다.

기존 블로그 글이나 개발하신 오픈소스, 선택하신 라이브러리들을 봤을 때

Performance를 매우 중시하며 Node.js에서 State of art 수준의 활용 능력을 보여주시는데요.

다른게 아니라 Prisma를 쓰시는 이유가 궁금하여 질문 드립니다.

ORM이 필요한 경우 Drizzle + Prepared statement나 Kysely 같은 일반적으로 알려진 라이브러리 들이나

raw query를 랩핑해서 쓰실 수도 있으셨을 것 같은데, 선택하신 이유가 있으실까요?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.