How microservices-demo/user works
Project Type and Purpose
• This is a microservice that handles user account storage, including functionality around cards, addresses, registration, login, and customer data management.
• The service is implemented in Go and is part of a larger microservices demo ecosystem.
• It includes a REST API (documented via an API spec in the “apispec” directory) and leverages a MongoDB backend. It also supports containerized deployment via Docker and docker-compose, with optional integration for distributed tracing using Zipkin.
File Structure
• Top-level directories:
• .github – Contains CI/CD configurations (GitHub workflows, issue templates, etc.).
• api – Houses the API endpoints, middlewares, transport, and service definitions – effectively your Controller layer.
• db – Contains database connection and logic, including a MongoDB-specific subdirectory.
• docker & docker-compose files – Provides Dockerfiles and docker-compose configurations for both the production service and supporting services like Zipkin.
• users – Contains business/domain logic (addresses, cards, users, links) and tests.
• Other files (main.go, Makefile, glide.yaml/lock) – Bootstrapping elements and dependency configurations.
Main Components
a. Client/External Consumers:
• Represents consumers making HTTP requests (via curl commands as seen in the README).
b. API Layer:
• Middlewares and transport functions that validate and authenticate requests.
c. Business Logic Layer:
• “users” directory which contains functions related to business rules, e.g., managing addresses, cards, and users.
d. Database Layer:
• A “db” component representing the persistence layer using MongoDB (detailed in db/mongodb).
e. Infrastructure & Deployment:
• Docker components, illustrating Dockerfiles, docker-compose for launching the service and supporting containers (user-db, Zipkin).
• CI/CD pipelines (GitHub workflows, Travis CI) as part of the deployment process.
f. External Services:
• External API clients (if applicable) and distributed tracing (Zipkin) that the service integrates with.
Relationships and Interactions
• The business logic layer interacts with the database layer (the db package, specifically the MongoDB connector) to persist or retrieve data.
• Separate a branch for middleware components between client request and the API endpoints to reflect authentication, logging, or tracing.
Design and Architectural Patterns
• This project utilizes separation of concerns by segregating the API (controller) components from the business logic and the persistence layer.
• It demonstrates a layered architecture – REST API, Services, and Database.
• Use of containerization to isolate and deploy components independently.
• Incorporate examples of testing practices by highlighting test files tied to major modules.