This project implements a simple backend REST API that classifies input text into one of the following categories:
- Complaint
- Query
- Feedback
- Other
The API accepts a text string as input and returns the predicted category along with a confidence score.
This project was developed as part of a technical assignment to demonstrate backend API design, service separation, and AI-inspired classification logic.
- Node.js
- Express.js
- Axios
- Nodemon
Request Body
{
"text": "My internet is not working properly"
}
Response:
{
"category": "Complaint",
"confidence": 0.85
}
Project Structure
text-classifier-api/
├── index.js
├── src/
│ ├── app.js
│ ├── controllers/
│ │ └── classifyController.js
│ ├── services/
│ │ └── aiService.js
│ ├── routes/
│ │ └── classifyRoutes.js
├── .env
├── .gitignore
├── package.json
└── README.md
Environment Setup:
1. Clone the repository
2. Install dependencies: npm install
3. Create a .env file in the project root and add: PORT=3000
4. Start the server: npm run dev
The server will start on: http://localhost:3000
AI Usage
The text classification logic is implemented in a dedicated service layer.
A lightweight AI-inspired, rule-based approach is used to classify text based on semantic keywords and patterns.
Each category is mapped with a predefined confidence score to ensure deterministic and explainable responses.
The service architecture is designed so that this logic can be easily replaced with an external AI or LLM-based model (such as OpenAI) without changing the API or controller layer.
Error Handling
Returns 400 Bad Request if the input text is missing or invalid
Returns 500 Internal Server Error for unexpected server errors
Testing
The API can be tested using tools such as Postman or Thunder Client by sending a POST request to:
http://localhost:3000/api/classify
Notes
This project focuses on clean backend architecture, modular design, and clarity of implementation rather than heavy AI or ML integration.