This is the backend of the Smart Brain application, which provides user registration, login, profile management, and face recognition features. The backend interacts with the Clarifai API to perform face detection on user-uploaded images. Built with Node.js, Express, and PostgreSQL, this backend supports the entire functionality of the Smart Brain web application.
You can view the live demo here, or you can test the API endpoints by using a tool like Postman or cURL with the following available routes.
- React.js: JavaScript library for building user interfaces.
- React Hooks: For managing component state and lifecycle methods.
- CSS: For styling the user interface.
- Node.js: JavaScript runtime environment used for server-side scripting.
- Express: Web framework for building the API.
- PostgreSQL: Relational database used for storing user data and image entries.
- Clarifai API: For face detection functionality.
- Knex.js: SQL query builder for interacting with the PostgreSQL database.
- bcrypt-nodejs: Library for password hashing.
- CORS: Middleware for enabling cross-origin requests.
- User Authentication: Allows users to register, sign in, and view their profiles.
- Face Detection: Uses the Clarifai API to detect faces in images.
- User Entries Tracking: Tracks the number of image submissions for each user.
- PostgreSQL Database: Stores user information, login credentials, and image entries.
- Secure Password Storage: Passwords are hashed using bcrypt for security.
- Node.js and npm should be installed on your system.
- PostgreSQL database should be set up and running.
-
Clone the repository:
git clone https://github.com/ahmetarslanS/SmartBrain-API cd smartbrain-api
-
Install the required dependencies:
npm install
-
Set up your environment variables:
- Create a .env file in the root directory and add the following:
DATABASE_URL=your_postgresql_database_url API_CLARIFAI=your_clarifai_api_key (which is free)
-
Start the server
npm start
- Alternatively, for development purposes, use
nodemon
to automatically restart the server on file changes:npm run start:dev
- The API will be available at http://localhost:3000.
-
Description: Sign in with email and password to get user information.
-
Request Body:
{ "email": "[email protected]", "password": "your_password" }
-
Response:
{ "id": 1, "name": "John Doe", "email": "[email protected]", "entries": 0, "joined": "2023-10-10T12:00:00.000Z" }
-
Description: Register a new user with email, name, and password.
-
Request Body:
{ "email": "[email protected]", "name": "John Doe", "password": "your_password" }
-
Response:
{ "id": 1, "name": "John Doe", "email": "[email protected]", "entries": 0, "joined": "2023-10-10T12:00:00.000Z" }
-
Description: Retrieve a user's profile by ID.
-
Request Parameters:
id
(User ID) -
Response:
{ "id": 1, "name": "John Doe", "email": "[email protected]", "entries": 0, "joined": "2023-10-10T12:00:00.000Z" }
- Description: Increment the user's entries count when they submit an image.
- Request Body:
{ "id": 1 }
- Response:
{ "entries": 1 }
- Description: Detect faces in an image using the Clarifai API.
- Request Body:
{ "input": "image_url" }
- Response: A JSON object with the detected face data.
The database contains two main tables:
- login: Stores email and hashed password.
- users: Stores user details (name, email, entries, join date).
To deploy this backend:
1. Set up environment variables (DATABASE_URL and API_CLARIFAI).
2. Push the code to your cloud server (e.g., Heroku, AWS).
3. Ensure PostgreSQL is properly configured and accessible.
Feel free to fork the repository and submit pull requests for improvements, bug fixes, or new features.
This project is licensed under the MIT License.