Skip to content

refactor: Refactor project structure for maintainability & modularity #309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
107 changes: 0 additions & 107 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[![Twitter/X](https://img.shields.io/badge/Twitter-1DA1F2?style=for-the-badge&logo=twitter&logoColor=white)](https://x.com/sashimikun_void)
[![Discord](https://img.shields.io/badge/Discord-7289DA?style=for-the-badge&logo=discord&logoColor=white)](https://discord.com/invite/VQMBGR8u5v)

[English](./README.md) | [简体中文](./README.zh.md) | [繁體中文](./README.zh-tw.md) | [日本語](./README.ja.md) | [Español](./README.es.md) | [한국어](./README.kr.md) | [Tiếng Việt](./README.vi.md) | [Português Brasileiro](./README.pt-br.md) | [Français](./README.fr.md) | [Русский](./README.ru.md)
[English](./docs/README.md) | [简体中文](./docs/README.zh.md) | [繁體中文](./docs/README.zh-tw.md) | [日本語](./docs/README.ja.md) | [Español](./docs/README.es.md) | [한국어](./docs/README.kr.md) | [Tiếng Việt](./docs/README.vi.md) | [Português Brasileiro](./docs/README.pt-br.md) | [Français](./docs/README.fr.md) | [Русский](./docs/README.ru.md)

## ✨ Features

Expand Down
File renamed without changes.
18 changes: 18 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# backend/Dockerfile
FROM python:3.11-slim
WORKDIR /app

# Install Python dependencies
COPY backend/api/requirements.txt ./api/
RUN python -m venv /opt/venv && \
/opt/venv/bin/pip install --no-cache -r api/requirements.txt

# Copy source
COPY backend/api/ ./api/

ENV PATH="/opt/venv/bin:$PATH"
ENV PORT=8001

# A health-check endpoint should be implemented in FastAPI
EXPOSE 8001
CMD ["sh", "-c", "uvicorn api.api:app --host 0.0.0.0 --port ${PORT}"]
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The use of sh -c in CMD can lead to issues with signal handling, as the shell might not forward signals to the uvicorn process, preventing a graceful shutdown. To ensure graceful shutdowns, you can use exec to replace the shell process with the uvicorn process. Also, the file should end with a newline character for POSIX compatibility.

CMD ["sh", "-c", "exec uvicorn api.api:app --host 0.0.0.0 --port ${PORT}"]

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
44 changes: 25 additions & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
version: '3.8'

services:
deepwiki:
backend:
build:
context: .
dockerfile: Dockerfile
dockerfile: backend/Dockerfile
container_name: deepwiki-backend
ports:
- "${PORT:-8001}:${PORT:-8001}" # API port
- "3000:3000" # Next.js port
- "8001:8001"
env_file:
- .env
Comment on lines 11 to 12
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The new backend service is missing the volumes and resource limits (mem_limit, mem_reservation) that were present in the old deepwiki service.

  • Volumes: The removed volumes (~/.adalflow:/root/.adalflow and ./api/logs:/app/api/logs) were responsible for persisting repository data, embeddings, and logs. Without them, all this data will be lost when the container is stopped or restarted. This is likely a critical regression.
  • Resource Limits: The memory limits helped ensure the container doesn't consume excessive resources.

I recommend re-adding these configurations to the backend service to ensure data persistence and resource management.

    env_file:
      - .env
    volumes:
      - ~/.adalflow:/root/.adalflow      # Persist repository and embedding data
      - ./backend/api/logs:/app/api/logs # Persist log files across container restarts
    mem_limit: 6g
    mem_reservation: 2g

environment:
- PORT=${PORT:-8001}
- NODE_ENV=production
- SERVER_BASE_URL=http://localhost:${PORT:-8001}
- LOG_LEVEL=${LOG_LEVEL:-INFO}
- LOG_FILE_PATH=${LOG_FILE_PATH:-api/logs/application.log}
volumes:
- ~/.adalflow:/root/.adalflow # Persist repository and embedding data
- ./api/logs:/app/api/logs # Persist log files across container restarts
# Resource limits for docker-compose up (not Swarm mode)
mem_limit: 6g
mem_reservation: 2g
# Health check configuration
- ./backend/api/logs:/app/api/logs # Persist log files across container restarts
Comment on lines 11 to +15
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The backend service configuration is missing some environment variables (LOG_LEVEL, LOG_FILE_PATH) and resource limits (mem_limit, mem_reservation) that were present in the original deepwiki service. While these might be set in the .env file, explicitly defining them with defaults in the compose file improves clarity and makes the service more resilient. Resource limits are also important for production stability.

    env_file:
      - .env
    environment:
      - LOG_LEVEL=${LOG_LEVEL:-INFO}
      - LOG_FILE_PATH=${LOG_FILE_PATH:-/app/api/logs/application.log}
    volumes:
      - ~/.adalflow:/root/.adalflow      # Persist repository and embedding data
      - ./backend/api/logs:/app/api/logs # Persist log files across container restarts
    mem_limit: 6g
    mem_reservation: 2g

healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:${PORT:-8001}/health"]
interval: 60s
timeout: 10s
test: ["CMD-SHELL", "curl -f http://localhost:8001/health || exit 1"]
interval: 30s
timeout: 5s
retries: 3
start_period: 30s

frontend:
build:
context: .
dockerfile: frontend/Dockerfile
container_name: deepwiki-frontend
ports:
- "3000:3000"
environment:
- NODE_ENV=production
Comment on lines +29 to +30
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The frontend service needs to know how to communicate with the backend service. The next.config.ts file uses the SERVER_BASE_URL environment variable for this, but it's not set for the frontend service.

Without it, the frontend will default to http://localhost:8001, which will not resolve to the backend container. You should set SERVER_BASE_URL to http://backend:8001 so the frontend can reach the backend service within the Docker network.

    environment:
      - NODE_ENV=production
      - SERVER_BASE_URL=http://backend:8001

Comment on lines +29 to +30
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The frontend service needs to communicate with the backend service. The next.config.ts file uses process.env.SERVER_BASE_URL with a fallback to http://localhost:8001. Inside the frontend container, localhost refers to the container itself, not the backend container. To fix this, you should set SERVER_BASE_URL to http://backend:8001 in the frontend service's environment, as the services are on the same Docker network.

    environment:
      - NODE_ENV=production
      - SERVER_BASE_URL=http://backend:8001

depends_on:
backend:
condition: service_healthy

networks:
default:
driver: bridge
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading