openserve 2.0.1

A modern, high-performance, AI-enhanced file server built in Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# OpenServe

[![Rust](https://img.shields.io/badge/rust-1.75+-orange.svg)](https://www.rust-lang.org)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![Docker](https://img.shields.io/badge/docker-ready-blue.svg)](Dockerfile)
[![Crates.io](https://img.shields.io/crates/v/openserve.svg)](https://crates.io/crates/openserve)

**OpenServe** is a modern, high-performance, AI-enhanced file server built in Rust. It combines the speed and safety of Rust with intelligent features powered by OpenAI, providing a comprehensive solution for file management, search, and collaboration.

## Features

### Core Features
- **High-Performance File Server**: Built with Axum and Tokio for maximum performance
- **RESTful API**: Complete REST API for file operations
- **WebSocket Support**: Real-time file change notifications
- **Authentication & Authorization**: JWT-based auth with role-based access control
- **Search Engine**: Full-text search powered by Tantivy
- **File Upload/Download**: Secure file operations with validation
- **Directory Management**: Complete directory operations

### AI-Powered Features
- **Intelligent File Classification**: Automatic file categorization
- **Content Analysis**: AI-powered content summarization and tagging
- **Smart Search**: Semantic search capabilities
- **File Organization Suggestions**: AI recommendations for file structure
- **Chat Interface**: Query your files using natural language

### Security & Safety
- **Path Traversal Protection**: Secure file access controls
- **Input Validation**: Comprehensive request validation
- **Rate Limiting**: Built-in rate limiting for API endpoints
- **CORS Support**: Configurable cross-origin resource sharing
- **TLS/SSL Support**: HTTPS encryption support

### Monitoring & Observability
- **Structured Logging**: JSON and text logging with tracing
- **Metrics Collection**: Prometheus metrics integration
- **Health Checks**: Built-in health monitoring
- **Performance Monitoring**: Request timing and performance metrics

### DevOps Ready
- **Docker Support**: Multi-stage Dockerfile for production
- **Docker Compose**: Complete stack with Redis, Prometheus, Grafana
- **Configuration Management**: Environment-based configuration
- **Automated Testing**: Comprehensive test suite
- **CI/CD Ready**: GitHub Actions integration

## Quick Start

### Prerequisites
- Rust 1.75 or later
- Docker & Docker Compose (optional)
- OpenAI API Key (for AI features)

### Installation

#### Option 1: Using Cargo
```bash
cargo install openserve
openserve --help
```

#### Option 2: From Source
```bash
git clone https://github.com/nikjois/openserve-rs.git
cd openserve-rs
cargo build --release
```

#### Option 3: Using Docker
```bash
git clone https://github.com/nikjois/openserve-rs.git
cd openserve-rs
docker-compose up -d
```

### Basic Usage

```bash
# Start the server
openserve --port 8080 --host 0.0.0.0 /path/to/files

# With AI features enabled
openserve --ai --openai-api-key your-key-here /path/to/files

# With custom configuration
openserve --config config.yml /path/to/files
```

## Configuration

### Environment Variables
```bash
# Server Configuration
OPENSERVE_HOST=0.0.0.0
OPENSERVE_PORT=8080
OPENSERVE_SERVE_PATH=/app/files

# AI Configuration
OPENAI_API_KEY=your-api-key-here
OPENSERVE_AI_ENABLED=true

# Database Configuration
DATABASE_URL=sqlite:///app/data/openserve.db
REDIS_URL=redis://localhost:6379

# Logging
RUST_LOG=info
```

### Configuration File (config.yml)
```yaml
server:
  host: "0.0.0.0"
  port: 8080
  serve_path: "./files"
  max_upload_size: 104857600  # 100MB
  enable_tls: false

ai:
  enabled: true
  api_key: "your-openai-api-key"
  model: "gpt-4o-mini"
  max_tokens: 2048
  temperature: 0.7

auth:
  enabled: true
  jwt_secret: "your-secret-key"
  session_timeout: 3600
  allow_registration: false

storage:
  database_url: "sqlite://./data.db"
  redis_url: "redis://localhost:6379"
  cache_size: 1000
  index_path: "./index"

telemetry:
  log_level: "info"
  log_format: "json"
  metrics_enabled: true
  tracing_enabled: false
```

## API Reference

### File Operations
```bash
# List directory contents
GET /api/files?path=/some/path

# Upload file
POST /api/files/upload
Content-Type: multipart/form-data

# Download file
GET /api/files/download?path=/file.txt

# Delete file
DELETE /api/files?path=/file.txt

# Get file metadata
GET /api/files/metadata?path=/file.txt
```

### Search Operations
```bash
# Search files
GET /api/search?q=query&limit=10

# Semantic search
GET /api/search?q=query&semantic=true

# Get search statistics
GET /api/search/stats
```

### AI Operations
```bash
# Analyze file content
POST /api/ai/analyze
{
  "path": "/document.txt",
  "options": {
    "summarize": true,
    "extract_entities": true,
    "generate_tags": true
  }
}

# Chat with files
POST /api/ai/chat
{
  "message": "What is this document about?",
  "context_paths": ["/document.txt"]
}
```

### Authentication
```bash
# Login
POST /api/auth/login
{
  "username": "user",
  "password": "password"
}

# Register (if enabled)
POST /api/auth/register
{
  "username": "user",
  "email": "user@example.com",
  "password": "password"
}
```

## Library Usage

OpenServe can also be used as a library in your Rust projects:

```rust
use openserve::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = Config::default();
    let server = Server::new(config).await?;
    server.run().await?;
    Ok(())
}
```

## Testing

```bash
# Run all tests
cargo test

# Run with coverage
cargo tarpaulin --out Html

# Run benchmarks
cargo bench

# Integration tests
cargo test --test integration
```

## Development

### Project Structure
```
openserve-rs/
├── src/
│   ├── ai/              # AI service integration
│   ├── config/          # Configuration management
│   ├── error/           # Error handling
│   ├── handlers/        # HTTP request handlers
│   ├── middleware/      # Custom middleware
│   ├── models/          # Data models
│   ├── services/        # Business logic
│   ├── utils/           # Utility functions
│   ├── lib.rs           # Library root
│   └── main.rs          # Application entry point
├── tests/               # Integration tests
├── benches/             # Benchmarks
├── docker/              # Docker configuration
└── docs/                # Documentation
```

### Building from Source
```bash
# Development build
cargo build

# Release build
cargo build --release

# With all features
cargo build --all-features

# Cross-compilation
cargo build --target x86_64-unknown-linux-musl
```

### Contributing
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## Deployment

### Docker Deployment
```bash
# Build and deploy
docker-compose up -d

# Scale services
docker-compose up -d --scale openserve=3

# View logs
docker-compose logs -f openserve
```

### Systemd Service
```bash
# Install service
sudo cp scripts/openserve.service /etc/systemd/system/
sudo systemctl enable openserve
sudo systemctl start openserve
```

## Monitoring

### Metrics
- Request count and latency
- File operation statistics
- Search performance metrics
- AI service usage
- System resource usage

### Dashboards
- Grafana dashboards included
- Prometheus metrics collection
- Real-time monitoring
- Alerting rules

### Health Checks
```bash
# Health endpoint
curl http://localhost:8080/health

# Metrics endpoint
curl http://localhost:8080/metrics

# Ready endpoint
curl http://localhost:8080/ready
```

## Troubleshooting

### Common Issues

**Port already in use**
```bash
# Find process using port
lsof -i :8080
# Kill process
kill -9 <PID>
```

**Permission denied**
```bash
# Check file permissions
ls -la /path/to/files
# Fix permissions
chmod -R 755 /path/to/files
```

**AI features not working**
```bash
# Check API key
echo $OPENAI_API_KEY
# Test API connection
curl -H "Authorization: Bearer $OPENAI_API_KEY" https://api.openai.com/v1/models
```

### Logs
```bash
# View logs
docker-compose logs -f openserve

# Increase log level
RUST_LOG=debug cargo run

# Structured logging
RUST_LOG=info,openserve=debug cargo run
```

## Performance

OpenServe is designed for high performance:

- Built with async Rust using Tokio
- Efficient file I/O with memory mapping
- Connection pooling and caching
- Optimized search indexing
- Zero-copy operations where possible

## Security

Security is a top priority:

- Path traversal protection
- Input validation and sanitization
- JWT token authentication
- Rate limiting
- CORS protection
- TLS/SSL support

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Support

- Issues: [GitHub Issues]https://github.com/nikjois/openserve-rs/issues
- Documentation: [docs.rs/openserve]https://docs.rs/openserve

## Acknowledgments

- [Axum]https://github.com/tokio-rs/axum - Web framework
- [Tantivy]https://github.com/quickwit-oss/tantivy - Search engine
- [OpenAI]https://openai.com - AI capabilities
- [Tokio]https://tokio.rs - Async runtime
- [Serde]https://serde.rs - Serialization

**Made with Rust**