Cache is a modern, full-stack web application designed to help users capture, organize, and revisit their thoughts, ideas, and inspirations. Built with Next.js, Prisma, and a modular component architecture, Cache provides a seamless and intuitive experience for personal knowledge management.
Quick Start: Press
Cmd/Ctrl + Kto add your first thought! π
- Features
- Tech Stack
- Getting Started
- Project Structure
- Architecture
- Scripts
- Technical Details
- Keyboard Shortcuts
- Security Features
- Performance Optimizations
- Contributing
- License
- User Authentication: Secure sign-in and session management with NextAuth.js.
- Thought Management: Add, edit, delete, and categorize thoughts easily.
- Category Organization: Group thoughts by categories for better organization.
- Link Previews: Automatically generate rich previews for links added to thoughts.
- Responsive UI: Clean, modern interface with reusable UI components.
- API-First: RESTful API endpoints for thoughts, categories, and link previews.
- Prisma ORM: Type-safe database access and migrations.
- Next.js
- TypeScript
- Prisma
- NextAuth.js
- Tailwind CSS (assumed for styling)
- Node.js (v18+ recommended)
- npm or yarn
- A PostgreSQL database (or update
prisma/schema.prismafor your DB)
-
Clone the repository:
git clone https://github.com/Ayroid/Cache.git cd Cache -
Install dependencies:
npm install # or yarn install -
Configure environment variables:
- Copy
.env.exampleto.envand fill in the required values (database URL, NextAuth secrets, etc).
- Copy
-
Run database migrations:
npx prisma migrate dev --name init
-
Start the development server:
npm run dev # or yarn dev -
Open http://localhost:3000 in your browser.
- app/ β Next.js app directory (routes, API, pages)
- app/page.tsx β Main application entry point
- app/api/thoughts/ β Thought management endpoints
- app/api/categories/ β Category management endpoints
- app/api/link-preview/ β Link metadata fetching
- app/api/auth/ β NextAuth.js authentication
- components/ β Reusable React components
- Dashboard.tsx β Main application interface
- AddThoughtModal.tsx β Thought creation modal (Cmd/Ctrl+K)
- ThoughtCard.tsx β Individual thought display
- CategoryBar.tsx β Category filter and management
- ui/ β Shadcn-style UI components
- lib/ β Utility functions, hooks, and Prisma client
- prisma/ β Prisma schema and migrations
- schema.prisma β Database schema (User, Category, Thought models)
- public/ β Static assets
- types/ β TypeScript type definitions
- index.ts β Core types and constants
Cache uses Prisma ORM with PostgreSQL for type-safe database access. The schema consists of three main models:
User Model
- Handles authentication via NextAuth.js
- Stores username, email, profile picture
- Relations: categories, thoughts
- See: auth.ts, app/api/auth/[...nextauth]/route.ts
Category Model (prisma/schema.prisma:24-33)
- User-defined thought organization (max 5 per user)
- Colors: amber, coral, teal, sage, lavender, stone
- Cascade deletes associated thoughts
- See: app/api/categories/route.ts
Thought Model (prisma/schema.prisma:35-48)
- Stores text or link-type thoughts
- Optional link metadata (title, image, favicon)
- Pin functionality for important thoughts
- See: app/api/thoughts/route.ts
All API routes are located in app/api/ and follow RESTful conventions:
Thoughts (app/api/thoughts/route.ts)
GET /api/thoughtsβ Fetch all user thoughts (ordered by newest)POST /api/thoughtsβ Create new thought (auto-detects URLs)PATCH /api/thoughts/[id]β Update content, category, or pin statusDELETE /api/thoughts/[id]β Delete thought
Categories (app/api/categories/route.ts)
GET /api/categoriesβ Fetch all user categoriesPOST /api/categoriesβ Create new category (enforces max 5)PATCH /api/categories/[id]β Update name or colorDELETE /api/categories/[id]β Delete category and all thoughts
Link Preview (app/api/link-preview/route.ts)
GET /api/link-preview?url=<url>β Fetch Open Graph metadata- Extracts title, image, and favicon for link-type thoughts
The useMind hook manages all application state:
- Fetches and caches categories/thoughts
- Provides CRUD methods for thoughts and categories
- Handles filtering, pinning, and sorting logic
- Auto-syncs with backend APIs
Key features:
filterThoughts()β Filters by category, sorts pinned firstformatRelativeTime()β Human-readable timestampstogglePin()β Pin/unpin thoughts to top
Dashboard (components/Dashboard.tsx)
- Main application container
- Sticky header with category filter
- Masonry grid layout for thoughts
- Empty state handling
AddThoughtModal (components/AddThoughtModal.tsx)
- Floating action button (bottom-right)
- Keyboard shortcut:
Cmd/Ctrl + K - Auto-detects URLs and fetches link previews
- Save with
Cmd/Ctrl + Enter
ThoughtCard (components/ThoughtCard.tsx)
- Displays individual thoughts
- Link preview for URL-type thoughts
- Pin, edit, move, delete actions
- Category badge with color coding
CategoryBar (components/CategoryBar.tsx)
- Horizontal scrollable category pills
- "All" filter to show everything
- Add/edit categories with color picker
- Authentication β Google OAuth via NextAuth.js
- Dashboard Load β useMind hook fetches data from API
- Add Thought β Modal β URL detection β Link preview API β Save to DB
- Organize β Filter, pin, edit, move via ThoughtCard actions
- Persistence β All changes saved to PostgreSQL via Prisma
devβ Start the development serverbuildβ Build the application for productionstartβ Start the production serverprismaβ Prisma CLI commands
For a comprehensive technical overview including:
- Complete API endpoint documentation
- Detailed database schema specifications
- Component architecture and data flow
- Security and permission patterns
- Performance optimizations
See the detailed codebase analysis section above, or explore the following key files:
- Database: prisma/schema.prisma
- State Management: lib/hooks.ts
- Type Definitions: types/index.ts
- Authentication: auth.ts
Cmd/Ctrl + Kβ Open add thought modalCmd/Ctrl + Enterβ Save thought (in modal)Escβ Close modal
- Authentication: Google OAuth via NextAuth.js
- Authorization: All API routes verify user ownership before modifications
- Data Isolation: Users can only access their own thoughts and categories
- Input Validation: Server-side validation for all user inputs
- SQL Injection Protection: Prisma ORM provides parameterized queries
- Connection Pooling: PostgreSQL connections pooled via
pg.Pool - Indexed Queries: Database indexes on userId, categoryId, isPinned, createdAt
- Client-side Caching: useMind hook caches data to minimize API calls
- Lazy Loading: Components load only when needed
- Masonry Layout: CSS-based layout for efficient rendering
- Chrome/Edge (latest)
- Firefox (latest)
- Safari (latest)
Contributions are welcome! Please open issues or pull requests for suggestions, bug fixes, or new features.
This project is licensed under the MIT License.