How zachgoll/microservices-architecture-example works
What this project is (type + purpose)
This repository is a Node.js microservices example application composed of three separately started processes:
UI Static Server (node app.js) on http://localhost:8080
2. Microservice #1: User Authentication (node user-authentication/server.js) on http://localhost:8081
Microservice #2: Game (node game/server.js) on http://localhost:8082
Both microservices persist data in MongoDB using credentials provided via environment variables: DB_USER, DB_PW.
Purpose-wise, the UI combines two independently deployable services into a single user experience:
• Auth service: register/authenticate/get user
• Game service: submit score/get score history (wins/losses)
How the file tree maps to architecture (what to reflect
From the tree:
Root
• app.js → the UI static server (serves /public assets; likely Express or Node HTTP server)
• public/ → front-end assets:
• index.html (entry page)
• script.js (calls microservices via HTTP)
• style.css
• package.json / package-lock.json → root dependencies for the UI server process
user-authentication/
• server.js → Auth microservice HTTP API listening on 8081
• data.js → auth data access layer / model definitions (MongoDB interactions)
• its own package.json / lock → indicates independent service lifecycle (separate dependencies, start commands, deployability)
game/
• server.js → Game microservice HTTP API listening on 8082
• data.js → game data access layer / model definitions (MongoDB interactions)
• its own package.json / lock → also independently deployable
Key architectural implication to show: this repo is “microservices” at the process boundary level: separate servers, separate dependency graphs, separate ports, communication over HTTP APIs, shared DB infra.
Clients / Edge
• Browser (end user)
UI tier
• UI Static Server (Node) app.js on :8080
• Serves public/index.html, public/script.js, public/style.css
• (Even if it’s “just static”, it’s a running server process and should be shown as such.)
Service tier (two microservices)
• Auth Service (Node/Express) user-authentication/server.js on :8081
• Endpoints (from README):
• POST /register
• POST /authenticate
• GET /get-user/:useremail
• Game Service (Node/Express) game/server.js on :8082
• Endpoints (from README):
• POST /score
• GET /score/:email
Data tier
• MongoDB (local in this tutorial; a single instance)
• As one DB server/cluster, but include logical separation:
• Collection for users (Auth service writes/reads)
• Collection for game results (Game service writes/reads)
• Credentials flow: both services use DB_USER/DB_PW
Static asset delivery
• Browser → UI Static Server (:8080): GET / returns index.html, GET /script.js, etc.
Auth flows
• Browser (script.js) → Auth Service (:8081):
• POST /register with {email, password}
• POST /authenticate with {email, password}
• optionally GET /get-user/:useremail
Game flows
• Browser (script.js) → Game Service (:8082):
• POST /score with {email, result(win/loss)}
• GET /score/:email
Persistence
• Auth Service → MongoDB: create/read user records
• Game Service → MongoDB: upsert/read score records (wins/losses per email)
• Browser ⇄ services: HTTP + JSON payloads
• Services ⇄ MongoDB: Mongo wire protocol via Node Mongo/Mongoose driver (implementation detail, but worth labeling as “MongoDB driver”)
“Don’t overthink it”: split into as many components as possible (but keep it truthful)
Given this repo’s simplicity, the most valuable “extra detail” (without inventing architecture) is:
• Explicitly show that there are three separate Node runtimes.
• Explicitly show that the browser JS calls microservices directly (unless you confirm the UI server proxies; don’t assume proxying).
• Explicitly show data ownership boundaries:
• Auth service owns “User” data
• Game service owns “GameResult/Score” data
• Explicitly show configuration boundary:
• Environment variables (DB creds) injected into each microservice process