Giter Site home page Giter Site logo

0x01001011 / ultimate-backend Goto Github PK

View Code? Open in Web Editor NEW

This project forked from juicycleff/ultimate-backend

0.0 1.0 0.0 3.09 MB

Multi tenant SaaS starter kit with cqrs graphql microservice architecture, apollo federation, event source and authentication

License: MIT License

Dockerfile 5.64% TypeScript 93.26% HCL 0.64% Shell 0.46%

ultimate-backend's Introduction

ULTIMATE BACKEND

(WIP): This is an enterprise scale advanced microservice pattern with GraphQL, based on Domain (DDD) using the command query responsibility segregation (CQRS) design pattern.

License Snyk Code Size Version Top Language Top Language

Description

This should be the go to backend base for your next scalable project. This is a proof of concept project designed to be extremely slim and scalable, with distributed data request and process handling, built from the ground up for production use. It comes with Multi-Tenancy SaaS support, following different multi-tenancy database strategy as well as different resolver patterns to identify your tenants. The goal is to give your next big project that extra leap to awesomeness. To get started read the instructions below

Features

Software features

  • ✅ CQRS
  • ✅ Software as a Service
  • ✅ Authentication by stateful session
  • ✅ User
  • ✅ Event Sourcing
  • ✅ Federated GraphQL Microservice
  • ✅ Emailing Queue
  • ✅ (WiP) Role Based Access Control
  • ✅ Multi Tenancy
  • ✅ Payment (Stripe)
  • ✅ SaaS Plans (Stripe)
  • ✅ (WiP) Security
  • ❌ (WiP) Documentation
  • ❌ (WiP) Support for language translation
  • ❌ Reactive health check for federated service and rebuilding gateway schema
  • ❌ Service Discovery (Based on Consul)
  • React SSR Starter Kit

Requirements

Store and Cache Stack and frameworks Deployment
Event Store (Event Source Store) NestJS (Server Framework) Docker
Redis (cache) NodeJS (System runtime) Kubernetes
MongoDB (Database) Typescript Azure Pipeline
ArangoDB (Database) Apollo Server
Express JS
Apollo Gateway
Fastify
GRPC

Installation

$ yarn

Configuration

In the config directory there are yaml files with defaults set for many things such as mongodb url and ports for services. However you will need to set your sendgrid api key so the backend can send emails on signup etc. If using stripe for payments you'll also need to put your public and private keys there too.

Usage

Running the databases

Mongodb, redis, and eventstore all need to be started first as our microservices need to connect to them.

Start mongodb locally

mongod

If you have docker installed

docker run -d -p 27017:27017 mongo
docker run -d -p 1113:1113 -p 2113:2113 eventstore/eventstore
docker run -d -p 6379:6379 redis

Otherwise you can install and run redis and eventstore locally if you choose.

Running the microservices

You should start the microservices of type service before the gateways. Example

# Start with staging environment for auth service
$ NODE_ENV=staging npx nest start service-auth

# Start with staging environment for user service
$ NODE_ENV=staging npx nest start service-user

# Start with testing environment for tenant service
$ NODE_ENV=testing npx nest start service-tenant

# Start with testing environment for payment service
$ NODE_ENV=testing npx nest start service-payment

# Start with testing environment for notification service
$ NODE_ENV=testing npx nest start service-notification

# Start with testing environment for project service
$ NODE_ENV=testing npx nest start service-project

Once all services are up and running, you can start the gateways

# development for admin gateway
$ yarn run start gateway-admin

# watch mode for admin gateway
$ yarn run start:dev gateway-admin

# development for client gateway
$ yarn run start gateway-client

# watch mode for client gateway
$ yarn run start:dev gateway-client

# production mode for admin gateway
$ yarn run start:prod

Alternative method of running services

If you find the nest cli using too much memory running each service, you can build them first and then run them:

Build each service:

npx nest build service-auth
npx nest build service-notification
npx nest build service-payment
npx nest build service-project
npx nest build service-tenant
npx nest build service-user

Each service is built and written into dist/apps directory from where you can directly run each service with nodejs. Running each service with npx nest start uses three orders of magnitude more memory than this method so you will use a lot less memory!

Run each service in a separate terminal:

node dist/apps/service-auth/main.js
node dist/apps/service-notification/main.js
node dist/apps/service-payment/main.js
node dist/apps/service-project/main.js
node dist/apps/service-tenant/main.js
node dist/apps/service-user/main.js

With the databases and the services running you can now start the gateways as mentioned above.

yarn start:dev gateway-admin
yarn start:dev gateway-client

Get started by registering a user on the admin gateway

In the graphql playground running at http://localhost:4000/graphql you can register a user:

mutation register {
  register(input:{
    firstname: "Alice"
    lastname: "Bob"
    email: "[email protected]"
    password: "supersecretpassword"
  }) {
    success
  }
}

All going well you should have received the following reply as well as an email with a verification code

{
    "data": {
        "register": {
            "success": true
        }
    }
}

Test

# unit tests
$ yarn run test

# e2e tests
$ yarn run test:e2e

# test coverage
$ yarn run test:cov

License

This project is MIT licensed.

ultimate-backend's People

Contributors

juicycleff avatar fabiofdsantos avatar av8ta avatar

Watchers

James Cloos avatar

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.