使用说明
Uncover Learning – Knowledge Backend
Knowledge backend for Uncover Learning, a system that teaches users how to use software by combining screen overlays, LLM reasoning, and a structured documentation database.
Architecture
This repository contains:
- Firestore data model - Structured collections for apps, tasks, steps, UI screens, elements, and documentation
- Firebase Storage - File storage for screenshots, images, and other files
- TypeScript types - Type-safe interfaces for all data structures
- Service functions - Query functions that will be exposed as MCP tools or HTTP endpoints
- Seed scripts - Load JSON data into Firestore
Project Structure
.
├── src/
│ ├── types/ # TypeScript interfaces for Firestore documents
│ ├── firebase/ # Firebase Admin SDK initialization
│ ├── data/ # Loaders/parsers for local JSON files
│ ├── services/ # Firestore query logic (MCP tools)
│ └── scripts/ # One-off scripts (e.g., seeding)
├── data/ # Local JSON seed data
│ └── figma/ # Example app data
│ ├── app.json
│ ├── tasks/
│ ├── taskSteps/
│ ├── uiScreens/
│ ├── uiElements/
│ └── docSections/
└── dist/ # Compiled TypeScript output
Setup
-
Install dependencies:
npm install -
Configure Firebase:
- Set up Firebase project
- Create
.env.localfile (copy fromenv.local.template):# Required: Your Firebase project ID FIREBASE_PROJECT_ID=your-project-id-here # Option 1: Service account JSON (recommended) GOOGLE_APPLICATION_CREDENTIALS=C:\path\to\your-service-account-key.json # Option 2: Use gcloud CLI instead # Run: gcloud auth application-default login # Optional: OpenAI API key for embeddings-based semantic search # Get from: https://platform.openai.com/api-keys # OPENAI_API_KEY=sk-... - Get your project ID from Firebase Console → Project Settings → General
- Get service account key from Firebase Console → Project Settings → Service Accounts
- Optional: Add OpenAI API key for semantic search (see EMBEDDINGS.md)
-
Build:
npm run build
Usage
Seed Firestore
Seed data from local JSON files:
# Seed all apps
npm run seed
# Seed specific app
npm run seed figma
Service Functions
The service functions are available for use as MCP tools or HTTP endpoints:
Task & Documentation Services:
searchTasks(appId, goalText, limit?)- Search tasks by goal textgetTask(taskId)- Get a task with all its stepssearchDocs(appId, queryText, limit?)- Search documentation sections (uses embeddings if available)getUIScreen(appId, slug)- Get a UI screen with all its elements
Storage Services:
uploadFile(path, fileBuffer, metadata?)- Upload any file to Firebase StorageuploadScreenshot(appId, screenshotBuffer, userId?, metadata?)- Upload a screenshotgetSignedUrl(path, expiresIn?)- Get a signed URL for private filesdownloadFile(path)- Download a file from storagedeleteFile(path)- Delete a file from storagelistFiles(prefix, maxResults?)- List files in a directory
Example:
import { searchTasks, getTask, uploadScreenshot } from "./src/index.js";
// Search for tasks
const results = await searchTasks("figma", "create a frame");
console.log(results);
// Get full task details
const task = await getTask("task-doc-id");
console.log(task);
// Upload a screenshot
const screenshotBuffer = Buffer.from(/* screenshot data */);
const url = await uploadScreenshot("figma", screenshotBuffer, "user123");
console.log("Screenshot URL:", url);
Data Model
Firestore Collections
- apps - App metadata
- tasks - High-level learning flows
- taskSteps - Step-by-step instructions
- uiScreens - UI screen definitions
- uiElements - UI element definitions
- docSections - Chunked documentation
See src/types/index.ts for full type definitions.
Firebase Storage
Files are organized by path structure:
screenshots/{appId}/{userId}/{timestamp}.png- User screenshotsdocuments/{appId}/{filename}- App-specific documents- Custom paths as needed
All files can be made public or accessed via signed URLs for private access.
Development
- Type check:
npm run type-check - Build:
npm run build - Dev mode:
npm run dev(watch mode with tsx)
API Server
The backend includes a REST API server for easy integration with applications.
Start the Server
Development:
npm run dev:server
Production:
npm run build
npm start
The server runs on http://localhost:3000 by default (set PORT env var to change).
API Endpoints
GET /health- Health checkGET /api/apps- List all appsGET /api/apps/:appId/tasks- List tasks for an appGET /api/tasks/search?appId=figma&goalText=create frame- Search tasksGET /api/docs/search?appId=figma&query=export- Search documentation (semantic search)GET /api/apps/:appId/screens- List UI screensPOST /api/storage/screenshots?appId=figma- Upload screenshots
See API Documentation for complete endpoint reference.
Example Usage
// Search for tasks
const response = await fetch('http://localhost:3000/api/tasks/search?appId=figma&goalText=create frame');
const tasks = await response.json();
// Search documentation with semantic search (uses embeddings automatically)
const docs = await fetch('http://localhost:3000/api/docs/search?appId=figma&query=how to export').then(r => r.json());
📚 Want to connect embeddings to your app? See Connecting Embeddings Guide for detailed examples and integration instructions.
📦 Want to access Firebase Storage directly from your app? See Client Storage Access Guide for direct client-side access setup.
MCP Server
The backend includes an MCP (Model Context Protocol) server for AI assistants like Claude, Cursor, and VS Code.
Quick Start
-
Build the server:
npm run build -
Configure your MCP client (see MCP Setup Guide)
-
Start using it! Ask your AI assistant questions about Figma, and it will automatically query the knowledge base.
Available MCP Tools
list_apps- List all appssearch_tasks- Search for tasks by goalget_task_with_steps- Get step-by-step instructionssearch_docs- Semantic search documentationlist_ui_screens_for_app- List UI screensget_ui_screen_with_elements- Get screen details
See MCP Setup Guide for detailed configuration instructions.
Future Work
- Additional apps (VS Code, Notion, etc.)
- Authentication/authorization for API endpoints
- MCP resources for exposing data as resources
