This project implements a folder and document management system with hierarchical organization using PostgreSQL's ltree extension. The API provides endpoints to manage folders, subfolders, documents, and access control.
- Hierarchical Folder Structure: Uses
ltreefor efficient folder and subfolder hierarchy management. - Document Storage: Associates documents with folders and maintains structured paths.
- User Access Control: Implements role-based permissions for document access.
- REST API Endpoints: Provides endpoints to manage folders and documents.
- Service Layer: Fetches all documents within a folder and its subfolders efficiently.
• Folder (id, name, parent_id, path ltree)
• SubFolder (id, name, folder_id, path ltree)
• Document (id, name, file_path, folder_id, path ltree)
• User (id, name, email)
• AccessControl (id, user_id, document_id, permission_level)
GET /folders/tree– Retrieve the entire folder hierarchyPOST /folders– Create a new folder (requiresCreateFolderDto)
POST /documents– Upload a document (requiresUploadDocumentDto)
{
"name": "Folder Name",
"parent_id": 1
}{
"name": "Document Name",
"file_path": "uploads/doc.pdf",
"folder_id": 1
}- Node.js & npm
- PostgreSQL with
ltreeextension enabled - NestJS framework
- Clone the repository:
git clone https://github.com/your-repo.git cd your-repo - Install dependencies:
npm install
- Configure the database in
.envfile:DATABASE_URL=postgres://user:password@localhost:5432/dbname
- Run database migrations:
npm run migrate
- Start the application:
npm run start
- Run Unit Tests:
npm run test
- NestJS – Framework for building scalable APIs
- PostgreSQL – Database with
ltreefor hierarchical data - TypeORM – ORM for database management
- Express.js – HTTP server framework
Feel free to open issues or submit pull requests for improvements and fixes.
This project is licensed under the MIT License.
Note: Ensure PostgreSQL's
ltreeextension is enabled using:CREATE EXTENSION ltree;