-
Notifications
You must be signed in to change notification settings - Fork 0
Architecture
Jair Avilés edited this page Feb 5, 2024
·
3 revisions
Essentially there are three main components:
- The API, which handles the HTTP requests
- The user data source where the user records are persisted
a. For the sake of this code challenge, I'm implementing the datafake library to generate user-mocked data.
- Risk calculator module to determine the risk level of a user record
b. For the sake of this code challenge, I'm implementing random functions defined as utilities classes to follow the proposed business rules.
sequenceDiagram
autonumber
actor Client
box Checker flow
participant API
participant User data source
participant Risk calculator
end
Client->>+API: GET /api/user?email&phone
API-->>-Client: Invalid input params returns a Bad request
API->>+User data source: Get user record
User data source->>User data source: Search for user record
User data source-->>-Client: User record not found
User data source->>+Risk calculator: User record found
Risk calculator->>Risk calculator: Determine user risk
Risk calculator->>+Client: Return user risk response
Detailed explanation:
- Client requests user risk checker via API call
- If any param value has an invalid format, API responses with a BadRequest run time error
- API request user record based on any of the provided query params
- User data source receives and search for user record
- If no user record is found, API returns a NotFound response
- If user record is found, send it to the risk calculator
- Determine user risk based on user record data such as country, if email or phone are blocklisted
- API returns user record and user risk determined by the module
A unique GET endpoint will be defined to check the user risk. Will accepts at least one of the following parameters
- Phone
Request Sample:
GET /api/users?email=john.doe@test.com&phone=5511223344
Sample 200 response:
{
"user": {
"id": "f5f0f4bd-fce2-44f8-bc57-219db97db0ca",
"firstName": "John",
"lastName": "Doe",
"phone": "5511223344",
"email": "john.doe@test.com",
"countryCode": "SB"
},
"riskLevel": "MID",
"riskFactors": [
"Email john.doe@test.com is blocklisted."
]
}
Sample 400 response:
{
"timestamp": "2024-02-05T21:51:17.557+00:00",
"status": 400,
"error": "Bad Request",
"path": "/api/users"
}
Sample 404 response:
{
"timestamp": "2024-02-05T21:46:58.543+00:00",
"status": 404,
"error": "Not Found",
"path": "/api/users"
}