Skip to content

This is the skeleton for API project, which already contains Auth, RBAC, GraphQL, Cache, DataLoader and layered architecture

License

Notifications You must be signed in to change notification settings

msevera/api-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

For the past couple of years, I've built dozens of MVPs and prototypes, and our team needed an API with a monolithic architecture that could be easily modified at its core and scaled as needed. This API was developed and improved incrementally. This repository contains the core code and demonstrates, using two example entities, User and Product, how to use and build on top of it.

The architecture consists of multiple layers:

  • GraphQL Resolver
  • Domain Layer with Cross-Domain Transactions
  • Datasource Layer
  • Security Layer with Token Management
  • Services Layer

The system is configured for deployment on a local Kubernetes cluster and uses Redis and MongoDB deployments.

Kubernetes setup

  1. Install Docker Desktop.
  2. Enable Kubernetes in Docker settings.
  3. Install Helm with brew install helm.
  4. Install ingress-nginx with:
    helm upgrade --install ingress-nginx ingress-nginx \
      --repo https://kubernetes.github.io/ingress-nginx \
      --namespace ingress-nginx --create-namespace
    

API setup

  1. Restore .env file from template.env.
  2. Add 127.0.0.1 dev.api.project.com entry to your hosts file.
  3. Decide whether you are going to use MongoDB Atlas or a local MongoDB instance and follow the relevant steps below.

MongoDB Atlas

  1. Update DB in .env to the connection string pointing to your MongoDB Atlas instance.
  2. Run skaffold.sh - that's it.
  3. Open http://dev.api.project.com/graphql in browser.

MongoDB local instance

  1. Run skaffold.sh - this command will set up all necessary Kubernetes resources. Note that the API will not start yet as MongoDB requires further configuration.

MongoDB configuration

  1. Run kubectl exec -ti mongo-statefulset-0 -n pt -- mongosh
    1. If configuring for the first time, this command will initialize the replica set:
      rs.initiate(
      {
         _id: "rs0",
         version: 1,
         members: [
            { _id: 0, host : "mongo-statefulset-0.mongo-headless:27017" }        
         ]
      }
      
    2. If reconfiguration is needed, run:
      rs.reconfig({
        _id: 'rs0',
        version: 1,
        members: [
          {
            _id: 0,
            host: 'mongo-statefulset-0.mongo-headless:27017',
            priority: 1
          }
        ]
      }, { force: true });
      
  2. Re-run skaffold.sh again - that's it.
  3. Open http://dev.api.project.com/graphql in browser
  4. To connect to the local MongoDB instance from external tools like MongoDB Compass, use the following connection string: mongodb://localhost:30020/?directConnection=true

About

This is the skeleton for API project, which already contains Auth, RBAC, GraphQL, Cache, DataLoader and layered architecture

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published