This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Memos Codebase Guide
## Project Overview
Memos is a lightweight, self-hosted knowledge management and note-taking platform. The architecture pairs a Go backend with a React+Vite frontend, using gRPC for internal communication and providing REST API access via gRPC-Gateway.
Memos is a self-hosted knowledge management platform with a Go backend and React frontend. The architecture uses gRPC for internal communication with REST access via gRPC-Gateway.
## Development Commands
## Architecture Decision Context
### Backend (Go)
**Why gRPC + gRPC-Gateway?**
- Native gRPC for performance, REST API for compatibility
- Both protocols served on same port via `cmux` connection multiplexer
- Frontend uses gRPC-Web (`nice-grpc-web`) for type-safe API calls
**Start Development Server:**
```bash
go run ./cmd/memos --mode dev --port 8081
```
**Build Binary:**
```bash
go build ./cmd/memos
```
**Why multi-database support?**
- Store interface (`store/driver.go`) abstracts persistence
- Three implementations: SQLite (default), MySQL, PostgreSQL
- Each driver has its own migration files in `store/db/{driver}/migration/`
- Schema version tracked in `instance_setting` table (key: `bb.general.version`)
**Run Tests:**
```bash
go test ./... # All tests
go test ./store/... # Store layer tests only
go test ./server/router/api/v1/test/... # API tests
```
**Why MobX for frontend state?**
- Simpler than Redux for this application's needs
- Stores in `web/src/store/` handle global state (user, memos, editor, dialogs)
**Lint:**
```bash
golangci-lint run # Full lint check (uses .golangci.yaml)
```
## Critical Development Commands
**Generate Protocol Buffers:**
```bash
cd proto
buf generate # Generate Go/TypeScript from .proto files
buf format -w# Format proto files
```
### Frontend (React + Vite)
**Install Dependencies:**
```bash
cd web
pnpm install
```
**Development Server:**
**Backend:**
```bash
cd web
pnpm dev # Hot-reload dev server (typically :5173)
go run ./cmd/memos --mode dev --port 8081 # Start dev server
go test ./... # Run tests
golangci-lint run # Lint
```
**Build:**
**Frontend:**
```bash
cd web
pnpm build # Build to web/dist/
pnpm release # Build and copy to server/router/frontend/dist/
cd web&& pnpm dev # Start dev server
cd web && pnpm lint:fix # Lint and fix
cd web && pnpm release # Build and copy to backend
```
**Lint and Format:**
**Protocol Buffers:**
```bash
cd web
pnpm lint # TypeScript check + Biome lint
pnpm lint:fix # Auto-fix linting issues
pnpm format # Format code with Biome
cd proto && buf generate # Regenerate Go + TypeScript from .proto
```
### CLI Flags and Environment Variables
The backend accepts the following configuration via flags or `MEMOS_*` environment variables:
Each driver contains its own migration files in subdirectories. Schema version tracking is stored in `instance_setting` (key: `bb.general.version`). The `store/migrator.go` orchestrates migrations across all drivers.
**Key Models:**
-`Memo` - Core note/memo entity
-`User` - User accounts
-`Attachment` - Uploaded files and images
-`MemoRelation` - Graph relationships between memos
-`Activity` - Activity log entries
-`Inbox` - Inbox items
-`Reaction` - Emoji reactions
-`InstanceSetting` - Instance-level configuration
-`UserSetting` - User preferences
-`IdentityProvider` - OAuth/SSO provider configs
### Frontend Architecture
**Tech Stack:**
-**Framework:** React 18 with TypeScript
-**Build Tool:** Vite 7
-**Routing:** React Router 7
-**State Management:** MobX
-**Styling:** Tailwind CSS 4 + Emotion
-**UI Components:** Radix UI primitives
-**i18n:** react-i18next with language files in `web/src/locales/`
**State Management:**
MobX stores in `web/src/store/` handle global state:
-`userStore` - Current user session
-`memoStore` - Memo collection and filters
-`editorStore` - Memo editor state
-`dialogStore` - Modal dialogs
- etc.
**gRPC-Web Client:**
The frontend uses `nice-grpc-web` to call backend services. Client setup is in `web/src/grpcweb.ts`.
### Authentication
**Dual Auth Support:**
1.**Session-based (Cookie):**`user_session` cookie with format `{userID}-{sessionID}`