Overview
Memos is built as a modern full-stack application with a clean separation between frontend and backend, using protocol buffers for type-safe API contracts.Technology Stack
Backend
- Language: Go 1.25+
- API Protocol: gRPC + Connect RPC
- Web Framework: Echo v5 (HTTP router)
- Databases: SQLite (default), MySQL, PostgreSQL
- Schema: Protocol Buffers v2 with buf code generation
Frontend
- Framework: React 18.3 with TypeScript
- Build Tool: Vite 7
- State Management: React Query v5 + React Context
- Styling: Tailwind CSS v4
- API Client: Connect RPC
Architecture Layers
1. API Layer: Dual Protocol Design
Memos implements a dual-protocol API layer that serves both browser clients and external tools:Connect RPC (Browser Clients)
- Metadata Interceptor: Extracts client metadata
- Logging Interceptor: Request/response logging
- Recovery Interceptor: Panic recovery
- Auth Interceptor: Authentication validation
gRPC-Gateway (REST API)
2. Authentication System
Memos implements a three-tier authentication system:JWT Access Tokens (Stateless)
- Lifetime: 15 minutes
- Storage: Memory (client-side)
- Validation: Signature verification only
- Use Case: Active user sessions
Secret: Auto-generated on first run (server/server.go:53-57) See: server/auth/token.go:133-160
JWT Refresh Tokens (Stateful)
- Lifetime: 30 days
- Storage: HTTP-only cookie
- Validation: Database lookup (revocation check)
- Use Case: Session persistence
Personal Access Tokens (Long-lived)
- Format:
memos_pat_<random32chars> - Storage: SHA-256 hash in database
- Validation: Database lookup + expiry check
- Use Case: API integrations, automation
- Bearer token (Access Token V2)
- Bearer token (PAT)
- Refresh token cookie (fallback)
3. Store Layer: Driver Pattern
The store layer abstracts database operations through a clean interface pattern:Driver Interface
Database Implementations
| Driver | Package | Connection |
|---|---|---|
| SQLite | modernc.org/sqlite | File-based, WAL mode |
| MySQL | go-sql-driver/mysql | TCP connection |
| PostgreSQL | lib/pq | TCP connection |
4. Caching Strategy
The Store wrapper maintains in-memory caches for frequently accessed data:- Default TTL: 10 minutes
- Cleanup Interval: 5 minutes
- Max Items: 1000
- Eviction Policy: LRU (Least Recently Used)
- Instance settings (global configuration)
- Users (authentication lookups)
- User settings (preferences)
5. Frontend State Management
React Query v5 (Server State)
All API interactions use React Query for automatic caching, background refetching, and optimistic updates:React Context (Client State)
| Context | Purpose | State |
|---|---|---|
AuthContext | Authentication | Current user, auth status |
ViewContext | UI preferences | Layout mode, sort order |
MemoFilterContext | Filtering | Active filters, shortcuts |
6. Database Migration System
Memos uses a version-based migration system with transactional safety:Migration Flow
Schema Versioning
Version Format:major.minor.patch (e.g., 0.28.5)Storage:
system_setting table, key BASIC, field schema_version
Migration Files:
Migration Safety
- Transactional: All migrations in single transaction
- Ordered: Lexicographic ordering by filename
- Idempotent: Checks current version before applying
- Downgrade Protection: Rejects schema version downgrades
- Minimum Version: Requires v0.22+ to upgrade (store/migrator.go:365-405)
7. Protocol Buffer Code Generation
Memos uses Protocol Buffers for type-safe API contracts:- Go:
proto/gen/api/v1/(backend services) - TypeScript:
web/src/types/proto/api/v1/(frontend)
- Lint rules: BASIC
- Breaking change detection: FILE
Plugin System
Memos supports pluggable components for extended functionality:| Plugin | Purpose | Location |
|---|---|---|
scheduler | Cron job scheduling | plugin/scheduler/ |
email | SMTP email delivery | plugin/email/ |
filter | CEL expression filtering | plugin/filter/ |
webhook | HTTP webhook dispatch | plugin/webhook/ |
markdown | Markdown parsing (goldmark) | plugin/markdown/ |
httpgetter | HTTP content fetching | plugin/httpgetter/ |
storage/s3 | S3-compatible storage | plugin/storage/s3/ |
Background Runners
Background jobs run in separate goroutines with cancellation support:- S3 Presign Runner: Generates presigned URLs for S3 objects (server/runner/s3presign/)
Server Initialization
See: server/server.go:38-88File Structure
Next Steps
Backup & Restore
Learn how to backup and restore your Memos data
Security
Security best practices and hardening
Performance Tuning
Optimize Memos for production workloads
API Reference
Complete API documentation