SPEC 007 — Documents and Document Generation
1. Feature Purpose
Documents and DocGen provides the file management infrastructure for the entire Equa platform. It covers three areas:- Data Room — General-purpose virtual file storage with folders, uploads, renaming, and deletion
- Governing Documents — Categorized legal document repository (formation, operating, shareholder, board, employment, investor, compliance)
- Document Generation — Automated creation of stock certificates (SVG templates rendered to PDF) and operating agreements (Handlebars DOCX templates)
2. Current State (Verified)
2.1 Backend
2.2 Frontend
3. Data Model
3.1 DirectoryItems
Virtual filesystem entries (files and folders) organized by path.
Extends:
CreatedModifiedDeleted
Source: schema.ts lines 564–582
3.2 Files
Content-addressed file records stored on S3.
Extends:
CreatedModified
Source: schema.ts lines 585–609
3.3 Authorizations
Document authorizations linking approval records to organizations.
Extends:
HashedTable
Source: schema.ts lines 1378–1402
3.4 OrganizationTemplates
Stored document templates (certificate legends, operating agreement content).
Extends:
CreatedModifiedDeleted
Source: schema.ts lines 1405–1414
3.5 DataRoomsMembers (Access Control)
This section covers the data model previously planned as Spec 008 (Data Rooms). The entity and persistence functions exist, but no REST API endpoints or frontend UI are implemented for managing data room membership. The legacy Microsoft path restriction (
processRestrictedPath in microsoft/src/reading.ts) is deprecated. Modern data room access control needs a separate specification.
Source:
schema.ts lines 164–174
Persistence functions (exist, not exposed via REST):
getDataRoomsPermissionsForMember(db, organization, member)— Query by org + member (common/reading.tsline 576)getDataRoomsPermissionsForOrganizationAnUser(db, organization, user)— Query by org + user, joins through Members (common/reading.tsline 580)insertDataRoomsMembers(db, record)— Insert single record (common/writing.tsline 319)
processRestrictedPath in microsoft/src/reading.ts line 51 restricts folder paths for non-admin users based on their dataRoomName entries. Admins bypass. This was built for Microsoft Graph/SharePoint storage and is not used with the current native file storage.
Gap: No endpoints exist for granting/revoking data room access. No frontend UI for data room member management. A future spec should define modern access control for Google Drive integration or native storage.
3.6 File Storage Backend
Files are stored on AWS S3 (file-storage/src/s3.ts):
- Upload:
uploadS3(config, hash, stream)— stores with hash as S3 object name - Download:
downloadS3(config, hash)— retrieves by hash - Configuration:
AwsFileStorageConfigwithaccessKeyId,secretAccessKey,bucket,cacheBucket,region,tempPath
Relationships
4. API Endpoints
Data Room Endpoints
Source:
data-room-endpoints.ts lines 40–117
Upload middleware: uploadMiddlewareUsingMemory with maxSizeMegabytes: parseInt(process.env.DATA_ROOM_UPLOAD_SIZE_LIMIT_MB || '10')
Organization File Endpoints
Source:
organization-endpoints.ts lines 208–251
Certificate Generation Endpoints
Source:
captable-endpoints.ts lines 207–222
5. Frontend Components
Data Room
DataRoomPage behavior:
- Dropzone supports file and folder uploads with progress tracking
- Link creation generates
.urlfiles (Windows Internet Shortcut format) - Permission-gated: checks
canEditDocumentfor write operations - Introduction modal shown on first visit to empty data room
- Supports legacy Microsoft Graph paths via
legacyDataRoomorg flag
Governing Documents
Agreement Categories (8 total, from
agreements/utils.ts):
Document Generation
Thedoc-gen module generates:
-
Stock certificates — Front and back pages rendered from SVG templates (
certificate-front.svg,certificate-back.svg) usingpdf-libfor PDF output. Populated with shareholding data (holder name, share count, serial number, legend text, signatures). - Legend certificates — Standalone legend document generated from legend content.
-
Operating agreements — DOCX documents generated from Handlebars templates via
modules/api/src/doc-gen/generation.ts. Templates stored inOrganizationTemplatesentity.
Shared Components
Routes
6. Business Rules and Validation
7. Acceptance Criteria
- Users with
editDocumentspermission can upload files to the data room (up to configured size limit) - Folder creation works with nested paths (e.g.,
/legal/contracts/) - Files can be renamed and moved between folders
- File deletion removes the DirectoryItem record (file content retained in S3 via hash)
- DOCX files can be viewed inline as PDF via the
?format=pdfparameter - Governing documents page filters correctly by all 8 categories
- Each category maps to the correct
governing/[category]storage path - Stock certificate generation produces a PDF with front/back pages containing holder info, legend, and signatures
- Authorizations can be created and deleted, with soft-delete flag
- Upload progress is displayed in the frontend during file uploads
- Link creation generates a valid
.urlfile in the data room - Introduction modal appears on first visit to an empty data room
-
canViewDocumentsandcanEditDocumentsguards correctly gate all endpoints - DataRoomsMembers entity stores access control records (no REST API or UI — documented gap)