Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"@ifinho/db": "*",
"@ifinho/env": "*",
"bullmq": "^5.70.1",
"cors": "^2.8.5",
"dotenv": "^17.2.2",
"express": "^5.1.0",
Expand Down
10 changes: 10 additions & 0 deletions apps/server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { env } from "@ifinho/env/server";
import cors from "cors";
import express from "express";
import { chatQueue } from "./queue";
import "./worker";
import { Ollama } from "ollama";

const app = express();
Expand Down Expand Up @@ -123,6 +125,14 @@ app.post("/api/chat", async (req, res) => {
}
});

app.post("/api/queue", async (req, res) => {
const { message } = req.body;

await chatQueue.add("chat-message", { message });

res.status(200).json({ ok: true });
});

app.listen(3000, () => {
console.log("Server is running on http://localhost:3000");
});
8 changes: 8 additions & 0 deletions apps/server/src/queue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { env } from "@ifinho/env/server";
import { Queue } from "bullmq";

export const chatQueue = new Queue("chat", {
connection: {
url: env.REDIS_URL,
},
});
27 changes: 27 additions & 0 deletions apps/server/src/worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { env } from "@ifinho/env/server";
import { Worker } from "bullmq";

export const chatWorker = new Worker(
"chat",
async (job) => {
console.log(`Processando mensagem: ${job.data.message}`);

// Aqui vai entrar futuramente:
// 1. Buscar no banco vetorial (RAG)
// 2. Mandar pra IA
// 3. Retornar a resposta
},
{
connection: {
url: env.REDIS_URL,
},
},
);

chatWorker.on("completed", (job) => {
console.log(`Mensagem ${job.id} processada com sucesso!`);
});

chatWorker.on("failed", (job, error) => {
console.log(`Mensagem ${job?.id} falhou: ${error.message}`);
});
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ services:
networks:
- ifinho-network

redis:
container_name: ifinho-redis
image: redis:7-alpine
restart: unless-stopped
ports:
- "6379:6379"
networks:
- ifinho-network
Comment on lines +33 to +40
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redis was added, but the server container is not being given REDIS_URL and does not depend on redis. Since @ifinho/env/server now requires REDIS_URL, the server will fail to start under this compose file. Add REDIS_URL to the server.environment (e.g., redis://ifinho-redis:6379) and consider adding a depends_on/healthcheck for Redis.

Copilot uses AI. Check for mistakes.


server:
container_name: ifinho-server
build:
Expand All @@ -42,11 +52,16 @@ services:
DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@ifinho-postgres:5432/${POSTGRES_DB}
CORS_ORIGIN: ${CORS_ORIGIN:-http://localhost}
OLLAMA_BASE_URL: http://ifinho-ollama:11434
REDIS_URL: redis://ifinho-redis:6379
OLLAMA_MODEL: ${OLLAMA_MODEL:-llama3.2}
NODE_ENV: production
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_started
ports:
- "3000:3000"
networks:
- ifinho-network

Expand All @@ -68,6 +83,7 @@ services:
volumes:
ifinho-postgres-data:
ifinho-ollama-data:
ifinho-redis-data:

networks:
ifinho-network:
Expand Down
Loading