Skip to content

Architecture

Jair Avilés edited this page Feb 5, 2024 · 3 revisions

User Fraud Check sequence

Essentially there are three main components:

  1. The API, which handles the HTTP requests
  2. 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.

  1. 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
Loading

Detailed explanation:

  1. Client requests user risk checker via API call
  2. If any param value has an invalid format, API responses with a BadRequest run time error
  3. API request user record based on any of the provided query params
  4. User data source receives and search for user record
  5. If no user record is found, API returns a NotFound response
  6. If user record is found, send it to the risk calculator
  7. Determine user risk based on user record data such as country, if email or phone are blocklisted
  8. API returns user record and user risk determined by the module

User Fraud Check API

A unique GET endpoint will be defined to check the user risk. Will accepts at least one of the following parameters

  1. Email
  2. 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"
}

Clone this wiki locally