GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — aimine/CLAUDE.md at main · IchenDEV/aimine

Expand file tree

/

CLAUDE.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
259 lines (202 loc) · 9.12 KB
/

CLAUDE.md

Copy path

File metadata and controls

259 lines (202 loc) · 9.12 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

AI Mine is an AI Agent exploration platform integrating RAG, Knowledge Graph, Memory, Skill, and MCP (Model Context Protocol) capabilities. This is a full-stack TypeScript monorepo with a React frontend and Hono backend, using tRPC for type-safe API communication.

Development Commands

Setup

pnpm install                    # Install dependencies
cp env.example .env             # Copy environment file
# Edit .env to add your API keys (OPENAI_API_KEY, E2B_API_KEY, etc.)
pnpm db:up                      # Start PostgreSQL + Neo4j via Docker
pnpm db:push                    # Push database schema to PostgreSQL

Development

pnpm dev                        # Start both frontend and backend (parallel)
pnpm dev:be                     # Start backend only (http://localhost:3000)
pnpm dev:fe                     # Start frontend only (http://localhost:5173)

Database

pnpm db:up                      # Start databases (PostgreSQL + Neo4j)
pnpm db:down                    # Stop databases
pnpm db:push                    # Push Drizzle schema to PostgreSQL
pnpm db:studio                  # Open Drizzle Studio

Other

pnpm build                      # Build all packages
pnpm lint                       # Type check all packages
pnpm promptfoo                  # Run prompt evaluation tests

Architecture

Monorepo Structure

aimine/
├── be/                         # Backend (Hono + tRPC)
│   └── src/
│       ├── index.ts            # Server entry: /api/chat/stream (SSE), /trpc (tRPC)
│       ├── db/                 # Drizzle ORM + schema
│       ├── lib/                # OpenAI, Neo4j clients
│       ├── services/           # Business logic
│       └── trpc/               # tRPC router + procedures
├── fe/                         # Frontend (React 19 + Vite)
│   └── src/
│       ├── App.tsx             # Main app component
│       ├── components/         # UI components (ChatPanel, RAGPanel, etc.)
│       ├── stores/             # Zustand state management
│       └── trpc/               # tRPC client setup
├── pkg/                        # Shared packages (workspace:*)
│   ├── types/                  # Shared TypeScript types
│   ├── schema/                 # Zod schemas
│   └── utils/                  # Utility functions
├── prompts/                    # Handlebars prompt templates
└── skills/                     # Pre-defined skill configurations

Agent Architecture

The system supports two agent execution modes:

1. ReAct Mode (be/src/services/agent/react-mode.ts)

Classic Reasoning + Acting loop for simple tasks:

User Query → Think → Act (tool call) → Observe → Think → ... → Final Answer

2. Plan Mode (be/src/services/agent/plan-mode.ts)

Planning-first approach for complex tasks:

User Query → Planner → Task Plan → Executor → SubAgents → Result

The orchestrator (be/src/services/agent/orchestrator.ts) selects the mode based on configuration.

Streaming Agent (be/src/services/agent/stream.ts)

Real-time streaming execution via Server-Sent Events (SSE):

  • /api/chat/stream endpoint returns SSE stream
  • Events: thinking, content, tool_call, tool_result, done, error
  • Used by frontend for live updates

Tool System

Tools are organized in a three-layer architecture (be/src/services/agent/tools.ts):

  1. Primitives - Atomic operations, stateless

    • bash: Execute shell commands in E2B sandbox
    • file_*: File operations
    • util_*: Utility operations
  2. Services - Domain-specific connectors with state

    • rag_*: RAG operations (upload, search, delete)
    • kg_*: Knowledge Graph operations (add entity/relation, query)
    • memory_*: Memory operations (add, search)
    • code_*: Code execution in E2B sandbox
    • todo_*: Task management
    • mcp_*: MCP server interactions
  3. Specialists - Expert agents for complex tasks

    • specialist_*: SubAgent delegation

Tools are registered in toolRegistry and dynamically available to the agent.

MCP (Model Context Protocol) Integration

The system can connect to external MCP servers (be/src/services/mcp/index.ts):

  • Supports both stdio (local commands) and http (SSE) transports
  • Dynamically discovers tools, resources, and prompts from connected servers
  • MCP tools are exposed via mcp_* tools in the agent tool system
  • Each MCP server runs in its own connection with its own client instance

Tool name convention: MCP server tools are registered with underscores replacing dots (e.g., github.list_repos becomes github_list_repos).

