Skip to content

Commit 4ca98c8

Browse files
Merge pull request #7 from LGICCommunity/demo
Design and implement a robust, modular Document Management System (DMS) in C programming language, operated entirely through a command-line interface (CLI). The system should support full CRUD operations (Create, Read, Update, Delete) on plain text files organized in a directory structure resembling a real-world digital document repository. The application must be cleanly architected using modular source files, and compiled via a Makefile. The user should be able to manage documents just like they would in a mini local Git or file manager via terminal commands.
2 parents 79b9362 + 35e6e47 commit 4ca98c8

27 files changed

Lines changed: 967 additions & 49 deletions

.gitignore

Whitespace-only changes.

.vscode/settings.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{
22
"files.associations": {
3-
"heading.h": "c"
3+
"errno.h": "c",
4+
"stdlib.h": "c",
5+
"ctype.h": "c",
6+
"time.h": "c",
7+
"stat.h": "c",
8+
"stdarg.h": "c",
9+
"string.h": "c",
10+
"utils.h": "c"
411
}
512
}

Makefile

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,59 @@
1-
all:
2-
gcc -o bin/tdms src/main.c
1+
CC = gcc
2+
CFLAGS = -Wall -Wextra -I./include
3+
LDFLAGS =
4+
5+
SRC_DIR = src
6+
OBJ_DIR = obj
7+
BIN_DIR = bin
8+
DATA_DIR = data
9+
LOG_FILE = $(DATA_DIR)/logs/history.txt
10+
11+
SRCS = $(wildcard $(SRC_DIR)/*.c)
12+
OBJS = $(SRCS:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
13+
TARGET = $(BIN_DIR)/dms
14+
15+
.PHONY: all clean clean-docs banner
16+
17+
all: banner $(TARGET)
18+
19+
banner:
20+
@echo " ____ _ "
21+
@echo "| _ \\ ___ ___ _ _ _ __ ___ ___ _ __ | |_ "
22+
@echo "| | | |/ _ \\ / __| | | | '_ \` _ \\ / _ \\ '_ \\| __|"
23+
@echo "| |_| | (_) | (__| |_| | | | | | | __/ | | | |_ "
24+
@echo "|____/ \\___/ \\___|\\__,_|_| |_| |_|\\___|_| |_|\\__|"
25+
@echo
26+
@echo " "
27+
@echo "| \\/ | __ _ _ __ __ _ __ _ ___ _ __ "
28+
@echo "| |\\/| |/ _\` | '_ \\ / _\` |/ _\` |/ _ \\ '__| "
29+
@echo "| | | | (_| | | | | (_| | (_| | __/ | "
30+
@echo "|_| |_|\\__,_|_| |_|\\__,_|\\__, |\\___|_| "
31+
@echo " |___/ "
32+
@echo
33+
34+
$(TARGET): $(OBJS)
35+
@mkdir -p $(BIN_DIR)
36+
$(CC) $(OBJS) -o $(TARGET) $(LDFLAGS)
37+
38+
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
39+
@mkdir -p $(OBJ_DIR)
40+
$(CC) $(CFLAGS) -c $< -o $@
41+
42+
clean:
43+
rm -rf $(OBJ_DIR) $(BIN_DIR)
44+
45+
clean-docs:
46+
@echo "WARNING: This will delete all documents (notes, recipes, and versions)."
47+
@echo -n "Are you sure you want to proceed? (y/N): "; \
48+
read answer; \
49+
if [ "$$answer" = "y" ] || [ "$$answer" = "Y" ]; then \
50+
echo "Cleaning all documents while preserving history..."; \
51+
echo "[`date '+%Y-%m-%d %H:%M:%S'`] CLEAN-DOCS: All documents cleared (notes, recipes, versions)" >> $(LOG_FILE); \
52+
rm -rf $(DATA_DIR)/notes/*; \
53+
rm -rf $(DATA_DIR)/recipes/*; \
54+
rm -rf $(DATA_DIR)/versions/*; \
55+
echo "Documents cleaned. History preserved in data/logs/history.txt"; \
56+
echo "Operation logged in history.txt"; \
57+
else \
58+
echo "Operation cancelled."; \
59+
fi

README.md

Lines changed: 224 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,226 @@
11
# Document Management System (DMS)
22

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

bin/dms

25.7 KB
Binary file not shown.

data/index.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

data/logs/deletion_history.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[2025-05-24 20:51:15] Deleted: notes/test.txt

data/logs/history.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[2025-05-24 20:55:56] CREATE: notes/test.txt
2+
[2025-05-24 20:56:07] READ: notes/test.txt
3+
[2025-05-24 20:56:15] UPDATE: notes/test.txt
4+
[2025-05-24 20:56:19] DELETE: notes/test.txt
5+
[2025-05-25 11:16:08] CREATE: notes/todo.txt
6+
[2025-05-25 11:16:40] UPDATE: notes/todo.txt
7+
[2025-05-25 11:20:52] UPDATE: notes/todo.txt
8+
[2025-05-25 11:21:05] UPDATE: notes/todo.txt
9+
[2025-05-25 11:23:01] UPDATE: notes/todo.txt
10+
[2025-05-25 11:23:06] UPDATE: notes/todo.txt
11+
[2025-05-25 11:24:31] UPDATE: notes/todo.txt
12+
[2025-05-25 11:24:37] UPDATE: notes/todo.txt
13+
[2025-05-25 11:26:37] UPDATE: notes/todo.txt
14+
[2025-05-25 11:31:55] CLEAN-DOCS: All documents cleared (notes, recipes, versions)
15+
[2025-05-25 15:28:30] CREATE: notes/todo.txt
16+
[2025-05-25 15:29:05] CREATE: notes/quick-note.txt
17+
[2025-05-25 15:29:49] UPDATE: notes/todo.txt
18+
[2025-05-25 15:30:18] READ: notes/todo.txt
19+
[2025-05-25 15:30:36] DELETE: notes/todo.txt
20+
[2025-05-25 15:31:59] CREATE: notes/todo.txt
21+
[2025-05-25 15:32:08] READ: notes/todo.txt
22+
[2025-05-25 15:32:29] UPDATE: notes/todo.txt
23+
[2025-05-25 15:32:32] READ: notes/todo.txt
24+
[2025-05-25 15:32:47] UPDATE: notes/todo.txt
25+
[2025-05-25 15:32:52] READ: notes/todo.txt
26+
[2025-05-25 15:33:05] DELETE: notes/todo.txt
27+
[2025-05-25 15:34:42] CLEAN-DOCS: All documents cleared (notes, recipes, versions)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,4 @@ while ((bytes = fread(buffer, 1, BUFFER_SIZE, source)) > 0) {
252252
2. **Resource Usage**
253253
- Controlled memory usage
254254
- Predictable performance
255-
- Scales well with file size
255+
- Scales well with file size
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,4 @@ graph TD
266266
4. **Memory Management**:
267267
- Free allocated memory
268268
- Check malloc return values
269-
- Close file handles properly
269+
- Close file handles properly

0 commit comments

Comments
 (0)