Skip to content

Latest commit

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

CORTEX

AI-Powered Code Editor

"Code with Intent. Build with Memory."

Product Requirements Document • Version 1.0
Shivam Garade • April 2026

1. Executive Summary

Cortex is a next-generation, AI-first code editor built on the MERN stack with Monaco Editor. Unlike conventional AI copilots that only autocomplete code, Cortex understands the intent behind your code, explains your entire codebase visually, and remembers every architectural decision you make — transforming coding from a solitary act into an intelligent, documented process.

1.1 The Problem

  • Developers write code but rarely document why — context is lost forever once a sprint ends.

  • AI tools today are glorified autocomplete engines with no understanding of codebase-level architecture.

  • Onboarding new devs is painful because no tool explains how data flows through a real project.

  • Code review is slow because reviewers don't know the intent behind specific implementations.

1.2 The Solution — Three Signature Features

FeatureWhat It DoesWhy It's Unique
Intent ModeRefactor/optimize the current file or entire codebase toward a chosen intent (Performance, Scalability, Security, Readability)No editor lets you optimize with a declared objective — it's intent-driven AI transformation
Codebase ExplainerOne-click visual map of how files relate, how data flows, and what every dependency doesConverts an entire MERN project into an interactive, annotated dependency graph
Decision MemoryAnnotate why code exists. Search, audit, and time-travel through architectural decisionsYour editor becomes a living architecture journal — zero extra tooling needed

1.3 Target Users

  • Solo developers building products — need context preservation across sessions

  • Small engineering teams (2–8 devs) — need shared architectural understanding

  • Students & bootcamp grads — need to understand codebases they didn't write

  • Indie hackers & startup CTOs — need to move fast without losing 'why'

2. Product Identity

2.1 Name & Branding

AttributeValue
Product NameCortex
TaglineCode with Intent. Build with Memory.
Version1.0.0 — MVP
CategoryAI-Powered Code Editor / Developer Tool
PlatformWeb App (Browser-based, Desktop-ready via Electron later)
Target StackMERN projects (React, Node.js, Express, MongoDB) — expandable
Logo ConceptHexagonal neural node — representing a cortex cell / code node

2.2 Brand Voice

  • Intelligent but not arrogant — it explains, doesn't lecture

  • Precise — every word in the UI has a reason

  • Dark & focused — like a terminal, not a toy

  • Dev-native — uses real terminology, not dumbed-down language

3. Technology Stack

3.1 Frontend

TechnologyVersionPurposeWhy This Choice
React18.xUI frameworkComponent model fits panel-based editor layout
Monaco Editor0.47.xCode editing coreSame engine as VS Code — syntax highlight, IntelliSense, multi-cursor
SCSS1.70.xStylingToken-based theming, nested rules, dark mode variables
Zustand4.xState managementMinimal boilerplate, perfect for editor state (tabs, file tree, memory)
React Router v66.xRoutingSPA navigation between editor, memory view, explainer view
D3.js7.xGraph visualizationCodebase Explainer force-directed graph
React Flow11.xInteractive diagramsDrag-and-drop dependency visualization fallback
Axios1.6.xHTTP clientAPI calls to backend & AI endpoints

3.2 Backend

TechnologyVersionPurposeWhy This Choice
Node.js20 LTSRuntimeNon-blocking I/O — handles concurrent AI streaming responses
Express.js4.xAPI frameworkMinimal, fast, production-proven
MongoDB7.xPrimary databaseFlexible schema for decision memories + codebase metadata
Mongoose8.xODMSchema validation for Decision Memory documents
Multer1.4.xFile uploadsFor codebase upload/analysis — handles zip files
Socket.IO4.xReal-timeStreaming AI responses token-by-token to the editor
dotenv16.xConfigEnv variable management for API keys & DB strings

3.3 AI Provider — Google Gemini Flash

After evaluating all major AI providers on free-tier generosity, Google Gemini 2.0 Flash is the clear winner for this project:

