📂 Document Management
CICADA provides a comprehensive system for managing constitutional archives, distinguishing between private and public documents, and organizing them into folders.Key Features
-
Dual File Systems:
- Private: Documents uploaded here are associated with the authenticated user and are only accessible by them. Stored in the
documents_privatetable andprivate-filesstorage bucket. - Public: Documents uploaded here are accessible to anyone (read-only for unauthenticated users). Uploads and modifications are restricted to authenticated users. Stored in the
documents_publictable andpublic-filesstorage bucket. Public documents use a predefined set of categories as folders.
- Private: Documents uploaded here are associated with the authenticated user and are only accessible by them. Stored in the
-
Folder Structure:
- Private documents can be organized into user-created nested folders.
- Public documents are organized by predefined categories (e.g., ‘Supreme Court Cases’, ‘Legislation’).
- The
FolderTreecomponent (src/components/admin/file/FolderTree.tsx) allows navigation and management of these folders.
-
CRUD Operations:
- Create: Upload new documents via
UploadForm.tsx. Create new folders viaFolderDialog.tsx. - Read: View and search documents. Document details and previews are available in
SourceModal.tsx. - Update: Edit document metadata (title, description, tags, etc.) using
FileEditDialog.tsx. Edit folder names. - Delete: Delete files and folders, with confirmation dialogs.
- Create: Upload new documents via
-
Metadata:
- Each document can have associated metadata: title, description, tags, source, date, folder/category.
- AI-generated insights: summary, key sections, citations.
-
File Handling:
- Uploads are handled by
UploadForm.tsx, which interacts withdocumentService.ts(facade) and ultimatelyprivateDocumentService.tsorpublicDocumentService.ts. - Files are stored in Supabase Storage.
parseUploadedDocumentsEdge Function processes uploaded files for text extraction and AI analysis.
- Uploads are handled by
Admin Interface (src/pages/AdminFiles.tsx)
The AdminFiles page, utilizing the FileTable.tsx component, is the central hub for document management. It offers:
- A toggle between private and public file systems.
- A folder tree for navigation.
- A table display of files in the current folder.
- Search and sorting capabilities.
- Actions for editing, deleting, and viewing files.
- Responsive design for mobile and desktop.
Workflow for a New Document
- User uploads a file via
UploadForm.tsx. - The file is uploaded to Supabase Storage (either
private-filesorpublic-filesbucket). - A record is created in the corresponding database table (
documents_privateordocuments_public). - The
uploadDocumentservice may trigger (or an event listener on the storage/table could trigger) theparseUploadedDocumentsSupabase Edge Function. - The Edge Function:
- Downloads the file from storage.
- Extracts text content.
- Generates embeddings for RAG.
- Calls Gemini API for summary, key sections, and citations.
- Updates the document record in the database with these AI-generated insights.
- Stores embeddings in the
private_vectorsorpublic_vectorstable.
Relevant Files
- Services:
src/services/api/documentService.ts: Facade for document operations.src/services/api/privateDocumentService.ts: Handles private documents.src/services/api/publicDocumentService.ts: Handles public documents.src/services/api/folderService.ts: Manages folder structures.
- Components:
src/components/admin/UploadForm.tsx: For uploading new documents.src/components/admin/FileTable.tsx: Main component for browsing and managing files.src/components/admin/file/*: Various sub-components for the file table (rows, headers, pagination, etc.).src/components/admin/FileEditDialog.tsx: For editing document metadata.src/components/admin/FolderDialog.tsx: For creating/editing folders.src/components/chat/SourceModal.tsx: Displays document details and AI insights.
- Supabase:
supabase/functions/parseUploadedDocuments/index.ts: Edge Function for processing documents.supabase/seed/Documents_table.sql: Definesdocuments_privateanddocuments_publictables.supabase/seed/Vectors_table.sql: Definesprivate_vectorsandpublic_vectorstables.