arymandeshwal commited on
Commit
a353db0
ยท
1 Parent(s): 4a580fb

fix: HF Spaces deployment

Browse files
Dockerfile CHANGED
@@ -1,9 +1,8 @@
1
  # Multi-stage Dockerfile for Hugging Face Spaces
2
- # This combines both frontend and backend into a single container
3
 
4
  # Stage 1: Build frontend
5
  FROM node:20-alpine AS frontend-builder
6
-
7
  WORKDIR /app/frontend
8
  COPY frontend/package*.json ./
9
  RUN npm ci
@@ -16,11 +15,15 @@ FROM python:3.11-slim
16
  # Install system dependencies
17
  RUN apt-get update && apt-get install -y \
18
  gcc \
 
19
  nginx \
20
  supervisor \
21
  curl \
22
  && rm -rf /var/lib/apt/lists/*
23
 
 
 
 
24
  # Set working directory
25
  WORKDIR /app
26
 
@@ -34,7 +37,7 @@ COPY backend/ ./backend/
34
  # Copy built frontend to nginx directory
35
  COPY --from=frontend-builder /app/frontend/dist /usr/share/nginx/html
36
 
37
- # Create nginx configuration for Hugging Face Spaces
38
  RUN echo 'server { \n\
39
  listen 7860; \n\
40
  server_name localhost; \n\
@@ -53,12 +56,18 @@ RUN echo 'server { \n\
53
  proxy_set_header X-Real-IP $remote_addr; \n\
54
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; \n\
55
  proxy_set_header X-Forwarded-Proto $scheme; \n\
 
 
56
  } \n\
57
- }' > /etc/nginx/sites-available/default
 
 
 
58
 
59
  # Create supervisor configuration
60
  RUN echo '[supervisord] \n\
61
  nodaemon=true \n\
 
62
  \n\
63
  [program:backend] \n\
64
  command=python -m uvicorn backend.app.main:app --host 0.0.0.0 --port 8000 \n\
@@ -77,11 +86,18 @@ redirect_stderr=true \n\
77
  stdout_logfile=/dev/stdout \n\
78
  stdout_logfile_maxbytes=0' > /etc/supervisor/conf.d/supervisord.conf
79
 
80
- # Create data directory for SQLite
81
- RUN mkdir -p /app/data
 
 
 
 
 
 
 
82
 
83
  # Hugging Face Spaces expects port 7860
84
  EXPOSE 7860
85
 
86
  # Start both services with supervisor
87
- CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
 
1
  # Multi-stage Dockerfile for Hugging Face Spaces
2
+ # Combines frontend and backend into a single container
3
 
4
  # Stage 1: Build frontend
5
  FROM node:20-alpine AS frontend-builder
 
6
  WORKDIR /app/frontend
7
  COPY frontend/package*.json ./
8
  RUN npm ci
 
15
  # Install system dependencies
16
  RUN apt-get update && apt-get install -y \
17
  gcc \
18
+ g++ \
19
  nginx \
20
  supervisor \
21
  curl \
22
  && rm -rf /var/lib/apt/lists/*
23
 
24
+ # Create non-root user for HF Spaces
25
+ RUN useradd -m -u 1000 user
26
+
27
  # Set working directory
28
  WORKDIR /app
29
 
 
37
  # Copy built frontend to nginx directory
38
  COPY --from=frontend-builder /app/frontend/dist /usr/share/nginx/html
39
 
40
+ # Create nginx configuration
41
  RUN echo 'server { \n\
42
  listen 7860; \n\
43
  server_name localhost; \n\
 
56
  proxy_set_header X-Real-IP $remote_addr; \n\
57
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; \n\
58
  proxy_set_header X-Forwarded-Proto $scheme; \n\
59
+ proxy_read_timeout 300s; \n\
60
+ proxy_connect_timeout 300s; \n\
61
  } \n\
62
+ }' > /etc/nginx/conf.d/default.conf
63
+
64
+ # Remove default nginx config that listens on port 80
65
+ RUN rm -f /etc/nginx/sites-enabled/default 2>/dev/null || true
66
 
67
  # Create supervisor configuration
68
  RUN echo '[supervisord] \n\
69
  nodaemon=true \n\
70
+ user=root \n\
71
  \n\
72
  [program:backend] \n\
73
  command=python -m uvicorn backend.app.main:app --host 0.0.0.0 --port 8000 \n\
 
86
  stdout_logfile=/dev/stdout \n\
87
  stdout_logfile_maxbytes=0' > /etc/supervisor/conf.d/supervisord.conf
88
 
89
+ # Create persistent data directory and set permissions
90
+ RUN mkdir -p /data && chown -R 1000:1000 /data
91
+ RUN chown -R 1000:1000 /app
92
+ RUN chown -R 1000:1000 /usr/share/nginx/html
93
+ RUN touch /var/run/nginx.pid && chown 1000:1000 /var/run/nginx.pid
94
+ RUN chown -R 1000:1000 /var/log/nginx /var/lib/nginx
95
+
96
+ # Set environment for database path
97
+ ENV DATABASE_PATH=/data/project_memory.db
98
 
99
  # Hugging Face Spaces expects port 7860
100
  EXPOSE 7860
101
 
102
  # Start both services with supervisor
103
+ CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
README copy.md ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: ProjectMemory
3
+ emoji: โšก
4
+ colorFrom: red
5
+ colorTo: indigo
6
+ sdk: docker
7
+ pinned: false
8
+ license: mit
9
+ short_description: Semantic, shared AI project memory.
10
+ tags:
11
+ - building-mcp-track-enterprise
12
+ ---
13
+
14
+
15
+ ## ๐ŸŽฏ Track 1: Building MCP - Enterprise Category
16
+
17
+ **Project Memory** is a multi-user, multi-project AI memory system powered by MCP (Model Context Protocol). It creates shared project memory where every action gets logged and becomes searchable via semantic search and AI chat.
18
+
19
+ ## ๐Ÿš€ What We Built
20
+
21
+ An MCP server that extends LLM capabilities for enterprise teams by:
22
+ - **Persistent Project Memory**: Every task completion generates AI documentation that becomes searchable knowledge
23
+ - **Semantic Search**: Vector-based memory retrieval across all project activities
24
+ - **MCP Tool Integration**: Exposes project management capabilities as MCP tools
25
+ - **Multi-User Collaboration**: Teams can share and search collective knowledge
26
+
27
+ ## ๐Ÿ› ๏ธ MCP Tools Exposed
28
+
29
+ Our MCP server provides these tools:
30
+ - `create_project`: Initialize a new project workspace
31
+ - `list_projects`: View all available projects
32
+ - `join_project`: Join an existing project
33
+ - `list_tasks`: Get project tasks with status
34
+ - `complete_task`: Mark task as done with AI-generated documentation
35
+ - `memory_search`: Semantic search across project history
36
+ - `list_activity`: View project activity feed
37
+
38
+ ## ๐Ÿ“น Demo Video
39
+
40
+ [Watch our 3-minute demo showing MCP integration with Claude Desktop](#) *(link to be added)*
41
+
42
+ ## ๐Ÿ—๏ธ Architecture
43
+
44
+ ```
45
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
46
+ โ”‚ Web Frontend โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚ FastAPI Backend โ”‚
47
+ โ”‚ (React) โ”‚ โ”‚ (MCP Client) โ”‚
48
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
49
+ โ”‚
50
+ โ–ผ
51
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
52
+ โ”‚ MCP Server โ”‚
53
+ โ”‚ (TypeScript) โ”‚
54
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
55
+ โ”‚
56
+ โ–ผ
57
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
58
+ โ”‚ SQLite + Vec โ”‚
59
+ โ”‚ (Embeddings) โ”‚
60
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
61
+ ```
62
+
63
+ ## ๐Ÿ’ก Key Features
64
+
65
+ 1. **Task Completion Pipeline**: Transforms user work into searchable documentation
66
+ 2. **Vector Search**: Semantic retrieval using sqlite-vec embeddings
67
+ 3. **Chat Interface**: Natural language queries using MCP tools
68
+ 4. **Activity Feed**: Real-time project activity tracking
69
+ 5. **Multi-Project Support**: Manage multiple projects with isolated memory
70
+
71
+ ## ๐Ÿ”ง Technical Stack
72
+
73
+ - **MCP Server**: TypeScript with @modelcontextprotocol/sdk
74
+ - **Backend**: FastAPI (Python) as MCP client
75
+ - **Frontend**: React + Vite + Tailwind CSS
76
+ - **Database**: SQLite with sqlite-vec for embeddings
77
+ - **AI**: Google Generative AI (Gemini) for documentation generation
78
+ - **Deployment**: Docker container for Hugging Face Spaces
79
+
80
+ ## ๐ŸŽฎ How to Use
81
+
82
+ 1. **Create or Join a Project**: Start by creating a new project or joining an existing one
83
+ 2. **Complete Tasks**: Mark tasks as done and provide context about your work
84
+ 3. **AI Documentation**: System automatically generates searchable documentation
85
+ 4. **Search Memory**: Use semantic search to find any past work or decision
86
+ 5. **Chat with Memory**: Ask questions about project history using natural language
87
+
88
+ ## ๐Ÿšข Deployment
89
+
90
+ This Space runs as a Docker container combining:
91
+ - FastAPI backend serving as MCP client
92
+ - React frontend for user interface
93
+ - MCP server handling all tool operations
94
+ - SQLite database with vector search capabilities
95
+
96
+ ## ๐Ÿ” Environment Variables
97
+
98
+ Configure in Space settings:
99
+ - `GOOGLE_API_KEY`: For Gemini AI integration
100
+ - `DATABASE_URL`: (Optional) Custom database connection
101
+
102
+ ## ๐Ÿ‘ฅ Team
103
+
104
+ Aryman235 (Aryman Deshwal)
105
+ AmalNLal (Amal Nimmy Lal)
106
+
107
+
108
+ ## ๐Ÿ“ License
109
+
110
+ MIT License - See LICENSE file for details
111
+
112
+ ## ๐Ÿ”— Links
113
+
114
+ - [GitHub Repository](https://github.com/YOUR_USERNAME/project-memory)
115
+ - [MCP Documentation](https://modelcontextprotocol.io)
116
+ - [Hackathon Page](https://huggingface.co/MCP-1st-Birthday)
backend/app/database.py CHANGED
@@ -3,9 +3,10 @@
3
  from sqlalchemy import create_engine
4
  from sqlalchemy.orm import sessionmaker, declarative_base
5
  from pathlib import Path
 
6
 
7
- # Database file location
8
- DB_PATH = Path(__file__).parent.parent / "project_memory.db"
9
  DATABASE_URL = f"sqlite:///{DB_PATH}"
10
 
11
  # Create engine with SQLite-specific settings
 
3
  from sqlalchemy import create_engine
4
  from sqlalchemy.orm import sessionmaker, declarative_base
5
  from pathlib import Path
6
+ import os
7
 
8
+ # Database file location - use env var for HF Spaces persistence
9
+ DB_PATH = os.environ.get("DATABASE_PATH", str(Path(__file__).parent.parent / "project_memory.db"))
10
  DATABASE_URL = f"sqlite:///{DB_PATH}"
11
 
12
  # Create engine with SQLite-specific settings
backend/app/main.py CHANGED
@@ -72,11 +72,10 @@ app = FastAPI(
72
  lifespan=lifespan
73
  )
74
 
75
- # Configure CORS
76
- frontend_url = os.getenv("FRONTEND_URL", "http://localhost:5173")
77
  app.add_middleware(
78
  CORSMiddleware,
79
- allow_origins=[frontend_url, "http://localhost:5173", "http://localhost:3000"],
80
  allow_credentials=True,
81
  allow_methods=["*"],
82
  allow_headers=["*"],
 
72
  lifespan=lifespan
73
  )
74
 
75
+ # Configure CORS - allow all origins for HF Spaces
 
76
  app.add_middleware(
77
  CORSMiddleware,
78
+ allow_origins=["*"],
79
  allow_credentials=True,
80
  allow_methods=["*"],
81
  allow_headers=["*"],
backend/app/vectorstore.py CHANGED
@@ -3,9 +3,10 @@ import sqlite_vec
3
  import struct
4
  from typing import Optional
5
  import os
 
6
 
7
- # Database path - same as main SQLite database
8
- DB_PATH = os.path.join(os.path.dirname(__file__), "..", "project_memory.db")
9
 
10
 
11
  def _serialize_vector(vec: list[float]) -> bytes:
 
3
  import struct
4
  from typing import Optional
5
  import os
6
+ from pathlib import Path
7
 
8
+ # Database path - use env var for HF Spaces persistence
9
+ DB_PATH = os.environ.get("DATABASE_PATH", str(Path(__file__).parent.parent / "project_memory.db"))
10
 
11
 
12
  def _serialize_vector(vec: list[float]) -> bytes: