Sentrimetric is an Express API that allows users to generate an API key and perform string analysis operations. It provides functionality to check the similarity between two strings, analyze the sentiment of a sentence, and determine if two words have the same phonetic sound.
The Sentrimetric API allows users to generate an API key, which they can use to perform string analysis operations such as checking the similarity between two strings, analyzing the sentiment of a sentence, and determining if two words have the same phonetic sound.
The API follows RESTful principles and uses JSON for request and response payloads. Authentication is required for certain endpoints using an API key.
To install and run the Sentrimetric API, follow these steps:
- Clone the repository:
git clone <repository-url>
- Install dependencies:
pnpm install
The Sentrimetric API requires a PostgreSQL database. You can use Docker to run a PostgreSQL container:
- Install Docker: Docker Installation Guide.
- Run the PostgreSQL container:
docker run --name postgres-container -e POSTGRES_PASSWORD=<password> -p 5432:5432 -d postgres
The Sentrimetric API uses Redis for rate limiting. You can also use Docker to run a Redis container:
- Install Docker: Docker Installation Guide.
- Run the Redis container:
docker run --name redis-container -p 6379:6379 -d redis
- Add the database link to the .env file
To sync the postgres database with the current prisma schema run the command
pnpm sync:db
This command also generates the prisma client
Start the server using this command
pnpm prod
The API server should now be running and accessible at http://localhost:$PORT
.
Make sure to adjust the PostgreSQL and PORT details in the .env
file if you are using custom configurations.
One notable addition to the project is the zenv
function, which is used to verify and parse the schema file using Zod. This function ensures that the environment variables are properly defined and validated based on the specified schema.
Deployed on render.com deployment-link
- @prisma/client: Prisma client for working with databases.
- argon2: Password hashing library for secure storage of user passwords.
- cookie-parser: Middleware for parsing cookies in Express.
- dotenv: Module for loading environment variables from a
.env
file. - express: Fast, unopinionated, minimalist web framework for Node.js.
- helmet: Middleware for securing Express apps with various HTTP headers.
- ioredis: Redis client for Node.js.
- jsonwebtoken: Library for generating and verifying JSON Web Tokens (JWT).
- nanoid: Unique ID generator.
- natural: Natural language processing library.
- pino: Fast and opinionated logger for Node.js.
- pino-pretty: Prettifier for Pino logs.
- zod: TypeScript-first schema validation library.
- @types/cookie-parser: TypeScript definitions for cookie-parser.
- @types/express: TypeScript definitions for Express.
- @types/jsonwebtoken: TypeScript definitions for jsonwebtoken.
- @types/node: TypeScript definitions for Node.js.
- prisma: Database toolkit and ORM.
- tsx: TypeScript transpiler.
- typescript: JavaScript superset that provides static typing.
- pnpm: Fast, disk space efficient package manager.
To run the Sentrimetric API, you can use the following npm scripts:
-
Development Mode
- Run the API server in development mode with automatic restart on file changes:
pnpm dev
- Run the API server in development mode with automatic restart on file changes:
-
Production Mode
- Build the TypeScript code and start the API server in production mode:
pnpm prod
- Build the TypeScript code and start the API server in production mode:
-
Synchronize Database
- Push database changes and generate Prisma client:
pnpm sync:db
- Push database changes and generate Prisma client:
-
Build
- Build the TypeScript code to the
dist
directory:pnpm build
- Build the TypeScript code to the
Make sure to set up your environment variables and configure the Prisma database connection before running the API. Refer to the "Installation" section for more details.
Once the API server is running, you can make HTTP requests to the specified endpoints using a tool like cURL, Postman, or your preferred API client.
Please note that certain endpoints require authentication using an API key. Ensure that you include the API key in the request headers or as specified in the API documentation.
-
Create User
POST /api/users/
- Create a new user.
-
Delete User
DELETE /api/users
- Delete the current user.
-
Create Session (Login)
POST /api/sessions
- Create a new session (login) for the user.
-
Get information about current session
GET /api/sessions
- Get information about the current session.
-
Get all active sessions
GET /api/sessions/all
- Get information about all active sessions.
-
Logout from current session
DELETE /api/sessions/
- Logout from the current session.
-
Log out from all devices
DELETE /api/sessions/all
- Log out from all devices and terminate all sessions.
-
Get Active API Key
GET /api/apikeys
- Get the active API key for the user.
-
Generate API Key
POST /api/apikeys
- Generate a new API key for the user.
-
Revoke API key
DELETE /api/apikeys
- Revoke the active API key for the user.
- Get information about all requests made to the API
GET /api/requests
- Get information about all requests made to the API.
-
Analyze how similar two texts are using Jaro-Winkler distance
POST /api/services/similarity
- Analyze the similarity between two texts using the Jaro-Winkler distance algorithm.
-
Analyze the sentiment of a given text
POST /api/services/sentiment
- Analyze the sentiment of a given text and return the sentiment score.
-
Check if two words are phonetically similar
POST /api/services/phonetics
- Check if two words are phonetically similar and return a boolean result.
Contributions are welcome! Here are the steps to contribute to the Sentrimetric API project:
- Fork the repository.
- Create a new branch for your feature or bug fix:
git checkout -b feature/your-feature-name
orgit checkout -b bugfix/your-bug-fix-name
. - Commit your changes:
git commit -m 'Add some feature'
orgit commit -m 'Fix some bug'
. - Push to the branch:
git push origin feature/your-feature-name
orgit push origin bugfix/your-bug-fix-name
. - Submit a pull request to the
main
branch of the original repository.
Please make sure to update tests, if applicable, and adhere to the existing code style and guidelines.
This project is licensed under the MIT License.
Feel free to modify this README.md file to fit your project's specific details and requirements.