|
1 | 1 | # Document Management System (DMS) |
2 | 2 |
|
3 | | -A simple terminal-based note management system with CRUD functionality for organized and productive note-taking. |
| 3 | +A command-line based Document Management System written in C that allows users to create, read, update, and delete text documents organized in categories. The system includes automatic versioning and comprehensive operation logging. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Create new text documents in different categories |
| 8 | +- Read existing documents |
| 9 | +- Update document content with automatic version backup |
| 10 | +- Delete documents |
| 11 | +- Organized file structure with categories |
| 12 | +- Version history for edited documents |
| 13 | +- Complete operation logging with timestamps |
| 14 | +- Error handling and input validation |
| 15 | +- Color-coded console output |
| 16 | +- Clean all documents with history preservation |
| 17 | + |
| 18 | +## Directory Structure |
| 19 | + |
| 20 | +``` |
| 21 | +DocumentManager/ |
| 22 | +├── bin/ # Compiled binary |
| 23 | +├── src/ # Source code files |
| 24 | +├── include/ # Header files |
| 25 | +├── data/ # Document storage |
| 26 | +│ ├── recipes/ # Recipe documents |
| 27 | +│ ├── notes/ # Note documents |
| 28 | +│ ├── logs/ # Operation logs and history |
| 29 | +│ │ └── history.txt # Complete operation history |
| 30 | +│ └── versions/ # Automatically saved old versions |
| 31 | +└── obj/ # Object files |
| 32 | +``` |
| 33 | + |
| 34 | +## Building |
| 35 | + |
| 36 | +To build the project, run: |
| 37 | + |
| 38 | +```bash |
| 39 | +make |
| 40 | +``` |
| 41 | + |
| 42 | +This will create the `dms` executable in the `bin` directory. |
| 43 | + |
| 44 | +To clean the build files: |
| 45 | + |
| 46 | +```bash |
| 47 | +make clean |
| 48 | +``` |
| 49 | + |
| 50 | +To clean all documents while preserving history: |
| 51 | + |
| 52 | +```bash |
| 53 | +make clean-docs |
| 54 | +``` |
| 55 | + |
| 56 | +This will: |
| 57 | +1. Ask for confirmation before proceeding |
| 58 | +2. Remove all documents in notes, recipes, and versions directories |
| 59 | +3. Preserve the operation history in data/logs/history.txt |
| 60 | +4. Log the cleanup operation with timestamp |
| 61 | + |
| 62 | +## Usage Guide |
| 63 | + |
| 64 | +### Basic Commands |
| 65 | + |
| 66 | +The DMS supports the following commands: |
| 67 | + |
| 68 | +```bash |
| 69 | +# Create a new document |
| 70 | +./bin/dms create <category> <filename> |
| 71 | + |
| 72 | +# Read a document |
| 73 | +./bin/dms read <category> <filename> |
| 74 | + |
| 75 | +# Update a document |
| 76 | +./bin/dms update <category> <filename> |
| 77 | + |
| 78 | +# Delete a document |
| 79 | +./bin/dms delete <category> <filename> |
| 80 | +``` |
| 81 | + |
| 82 | +### Available Categories |
| 83 | +The system organizes documents into these categories: |
| 84 | +- `recipes` - For storing cooking recipes |
| 85 | +- `notes` - For general notes and todos |
| 86 | +- `logs` - For logs and records |
| 87 | + |
| 88 | +### How to Use |
| 89 | + |
| 90 | +#### 1. Creating Documents |
| 91 | +There are two ways to create documents: |
| 92 | + |
| 93 | +a. Interactive Mode: |
| 94 | +```bash |
| 95 | +./bin/dms create notes todo.txt |
| 96 | +# Then type your content and press Ctrl+D when finished |
| 97 | +``` |
| 98 | + |
| 99 | +b. Using Echo (for quick creation): |
| 100 | +```bash |
| 101 | +echo "My content here" | ./bin/dms create notes quick-note.txt |
| 102 | +``` |
| 103 | + |
| 104 | +#### 2. Reading Documents |
| 105 | +To read any document: |
| 106 | +```bash |
| 107 | +./bin/dms read notes todo.txt |
| 108 | +``` |
| 109 | + |
| 110 | +#### 3. Updating Documents |
| 111 | +When you update a document, the old version is automatically saved in the versions directory: |
| 112 | + |
| 113 | +a. Interactive Mode: |
| 114 | +```bash |
| 115 | +./bin/dms update notes todo.txt |
| 116 | +# Enter new content and press Ctrl+D when finished |
| 117 | +``` |
| 118 | + |
| 119 | +b. Using Echo: |
| 120 | +```bash |
| 121 | +echo "Updated content" | ./bin/dms update notes todo.txt |
| 122 | +``` |
| 123 | + |
| 124 | +The old version will be saved as: `data/versions/notes_YYYYMMDD_HHMMSS_todo.txt` |
| 125 | + |
| 126 | +#### 4. Deleting Documents |
| 127 | +To delete a document (will ask for confirmation): |
| 128 | +```bash |
| 129 | +./bin/dms delete notes todo.txt |
| 130 | +``` |
| 131 | + |
| 132 | +### Operation History and Logging |
| 133 | + |
| 134 | +The system maintains a complete history of all operations in `data/logs/history.txt`. Each operation is logged with: |
| 135 | + |
| 136 | +1. Timestamp: `[YYYY-MM-DD HH:MM:SS]` |
| 137 | +2. Operation Type: `CREATE`, `READ`, `UPDATE`, `DELETE`, or `CLEAN-DOCS` |
| 138 | +3. File Path or Operation Details |
| 139 | + |
| 140 | +Example log entries: |
| 141 | +``` |
| 142 | +[2025-05-24 20:55:56] CREATE: notes/todo.txt |
| 143 | +[2025-05-24 20:56:07] READ: notes/todo.txt |
| 144 | +[2025-05-24 20:56:15] UPDATE: notes/todo.txt |
| 145 | +[2025-05-24 20:56:19] DELETE: notes/todo.txt |
| 146 | +[2025-05-24 21:00:00] CLEAN-DOCS: All documents cleared (notes, recipes, versions) |
| 147 | +``` |
| 148 | + |
| 149 | +To view the operation history: |
| 150 | +```bash |
| 151 | +cat data/logs/history.txt |
| 152 | +``` |
| 153 | + |
| 154 | +### Version Control |
| 155 | + |
| 156 | +- All document updates are automatically versioned |
| 157 | +- Old versions are stored in `data/versions/` |
| 158 | +- Version files are named using the format: `category_YYYYMMDD_HHMMSS_filename` |
| 159 | +- You can access old versions directly in the versions directory |
| 160 | + |
| 161 | +### Practical Examples |
| 162 | + |
| 163 | +1. Creating and managing a recipe: |
| 164 | +```bash |
| 165 | +# Create a new recipe |
| 166 | +echo "Pasta Recipe: |
| 167 | +1. Boil water |
| 168 | +2. Add pasta |
| 169 | +3. Cook for 10 minutes" | ./bin/dms create recipes pasta.txt |
| 170 | + |
| 171 | +# Read the recipe |
| 172 | +./bin/dms read recipes pasta.txt |
| 173 | + |
| 174 | +# Update the recipe (old version will be saved automatically) |
| 175 | +echo "Improved Pasta Recipe: |
| 176 | +1. Boil water with salt |
| 177 | +2. Add pasta |
| 178 | +3. Cook for 8-10 minutes |
| 179 | +4. Add olive oil" | ./bin/dms update recipes pasta.txt |
| 180 | +``` |
| 181 | + |
| 182 | +2. Managing a todo list: |
| 183 | +```bash |
| 184 | +# Create todo list |
| 185 | +echo "1. Buy groceries |
| 186 | +2. Call mom |
| 187 | +3. Study C programming" | ./bin/dms create notes todo.txt |
| 188 | + |
| 189 | +# Update with completed items |
| 190 | +echo "1. Buy groceries - DONE |
| 191 | +2. Call mom |
| 192 | +3. Study C programming |
| 193 | +4. Go to gym" | ./bin/dms update notes todo.txt |
| 194 | +``` |
| 195 | + |
| 196 | +### Input Guidelines |
| 197 | + |
| 198 | +- Filenames can only contain: |
| 199 | + - Letters (a-z, A-Z) |
| 200 | + - Numbers (0-9) |
| 201 | + - Dots (.) |
| 202 | + - Hyphens (-) |
| 203 | + - Underscores (_) |
| 204 | +- Directory traversal is not allowed in filenames |
| 205 | +- Maximum input size for document content is 4KB |
| 206 | + |
| 207 | +### Error Handling |
| 208 | + |
| 209 | +The system provides clear error messages for: |
| 210 | +- Invalid commands |
| 211 | +- Invalid categories |
| 212 | +- Invalid filenames |
| 213 | +- File operation failures |
| 214 | +- Memory allocation failures |
| 215 | +- Version backup failures |
| 216 | +- Logging failures |
| 217 | + |
| 218 | +### Tips |
| 219 | + |
| 220 | +1. Use meaningful filenames that describe the content |
| 221 | +2. Check the versions directory for document history |
| 222 | +3. Review the operation history in `data/logs/history.txt` to track all actions |
| 223 | +4. Use the appropriate category for better organization |
| 224 | +5. Make sure to press Ctrl+D after entering content in interactive mode |
| 225 | +6. For multiline content, using echo with newlines (\n) is recommended |
| 226 | +7. Check both version backups and operation logs for complete document history |
0 commit comments