Skip to content

JohnsonOduri/SecondMind

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SecondMind Collective

AI-powered second brain for capturing, enriching, and querying personal knowledge.

Live Links

Demo GIF

SecondMind product walkthrough demo

What This App Does

  • Captures knowledge items (note/link/insight) with optional source + manual tags
  • Enriches notes with AI summary + AI tags on create/update
  • Shows a searchable, filterable dashboard with detail view
  • Supports grounded conversational query over saved notes
  • Exposes a public query endpoint for infrastructure-style access

Documentation Map

  • In-app docs: /docs
  • API routes: src/app/api/**
  • AI service: src/lib/gemini.ts
  • Notes/data service: src/lib/notes.ts
  • Database migrations: supabase/migrations/**

Tech Stack

  • Frontend: Next.js App Router, React, TypeScript, Tailwind CSS, shadcn/ui
  • Backend: Next.js API Routes
  • Database: Supabase Postgres
  • AI: Google Gemini (server-side)
  • Motion/UI: Framer Motion
  • Deploy: Vercel

Architecture & Diagrams

  • In-app architecture visuals: /docs → Architecture Diagrams section
  • Mermaid source diagrams are included below for portability/documentation

System Architecture

flowchart TD
  U[User] --> UI[Next.js UI\nLanding • Dashboard • New Note • Docs]
  UI --> API[Next.js API Routes]

  subgraph API_Layer[Application + Service Layer]
    N1[/POST /api/notes/]
    N2[/GET /api/notes/]
    N3[/POST /api/brain/query/]
    N4[/POST /api/public/brain/query/]
  end

  API --> N1
  API --> N2
  API --> N3
  API --> N4

  N1 --> S1[lib/notes.ts\ncreateNote • updateNote]
  N3 --> S2[lib/notes.ts\nfindCandidateNotes • logQuery]
  N3 --> G1[lib/gemini.ts\nextractQueryTags • answerQuestionWithNotes]
  N4 --> S2
  N4 --> G1

  S1 --> DB[(Supabase Postgres)]
  S2 --> DB
  G1 --> AI[Gemini API]
Loading

Ingestion Pipeline

sequenceDiagram
  participant User
  participant NewNotePage
  participant APINotes as /api/notes
  participant NotesLib as lib/notes.ts
  participant Gemini as lib/gemini.ts
  participant Supabase

  User->>NewNotePage: Submit title/content/type + optional tags/source
  NewNotePage->>APINotes: POST /api/notes
  APINotes->>NotesLib: createNote(payload)
  NotesLib->>Gemini: enrichNote(content, existingTags)
  Gemini-->>NotesLib: summary + aiTags + mergedTags
  NotesLib->>Supabase: insert into notes
  NotesLib->>Supabase: upsert tags + note_tags
  NotesLib-->>APINotes: created note
  APINotes-->>NewNotePage: 201 Created
Loading

Query Pipeline

sequenceDiagram
  participant User
  participant AskBrain
  participant APIQuery as /api/brain/query
  participant NotesLib as lib/notes.ts
  participant Gemini as lib/gemini.ts
  participant Supabase

  User->>AskBrain: Ask natural language question
  AskBrain->>APIQuery: POST /api/brain/query
  APIQuery->>NotesLib: listExistingTags()
  APIQuery->>Gemini: extractQueryTags(question, existingTags)
  Gemini-->>APIQuery: queryTags
  APIQuery->>NotesLib: findCandidateNotes(queryTags, question)
  NotesLib->>Supabase: tag overlap + full-text retrieval
  Supabase-->>NotesLib: candidate notes
  APIQuery->>Gemini: answerQuestionWithNotes(question, candidates)
  Gemini-->>APIQuery: answer + sources
  APIQuery->>NotesLib: logQuery(question, resultCount)
  APIQuery-->>AskBrain: JSON response
Loading

Data Model (High-Level)

  • notes: primary knowledge entries with content, summary, and tags
  • tags: canonical taxonomy and usage counter
  • note_tags: many-to-many note-tag mapping
  • query_logs: query observability (question + result count)
  • note_updates: update history for prior summary/tags

Quick Start

1) Environment Variables

Create .env.local:

NEXT_PUBLIC_SUPABASE_URL=
NEXT_PUBLIC_SUPABASE_ANON_KEY=
SUPABASE_SERVICE_ROLE_KEY=
GEMINI_API_KEY=

Security notes:

  • Keep SUPABASE_SERVICE_ROLE_KEY and GEMINI_API_KEY server-only.
  • Never commit .env.local.

2) Install & Run

npm install
npm run dev

Open http://localhost:3000.

3) Database Migrations

Apply in order:

  1. supabase/migrations/20260316_create_notes.sql
  2. supabase/migrations/20260316_add_user_scoping_and_rls.sql
  3. supabase/migrations/20260316_add_supporting_tables.sql

Runtime Behavior

  • Ingestion flow: form input → validation → Gemini enrichment → note persistence → canonical tag sync
  • Query flow: question → query-tag extraction → candidate retrieval (tag/full-text) → grounded answer + sources
  • Public access: external callers can use POST /api/public/brain/query

Scripts

  • npm run dev — Start local dev server
  • npm run build — Production build
  • npm run start — Run production server
  • npm run lint — Lint checks
  • npm run test — Unit tests (Vitest)

API Endpoints

  • GET /api/notes
  • POST /api/notes
  • GET /api/notes/:id
  • PATCH /api/notes/:id
  • DELETE /api/notes/:id
  • POST /api/brain/query
  • POST /api/public/brain/query

Public query payload example:

{
  "question": "What did I note about distributed systems?",
  "userId": "optional-uuid"
}

Tradeoffs & Future Improvements

Due to the 6–10 hour time constraint of the assignment, I prioritized core product functionality, UI polish, and AI integration over advanced features.

Planned Improvements

  • Tree-based Knowledge Visualization
    Instead of a flat list of notes, I would introduce a “tree of thoughts” or whiteboard-style visualization to represent relationships between ideas and improve navigation.

  • Semantic Search (RAG)
    Implement vector embeddings and retrieval-augmented generation for more accurate and context-aware querying.

  • Enhanced Conversational Querying
    Improve multi-turn conversations and contextual memory instead of single-shot queries.

  • Authentication & User Isolation
    Add proper auth (e.g., Supabase Auth / Google Auth) with user-scoped data.

  • Improved Motion & Splash Integration
    Blend the splash screen animation more seamlessly with the application background and transitions.

Tradeoff Decision

Given the time constraint, I chose to:

  • prioritize a working end-to-end system
  • focus on UI/UX polish and responsiveness
  • implement meaningful AI features instead of partially built advanced systems

About

SecondMind — a premium AI-powered second brain application for capturing, enriching, and querying personal knowledge with summarization, auto-tagging, and conversational search.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors