{"id":16770171,"url":"https://github.com/irishdan/chat-bot-api","last_synced_at":"2025-08-30T09:35:40.040Z","repository":{"id":217402014,"uuid":"741659476","full_name":"irishdan/chat-bot-api","owner":"irishdan","description":"NestJs Ai chat bot api","archived":false,"fork":false,"pushed_at":"2025-04-09T20:09:01.000Z","size":243,"stargazers_count":6,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T20:08:49.416Z","etag":null,"topics":["aws","cdk","cqrs","ddd","langchain","nestjs","ollama","openai","prisma"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/irishdan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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,"zenodo":null}},"created_at":"2024-01-10T21:06:21.000Z","updated_at":"2025-04-09T20:09:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"d1ae9761-1084-4c66-9aee-71ab064f7226","html_url":"https://github.com/irishdan/chat-bot-api","commit_stats":null,"previous_names":["irishdan/chat-bot-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/irishdan/chat-bot-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irishdan%2Fchat-bot-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irishdan%2Fchat-bot-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irishdan%2Fchat-bot-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irishdan%2Fchat-bot-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/irishdan","download_url":"https://codeload.github.com/irishdan/chat-bot-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/irishdan%2Fchat-bot-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272833294,"owners_count":25000870,"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","status":"online","status_checked_at":"2025-08-30T02:00:09.474Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["aws","cdk","cqrs","ddd","langchain","nestjs","ollama","openai","prisma"],"created_at":"2024-10-13T06:22:56.041Z","updated_at":"2025-08-30T09:35:39.983Z","avatar_url":"https://github.com/irishdan.png","language":"TypeScript","readme":"# Minimal AI Chat API\n\nThis API is a starting point for building AI chat applications! It's built in Typescript with [NestJs](https://nestjs.com).\n\n## Getting started\n\n- Ensure docker is running on your machine\n- Copy .env.dist to .env and set api keys as needed\n- Install dependencies:\n```\n    yarn install\n```\n- Start containers and run migrations:\n```\n    yarn docker:up\n    yarn prisma:migrate\n    yarn prisma:generate\n```\n- Start the application:\n\n```\n    yarn dev\n```\n\n### Creating a chat\n- POST /chats with a title for the chat\n```json\n{\n  \"title\": \"test chat\"\n}\n```\n- GET /chats/{id}/stream and subscribe to the SSE stream on the front end\n- POST /chats/{id}/messages with a message\n```json\n{\n  \"message\": \"where is my mind?\"\n}\n```\n- If you have subscribed to the SSE stream you should see a response from the AI streamed to the front end\n- POST /chats/{id}/messages again to continue the conversation\n- The full openapi spec is [here](docs/openapi/open-api.yml)\n\n## API Architecture\n\nThe API loosely follows the principles of Domain-Driven Design (DDD) and Command Query Responsibility Segregation (CQRS).\n\n### Modules (or Domains)\nNestJS promotes a modular structure. \nEach domain or bounded context can be represented as a module. \nEach module then has its application, domain, and infrastructure layers.\n\n#### Application Layer\nThis contains commands, queries, and their respective handlers. It's also where DTOs (Data Transfer Objects) are defined.\n\n#### Domain Layer\nThis includes your core business logic - entities (or aggregates), value objects, domain services, events, and domain-specific interfaces for repositories and providers.\n\n#### Infrastructure Layer\nHouses technical implementations such as controllers (for HTTP routes), concrete repository implementations, and other providers.\n\n### Directory Structure\nThe directory structure maintains the separation of concerns recommended by DDD while leveraging NestJS's modular system to organize code around domain boundaries effectively.\n\n```yaml\n|-- /src\n|   |   /ai (domain module)\n|   |   |-- /application\n|   |   |   |-- /command\n|   |   |   |   |-- commands and command handlers\n|   |   |   |-- /query\n|   |   |   |   |-- queries and query handlers, DTOs, DTO providers and response builders\n|   |   |-- /domain\n|   |   |   |-- /model\n|   |   |   |   |-- models and repository interfaces, provider interfaces\n|   |   |   |-- /service\n|   |   |   |   |-- domain services\n|   |   |-- /infrastructure\n|   |   |   |-- /persistence\n|   |   |   |   |-- repository implementations\n|   |   |   |-- /controllers\n|   |   |   |   |-- controllers for HTTP routes\n|   |   |   |-- /providers\n|   |   |   |   |-- third party providers\n|   |   /common (cross-cutting concerns, shared utilities, core functionality)\n|   |   |-- ... (similar structure as above)\n```\n\n## Large Language Model\n\nOut of the box the API uses the OpenAiChatResponseProvider which uses the OpenAI API to generate responses. \nThere's also a LangChainChatResponseProvider which uses the [LangChainJs](https://js.langchain.com/) library and a HuggingFaceChatResponseProvider which uses the HuggingFace API. \nOllama is supported with the OllamaChatResponseProvider also.\nThese providers implement the ChatResponseProvider interface and can be swapped around easily using dependency injection.\n\n## Persistence\n\nOut of the box the API uses a Postgres database with Prisma as the ORM. This is also easily swappable.\n\n## Caching\n\nAs part of the Query side of CQRS, the API uses Redis to cache all DTO's for lightning-fast responses. \nThe LangChainOpenAiRedisBufferChatResponseProvider uses Redis and memory to cache message history and responses from the OpenAI API.\n\n## API Specification\n\nThe rest API is documented using Swagger [here](docs/openapi/open-api.yml) \n\n## Deploying to AWS\n\nAn AWS CDK application is included in the AWS directory. \nThis will deploy the API to AppRunner with an RDS database and an ElastiCache Redis cluster in a custom VPC.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Firishdan%2Fchat-bot-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Firishdan%2Fchat-bot-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Firishdan%2Fchat-bot-api/lists"}