MCPcopy
hub / github.com/lujakob/nestjs-realworld-example-app

github.com/lujakob/nestjs-realworld-example-app @main sqlite

repository ↗ · DeepWiki ↗
135 symbols 214 edges 36 files 0 documented · 0%
README

Node/Express/Mongoose Example App

Build Status

NestJS codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld API spec.


Getting started

Installation

Clone the repository

git clone https://github.com/lujakob/nestjs-realworld-example-app.git

Switch to the repo folder

cd nestjs-realworld-example-app

Install dependencies

npm install

Copy config file and set JsonWebToken secret key

cp src/config.ts.example src/config.ts

Database

The codebase contains examples of two different database abstractions, namely TypeORM and Prisma.

The branch master implements TypeORM with a mySQL database.

The branch prisma implements Prisma with a mySQL database.


TypeORM

Create a new mysql database with the name nestjsrealworld\ (or the name you specified in the ormconfig.json)

Copy TypeORM config example file for database settings

cp ormconfig.json.example

Set mysql database settings in ormconfig.json

{
  "type": "mysql",
  "host": "localhost",
  "port": 3306,
  "username": "your-mysql-username",
  "password": "your-mysql-password",
  "database": "nestjsrealworld",
  "entities": ["src/**/**.entity{.ts,.js}"],
  "synchronize": true
}

Start local mysql server and create new database 'nestjsrealworld'

On application start, tables for all entities will be created.


Prisma

To run the example with Prisma checkout branch prisma, remove the node_modules and run npm install

Create a new mysql database with the name nestjsrealworld-prisma (or the name you specified in prisma/.env)

Copy prisma config example file for database settings

cp prisma/.env.example prisma/.env

Set mysql database settings in prisma/.env

DATABASE_URL="mysql://USER:PASSWORD@HOST:PORT/DATABASE"

To create all tables in the new database make the database migration from the prisma schema defined in prisma/schema.prisma

npx prisma migrate save --experimental
npx prisma migrate up --experimental

Now generate the prisma client from the migrated database with the following command

npx prisma generate

The database tables are now set up and the prisma client is generated. For more information see the docs:

  • https://www.prisma.io/docs/getting-started/setup-prisma/add-to-existing-project-typescript-mysql

NPM scripts

  • npm start - Start application
  • npm run start:watch - Start application in watch mode
  • npm run test - run Jest test runner
  • npm run start:prod - Build application

API Specification

This application adheres to the api specifications set by the Thinkster team. This helps mix and match any backend with any other frontend without conflicts.

Full API Spec

More information regarding the project can be found here https://github.com/gothinkster/realworld


Start application

  • npm start
  • Test api with http://localhost:3000/api/articles in your favourite browser

Authentication

This applications uses JSON Web Token (JWT) to handle authentication. The token is passed with each request using the Authorization header with Token scheme. The JWT authentication middleware handles the validation and authentication of the token. Please check the following sources to learn more about JWT.


Swagger API docs

This example repo uses the NestJS swagger module for API documentation. NestJS Swagger - www.swagger.io

Extension points exported contracts — how you extend this code

UserData (Interface)
(no doc)
src/user/user.interface.ts
ProfileData (Interface)
(no doc)
src/profile/profile.interface.ts
Comment (Interface)
(no doc)
src/article/article.interface.ts
UserRO (Interface)
(no doc)
src/user/user.interface.ts
ProfileRO (Interface)
(no doc)
src/profile/profile.interface.ts
ArticleData (Interface)
(no doc)
src/article/article.interface.ts
CommentsRO (Interface)
(no doc)
src/article/article.interface.ts
ArticleRO (Interface)
(no doc)
src/article/article.interface.ts

Core symbols most depended-on inside this repo

findOne
called by 12
src/article/article.service.ts
findOne
called by 6
src/profile/profile.service.ts
findOne
called by 4
src/user/user.service.ts
buildUserRO
called by 3
src/user/user.service.ts
generateJWT
called by 2
src/user/user.service.ts
bootstrap
called by 1
src/main.ts
create
called by 1
src/user/user.service.ts
delete
called by 1
src/user/user.service.ts

Shape

Method 70
Class 54
Interface 9
Function 2

Languages

TypeScript100%

Modules by API surface

src/article/article.service.ts15 symbols
src/article/article.controller.ts14 symbols
src/user/user.service.ts12 symbols
src/user/user.controller.ts8 symbols
src/profile/profile.service.ts8 symbols
src/profile/profile.controller.ts6 symbols
src/shared/pipes/validation.pipe.ts5 symbols
src/article/article.interface.ts5 symbols
src/user/auth.middleware.ts4 symbols
src/tag/tag.service.ts4 symbols
src/tag/tag.controller.ts4 symbols
src/shared/base.controller.ts4 symbols

Dependencies from manifests, versioned

@nestjs/common7.0.5 · 1×
@nestjs/core7.0.5 · 1×
@nestjs/microservices7.0.5 · 1×
@nestjs/platform-express7.0.5 · 1×
@nestjs/swagger4.4.0 · 1×
@nestjs/testing7.0.5 · 1×
@nestjs/typeorm7.0.0 · 1×
@nestjs/websockets7.0.5 · 1×
@types/jest25.2.1 · 1×
@types/node13.13.4 · 1×
argon20.26.2 · 1×
atob>=2.1.0 · 1×

Datastores touched

(mysql)Database · 1 repos

For agents

$ claude mcp add nestjs-realworld-example-app \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact