Skip to content
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
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Stage 1: build frontend
FROM node:18 AS frontend-build
WORKDIR /app/frontend
COPY frontend/package*.json ./
# Use npm install to avoid CI lockfile/peer-deps failures during image build
RUN npm install --legacy-peer-deps
COPY frontend/ .
RUN npm run build

# Stage 2: build python image
FROM python:3.11-slim
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
WORKDIR /app

# system deps if needed
RUN apt-get update && apt-get install -y build-essential curl && rm -rf /var/lib/apt/lists/*

# copy requirements and install
COPY backend/requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir -r /app/requirements.txt

# lightweight ASGI server + async HTTP client for streaming
RUN pip install --no-cache-dir "uvicorn[standard]" httpx

# copy backend app
COPY backend/ /app/backend

# copy frontend build into Django static locations
# Place index.html under backend/static and the built JS/CSS under STATIC_ROOT
COPY --from=frontend-build /app/frontend/build/index.html /app/backend/static/index.html
COPY --from=frontend-build /app/frontend/build/static /app/backend/staticfiles

WORKDIR /app/backend
# run collectstatic to pick up any additional static files
ENV DJANGO_SETTINGS_MODULE=backend.settings
RUN mkdir -p /app/backend/staticfiles
RUN python manage.py collectstatic --noinput

EXPOSE 8000
# Run as ASGI server for non-blocking streaming (uvicorn + uvloop + httptools from uvicorn[standard])
CMD ["uvicorn", "backend.asgi:application", "--host", "0.0.0.0", "--port", "8000", "--workers", "1", "--loop", "uvloop", "--http", "httptools"]
5 changes: 4 additions & 1 deletion backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"corsheaders.middleware.CorsMiddleware",

'django.middleware.security.SecurityMiddleware',
"whitenoise.middleware.WhiteNoiseMiddleware",
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',

Expand All @@ -47,7 +48,7 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [BASE_DIR / 'static'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand Down Expand Up @@ -89,6 +90,8 @@

# ---------------- STATIC ----------------
STATIC_URL = 'static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'
STATICFILES_DIRS = [BASE_DIR / 'static']


# =====================================================
Expand Down
6 changes: 5 additions & 1 deletion backend/backend/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from django.contrib import admin
from django.urls import path, include
from django.urls import path, include, re_path
from django.views.generic import TemplateView

urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include('generator.urls')), # MUST be 'api/'
# Serve React app at root and for any non-API/admin path (client-side routing)
path('', TemplateView.as_view(template_name='index.html'), name='home'),
re_path(r'^(?!admin/|api/).*$', TemplateView.as_view(template_name='index.html')),
]
Binary file modified backend/db.sqlite3
Binary file not shown.
4 changes: 2 additions & 2 deletions backend/generator/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def generate_documentation(request):
user_model = request.data.get("model", "qwen2.5-coder:3b")

ALLOWED_MODELS = [
"phi3:mini",
"phi3:latest",
"qwen2.5-coder:3b",
"qwen2.5-coder:7b"
]
Expand Down Expand Up @@ -251,4 +251,4 @@ def download_pdf(request):
@api_view(["POST"])
def download_docx(request):
docs = request.data.get("docs", "")
return FileResponse(create_docx(docs), as_attachment=True, filename="Doc.docx")
return FileResponse(create_docx(docs), as_attachment=True, filename="Doc.docx")
10 changes: 10 additions & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Django
djangorestframework
django-cors-headers
requests
reportlab
gunicorn
whitenoise
djangorestframework-simplejwt
wikipedia
python-docx
22 changes: 22 additions & 0 deletions backend/stream_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import requests
import sys

url = "http://localhost:8000/api/generate/"
json = {
"code": "print(\"hello world\")",
"max_output_tokens": 256
}

try:
r = requests.post(url, json=json, stream=True, timeout=60)
print("STATUS", r.status_code)
r.raise_for_status()
for chunk in r.iter_content(chunk_size=None):
if chunk:
try:
s = chunk.decode()
except Exception:
s = str(chunk)
print(s, end='', flush=True)
except Exception as e:
print("ERROR", e)
6 changes: 4 additions & 2 deletions backend/users/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from django.urls import path
from .views import register, login_user, logout_user, profile

from .views import register, login_user, logout_user, profile,login_view
from rest_framework_simplejwt.views import TokenRefreshView
urlpatterns = [
path("register/", register),
path("login/", login_user),
path("logout/", logout_user),
path("profile/", profile),
path("api/login/", login_view),
path("api/token/refresh/", TokenRefreshView.as_view()),
]
30 changes: 30 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: "3.8"
services:
ollama:
image: ollama/ollama:latest # replace with trusted image if needed
container_name: ollama
ports:
- "11434:11434"
volumes:
- ollama_data:/root/.ollama
restart: unless-stopped

docgen:
build:
context: .
dockerfile: Dockerfile
image: rakshaknaik/docgen:latest
environment:
- OLLAMA_URL=http://ollama:11434/api/generate
- OLLAMA_MODEL=qwen2.5-coder:3b
- DJANGO_SETTINGS_MODULE=backend.settings
depends_on:
- ollama
ports:
- "8000:8000"
restart: unless-stopped
volumes:
- ./backend/db.sqlite3:/app/backend/db.sqlite3

volumes:
ollama_data:
34 changes: 34 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.2",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.13.4",
"framer-motion": "^12.31.0",
"lucide-react": "^0.563.0",
"react": "^19.2.4",
Expand Down
Loading