ProviderFree Tier RPMFree Tier RPDToken LimitCost After Free
Google Gemini 2.0 Flash15 req/min1,500 req/day1M tokens/day FREE~$0.075 / 1M tokens
Groq (Llama 3.3 70B)30 req/min14,400 req/dayLimited contextPay-as-you-go
OpenAI GPT-4o-miniLimited200 req/dayRestricted$0.15 / 1M tokens
Anthropic Claude HaikuLimited~50/day trialRestricted$0.25 / 1M tokens

Decision: Google Gemini 2.0 Flash via @google/generative-ai SDK. Model ID: gemini-2.0-flash-exp. 1 million free tokens per day is more than enough for MVP usage. Add Groq as fallback for burst traffic.

3.4 Database — MongoDB Atlas

  • Free tier: 512 MB storage, unlimited read/write for dev usage

  • Hosts: DecisionMemory, CodebaseSnapshot, UserSession collections

  • Index: decision memories are indexed by fileHash + projectId for fast lookup

3.5 Auth

  • Clerk — free tier, 10,000 MAU, handles JWT, OAuth (Google/GitHub), user sessions

  • All backend routes protected via Clerk JWT middleware

4. Design System

4.1 Philosophy

Cortex follows a Dark-First, Token-Based design system. Every color, spacing, and typography value is stored as a SCSS variable. There is no hardcoded value anywhere in the codebase. The system is inspired by VS Code's density with Linear's visual refinement.

4.2 Color Tokens (SCSS Variables)

SCSS TokenHex ValueUsage
$color-bg-base#0A0A0FOutermost background — editor shell
$color-bg-surface#111118Sidebar, panels, modals
$color-bg-elevated#1A1A28Dropdowns, tooltips, cards
$color-bg-input#0F0F1AInput fields, search bar
$color-border-subtle#1E1E30Dividers, inactive tab borders
$color-border-default#2E2E45Active panels, focused inputs
$color-text-primary#E5E5F0Main readable text
$color-text-secondary#8888AALabels, metadata, hints
$color-text-disabled#44445APlaceholder, disabled state
$color-primary#4F6EF7CTAs, active tabs, selections, links
$color-primary-hover#6B85FFButton hover state
$color-primary-muted#1E2A5CSelected row backgrounds
$color-secondary#8B5CF6Intent Mode accent — Violet
$color-accent#22D3EECodebase Explainer accent — Cyan
$color-memory#F59E0BDecision Memory accent — Amber
$color-success#22C55EPass states, positive confirmations
$color-warning#F97316Warnings, caution states
$color-error#EF4444Errors, destructive actions
$color-code-bg#0D0D17Monaco editor background
$color-highlight#4F6EF720Selection highlight in editor

4.3 Typography

TokenValueUsage
$font-uiInter, system-ui, sans-serifAll UI text — sidebar, menus, panels
$font-monoJetBrains Mono, Fira Code, monospaceCode in Monaco, inline code snippets
$font-size-xs11pxMetadata, timestamps, badges
$font-size-sm12pxFile tree labels, tab names
$font-size-base13pxDefault panel text, inputs
$font-size-md14pxPrimary content, descriptions
$font-size-lg16pxSection headers
$font-size-xl20pxPanel titles, modal headers
$font-size-2xl24pxFeature headings
$font-weight-normal400Default body text
$font-weight-medium500Labels, emphasis
$font-weight-semibold600Section headers, active states
$font-weight-bold700Feature titles, primary CTAs

4.4 Spacing Scale

TokenValueUsage
$space-14pxIcon internal padding
$space-28pxTight component gaps
$space-312pxDefault padding inside small components
$space-416pxStandard padding — sidebar items, inputs
$space-520pxPanel sections
$space-624pxCard padding, modal padding
$space-832pxBetween major sections
$space-1248pxPage-level margins

4.5 Border Radius

