Skip to content

Welcome to Client Microservice

1. Installation

1.1 Prerequisites

Before installing the Client Microservice, ensure that the following dependencies are installed on your system:

  • Node.js: Version 14.x or later
  • npm: Version 6.x or later
  • Docker: If you plan to run the service in a containerized environment
  • TypeScript: Ensure TypeScript is installed globally

1.2 Cloning the Repository

Start by cloning the repository that contains the Client Microservice code:

git clone <repository url>
cd client-microservice

1.3 Installing Dependencies

Install the necessary Node.js packages:

npm i

1.4 Running the Service

You can run the service in development mode using:

npm run start:dev

Alternatively, to run the service in production mode:

npm run build
npm run start:prod

If using Docker, build and run the container:

docker-compose up --build

2. Overview of the Client Microservice Architecture

The Client Microservice manages various entities such as suppliers, servicers, persons, organizations, distributors, and agents. It provides a RESTful and GraphQL API for interacting with these entities.

2.1 Core Components

  • Modules:
    • ClientModule: The main module that brings together all services, resolvers, and repositories.
    • AuthModule: Handles authentication within the microservice.
  • Services:
    • SupplierService, ServicerService, PersonService, OrganizationService, DistributorService, AgentService, and ClientExclusiveService.
    • These services encapsulate the business logic for each entity.
  • Resolvers:
    • GraphQL resolvers that handle queries and mutations for the above entities.
  • Repositories:
    • Manage data persistence, handling CRUD operations for each entity in the database.

Client Microservice Architecture

Client Architecture

3. Core Services

3.1 Supplier Service

The SupplierService handles all logic related to managing suppliers within the system.

Supplier Service Interaction

Supplier Service Interaction

Supplier Service

@Injectable()
export class SupplierService {
  constructor(
    @InjectRepository(Supplier) private supplierRepo: Repository<Supplier>,
  ) {}

  async createSupplier(data: CreateSupplierDto): Promise<Supplier> {
    const newSupplier = this.supplierRepo.create(data);
    return await this.supplierRepo.save(newSupplier);
  }

  async findAllSuppliers(): Promise<Supplier[]> {
    return await this.supplierRepo.find();
  }
}

3.2 Person Service

The PersonService manages data related to persons within the system.

Person Service Interaction

Person Service Interaction

** Person Service**

@Injectable()
export class PersonService {
  constructor(
    @InjectRepository(Person) private personRepo: Repository<Person>,
  ) {}

  async createPerson(data: CreatePersonDto): Promise<Person> {
    const newPerson = this.personRepo.create(data);
    return await this.personRepo.save(newPerson);
  }

  async findAllPersons(): Promise<Person[]> {
    return await this.personRepo.find();
  }
}

4. GraphQL Resolvers

The resolvers translate incoming GraphQL queries and mutations into service calls. Each entity has a corresponding resolver.

4.1 Supplier Resolver

Handles queries and mutations related to suppliers.

Supplier Resolver Flow

Supplier Resolver Flow

5. Repositories

Repositories manage data persistence and interaction with the database.

5.1 Supplier Repository

The SupplierRepository handles CRUD operations for suppliers.

Supplier Repository Interaction

Supplier Repository Interaction

Supplier Repository

@EntityRepository(Supplier)
export class SupplierRepository extends Repository<Supplier> {}

6. Security and Authentication

The Client Microservice uses JWT tokens for securing access to its endpoints. Authentication is handled by the AuthModule, which integrates with the JwtStrategy and JwtAuthGuard.

6.1 JWT Authentication Flow

  1. Client Request: A client sends a request with a JWT token.
  2. JWT Validation: The JwtAuthGuard intercepts the request and validates the JWT token.
  3. Authorized Access: If the token is valid, the request is processed by the appropriate resolver and service.

JWT Authentication Flow

JWT Authentication Flow

JWT Auth Guard

@Injectable()
export class JwtAuthGuard extends AuthGuard('jwt') {}

7. Data Flow

The data flow within the Client Microservice involves interaction between the client, resolvers, services, and repositories. Each component plays a specific role in processing requests and managing data.

Data Flow in Client Microservice

Data Flow in Client Microservice


8. Conclusion

The Client Microservice is a well-structured and modular system that efficiently manages entities like suppliers, servicers, and persons.

Purpose of the Client Microservice

The Client microservice is designed to manage and store information about clients that your company interacts with or serves, such as businesses, institutions, or individual clients.

Goals

  • Client Data Management: Centralize and manage data pertaining to clients, streamlining client information access and maintenance.
  • Personalization and Segmentation: Enable the customization of services and interactions based on client types and individual profiles.
  • Client Relationship Enhancement: Enhance client relationships through better understanding and management of client interactions, preferences, and history.

Key Components

Core Elements of the Client Service

  • Client: This object profiles an organization or individual that is a client of your company. It includes essential details like name, contact information, transaction history, preferences, and any other relevant client-specific data.
  • ClientType: Represents different categories or types of clients. This could be based on the size of the organization, the industry sector, the nature of the business relationship, etc.

How It Works in Our Company

  1. Client Data Centralization:
  2. What it Means: The Client microservice acts as a single, unified storage point for all data related to your clients. This includes information such as contact details, transaction histories, client preferences, and any other relevant data.
  3. Why It's Important: Centralizing client data means that all departments in your company can access the same, up-to-date information. This avoids inconsistencies and ensures everyone is working with the most current client data. Whether it's the sales team, customer service, or marketing, each department can retrieve the information they need from this central repository.
  4. Benefit: Improved efficiency and coordination across various departments, leading to smoother operations and better overall management of client information.
  5. Customization and Personalization:
  6. What it Means: The microservice not only stores client data but also allows your company to understand and categorize clients into different types. This understanding enables your company to tailor interactions and services to meet the specific needs or preferences of different client groups or individual clients.
  7. Why It's Important: Personalization is key in today’s business world. Clients expect services and interactions that are relevant to their specific needs. By leveraging the data stored in the Client microservice, your company can offer more personalized products, services, and interactions.
  8. Benefit: This leads to higher client satisfaction, increased loyalty, and potentially, more business from clients who feel their unique needs are being met.
  9. Client Relationship Enhancement:
  10. What it Means: The microservice helps in tracking all interactions with clients, their preferences, and their history with your company. This includes keeping track of past communications, purchases, preferences, feedback, and any other interactions that have occurred.
  11. Why It's Important: Understanding the history and preferences of your clients is crucial for building strong, ongoing relationships. This information can be used to anticipate client needs, resolve issues more effectively, and communicate in a way that resonates with each client.
  12. Benefit: Enhanced client relationships lead to improved client retention, more opportunities for upselling and cross-selling, and a better reputation for your company as one that truly understands and values its clients.