- Node.js (v22.x)
- TypeScript
- pnpm (package manager)
- PostgreSQL
- Ollama (LLM integration)
- Docker & Docker Compose
- Express.js
- Prisma ORM
- ESLint & Prettier (code quality) (Prettier)
- nginx - Used in Production Docker container
- Vitest
git clone <repo-url>
cd ai-chat-backendMake sure you have pnpm installed:
pnpm installCreate a .env file in the root directory with the following variables:
APP_PORT=<port that will used to start the server>
FRONTEND_ALLOWED_URL=<frontend app allowed url>
OLLAMA_HOST=<host where ollama server will run>
OLLAMA_PORT=<port where ollama server will run>
MODEL_ID=<ollama llm model id>
DB_NAME=<database name>
DB_USER=<database user name>
DB_PASSWORD=<database user password>
DB_PORT=<database port>
DATABASE_URL=<database connection string for ORM>Adjust values as needed for your setup.
By default the values are:
APP_PORT=3000
FRONTEND_ALLOWED_URL=http://localhost:5173
OLLAMA_HOST=ollama
OLLAMA_PORT=11434
MODEL_ID=llama3.2:latest
DB_NAME=ai_chat
DB_USER=postgres
DB_PASSWORD=12345
DB_PORT=5432
DATABASE_URL="postgresql://postgres:12345@postgres-db:5432/ai_chat?schema=public"Make sure you have Ollama installed locally. In a separate terminal, run:
ollama serveThis will start the Ollama LLM server required by the backend.
Make sure you have PostgreSQL running and the credentials match your .env file.
Run migrations and generate Prisma client:
pnpm db:migrate:devpnpm db:seedpnpm devThe server will start on http://localhost:3000 by default.
7. Run Prisma Studio Web UI
pnpm prisma-studiopnpm testor
pnpm test:watchpnpm docker:devThis will start:
- The backend app
- PostgreSQL database
- Ollama LLM service
- Prisma Studio Web UI
Ports will be gotten from .env file
Docker Compose will use the .env file in the root directory. Make sure it is set up as described above.
- API:
http://localhost:3000/api - Health check:
http://localhost:3000/api/health-check
pnpm docker:prodThis will start:
- nginx server gateway
- The backend app
- PostgreSQL database
- Ollama LLM service
Ports will be gotten from .env file
Docker Compose will use the .env file in the root directory. Make sure it is set up as described above.
- API:
http://localhost:80/api - Health check:
http://localhost:80/api/health-check
pnpm start- Start the backend in production modepnpm dev— Start the backend in development modepnpm db:migrate:dev— Run database migrations and generate Prisma client in Development environmentpnpm db:migrate:prod- Run database migrations and generate Prisma client in Production environmentpnpm db:seed- Run seed script to populate the databasepnpm lint— Lint the codebasepnpm format— Format the codebasepnpm prisma-studio- Run Prisma Studio Web UI to inspect models in the databasepnpm docker:dev- Run development Docker containerpnpm docker:prod- Run production Docker containerpnpm test- Run tests oncepnpm test:watch- Run tests in the watch modepnpm test:coverage- Display test coveragepnpm test:ui- Run vitest ui