{"id":17717147,"url":"https://github.com/willacosta/genai-langchain-api","last_synced_at":"2026-04-14T10:32:08.679Z","repository":{"id":259232578,"uuid":"858234541","full_name":"WillACosta/genai-langchain-api","owner":"WillACosta","description":"This is an Express service that provides authorization functionality and includes gen-AI features using RAG and Redis.","archived":false,"fork":false,"pushed_at":"2024-10-23T15:48:36.000Z","size":533,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-23T18:31:14.374Z","etag":null,"topics":["ai","artificial-intelligence","docker","docker-compose","express","langchain","langchain-js","llm","nodejs","rag","redis","redis-database","vector-database"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WillACosta.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-16T14:43:28.000Z","updated_at":"2024-10-23T15:51:51.000Z","dependencies_parsed_at":"2024-10-23T18:36:22.064Z","dependency_job_id":"f7b97d2e-37ca-48f8-9923-bab4a60e915b","html_url":"https://github.com/WillACosta/genai-langchain-api","commit_stats":null,"previous_names":["willacosta/genai-langchain-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/WillACosta/genai-langchain-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WillACosta%2Fgenai-langchain-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WillACosta%2Fgenai-langchain-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WillACosta%2Fgenai-langchain-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WillACosta%2Fgenai-langchain-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WillACosta","download_url":"https://codeload.github.com/WillACosta/genai-langchain-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WillACosta%2Fgenai-langchain-api/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263885745,"owners_count":23525152,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","artificial-intelligence","docker","docker-compose","express","langchain","langchain-js","llm","nodejs","rag","redis","redis-database","vector-database"],"created_at":"2024-10-25T14:11:54.561Z","updated_at":"2026-04-14T10:32:08.634Z","avatar_url":"https://github.com/WillACosta.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Gen-AI API with Langchain and NodeJS\n\nThis is an Express service written in [TypeScript](https://www.typescriptlang.org/) that provides authorization functionality and includes gen-AI features, using RAG concepts, vector database and implements AI memory history with Redis DB.\n\n![Swagger UI screenshot](docs/docs-screenshot.jpeg 'Swagger UI screenshot')\n\n## Resources\n\n- [Express](https://expressjs.com/) and [Node](https://nodejs.org/en/) for creating backend service.\n- [LangChain](https://js.langchain.com/docs/introduction/) for handling LLM and RAG functionality.\n- [JWT](https://jwt.io/) for handling authentication\n- [GoogleGenAI langchain](https://v02.api.js.langchain.com/modules/_langchain_google_genai.html) plugin.\n- [Google Gemini - API](https://ai.google.dev/)\n- [Docker](https://docs.docker.com/) containers for setting up environment.\n- [Redis](https://redis.io/) database for storing AI messages.\n- [ZOD](https://zod.dev/) as body parameters validation.\n- [PostgreSQL](https://www.postgresql.org/) database for store user data\n- [Prisma ORM](https://www.prisma.io/) for managing the database\n- Automated [OpenAPI](https://www.openapis.org/what-is-openapi) specifications using [JsDocs](https://jsdoc.app/) and [Swagger UI](https://swagger.io/tools/swagger-ui/) for generating documentation.\n- [Role-Based Access Control (RBAC)](https://www.redhat.com/en/topics/security/what-is-role-based-access-control) for managing API resources\n- Rotate Logs using [Winston](https://github.com/winstonjs/winston)\n\n## Project Structure\n\n```yaml\ncommon: common code and utilities for all modules\ndi: dependency injection container\nmodules: application features\n  module_name:\n    adapters: class adapters for external resources\n      dataproviders:\n      services:\n\n    application: application layer for controllers and routes\n      controllers:\n      routes:\n\n    core: application core logic\n      entities:\n      usecases:\n      utils: class and constant utilities for this module\n```\n\n### Search In Documents Flow\n\nTo perform a search in documents and ask questions about them, we have two endpoints for that:\n\n- `POST /resources/docs`\n- `POST /genai/search-in-documents`\n\nOn `/resources/docs` the documents are uploaded to local system and then broke down into small chunks to be stored on a vector database.\n\nThe `/genai/search-in-documents` endpoint uses RAG concept, it's responsible to create an Embedding of the user question, and retrieve the most relevant chunks from vector database using it as context for follow-up questions. Also, it uses Redis to store and retrieve chat history during user's session.\n\nCheck this process on the diagram below:\n\n![GenAI Search in Document Flow](docs/genai-flow.png 'GenAI Search in Document Flow')\n\n## Prerequisites\n\nBefore running the application, make sure you have the following installed:\n\n- NodeJS (v20.12.1)\n- PNPM (v9.7.0)\n- Docker (v27.2.0)\n\n## Running the application\n\n1. Clone this repository\n\n```shell\ngit clone https://github.com/WillACosta/genai-langchain-api\n```\n\n\u003e Copy the `.env.example` file to `.env` and fill it with your own credentials. Get here:\n\u003e [Google Gemini](https://ai.google.dev/) | [LangChain](https://js.langchain.com/docs/introduction/)\n\n```shell\ncp .env.example .env\n```\n\n2. You'll need [Docker](https://docs.docker.com/) to setup and running the application services\n\n\u003e From the app's root directory, run the following command to build and running docker containers:\n\n```shell\nmake run\n```\n\n\u003e The application will be available at `http://localhost:3000`.\u003cbr\u003eFor more commands see `Makefile` or run `make help`.\n\n## Documentation\n\nThe documentation process is automated using `swagger-ui-express` and `swagger-jsdoc` libraries, on each application route definition you will find a comment with the necessary specifications for that route in particular.\n\nDuring the build process the application will handle the route comments and generate the final `OpenApi` specification for the `Swagger UI`.\n\nAfter that you will be able to access: `localhost:3000/docs` in your browser and see the docs.\n\n\u003e The application will be available at `http://localhost:3000`.\n\n## Prisma ORM\n\nThis project uses Prisma ORM (Object-Relational Mapping), at every modifications related to the database schema,\na new migration is needed, create a new one running:\n\n```shell\nnpx prisma migrate dev\n```\n\nAfter that generate a new prisma client instance with:\n\n```shell\nnpx prisma generate\n```\n\n## Authenticating and RBAC\n\nThis project uses `jwt` for authenticating users and managing sessions. It also uses Role-Based Access Control to limit some aspects of the API, such as user management.\n\nCurrent supported roles are: [`admin`, `user`]:\n\n| Endpoint                       | Admin | User |\n| ------------------------------ | ----- | ---- |\n| GET users/                     | [x]   | [x]  |\n| PATCH users/                   | [x]   | [x]  |\n| PATCH users/change-role/:id    | [x]   |      |\n| GET users/all                  | [x]   |      |\n| DELETE users/:id               | [x]   |      |\n| GET status/                    | [x]   | [x]  |\n| POST /genai/translate          | [x]   | [x]  |\n| POST /genai/search-in-document | [x]   | [x]  |\n| GET /genai/chat-history        | [x]   | [x]  |\n| POST /resources/docs           | [x]   | [x]  |\n\n## Services Dashboards\n\nQdrant Dashboard: https://localhost:6333/dashboard\nPostgreSQL via Prisma: `npx prisma studio`\nRedis: Access via vs code extension [Redis for VS Code](https://redis.io/docs/latest/develop/tools/redis-for-vscode/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillacosta%2Fgenai-langchain-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillacosta%2Fgenai-langchain-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillacosta%2Fgenai-langchain-api/lists"}