# DocSys 📁

A beautiful, modern document management web UI built in Go.

![Dashboard](docs/screenshot.png)

## Features

- 🎨 **Modern UI** - Clean design with Sora font, Tailwind CSS, smooth animations
- 🌙 **Dark Mode** - Toggle between light and dark themes
- 🔍 **Full-Text Search** - Search across all OCR content using SQLite FTS5
- 📱 **Mobile Responsive** - Works great on all devices
- 📄 **PDF Viewer** - Inline PDF viewing with PDF.js
- 🏷️ **Categories** - Organize documents by type (taxes, bills, medical, etc.)
- 📤 **Drag & Drop Upload** - Easy file upload to inbox
- ✏️ **Edit Metadata** - Update titles, categories, and notes
- 📊 **Export CSV** - Export filtered results for analysis
- ⚡ **htmx Powered** - Fast, lightweight interactivity without heavy JS

## Tech Stack

- **Backend**: Go with Chi router
- **Database**: SQLite with FTS5 for full-text search
- **Frontend**: Tailwind CSS, htmx, PDF.js
- **Font**: Sora (Google Fonts)

## Installation

### Prerequisites

- Go 1.22+
- Documents directory at `~/documents/` with:
  - `records/{category}/*.md` - Document record files
  - `store/*.pdf` - PDF files
  - `index/` - Database directory

### Build

```bash
cd /home/johan/dev/docsys

# Build with FTS5 support
CGO_ENABLED=1 go build -tags "fts5" -o docsys .
```

### Run

```bash
./docsys
# Server starts at http://localhost:9201
```

### Install as Service

```bash
chmod +x install.sh
./install.sh
```

## Configuration

The app uses these default paths:

| Path | Purpose |
|------|---------|
| `~/documents/records/{category}/*.md` | Document record files |
| `~/documents/store/*.pdf` | PDF storage |
| `~/documents/index/docsys.db` | SQLite database |
| `~/documents/inbox/` | Upload inbox |

## API Endpoints

| Endpoint | Method | Description |
|----------|--------|-------------|
| `/` | GET | Dashboard |
| `/browse` | GET | Category browser |
| `/browse/{category}` | GET | Documents in category |
| `/document/{id}` | GET | Document detail view |
| `/search?q=` | GET | Search page |
| `/pdf/{hash}` | GET | Serve PDF file |
| `/api/search` | POST | HTMX search |
| `/api/documents` | GET | List documents (JSON) |
| `/api/upload` | POST | Upload file to inbox |
| `/api/document/{id}` | PUT | Update document |
| `/api/document/{id}` | DELETE | Delete document |
| `/api/export` | GET | Export to CSV |
| `/api/reindex` | POST | Rebuild index |

## Document Record Format

Documents are stored as Markdown files:

```markdown
# Document Record

**ID:** abc123def
**Original File:** invoice.pdf
**Processed:** 2026-01-15T10:30:00
**Category:** bills
**Type:** invoice

## Extracted Info

| Field | Value |
|-------|-------|
| Date | January 15, 2026 |
| Vendor | Example Corp |
| Amount | $99.99 |

## Summary

Brief summary of the document...

## Full Text

```
OCR text content here...
```

## Files

- **PDF:** [store/abc123def.pdf](../../store/abc123def.pdf)
```

## License

MIT
