How hamedmp/cursorlens works
Project Type and Purpose
• Cursor Lens is an open-source, full-stack web application built with Next.js and React.
• It functions as a proxy between the Cursor IDE and multiple AI providers (OpenAI, Anthropic, etc.), logging all AI-assisted coding requests and exposing an analytics dashboard.
Top-Level File Structure and Architectural Indicators
• Next.js App:
• src/app – Server and client routes under the App Router.
• src/components – Reusable UI components (shadcn/ui + Tailwind CSS).
• next.config.js / next.config.mjs – Next.js configuration.
• API / Proxy Layer:
• src/app/[...openai]/route.ts – Catch-all proxy endpoint for Cursor→AI requests.
• src/app/api/* – RESTful endpoints for configurations, logs, stats.
• Data Layer:
• prisma/schema.prisma & prisma/migrations – Database schema and migrations for PostgreSQL.
• src/lib/prisma.ts – Prisma client setup.
• src/lib/db.ts, lib/utils.ts, lib/cost-calculator.ts – DB helpers and business logic (cost estimation, metadata).
• Scripts & Jobs:
• scripts/update-log-costs.ts – Scheduled job for back-filling cost metadata.
• prisma/seed.ts – Initial seed script.
• DevOps / Deployment:
• Dockerfile & docker-compose.yml – Containerization.
• start.sh – Startup script.
• .env.example – Environmental variables (.env).
Core Components
A. Frontend (Next.js + React)
• Pages & UI: src/app/* pages, NavBar, LogsList, Stats page, ConfigurationModal.
• Theme system via theme-provider & theme-toggle.
B. Backend API (Next.js Serverless Routes)
• Proxy endpoint: “[...openai]” route that intercepts and forwards requests to AI providers.
• REST APIs: /configurations, /logs, /stats.
C. Database Layer (PostgreSQL + Prisma ORM)
• Prisma client handling CRUD on configurations, logs, stats, cost_model, metadata.
D. External AI Providers
• OpenAI, Anthropic, Mistral, Cohere, Groq, Ollama.
• Vercel AI SDK integrates with these providers.
E. Auxiliary Services
• ngrok (tunnel for exposing localhost to Cursor).
• Caching layer for Anthropic prompt caching (TTL logic in DB or in-memory).
• Scheduled jobs: update-log-costs cron job.
Relationships and Data Flows
• Proxy route ↔ AI providers (forwards requests, receives responses).
• Proxy route → writes to DB (logs request & response metadata).
• Frontend UI → Backend REST APIs → DB (fetch configurations, logs, stats).
• Scripts (update-log-costs) → DB (update cost_model fields).
• Frontend periodically polls /stats endpoint for real-time monitoring.
Architectural Patterns and Design Principles
• Separation of Concerns: Frontend / API / Data layers are clearly separated within Next.js.
• Serverless Functions: Each API route is an isolated handler.
• ORM Abstraction: Prisma provides type-safe DB access.
• Proxy Pattern: Catch-all route delegates to multiple AI providers with dynamic configuration.
• Modular UI: shadcn/ui and Tailwind components promote reuse.