Database Schema

PostgreSQL (with pgvector)

  • conversations: Chat sessions with mode (plan/react)
  • messages: Chat history with tool calls
  • documents: RAG documents
  • document_chunks: Vector embeddings (1536 dimensions)
  • memories: Short/long-term memory with embeddings
  • task_plans: Plan mode task plans
  • todos: Task management

Neo4j (Knowledge Graph)

  • Stores entities and relationships
  • APOC plugin enabled for graph algorithms
  • Accessed via neo4j-driver in be/src/lib/neo4j.ts

Frontend Architecture

  • State Management: Zustand stores in fe/src/stores/
  • tRPC Client: Type-safe API calls via @trpc/react-query
  • Streaming: Native EventSource for SSE in ChatPanel
  • UI Components:
    • ChatPanel: Main chat interface with streaming
    • RAGPanel: Document upload and management
    • KGPanel: Knowledge graph visualization
    • MemoryPanel: Memory browsing
    • MCPPanel: MCP server management
    • SkillPanel: Skill library
    • TodoPanel: Task management

API Communication Patterns

  1. tRPC (/trpc/*): Type-safe procedures for CRUD operations

    • Routers: chat, rag, kg, memory, agent, skill, todo, mcp
    • Defined in be/src/trpc/routers/
    • Type inference via AppRouter export
  2. SSE (/api/chat/stream): Real-time agent execution

    • POST with { content, conversationId, mode }
    • Returns SSE stream with events
    • Handles conversation creation automatically

E2B Code Interpreter

Code execution happens in secure E2B sandboxes (be/src/services/e2b/index.ts):

  • Used by bash and code_* tools
  • Executes Python, JavaScript, shell commands
  • Isolated environment for safety

Prompt System

Prompts are managed with Handlebars templates in prompts/:

  • prompts/agent/: Agent system prompts (react.hbs, planner.hbs)
  • prompts/subagent/: SubAgent prompts
  • prompts/extraction/: Information extraction prompts
  • prompts/system/: System-level prompts

Testing with promptfoo:

pnpm promptfoo                  # Runs tests defined in promptfooconfig.yaml

Skills System

Skills are pre-configured task templates (skills/ directory):

  • code-review/: Code review skill
  • data-analysis/: Data analysis skill
  • summarize-doc/: Document summarization
  • web-research/: Web research skill

Each skill has:

  • skill.json: Metadata and configuration
  • Prompt templates
  • Tool specifications

Environment Variables

Required variables in .env:

# OpenAI (required for LLM)
OPENAI_API_KEY=sk-xxx
OPENAI_BASE_URL=https://api.openai.com/v1  # Optional: for proxies
OPENAI_MODEL=gpt-4o                        # Optional: default model
OPENAI_EMBEDDING_MODEL=text-embedding-3-small  # Optional

# PostgreSQL (required for RAG/memory)
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/aimine

# Neo4j (required for Knowledge Graph)
NEO4J_URI=bolt://localhost:7687
NEO4J_USER=neo4j
NEO4J_PASSWORD=password

# E2B (required for code execution)
E2B_API_KEY=e2b_xxx

# Server
PORT=3000
NODE_ENV=development

Key Technical Patterns

Type Safety

  • Shared types in pkg/types/ imported as @aimine/types
  • tRPC provides end-to-end type safety from backend to frontend
  • Drizzle ORM for type-safe database queries

Streaming Responses

  • Agent execution streams via SSE
  • Frontend uses EventSource for real-time updates
  • Messages are saved to DB only on completion

Tool Execution Flow

  1. Agent decides to use tool (via OpenAI function calling)
  2. executeTool() routes to appropriate service
  3. Service executes and returns string result
  4. Result fed back to agent for next iteration

Database Connections

  • PostgreSQL: Connected via drizzle-orm with postgres driver
  • Neo4j: Connected via neo4j-driver with session management
  • Connections initialized in be/src/db/ and be/src/lib/

Common Gotchas

  1. Tool Names: MCP tools must use underscores instead of dots (enforced in be/src/services/agent/tools.ts)
  2. Streaming: The /api/chat/stream endpoint doesn't use tRPC; it's a plain Hono route
  3. Embeddings: All embeddings are 1536-dimensional (OpenAI text-embedding-3-small)
  4. Database: Must run pnpm db:push after schema changes in be/src/db/schema.ts
  5. Workspaces: Use workspace:* protocol for internal package dependencies

Testing

Currently using promptfoo for prompt evaluation. No unit tests present yet.

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.