cagodoy / demo-mobile-app-arch

Solution proposal using microservices oriented architecture through 5 microservices showcasing React Native, GraphQL, Kubernetes, Linkerd, gRPC, NATS, Terraform and Skaffold.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tenpo Challenge

Solution proposal with microservice oriented architecture. The mobile application is implemented by React Native and in it users can search for nearby restaurants according to the GPS coordinate.

The backend architecture depends on a network of microservices that communicate through GraphQL for external access, Grpc for internal back-end communications and NATS for asynchronous communication processes.

The infrastructure was implemented with Terraform, using recipes associated with the implementation of a Kubernetes cluster through the Azure Kubernetes Service (AKS). On the other hand, there is also a service mesh implemented in Linkerd that allows you to manage package tracking between microservices, service logs, infrastructure metrics with Prometheus/Grafana and other things.

It is possible to use Skaffold to run a cluster through Minikube. In this way, each functionality will be tested in the most similar way to the production environment.

Screenshots

See Architecture and Application screenshots at the ./docs/images folder.

Service Architecture

The solution is composed of 5 microservices written in various languages. The main repository (where we are now) is a monorepo but each of the services has its respective repository and everything is linked through the Git sub-modules.

Architecture of microservices

Find Protocol Buffers Descriptions at the ./lib/proto/demo.proto file.

Service Language Description
Mobile App Javascript Mobile application with login, signup, search and history screens.
Gateway Service Typescript service that acts as a 'data aggregation layer' through GraphQL. Through it you can access the resources provided by the back-end microservices.
Users Service Golang Microservice implemented in Golang that stores user information into postgres DB.
Auth Service Golang Microservice implemented in Typecript that allows authenticating access to the backend through a JWT token. On the other hand, it manages user signup and login.
Restaurants Service Golang Microservice implemented in Golang that get nearby restaurants from Google Places API.
History Service Golang The microservice implemented in Golang saves the history associated with searches performed in the restaurant service.
NATS Server - NATS is an open-source, high-performance, cloud native messaging system.

Production links

Prepare Project

  • Clone repo: git clone git@github.com:cagodoy/tenpo-challenge.git.
  • Prepare all repos with make prepare command.

Docker Commands (Development)

  • make compose: start docker-compose in local with all services.
  • make stop: stop docker-compose.

Skaffold Commands (Pre Production)

  • brew install skaffold: install skaffold dependency.
  • brew install kubectl: install kubectl cli.
  • brew install minikube: install minikube.
  • minikube start: start minikube.
  • skaffold run: start skaffold.

Infrastructure Terraform Commands

  1. Configure Terraform with azure in our machine. [Link]
  2. Set up Azure storage to store Terraform state. [Link]
  3. Run az storage container create -n tfstate --account-name <YourAzureStorageAccountName> --account-key <YourAzureStorageAccountKey>
  4. Run terraform init -backend-config="storage_account_name=<YourAzureStorageAccountName>" -backend-config="container_name=tfstate" -backend-config="access_key=<YourStorageAccountAccessKey>" -backend-config="key=codelab.microsoft.tfstate"
  5. Configure ENV values in shell:
    • export TF_VAR_client_id=<service-principal-appid>
    • export TF_VAR_client_secret=<service-principal-password>
  6. Run inside ./infra/terraform the following commands.
    • terraform plan -out out.plan for generate tf plan file. (Wait 3 minutes approximately)
    • terraform apply out.plan for apply plan directly azure provider. (Wait 15 minutes approximately)
  7. Check cluster with kubectl get nodes.
  8. Configure Static Ip to use with HTTPS. [Link]

Deploy services to Kubernetes cluster

  • Run inside ./infra/kubernetes the following commands.
    • kubectl apply -f ingress for deploy yaml ingress files.
    • kubectl apply -f services for deploy yaml services files.

Deploy Linkerd mesh service to Kubernetes cluster.

  • brew install linkerd: install linkerd dependency.
  • linkerd check --pre: checks to determine if the control plane can be installed on our cluster.
  • linkerd install | kubectl apply -f -: install Linkerd to cluster.
  • kubectl get svc/pod --namespace linkerd --output wide: confirm that the svc/pod resources are created.
  • linkerd check: check cluster before Linkerd installation.
  • kubectl get deploy -o yaml | linkerd inject - | kubectl apply -f -: inject all the deployments in the default namespace.
  • linkerd dashboard: open linkerd web dashboard.

TODO

  • Implements CI/CD for each service. (check /src folder)
  • Integration test for auth service for check GraphQL responses.
  • Integration test for restaurants service for check GraphQL responses.
  • Integration test for history service for check GraphQL responses.

About

Solution proposal using microservices oriented architecture through 5 microservices showcasing React Native, GraphQL, Kubernetes, Linkerd, gRPC, NATS, Terraform and Skaffold.


Languages

Language:Go 54.4%Language:TypeScript 32.9%Language:HCL 8.5%Language:Makefile 4.1%