TokenValueUsage
$radius-sm4pxBadges, tags, tiny pills
$radius-md8pxButtons, input fields, file tree items
$radius-lg12pxPanels, cards, modals
$radius-xl16pxFeature callout boxes
$radius-full9999pxAvatar, toggle switches, circular icons

4.6 Shadow & Elevation

TokenValueUsage
$shadow-sm0 1px 3px rgba(0,0,0,0.4)Subtle card lift
$shadow-md0 4px 12px rgba(0,0,0,0.5)Dropdown, tooltip
$shadow-lg0 8px 32px rgba(0,0,0,0.6)Modal, feature panel
$shadow-glow-primary0 0 20px rgba(79,110,247,0.25)Active intent mode button glow
$shadow-glow-memory0 0 20px rgba(245,158,11,0.25)Active memory annotation glow

4.7 Component Design Patterns

Buttons

  • Primary: bg=$color-primary, text=white, radius=$radius-md, height=36px, hover=primary-hover + glow

  • Ghost: bg=transparent, border=$color-border-default, hover=bg-elevated

  • Icon: 32x32px, radius=$radius-md, hover=bg-elevated — used in toolbar

  • Feature CTA (Intent / Explainer / Memory): 40px height, left icon, gradient border animation on hover

Tabs

  • Active tab: $color-primary bottom border (2px), $color-text-primary text

  • Inactive tab: $color-bg-surface bg, $color-text-secondary text, close icon on hover

  • Tab strip: horizontal scroll when > 8 tabs open, pinned tabs support

File Tree

  • Indent per level: 16px — folder chevron + icon + filename pattern

  • Active file: $color-primary-muted background, $color-primary-hover text

  • Right-click context menu: rename, delete, add decision memory, copy path

5. System Architecture

5.1 High-Level Architecture

Cortex follows a clean Client → API Server → AI Service → Database pipeline:

LayerTechnologyResponsibility
Client (Browser)React + Monaco + D3 + SCSSEditor UI, file tree, feature panels, real-time AI response streaming
API GatewayExpress.js (Node 20)Route handling, auth middleware (Clerk JWT), rate limiting, request queueing
AI Service LayerGemini 2.0 Flash SDKIntent analysis, codebase parsing, decision extraction — prompt engineering lives here
DatabaseMongoDB Atlas (Mongoose)Decision Memory documents, project metadata, user sessions, codebase snapshots
File System (Temp)Node fs + multer + archiverHandling uploaded project zips, parsing directory trees, extracting file content for analysis
Real-time LayerSocket.IOStreaming AI token responses to Monaco editor panels in real-time
AuthClerkJWT issuance, OAuth, user identity across sessions

5.2 Frontend Architecture

Folder Structure

