• This repository has been archived on 28/Sep/2022
  • Stars
    star
    145
  • Rank 254,144 (Top 6 %)
  • Language
    JavaScript
  • Created about 7 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Serverless GCP Cloud Functions + Datastore implementation of RealWorld Backend

RealWorld Backend TravisCI Coverage Status Docs dependencies Status Known Vulnerabilities

Google Cloud Platform (Datastore + Cloud Functions) serverless codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld API Spec.

This codebase was created to demonstrate a fully fledged fullstack application built with Google Cloud Platform (Datastore + Cloud Functions) including CRUD operations, authentication, routing, pagination, and more.

We've gone to great lengths to adhere to community style guides & best practices.

For more information on how to this works with other frontends/backends, head over to the RealWorld repo.

How it works

Background

This codebase is meant to be deployed to Google Cloud Functions, a serverless environment which allows you to run NodeJS code in response to events like HTTP triggers scaling up and down elastically without the need for spinning up or maintaining servers.

Life of a Request

For every API call made, a new invocation of the top level function index.js occurs. It calls Router.js which parses the HTTP route and calls the appropriate handler in User.js or Article.js. The handler applies business logic and returns a response which is marshalled back to the caller by Cloud Functions.

For data persistence, Google Cloud Datastore is used which is a fully managed NoSQL database as a service. Cloud Datastore multitenancy is supported and can be leveraged by specifying a DATASTORE_NAMESPACE environment variable at runtime.

Datastore Schema

User

{ username: 'Julie_Stracke',
  password: '$2a$05$Unbla43FRv5Zb...',
  email: '[email protected]',
  image: '',
  bio: '',
  followers: [],
  following: [],
  [Symbol(KEY)]:
   Key {
     namespace: 'test-unit',
     name: 'Julie_Stracke',
     kind: 'User',
     path: [Getter] } }

Article

{ slug: 'In-enim-nur2bx',
  title: 'In enim',
  description: 'Suscipit voluptas minima...',
  body: 'Voluptates doloremque unde...',
  tagList: [ 'temporibus', 'quae', 'omnis', 'aut' ],
  createdAt: 1509036552780,
  updatedAt: 1509036552780,
  author: 'author_Paul_Heaney',
  favoritedBy: [],
  [Symbol(KEY)]:
   Key {
     namespace: 'test-unit',
     name: 'In-enim-nur2bx',
     kind: 'Article',
     path: [Getter] } }

Comment

{ body: 'Voluptatem dolorem repellat...',
  author: 'Wiegand_Hattie',
  createdAt: 1509036740596,
  updatedAt: 1509036740596,
  [Symbol(KEY)]:
   Key {
     namespace: 'test-unit',
     id: '5629499534213120',
     kind: 'Comment',
     parent:
      Key {
        namespace: 'test-unit',
        name: 'In-enim-nur2bx',
        kind: 'Article',
        path: [Getter] },
     path: [Getter] } }

Testing

Unit Tests

