This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
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.
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
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)
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
pnpm build # Build all packages pnpm lint # Type check all packages pnpm promptfoo # Run prompt evaluation tests
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
The system supports two agent execution modes:
Classic Reasoning + Acting loop for simple tasks:
User Query → Think → Act (tool call) → Observe → Think → ... → Final Answer
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.
Real-time streaming execution via Server-Sent Events (SSE):
/api/chat/streamendpoint returns SSE stream- Events:
thinking,content,tool_call,tool_result,done,error - Used by frontend for live updates
Tools are organized in a three-layer architecture (be/src/services/agent/tools.ts):
-
Primitives - Atomic operations, stateless
bash: Execute shell commands in E2B sandboxfile_*: File operationsutil_*: Utility operations
-
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 sandboxtodo_*: Task managementmcp_*: MCP server interactions
-
Specialists - Expert agents for complex tasks
specialist_*: SubAgent delegation
Tools are registered in toolRegistry and dynamically available to the agent.
The system can connect to external MCP servers (be/src/services/mcp/index.ts):
- Supports both
stdio(local commands) andhttp(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).
conversations: Chat sessions with mode (plan/react)messages: Chat history with tool callsdocuments: RAG documentsdocument_chunks: Vector embeddings (1536 dimensions)memories: Short/long-term memory with embeddingstask_plans: Plan mode task planstodos: Task management
- Stores entities and relationships
- APOC plugin enabled for graph algorithms
- Accessed via
neo4j-driverin be/src/lib/neo4j.ts
- State Management: Zustand stores in
fe/src/stores/ - tRPC Client: Type-safe API calls via
@trpc/react-query - Streaming: Native
EventSourcefor SSE in ChatPanel - UI Components:
ChatPanel: Main chat interface with streamingRAGPanel: Document upload and managementKGPanel: Knowledge graph visualizationMemoryPanel: Memory browsingMCPPanel: MCP server managementSkillPanel: Skill libraryTodoPanel: Task management
-
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
AppRouterexport
-
SSE (
/api/chat/stream): Real-time agent execution- POST with
{ content, conversationId, mode } - Returns SSE stream with events
- Handles conversation creation automatically
- POST with
Code execution happens in secure E2B sandboxes (be/src/services/e2b/index.ts):
- Used by
bashandcode_*tools - Executes Python, JavaScript, shell commands
- Isolated environment for safety
Prompts are managed with Handlebars templates in prompts/:
prompts/agent/: Agent system prompts (react.hbs, planner.hbs)prompts/subagent/: SubAgent promptsprompts/extraction/: Information extraction promptsprompts/system/: System-level prompts
Testing with promptfoo:
pnpm promptfoo # Runs tests defined in promptfooconfig.yamlSkills are pre-configured task templates (skills/ directory):
code-review/: Code review skilldata-analysis/: Data analysis skillsummarize-doc/: Document summarizationweb-research/: Web research skill
Each skill has:
skill.json: Metadata and configuration- Prompt templates
- Tool specifications
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
- 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
- Agent execution streams via SSE
- Frontend uses
EventSourcefor real-time updates - Messages are saved to DB only on completion
- Agent decides to use tool (via OpenAI function calling)
executeTool()routes to appropriate service- Service executes and returns string result
- Result fed back to agent for next iteration
- PostgreSQL: Connected via
drizzle-ormwithpostgresdriver - Neo4j: Connected via
neo4j-driverwith session management - Connections initialized in
be/src/db/andbe/src/lib/
- Tool Names: MCP tools must use underscores instead of dots (enforced in be/src/services/agent/tools.ts)
- Streaming: The
/api/chat/streamendpoint doesn't use tRPC; it's a plain Hono route - Embeddings: All embeddings are 1536-dimensional (OpenAI text-embedding-3-small)
- Database: Must run
pnpm db:pushafter schema changes in be/src/db/schema.ts - Workspaces: Use
workspace:*protocol for internal package dependencies
Currently using promptfoo for prompt evaluation. No unit tests present yet.