PathContents
src/Root of React application
src/components/Reusable UI atoms and molecules — Button, Modal, Badge, Tag, Tooltip, etc.
src/layouts/AppShell.jsx — main 3-panel layout (Sidebar
src/features/Feature-level modules — intent/, explainer/, memory/ — each has its own components, hooks, store slice
src/features/intent/IntentMode.jsx, IntentSelector.jsx, IntentResultPanel.jsx, useIntentMode.js
src/features/explainer/CodebaseExplainer.jsx, DependencyGraph.jsx, FlowOverlay.jsx, useExplainer.js
src/features/memory/DecisionMemory.jsx, MemoryAnnotation.jsx, MemorySearch.jsx, useMemory.js
src/editor/MonacoWrapper.jsx, EditorTabs.jsx, FileTree.jsx, EditorToolbar.jsx
src/store/Zustand store slices — editorStore.js, projectStore.js, memoryStore.js, uiStore.js
src/api/Axios instance + service files — intentApi.js, explainerApi.js, memoryApi.js
src/hooks/Shared custom hooks — useProject.js, useSocket.js, useTheme.js, useDebounce.js
src/styles/SCSS architecture — _variables.scss, _reset.scss, _typography.scss, _utilities.scss, main.scss
src/styles/components/Per-component SCSS — _button.scss, _tabs.scss, _sidebar.scss, _modal.scss
src/pages/Route-level pages — Editor.jsx, MemoryVault.jsx, ExplainerView.jsx, Settings.jsx
src/utils/Helpers — fileParser.js, tokenCounter.js, graphBuilder.js, diffHighlighter.js
public/Static assets — favicon, fonts, editor themes

5.3 Backend Architecture

Folder Structure

PathContents
server/Root of Express application
server/index.jsApp entry — Express setup, Socket.IO, CORS, middleware chain
server/routes/Route definitions — intent.routes.js, explainer.routes.js, memory.routes.js, project.routes.js
server/controllers/Business logic — IntentController.js, ExplainerController.js, MemoryController.js
server/services/Service abstractions — GeminiService.js, CodeParserService.js, GraphBuilderService.js
server/models/Mongoose schemas — DecisionMemory.js, Project.js, CodebaseSnapshot.js
server/middleware/Auth.js (Clerk JWT), RateLimit.js, ErrorHandler.js, RequestLogger.js
server/utils/Helpers — fileExtractor.js, promptBuilder.js, tokenEstimator.js
server/sockets/Socket event handlers — streamHandler.js, intentStream.js
.envGEMINI_API_KEY, MONGODB_URI, CLERK_SECRET_KEY, PORT, CLIENT_URL

5.4 Data Flow — Request Lifecycle

StepWhat Happens
1. User actionUser clicks Intent Mode → selects 'Performance' → selects scope (current file)
2. React firesuseIntentMode hook calls intentApi.analyze({ code, intent, scope, projectId })
3. Express receivesPOST /api/intent/analyze — Clerk JWT middleware validates, rate limiter checks
4. ControllerIntentController extracts code payload, calls GeminiService.streamAnalysis()
5. Gemini SDKgenerateContentStream() called with system prompt + user code — response streams token by token
6. Socket.IOServer emits 'intent:token' events per token — client Socket.IO listener appends to result panel
7. Stream completeServer emits 'intent:done' with metadata — client saves diff to Zustand store
8. User acceptsClient calls PATCH /api/memory/attach to link this refactor to a decision memory entry

6. Feature Specifications

6.1 Feature 1 — Intent Mode

Overview

Intent Mode is Cortex's most powerful feature. A developer declares an intent (what they want the code to become), selects a scope (current selection, file, folder, or full project), and Cortex's AI rewrites and annotates the code to fulfill that intent — showing a clear diff, explanation, and confidence score.

Intent Types

IntentColor TokenWhat Cortex DoesExample Output
Performance$color-success (Green)Identifies bottlenecks, removes unnecessary re-renders, replaces O(n²) with O(n), adds memoizationWraps heavy computations in useMemo, replaces forEach chains with Map lookups
Scalability$color-primary (Blue)Decouples modules, moves inline logic to services, separates concerns, adds abstraction layersExtracts API calls to service layer, adds pagination-ready data structures
Security$color-error (Red)Finds injection risks, adds input sanitization, identifies exposed secrets, validates data shapesAdds Joi/Zod validation, escapes HTML, moves secrets to env
Readability$color-accent (Cyan)Renames vague variables, adds JSDoc comments, splits long functions, adds meaningful constantsConverts 'x' to 'userCount', splits 80-line function into 3 named functions
Maintainability$color-memory (Amber)Removes duplication, extracts reusable hooks/utilities, adds error boundariesCreates useLocalStorage hook from 3 duplicated useState patterns

Intent Mode UI Flow

  1. Toolbar button 'Intent Mode' clicked → Intent selector panel slides in from right

  2. User selects intent type (radio button with color-coded icon)

  3. User selects scope: Selection, Current File, Current Folder, Entire Project

  4. Optional: User adds a custom instruction field (e.g., 'Focus on the fetchUsers function only')

  5. Click 'Run Intent' → loading state shows AI processing badge with spinner

  6. Results stream into a split-pane diff view (left = original, right = refactored)

  7. Confidence badge shown per suggestion (High / Medium / Low)

  8. User can Accept All, Accept Selected, or Reject — with keyboard shortcuts

  9. On accept, changes apply to Monaco editor + a Decision Memory entry is auto-created

Intent Mode — Backend API

EndpointMethodBodyResponse
POST /api/intent/analyzePOST{ code, intent, scope, projectId, customInstruction }Stream of { token, type } events via Socket.IO
GET /api/intent/history/:projectIdGET-Array of past intent runs with diffs
POST /api/intent/acceptPOST{ intentRunId, acceptedDiffs[] }{ success, memoryId }

Intent Mode — System Prompt Template

The GeminiService builds this prompt dynamically based on intent and scope:

  • Role: You are a senior software architect specializing in {intent} optimization.

  • Input: A code file written in {detectedLanguage}. Project context: {projectContext}.

  • Task: Refactor this code for {intent}. Preserve all existing functionality.

  • Output format: Return ONLY a JSON object with { refactoredCode, changes[], explanation, confidenceScore }.

  • Each change in changes[] must have: { lineFrom, lineTo, reason, type }.

6.2 Feature 2 — Codebase Explainer

Overview

The Codebase Explainer converts an entire project directory into an interactive visual graph. Developers can see which files import which, how data flows from a user action all the way to the database, and what every major dependency does — without reading a single line of code.

Visualization Layers

LayerView TypeWhat Is Shown
File Dependency GraphForce-directed D3 graphNodes = files. Edges = import/require relationships. Cluster by folder with color coding.
Data Flow ViewDirected acyclic graphTraces a specific user action (e.g., 'user clicks login') through components → API call → server route → DB query
Dependency AuditFlat list + treemapAll npm packages, their size, last updated, whether they are used, and AI-generated one-line summaries
Component TreeTree diagramReact component hierarchy — parent/child relationships, which components hold state, which are pure

Explainer UI Flow

  1. User clicks 'Explain Codebase' in toolbar → Explainer view opens as full-screen overlay

  2. If project not yet analyzed: upload project as ZIP or point to local folder path

  3. Parser runs on backend — extracts all imports, exports, function calls, and component trees

  4. AI summarizes each file's purpose in one line — shown as tooltip on hover in the graph

  5. User can switch between 4 visualization layers via tab bar at top

  6. Clicking any node opens a side panel with: file summary, what it imports, what imports it, key functions

  7. Search bar filters the graph — typing a filename highlights it and its direct connections

  8. Export button saves the graph as SVG or PDF for documentation/onboarding

Explainer — Backend API

EndpointMethodBodyResponse
POST /api/explainer/analyzePOST{ projectZip } multipart OR { projectPath }{ snapshotId, fileCount, graphData, summary }
GET /api/explainer/:snapshotId/graphGET-{ nodes[], edges[], clusters[] }
GET /api/explainer/:snapshotId/flowGETquery: { entryPoint }{ flowNodes[], flowEdges[] }
GET /api/explainer/:snapshotId/depsGET-{ dependencies[], devDependencies[], unusedList[] }
POST /api/explainer/summarize-filePOST{ fileContent, fileName, projectContext }{ summary, keyFunctions[], importedBy[], imports[] }

Graph Node Schema

  • id: Unique file path string

  • label: Filename (e.g., UserController.js)

  • type: component | route | model | service | utility | config | test

  • summary: AI-generated one-line description

  • imports: string[] — list of files this imports

  • importedBy: string[] — list of files that import this

  • linesOfCode: number

  • lastModified: ISO timestamp

6.3 Feature 3 — Decision Memory

Overview

Decision Memory is the feature that makes Cortex truly irreplaceable. Every piece of code can carry a 'memory' — a developer-written annotation explaining WHY it exists, what it prevents, what tradeoff it makes, or what bug it was added to fix. These memories are searchable, timestamped, linkable, and AI-summarizable — creating a living architecture decision record inside your editor.

Memory Entry Schema (MongoDB)

FieldTypeDescription
_idObjectIdMongoDB document ID
projectIdStringLinks memory to a project — from Clerk user context
filePathStringRelative file path — e.g., src/features/auth/AuthService.js
lineFromNumberStart line of the annotated code block
lineToNumberEnd line of the annotated code block
codeSnapshotStringThe exact code at time of annotation (for diff comparison later)
reasonString (required)The 'why' — what this code does that isn't obvious
categoryEnumPERFORMANCE
tagsString[]Developer-defined tags — ['re-render', 'race-condition', 'api-contract']
linkedToObjectId[]Other memory entries this decision references or depends on
intentRunIdObjectId (optional)If created from an Intent Mode run — links to that analysis
authorStringClerk userId — for team memory attribution
createdAtDateWhen the memory was created
updatedAtDateLast edited timestamp

Decision Memory UI Flow

  1. Right-click on any code range in Monaco → context menu shows 'Add Decision Memory'

  2. OR: Click the Memory icon in the toolbar → opens Memory Annotation panel

  3. A drawer opens from the right with pre-filled file path and line range

  4. Developer fills: Reason field (required), Category (dropdown), Tags (comma input), Links (search other memories)

  5. Saved memory appears as an amber gutter decoration in Monaco — hover shows preview

  6. Memory Vault view: full-screen list/search of all memories in the project

  7. Search memories by text, category, tag, date range, file, or author

  8. Timeline view: shows all memories in chronological order with code diffs

  9. AI Summary: click 'Summarize Decisions' to get a paragraph explaining the most important architectural choices

Decision Memory — Backend API

EndpointMethodBodyResponse
POST /api/memoryPOSTFull memory schema object{ memory, _id }
GET /api/memory/:projectIdGETquery: { file, category, tag, search }{ memories[], count }
PATCH /api/memory/:idPATCHPartial memory object{ updated memory }
DELETE /api/memory/:idDELETE-{ success }
POST /api/memory/summarizePOST{ projectId, filters }{ aiSummary, keyDecisions[] }
GET /api/memory/timeline/:projectIdGET-{ memories[] sorted by createdAt }

Gutter Decoration in Monaco

  • Monaco Editor API: editor.deltaDecorations() — adds colored left-border gutter marks

  • Amber color (#F59E0B) — consistent with $color-memory SCSS token

  • Hover over gutter mark → shows memory preview tooltip (reason + category badge)

  • Click gutter mark → opens full memory in right panel

  • Multiple memories on same file: stacked gutter marks, click opens all in sidebar

7. UI / UX Layout

7.1 App Shell Layout

Cortex uses a classic 3-panel IDE layout with a right feature panel for AI output:

PanelWidthContentResizable?
Activity Bar (leftmost)48px fixedIcon nav — File Tree, Search, Memory Vault, Settings, User AvatarNo
Sidebar240px defaultFile tree, project switcher, git status indicatorsYes (min 160px, max 400px)
Editor AreaFlexible (fills remaining)Monaco Editor, tab strip, breadcrumb, toolbar rowYes
Feature Panel (right)380px defaultIntent Mode result, Memory annotation, Explainer detail — slides in on activationYes (min 300px, max 600px)
Bottom Panel200px default, collapsibleTerminal, AI logs, console outputYes (min 120px, max 50%)

7.2 Toolbar Design

The editor toolbar sits between the tab strip and the Monaco canvas. It contains 5 zones:

  • Left: Breadcrumb (project > folder > file > function)

  • Center-Left: Language badge, line:col indicator, encoding

  • Center: Three Feature CTA buttons — Intent Mode, Explain Codebase, Add Memory — always visible, color-coded

  • Center-Right: Format Document, Toggle Word Wrap, Minimap toggle

  • Right: Collaboration indicator (future), Settings gear, User avatar

7.3 Keyboard Shortcuts

ActionShortcut (Mac)Shortcut (Win/Linux)
Open Intent ModeCmd + Shift + ICtrl + Shift + I
Open Codebase ExplainerCmd + Shift + ECtrl + Shift + E
Add Decision MemoryCmd + Shift + MCtrl + Shift + M
Open Memory VaultCmd + Shift + VCtrl + Shift + V
Run Intent (after selection)Cmd + EnterCtrl + Enter
Accept All SuggestionsCmd + Shift + ACtrl + Shift + A
Reject All SuggestionsEscapeEscape
Toggle Feature PanelCmd + B (right)Ctrl + B (right)
Switch Editor TabsCmd + [1-9]Ctrl + [1-9]

8. Scalability & Architecture Decisions

8.1 AI Rate Limiting Strategy

Gemini Flash free tier gives 15 RPM and 1,500 RPD. Cortex handles this gracefully:

  • Request queue: Bull (Redis-backed) queues AI requests — no dropped requests, shows position in queue

  • Token estimation: Before each AI call, estimate token count — warn user if > 50K tokens (large codebase)

  • Scope limiting: Codebase Explainer never sends more than 20 files per batch — splits large projects

  • Response caching: Redis caches Explainer results for 24 hours per project hash — avoid duplicate analysis

  • Fallback: If Gemini rate limit hit, switch to Groq Llama 3.3 70B automatically

8.2 MongoDB Index Strategy

CollectionIndexReason
DecisionMemory{ projectId: 1, filePath: 1 }Fast lookup of all memories for a file
DecisionMemory{ projectId: 1, category: 1 }Filter memories by category in vault
DecisionMemory{ projectId: 1, createdAt: -1 }Timeline view — latest first
DecisionMemory{ tags: 1 }Tag-based search
CodebaseSnapshot{ projectId: 1, createdAt: -1 }Latest snapshot fast lookup
Project{ clerkUserId: 1 }User's project list

8.3 Future Scalability Path

PhaseUpgradeTrigger
Phase 1 (MVP)Gemini free tier, MongoDB Atlas free, Clerk free0–100 users
Phase 2 (Growth)Gemini paid tier, Redis caching, MongoDB M10 cluster100–1,000 users
Phase 3 (Scale)Multiple AI provider routing, horizontal Express scaling, CDN for graph assets1,000–10,000 users
Phase 4 (Product)Team workspaces, shared Memory Vault, Electron desktop app, VS Code extension10,000+ users

9. Development Phases

Phase 1 — Foundation (Week 1–2)

  1. Initialize MERN project: Vite + React, Express server, MongoDB Atlas connection, Clerk auth

  2. Build Monaco Editor wrapper — file tree integration, tab management, SCSS theming

  3. Implement SCSS design system — all tokens, base components: Button, Badge, Tag, Modal

  4. Build App Shell layout — Activity Bar, Sidebar, Editor Area, Feature Panel, Bottom Panel

  5. Create project management — create/open/switch projects, persist file tree to MongoDB

Phase 2 — Decision Memory (Week 3–4)

  1. Build DecisionMemory Mongoose model + all CRUD API endpoints

  2. Integrate Monaco gutter decorations for memory display

  3. Build Memory Annotation drawer UI — form with all fields, tag input, category selector

  4. Build Memory Vault page — list, search, filter, timeline view

  5. Add AI Summarize endpoint — generates architectural summary from a project's memories

Phase 3 — Intent Mode (Week 5–6)

  1. Build GeminiService with streaming support + Socket.IO stream relay

  2. Implement Intent Mode panel — intent selector, scope selector, custom instructions

  3. Build diff viewer — split-pane view, accept/reject per change

  4. Add rate limiting middleware — queue, Groq fallback, user feedback on wait

  5. Auto-create Decision Memory from Intent Mode accepted changes

Phase 4 — Codebase Explainer (Week 7–8)

  1. Build CodeParserService — extract imports/exports from JS/TS/JSX files using AST (acorn + estree-walker)

  2. Build GraphBuilderService — convert parsed data to D3 node/edge format

  3. Build Explainer page — D3 force-directed graph with hover, search, filter

  4. Add data flow tracer — given an entry point, trace execution path through graph

  5. Add dependency audit view — treemap + AI-generated package summaries

  6. Add export to SVG/PDF functionality

Phase 5 — Polish & Launch (Week 9–10)

  1. Responsive design audit — ensure usable at 1280px, 1440px, 1920px widths

  2. Keyboard shortcut system — all shortcuts implemented and shown in Command Palette

  3. Error handling — every AI call has graceful fallback, user-visible error states

  4. Loading skeleton states — every async action shows skeleton loaders, not spinners alone

  5. Performance audit — Monaco lazy-loaded, D3 graph virtualized, large files chunked

  6. Deploy — Frontend on Vercel, Backend on Railway, DB on MongoDB Atlas

10. Environment & Deployment

10.1 Environment Variables

VariableServiceWhere Used
GEMINI_API_KEYGoogle AI Studio (free)GeminiService — all AI calls
GROQ_API_KEYGroq Cloud (free)Fallback AI service
MONGODB_URIMongoDB Atlas (free M0)Mongoose connection string
CLERK_SECRET_KEYClerk (free tier)Server-side JWT verification
VITE_CLERK_PUBLISHABLE_KEYClerk (free tier)Frontend auth initialization
REDIS_URLUpstash Redis (free)Request queuing, response caching (Phase 2)
PORT3001 (default)Express server port
CLIENT_URLhttp://localhost:5173CORS whitelist

10.2 Deployment Stack

ServicePlatformCost
Frontend (React)Vercel — Hobby planFree
Backend (Express)Railway — Dev planFree $5 credit/month
Database (MongoDB)MongoDB Atlas M0Free 512MB
Auth (Clerk)Clerk FreeFree up to 10,000 MAU
AI (Gemini)Google AI StudioFree 1M tokens/day
AI Fallback (Groq)Groq CloudFree tier 14,400 req/day
Redis (optional)Upstash RedisFree 10K commands/day

Total MVP Cost: $0/month until meaningful scale.

11. Success Metrics

MetricMVP Target6-Month Target
Decision Memories Created / User / Week> 5> 20
Intent Mode Runs / Week (total)> 50> 500
Codebase Explainer Views / Week> 20> 200
AI Response Time (first token)< 1.5s< 0.8s
Intent Suggestion Acceptance Rate> 60%> 75%
Memory Search Satisfaction (qualitative)PositiveHighly positive
Monthly Active Users501,000

12. Risks & Mitigations

RiskProbabilityImpactMitigation
Gemini free tier rate limits hit during peakHighHighGroq fallback + request queue + user wait indicator
Monaco Editor performance on very large files (10K+ lines)MediumMediumLazy load sections, disable heavy features on large files, show warning
AST parsing fails on unusual JS patternsMediumMediumFallback to regex-based import parsing, skip unparseable files gracefully
User uploads huge project ZIP (100MB+)LowHigh10MB upload limit + warn user to select specific folders, not entire repo
Decision Memory search performance degrades at scaleLowMediumFull-text index on MongoDB, pagination, Redis cache for common queries
Gemini API changes or deprecates free tierLowHighProvider-agnostic service layer — swap Gemini for any provider in one file

13. Competitive Analysis

FeatureCortexGitHub CopilotCursorVS Code + Extensions
Intent-driven optimization✅ Core feature⚠️ Partial (Composer)
Visual codebase graph✅ Built-in⚠️ Via extensions only
Decision Memory / ADR✅ Core feature
Free tier AI✅ Generous❌ Paid only❌ Paid only⚠️ Copilot needed
Browser-based✅ Web app❌ Desktop only❌ Desktop only
MERN-first experience✅ Designed for it⚠️ Generic⚠️ Generic⚠️ Generic
Streaming AI responses⚠️ Varies

— End of Document —
Cortex PRD v1.0 • Shivam Garade • 2026

About

AI-Powered Code Editor [ Code with Intent. Build with Memory. ]

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages