# Memento - Smart Note-Taking App

A modern, AI-powered note-taking application inspired by Google Keep. Built with Next.js 16, PostgreSQL, Prisma, and Tailwind CSS 4.

![License](https://img.shields.io/badge/license-MIT-blue)
![Docker](https://img.shields.io/badge/docker-ready-blue)
![Node](https://img.shields.io/badge/node-22-green)

## Features

### Core
- Create, edit, delete notes with text or checklists
- Pin, archive, and organize notes into notebooks
- Labels with contextual colors
- Real-time search across all notes
- 10 soft pastel color themes + dark mode
- Responsive masonry grid layout (1-5 columns)
- Image upload with original size preservation
- Drag-and-drop note reordering
- Markdown support

### AI-Powered
- Automatic title suggestions
- Semantic search across notes
- Paragraph refactoring
- Memory Echo: surfaces connections between your notes
- Multi-provider: OpenAI, Ollama, or auto-detect

### MCP Server (22 Tools)
Full Model Context Protocol server for AI agent integration:
- **Notes**: create, read, update, delete, search, duplicate
- **Notebooks**: create, list, update, delete
- **Labels**: create, list, update, delete, assign to notes
- **System**: health check, stats, bulk operations
- Modes: stdio (Claude Desktop) or SSE (N8N, HTTP)

### Authentication & Security
- NextAuth.js with credentials provider
- Email/password authentication
- Password reset via SMTP
- Role-based access (USER/ADMIN)

## Quick Start (Local)

**Prerequisites:** Node.js 22, PostgreSQL 16

```bash
cd memento-note
npm install

# Configure database
cp .env.example .env
# Edit .env with your PostgreSQL connection string

# Setup database
npx prisma migrate dev --name init

# Start development server
npm run dev
```

Open http://localhost:3000

## Docker Deployment

### Using Docker Compose (root)

```bash
# Configure environment
cp .env.docker.example .env.docker
# Edit .env.docker with your settings

# Start all services (PostgreSQL + app + MCP server)
docker compose up -d

# Check status
docker compose ps
```

Services:
- **memento-note** - Web app on port 3000
- **postgres** - PostgreSQL 16 on port 5432 (configurable via `POSTGRES_PORT`)
- **mcp-server** - MCP server on port 3001 (SSE mode)
- **ollama** - Optional local LLM (use profile `--profile ollama`)

### Standalone (memento-note only)

```bash
cd memento-note
chmod +x deploy.sh
./deploy.sh build
./deploy.sh start
```

### Useful Commands

```bash
docker compose logs -f memento-note   # View logs
docker compose exec memento-note sh   # Shell access
./deploy.sh backup                    # PostgreSQL backup (pg_dump)
./deploy.sh update                    # Pull, rebuild, restart
```

## MCP Server

The MCP server enables AI agents to interact with your notes programmatically.

### Configuration

Set in `.env.docker`:
```
MCP_MODE=stdio    # or "sse" for HTTP/N8N
MCP_PORT=3001     # SSE mode port
```

### N8N Integration

Configure an MCP tool node in N8N pointing to:
```
http://mcp-server:3001/sse
```

### Claude Desktop

Add to your `claude_desktop_config.json`:
```json
{
  "mcpServers": {
    "memento": {
      "command": "node",
      "args": ["path/to/mcp-server/index.js"],
      "env": {
        "DATABASE_URL": "postgresql://memento:memento@localhost:5432/memento"
      }
    }
  }
}
```

## Tech Stack

| Component | Technology |
|-----------|-----------|
| Frontend | Next.js 16, React 19, TypeScript |
| Styling | Tailwind CSS 4, shadcn/ui |
| Database | PostgreSQL 16, Prisma 5 |
| Auth | NextAuth.js v5 |
| AI | OpenAI SDK, Ollama |
| MCP | @modelcontextprotocol/sdk |
| Deploy | Docker, Docker Compose |

## Project Structure

```
memento-note/           # Main Next.js application
├── app/                # App Router pages & API routes
├── components/         # React components
├── lib/                # Utilities, Prisma client, i18n
├── prisma/             # Database schema & migrations
├── public/             # Static assets, icons, uploads
└── scripts/            # Utility scripts

mcp-server/             # MCP protocol server
├── index.js            # Stdio mode entry
├── index-sse.js        # SSE mode entry
├── prisma/             # Shared database schema
└── Dockerfile

docker-compose.yml      # Root orchestration
.env.docker.example     # Environment template
```

## Configuration

### Environment Variables

| Variable | Description | Default |
|----------|-------------|---------|
| `DATABASE_URL` | PostgreSQL connection string | `postgresql://memento:memento@localhost:5432/memento` |
| `POSTGRES_PORT` | PostgreSQL host port | `5432` |
| `POSTGRES_PASSWORD` | PostgreSQL password | `memento` |
| `NEXTAUTH_SECRET` | Auth encryption key | (required) |
| `NEXTAUTH_URL` | Public URL | `http://localhost:3000` |
| `AI_PROVIDER` | AI provider (`openai`, `ollama`, `auto`) | `auto` |
| `OPENAI_API_KEY` | OpenAI API key | (optional) |
| `OLLAMA_BASE_URL` | Ollama endpoint | (optional) |
| `MCP_MODE` | MCP server mode (`stdio` or `sse`) | `stdio` |

## Contributing

Contributions welcome! Please:

- [Report bugs](https://github.com/yourusername/memento/issues)
- [Suggest features](https://github.com/yourusername/memento/discussions)
- Submit pull requests

## Support

Memento is free and open-source. If you find it useful:

- [Ko-fi](https://ko-fi.com/yourusername) - One-time or monthly support
- [BuyMeACoffee](https://buymeacoffee.com/yourusername) - Buy me a coffee
- [GitHub Sponsors](https://github.com/sponsors/yourusername) - Recurring support
- Star the repo - Free and helps visibility!

## License

MIT License - feel free to use for personal or commercial projects.
