https://github.com/ansh-devs/userdatalink
RPC based User Service with Search functionality
https://github.com/ansh-devs/userdatalink
remote-procedure-call
Last synced: 10 months ago
JSON representation
RPC based User Service with Search functionality
- Host: GitHub
- URL: https://github.com/ansh-devs/userdatalink
- Owner: ansh-devs
- Created: 2024-05-29T07:39:33.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-26T10:13:03.000Z (about 2 years ago)
- Last Synced: 2024-07-13T09:13:28.595Z (almost 2 years ago)
- Topics: remote-procedure-call
- Language: Go
- Homepage:
- Size: 44.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## **User Service with Search Functionality using gRPC as transportation layer**
[](https://github.com/ansh-devs/userdatalink/actions/workflows/go-test.yml/badge.svg)
### **Software Architecture Patterns and paradiagms used -**
- **_Repository Pattern_** → used in Repository-Layer/Database layer inside the _`internal/database`_ directory to make business logic and database layer logic decoupled. In future if needed just make the struct and implement the [_`UserRepository`_](/internal/database/repository.go) interface to the desired database (Postgres/Cassandra/MongoDb) such that there will be no need to make any changes in the [_`UserService`_](/internal/gapi/server.go) Service layer.
- **_Separation Of Concern (from SOLID)_** → there is a separation between the transportation layer **_gRPC_** and the Service layer and the repository layer
- **_Dependency Inversion Principle (from SOLID)_** → Dependency of `UserRepository` is injected in the `UserService` to perform **Db-calls**.
- **_Builder Pattern from Design Principles_** → used in the constructor of the `UserService` which itself configure the **gRPC's Reflection** and bind the **PORT** to the service.
- **_Idiomatic practices encouraged by the Golang Community_** → efficient use of `maps`, `slices` etc.
### **Protocol Buffers v3 Definition**
- UserService Proto Definition-
```
+-------------+--------------------+---------------------------+----------------------------+
| SERVICE | RPC | REQUEST TYPE | RESPONSE TYPE |
+-------------+--------------------+---------------------------+----------------------------+
| UserService | GetUserById | GetUserByIdRequest | GetUserByIdResponse |
| UserService | GetUsersListByIds | GetUsersListByIdsRequest | GetUsersListByIdsResponse |
| UserService | GetUsersByCriteria | GetUsersByCriteriaRequest | GetUsersByCriteriaResponse |
+-------------+--------------------+---------------------------+----------------------------+
```
- Available Proto Message Types-
```
+----------------------------+
| MESSAGE |
+----------------------------+
| GetUserByIdRequest |
| GetUserByIdResponse |
| GetUsersByCriteriaRequest |
| GetUsersByCriteriaResponse |
| GetUsersListByIdsRequest |
| GetUsersListByIdsResponse |
+----------------------------+
```
* **GetUserById RPC types-**
* _Request_
```
+-------+------------+----------+
| FIELD | TYPE | REPEATED |
+-------+------------+----------+
| id | TYPE_INT64 | false |
+-------+------------+----------+
```
* _Response_
```
+-------+---------------------+----------+
| FIELD | TYPE | REPEATED |
+-------+---------------------+----------+
| user | TYPE_MESSAGE (User) | false |
+-------+---------------------+----------+
```
* **GetUsersListByIds RPC types-**
* _Request_
```
+-------+------------+----------+
| FIELD | TYPE | REPEATED |
+-------+------------+----------+
| ids | TYPE_INT64 | true |
+-------+------------+----------+
```
* _Response_
```
+-------+---------------------+----------+
| FIELD | TYPE | REPEATED |
+-------+---------------------+----------+
| users | TYPE_MESSAGE (User) | true |
+-------+---------------------+----------+
```
* **GetUsersByCriteria RPC types-**
* _Request_
```
+-------+---------------------------+----------+
| FIELD | TYPE | REPEATED |
+-------+---------------------------+----------+
| type | TYPE_ENUM (UserCriterias) | false |
| value | TYPE_STRING | false |
+-------+---------------------------+----------+
```
* _Response_
```
+-------+---------------------+----------+
| FIELD | TYPE | REPEATED |
+-------+---------------------+----------+
| users | TYPE_MESSAGE (User) | true |
+-------+---------------------+----------+
```
For the request and response of RPC calls checkout the [`user_service.proto`](/protos/user_service.proto)
* **Grpc Interceptor Logging for Incoming Requests**

### **Environment Variable**
To run this project, The environment variable `PORT` must be in the accessible scope which is used to set the port where the _gRPC_ server will be listening for the incoming connections.
### **Steps To Run**
* Without Docker in Linux/WSL Environment:
* `make run` - will execute the source code.
* `make build` - will build the executable binary from the source code.
* With Docker:
* `docker build . -t user-service` - will build image from Dockerfile.
* `docker run -d --restart=always -p 8080:8080 user-service` - will run the image inside container.