This repository contains the backend API for a mentorship platform that connects mentees with mentors across various domains. The API is built with Express.js, TypeScript, and Prisma ORM with PostgreSQL database.
- Mentor search functionality with keyword extraction
- Fallback search mechanism when no results are found
- Integration with LLM for enhanced search capabilities
- Data model for mentors, mentees, bookings, services, and more
- Database acceleration with Prisma Accelerate
- Node.js (v14 or higher)
- PostgreSQL database
- Hugging Face API key (for LLM integration)
-
Clone the repository:
git clone https://github.com/yourusername/searchbox.git cd searchbox -
Install dependencies:
npm install
-
Create a
.envfile in the root directory with the following variables:PORT=4000 DATABASE_URL="postgresql://username:password@localhost:5432/mentorship?schema=public" DIRECT_URL="postgresql://username:password@localhost:5432/mentorship?schema=public" HUGGING_FACE_API_KEY="your-hugging-face-api-key" -
Set up the database:
npx prisma generate npx prisma db push
npm run devOr with Nodemon for automatic reloading:
npx nodemonnpm run build
npm startGET /
Returns the server status and health information.
Response:
{
"message": "Welcome to the server!",
"health": "100%",
"state": "running"
}POST /api/search
Search for mentors based on a query string. The API will extract keywords from the query and find relevant mentors.
Request Body:
{
"query": "experienced javascript developer for career guidance"
}Response:
{
"mentors": [
{
"id": 1,
"userId": 1,
"firstName": "John",
"lastName": "Doe",
"profilePicture": "https://example.com/profile.jpg",
"bio": "Experienced JavaScript developer with 10 years in the industry."
}
],
"keywords": ["experienced", "javascript", "developer", "career", "guidance"]
}If no mentors are found with the extracted keywords, the API will use fallback keywords to find mentors:
Response with Fallback:
{
"mentors": [
{
"id": 2,
"userId": 2,
"firstName": "Jane",
"lastName": "Smith",
"profilePicture": "https://example.com/jane.jpg",
"bio": "Career coach specializing in tech industry."
}
],
"keywords": ["programming", "software", "development", "coding", "tech"],
"usedFallback": true
}The application uses a PostgreSQL database with the following key models:
- User: Base user model for both mentors and mentees
- MentorProfile: Profile information for mentors
- MenteeProfile: Profile information for mentees
- Service: Services offered by mentors
- Booking: Session bookings between mentors and mentees
- Domain: Expertise domains of mentors
- Rating: Ratings given by mentees to mentors
- Availability: Mentor availability schedule
For the complete schema, please check the prisma/schema.prisma file.
The search functionality works in the following way:
- Extract keywords from the user's search query
- If fewer than 2 keywords are found, enhance the query using the LLM
- Search for mentors using the extracted keywords
- If no mentors are found, use fallback keywords based on the domain of the query
- Return mentors sorted by rating (highest first)
The API is configured to accept requests only from https://mentg.in. Set-up your own frontend url in the cors orgin option (eg. http://localhost:5173).
- Express: Web framework
- Prisma: ORM for database interactions
- TypeScript: Type-safe JavaScript
- Cors: Cross-Origin Resource Sharing
- Dotenv: Environment variable management
npm testNote: Tests need to be implemented.
The project uses TypeScript for type safety. The source code is in the src directory, and it gets compiled to JavaScript in the dist directory.
To build the project:
npm run buildISC
Made with ❤️ for connecting mentors and mentees worldwide.