Unit tests live adjacent to source code as src/*.test.js and can be run by executing npm run test:unit. They use mocha as a test runner and istanbul/nyc for coverage.

API Tests

You can also run Postman based API tests by executing npm run test:api. These are run using the newman command line runner. The code is deployed locally to a Cloud Functions Local Emulator environment and tested. See run-api-tests.sh for details.

Linting

Code linting is enforced using eslint configured by .eslintrc.js. You can run the linter by executing npm run lint.

CI

Continuous integration is performed by TravisCI. See .travis.yml for details.

CD

If all tests pass, the code is automatically deployed to a Cloud Functions Endpoint. See deploy-to-cloud.sh for details.

Getting started

Setup Google Cloud Platform (GCP)

  • Signup for a Google Cloud Platform (GCP) Free Account here and create a new project
  • Setup Cloud Datastore for this project by following steps here
  • Install and setup gcloud CLI tool by following help here

Setup local development environment

Note: Node.js 8.0 or greater is required

  • Clone this repo
  • Create GCP Datastore indexes
gcloud datastore indexes create index.yaml
  • Create a service account and store the credentials as service-account-key.json in the repo root folder - DO NOT SHARE THIS FILE!
  • Ensure Datastore indexes are created before proceeding by checking here
  • Specify details about your GCP project,
export GOOGLE_APPLICATION_CREDENTIALS=service-account-key.json
export GCP_PROJECT_ID=<your-GCP-project-id>
  • Install dependencies
npm install
npx functions config set projectId $GCP_PROJECT_ID
  • Test
npm test

Deploy to Cloud Functions

npm run deploy

More details in deploy-to-cloud.sh.

More Repositories

1

realworld

"The mother of all demo apps" — Exemplary fullstack Medium.com clone powered by React, Angular, Node, Django, and many more
TypeScript
80,404
star
2

react-redux-realworld-example-app

Exemplary real world application built with React + Redux
JavaScript
5,569
star
3

angular-realworld-example-app

Exemplary real world application built with Angular
TypeScript
5,231
star
4

vue-realworld-example-app

An exemplary real-world application built with Vue.js, Vuex, axios and different other technologies. This is a good example to discover Vue for beginners.
JavaScript
4,065
star
5

node-express-realworld-example-app

TypeScript
3,591
star
6

golang-gin-realworld-example-app

Exemplary real world application built with Golang + Gin
Go
2,504
star
7

aspnetcore-realworld-example-app

ASP.NET Core backend implementation for RealWorld
C#
1,935
star
8

django-realworld-example-app

Python
1,611
star
9

spring-boot-realworld-example-app

Example Spring codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld API spec.
Java
1,304
star
10

react-mobx-realworld-example-app

Exemplary real world application built with React + MobX
JavaScript
1,248
star
11

laravel-realworld-example-app

Exemplary real world backend API built with Laravel
PHP
1,194
star
12

flask-realworld-example-app

Exemplary real world JSON API built with Flask (Python)
Python
898
star
13

elixir-phoenix-realworld-example-app

Exemplary real world application built with Elixir + Phoenix
Elixir
892
star
14

kotlin-spring-realworld-example-app

Kotlin
455
star
15

angularjs-realworld-example-app

Exemplary real world application built with Angular 1.5 + ES6
JavaScript
454
star
16

rails-realworld-example-app

Ruby
430
star
17

realworld-starter-kit

Starter kit for new RealWorld framework implementations
429
star
18

slim-php-realworld-example-app

Exemplary real world application built with Slim
PHP
427
star
19

swift

A better way to learn swift.
275
star
20

koa-knex-realworld-example

JavaScript
240
star
21

ember-realworld

Ember.js RealWorld Implementation
JavaScript
183
star
22

aurelia-realworld-example-app

Exemplary real world application built with Aurelia
JavaScript
183
star
23

web-components-realworld-example-app

Exemplary real world application built with Vanilla JS Web Components
JavaScript
178
star
24

node-express-prisma-v1-official-app

Official real world application built with Node + Express + Typescript + Prisma
TypeScript
155
star
25

scala-play-realworld-example-app

Exemplary real world application built with Scala 2.13 & Play
Scala
154
star
26

moleculer-node-realworld-example-app

Exemplary real world application built with Moleculer
JavaScript
103
star
27

apprun-realworld-example-app

Exemplary real world application built with AppRun
TypeScript
103
star
28

cakephp-realworld-example-app

PHP
103
star
29

clojurescript-reframe-realworld-example-app

Exemplary real world application built with ClojureScript + re-frame
Clojure
102
star
30

fsharp-realworld-example-app

Exemplary real world application built with F#
F#
94
star
31

hapijs-realworld-example-app

Real World Hapi.JS + Mongoose backend implementations
JavaScript
78
star
32

clojurescript-keechma-realworld-example-app

Exemplary real world application built with ClojureScript & Keechma
Clojure
72
star
33

reasonml-realworld-example-app

Exemplary real world application built with ReasonML
Reason
59
star
34

conduit-bootstrap-template

HTML
34
star
35

dojo-realworld-example-app

Exemplary real world application built with Dojo2
TypeScript
30
star
36

angularfire-slack

JavaScript
27
star
37

QEWD-realworld-example-app

JavaScript
22
star
38

crizmas-mvc-realworld-example-app

Exemplary real world application built with Crizmas MVC (React)
JavaScript
18
star
39

express-prisma-official-app

TypeScript
17
star
40

jswiki

The wiki for modern Javascript terminology
HTML
13
star
41

conduit-angularjs-final

JavaScript
10
star
42

conduit-django

Python
9
star
43

conduit-sass

HTML
8
star
44

test-routes

JavaScript
6
star
45

thinkdown

Preview markdown as it appears on https://thinkster.io
CSS
5
star
46

conduit-react-client-final

JavaScript
4
star
47

conduit-rails4-api-final

Ruby
4
star
48

realworld-api-action

GitHub Action running a Postman collection to test the compliance of a backend implementation of RealWorld specs
JavaScript
4
star
49

course-boilerplate

3
star
50

mean-stack-tutorial

3
star
51

realworld-e2e-tests

E2e test suite for RealWorld demo
JavaScript
3
star
52

api-realworld

TypeScript
2
star
53

gothinkster.github.io

HTML
2
star
54

conduit-rails4

Ruby
2
star
55

conduit-rails

Ruby
2
star
56

conduit-angular

HTML
1
star
57

thinkster-author

Authoring site for Thinkster.io Authors
1
star
58

blog

Thinkster blog
1
star
59

imperial

JavaScript
1
star
60

conduit-api

TypeScript
1
star
61

transactional

1
star
62

realworld-tribe-angular-app

HTML
1
star
63

realworld-tribe-nestjs-app

TypeScript
1
star
64

realdworld-docs

1
star