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.
- Install Docker Desktop.
- Enable Kubernetes in Docker settings.
- Install Helm with
brew install helm
. - Install
ingress-nginx
with:helm upgrade --install ingress-nginx ingress-nginx \ --repo https://kubernetes.github.io/ingress-nginx \ --namespace ingress-nginx --create-namespace
- Restore
.env
file fromtemplate.env
. - Add
127.0.0.1 dev.api.project.com
entry to yourhosts
file. - Decide whether you are going to use MongoDB Atlas or a local MongoDB instance and follow the relevant steps below.
- Update
DB
in.env
to the connection string pointing to your MongoDB Atlas instance. - Run
skaffold.sh
- that's it. - Open
http://dev.api.project.com/graphql
in browser.
- 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.
- Run
kubectl exec -ti mongo-statefulset-0 -n pt -- mongosh
- 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" } ] }
- 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 });
- If configuring for the first time, this command will initialize the replica set:
- Re-run
skaffold.sh
again - that's it. - Open
http://dev.api.project.com/graphql
in browser - To connect to the local MongoDB instance from external tools like MongoDB Compass, use the following connection string:
mongodb://localhost:30020/?directConnection=true