Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


🧠 BiteSpeed Identity Resolution API

This is a backend service built for the [BiteSpeed Identity Resolution Challenge]. The API helps unify user identity by linking contacts with the same email or phone number across multiple records.

🚀 Hosted API:

Base URL: https://bitespeed-assignment-2u07.onrender.com


📘 Table of Contents


⚙️ Tech Stack

  • Backend: Node.js, Express.js
  • Database: PostgreSQL (via Prisma ORM)
  • Deployment: Render
  • API Docs: Swagger (OpenAPI 3.0)

🔗 API Endpoints

1. POST /identify

  • Purpose: Resolves identity based on email and/or phone number.
  • Body:
{
  "email": "john.doe@example.com",
  "phoneNumber": "9876543210"
}
  • Response:
{
  "contact": {
    "primaryContactId": 1,
    "emails": ["john.doe@example.com", "another@example.com"],
    "phoneNumbers": ["9876543210"],
    "secondaryContactIds": [2, 3]
  }
}

2. DELETE /identify/{id}

  • Purpose: Soft deletes the contact with given ID.
  • Response:
{
  "message": "Contact soft deleted",
  "contact": {
    "id": 11,
    "email": "john.doe@example.com",
    "phoneNumber": "9876543210",
    "linkPrecedence": "primary",
    "deletedAt": "timestamp"
  }
}

3. PATCH /identify/restore/{id}

  • Purpose: Restores a soft-deleted contact.
  • Response:
{
  "message": "Contact restored",
  "contact": {
    "id": 11,
    "email": "john.doe@example.com",
    "phoneNumber": "9876543210",
    "linkPrecedence": "primary"
  }
}

🔍 Identity Resolution Logic

  • A primary contact is created if neither email nor phone exists.
  • If either matches an existing contact, a secondary contact is created or linked to the existing primary.
  • All linked contacts are grouped by a linkedId, ensuring a unified identity across duplicates.
  • Conflicts are resolved by assigning the oldest contact as primary.

💾 How to Run Locally

git clone https://github.com/yourusername/bitespeed-assignment.git
cd bitespeed-assignment
npm install
npx prisma generate
npx prisma migrate dev --name init
npm run dev

Ensure .env is configured with:

DATABASE_URL="postgresql://<user>:<password>@localhost:5432/<dbname>"

🗃️ Database Schema

Field Type Description
id Integer Primary key
phoneNumber String User's phone number
email String User's email address
linkedId Integer Link to primary contact
linkPrecedence Enum 'primary' or 'secondary'
createdAt Timestamp Auto-generated
updatedAt Timestamp Auto-generated
deletedAt Timestamp Nullable (for soft delete)

🔄 Soft Delete & Restore Feature

  • Contacts are soft deleted using a deletedAt timestamp.
  • Deleted contacts can be restored using the /identify/restore/{id} endpoint.
  • Identity resolution ignores soft-deleted contacts by default.

🧪 Swagger API Docs

You can explore the full API documentation via Swagger UI:

🔗 /api-docs


👨‍💻 Author

Aryan Bachute Full Stack Developer | IEEE Treasurer


Releases

Packages

Contributors

Languages