Skip to content

nasirmasud/mindagent-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

57 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 MindAgent β€” AI-Powered Multi-Agent Productivity Platform

Project Summary

MindAgent is a full-stack AI-powered productivity platform where users interact with multiple specialized AI Agents to generate content, analyze data, understand images, and chat with an intelligent assistant. Each agent is purpose-built for a specific task β€” Content Writer, Data Analyzer, Image Analyst, Chat Assistant β€” making this a multi-agent workflow platform, not a single-purpose chatbot. Built with Next.js, Express.js, MongoDB, and OpenRouter, it emphasizes agentic behavior (memory, reasoning, tool-calling), streaming responses, and a polished user experience.


Architecture Overview

Tech Stack

Frontend

  • Framework: Next.js 15 (React 19) with App Router
  • Language: TypeScript
  • Styling: Tailwind CSS 3 + PostCSS
  • UI Components: shadcn/ui (Radix UI primitives + CVA + tailwind-merge)
  • State/Data Fetching: TanStack React Query v5
  • Charts: Recharts
  • Forms: Native React controlled inputs
  • Notifications: Sonner (toast library)
  • Carousel: Swiper
  • Theme: next-themes (Dark/Light mode support)
  • Icons: Lucide React
  • Markdown: react-markdown

Backend

  • Runtime: Node.js + Express.js + TypeScript
  • Database: MongoDB (Mongoose ODM)
  • Auth: JWT (7-day expiry) + Google OAuth
  • Password Hashing: bcryptjs (12 rounds)
  • AI Provider: OpenRouter (GPT-4o-mini for text, GPT-4o for vision)
  • File Parsing: PapaParse (CSV), SheetJS/XLSX (Excel), native JSON
  • Validation: Zod (request body validation)
  • File Upload: Multer (memory storage, 5MB limit)
  • Rate Limiting: express-rate-limit (10 AI req/min, 20 auth req/15min)
  • Security: Helmet (HTTP headers), CORS

Database Schema

Collections

1. users

  • User accounts (email/password or Google OAuth)
  • Fields: name, email (unique), password (hashed, optional for Google users), authProvider (email/google), googleId, avatar, preferredProvider (default: openrouter), createdAt

2. agents

  • AI agent catalog (seeded)
  • Fields: name, category, description, icon, rating, usageCount

3. chatsessions

  • AI chat conversation history per user
  • Fields: userId (ObjectId β†’ User), agentType, messages: [{ role (user/assistant/system), content, timestamp }]

4. generatedcontents

  • AI-generated content history
  • Fields: userId (ObjectId β†’ User), prompt, output, contentType, provider, createdAt

5. imageanalyses

  • Image analysis history
  • Fields: userId (ObjectId β†’ User), imageData (base64), imageName, prompt, analysis, tags [{label, conf}], dimensions {width, height}, palette [string], createdAt

6. dataanalyses

  • Data analysis history
  • Fields: userId (ObjectId β†’ User), fileName, fileType (csv/xlsx/json), originalRowCount, parsedPreview [Mixed], aiInsights {summary, trends[], risks[], kpis[{label, value}]}, provider, reportUrl, createdAt

7. items

  • Uploaded data files with AI-generated insights
  • Fields: ownerId (ObjectId β†’ User), title, shortDescription, fullDescription, sourceFileName, sourceFileType (csv/xlsx/json), rowCount, columns[], parsedPreview [Mixed], insights {summary, trends[], kpis[], risks[]}, chartData [{label, value}], status (processing/completed/failed), createdAt

Project Structure

MindAgent/
β”œβ”€β”€ client/                             # Next.js 15 frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/                        # Next.js App Router pages (16 routes)
β”‚   β”‚   β”‚   β”œβ”€β”€ layout.tsx              # Root layout (ThemeProvider, QueryProvider, AuthProvider, Navbar, Footer)
β”‚   β”‚   β”‚   β”œβ”€β”€ page.tsx                # Home page (9 sections)
β”‚   β”‚   β”‚   β”œβ”€β”€ globals.css             # Global styles + Tailwind theme tokens
β”‚   β”‚   β”‚   β”œβ”€β”€ not-found.tsx           # Custom 404 page
β”‚   β”‚   β”‚   β”œβ”€β”€ login/page.tsx          # Login + demo login
β”‚   β”‚   β”‚   β”œβ”€β”€ register/page.tsx       # User registration
β”‚   β”‚   β”‚   β”œβ”€β”€ profile/page.tsx        # User profile with sidebar, stats, donut charts
β”‚   β”‚   β”‚   β”œβ”€β”€ ai-chat/page.tsx        # Streaming AI chat assistant
β”‚   β”‚   β”‚   β”œβ”€β”€ content-generator/page.tsx  # AI content generation
β”‚   β”‚   β”‚   β”œβ”€β”€ image-analyzer/page.tsx # AI image analysis
β”‚   β”‚   β”‚   β”œβ”€β”€ data-analyzer/page.tsx  # CSV/XLSX/JSON data analysis
β”‚   β”‚   β”‚   β”œβ”€β”€ explore/page.tsx        # Agent/tool catalog
β”‚   β”‚   β”‚   β”œβ”€β”€ pricing/page.tsx        # Pricing plans
β”‚   β”‚   β”‚   β”œβ”€β”€ about/page.tsx          # About page
β”‚   β”‚   β”‚   β”œβ”€β”€ contact/page.tsx        # Contact form
β”‚   β”‚   β”‚   β”œβ”€β”€ blog/page.tsx           # Blog listing
β”‚   β”‚   β”‚   └── items/                  # Data item routes
β”‚   β”‚   β”‚       β”œβ”€β”€ add/page.tsx        # Upload & analyze file
β”‚   β”‚   β”‚       β”œβ”€β”€ manage/page.tsx     # Manage user's items
β”‚   β”‚   β”‚       └── [id]/page.tsx       # Item detail with charts
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ ui/                     # Reusable UI primitives (11 components)
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ button.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ card.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ input.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ label.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ badge.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ avatar.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ dialog.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ dropdown-menu.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ select.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ sheet.tsx
β”‚   β”‚   β”‚   β”‚   └── textarea.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ layout/                 # Layout components (10)
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ navbar.tsx          # Sticky nav with auth-aware links, avatar dropdown, mobile sheet
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ footer.tsx          # Site footer
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ theme-toggle.tsx    # Dark/light mode toggle
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ hero-swiper.tsx     # Hero carousel (Swiper)
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ feature-strip.tsx   # Feature highlights
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ agent-categories.tsx # Agent category grid
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ how-it-works.tsx    # How it works section
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ testimonials.tsx     # Testimonials carousel
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ faq-section.tsx     # FAQ accordion
β”‚   β”‚   β”‚   β”‚   └── newsletter-section.tsx # Newsletter signup
β”‚   β”‚   β”‚   β”œβ”€β”€ auth/
β”‚   β”‚   β”‚   β”‚   └── google-auth-button.tsx # Google OAuth login button
β”‚   β”‚   β”‚   β”œβ”€β”€ shared/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ error-boundary.tsx  # React error boundary
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ loading-skeleton.tsx # Page skeleton loaders
β”‚   β”‚   β”‚   β”‚   └── toaster.tsx         # Sonner toast provider
β”‚   β”‚   β”‚   └── items/
β”‚   β”‚   β”‚       └── manage/
β”‚   β”‚   β”‚           └── item-actions.tsx # Delete/view actions for item rows
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ hooks/
β”‚   β”‚   β”‚   β”œβ”€β”€ useAuth.ts              # Auth context hook
β”‚   β”‚   β”‚   β”œβ”€β”€ use-queries.ts          # TanStack Query hooks for data fetching
β”‚   β”‚   β”‚   └── useCountUp.ts           # Animated number counter
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ providers/
β”‚   β”‚   β”‚   β”œβ”€β”€ auth-provider.tsx       # JWT auth context (login, logout, user state)
β”‚   β”‚   β”‚   β”œβ”€β”€ query-provider.tsx      # TanStack Query client provider
β”‚   β”‚   β”‚   └── theme-provider.tsx      # next-themes dark/light provider
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”‚   β”œβ”€β”€ api.ts                  # Fetch wrapper (base URL, auth headers, error handling)
β”‚   β”‚   β”‚   └── utils.ts               # cn() classname utility
β”‚   β”‚   β”‚
β”‚   β”‚   └── types/
β”‚   β”‚       └── globals.d.ts            # Global TypeScript declarations
β”‚   β”‚
β”‚   β”œβ”€β”€ tailwind.config.ts
β”‚   β”œβ”€β”€ next.config.ts
β”‚   β”œβ”€β”€ tsconfig.json
β”‚   └── package.json
β”‚
└── server/                             # Express.js backend
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ server.ts                   # Entry point (connect DB, start server)
    β”‚   β”œβ”€β”€ app.ts                      # Express app setup (middleware, routes, error handler)
    β”‚   β”‚
    β”‚   β”œβ”€β”€ config/
    β”‚   β”‚   β”œβ”€β”€ env.ts                  # Environment variable loader
    β”‚   β”‚   └── db.ts                   # MongoDB connection
    β”‚   β”‚
    β”‚   β”œβ”€β”€ models/                     # Mongoose schemas (7)
    β”‚   β”‚   β”œβ”€β”€ User.ts
    β”‚   β”‚   β”œβ”€β”€ Agent.ts
    β”‚   β”‚   β”œβ”€β”€ ChatSession.ts
    β”‚   β”‚   β”œβ”€β”€ GeneratedContent.ts
    β”‚   β”‚   β”œβ”€β”€ ImageAnalysis.ts
    β”‚   β”‚   β”œβ”€β”€ DataAnalysis.ts
    β”‚   β”‚   └── Item.ts
    β”‚   β”‚
    β”‚   β”œβ”€β”€ routes/                     # Express route handlers (6)
    β”‚   β”‚   β”œβ”€β”€ auth.ts                 # Register, login, demo-login, Google OAuth, profile update, password change
    β”‚   β”‚   β”œβ”€β”€ ai.ts                   # Content generation, image analysis, chat (SSE streaming), sessions
    β”‚   β”‚   β”œβ”€β”€ items.ts                # File upload, CRUD, AI analysis, report export (XLSX)
    β”‚   β”‚   β”œβ”€β”€ agents.ts               # Agent catalog
    β”‚   β”‚   β”œβ”€β”€ recommendations.ts      # AI-powered agent recommendations
    β”‚   β”‚   └── contact.ts              # Contact form handler
    β”‚   β”‚
    β”‚   β”œβ”€β”€ middleware/                  # Express middleware (4)
    β”‚   β”‚   β”œβ”€β”€ protect.ts              # JWT auth guard (Bearer token β†’ user attach)
    β”‚   β”‚   β”œβ”€β”€ errorHandler.ts         # Global error handler
    β”‚   β”‚   β”œβ”€β”€ rateLimiter.ts          # Rate limiters (AI: 10/min, Auth: 20/15min)
    β”‚   β”‚   └── upload.ts              # Multer file upload (CSV/XLSX/JSON, 5MB max)
    β”‚   β”‚
    β”‚   β”œβ”€β”€ services/
    β”‚   β”‚   β”œβ”€β”€ ai/
    β”‚   β”‚   β”‚   β”œβ”€β”€ aiProvider.interface.ts  # AIProvider interface (generateText, streamChat, analyzeImage)
    β”‚   β”‚   β”‚   β”œβ”€β”€ aiProviderFactory.ts     # Factory: returns OpenRouterProvider
    β”‚   β”‚   β”‚   └── openrouterProvider.ts    # OpenRouter implementation (GPT-4o-mini, GPT-4o vision)
    β”‚   β”‚   └── data/
    β”‚   β”‚       └── fileParser.ts        # CSV/XLSX/JSON file parser (PapaParse + XLSX)
    β”‚   β”‚
    β”‚   β”œβ”€β”€ validators/                 # Zod request validation schemas (3)
    β”‚   β”‚   β”œβ”€β”€ auth.ts                 # register, login, google, updateProfile, changePassword
    β”‚   β”‚   β”œβ”€β”€ ai.ts                   # generateContent, analyzeImage, chat
    β”‚   β”‚   └── contact.ts             # contact form
    β”‚   β”‚
    β”‚   β”œβ”€β”€ utils/
    β”‚   β”‚   └── jwt.ts                  # signToken / verifyToken (JWT helpers)
    β”‚   β”‚
    β”‚   └── seed.ts                     # Database seeder (demo user + 4 sample reports)
    β”‚
    β”œβ”€β”€ package.json
    β”œβ”€β”€ tsconfig.json
    β”œβ”€β”€ nodemon.json
    └── .env.example

Data Flow

File Upload & AI Analysis Flow

User uploads CSV/XLSX/JSON file
  β†’ Multer middleware (5MB limit, type validation)
  β†’ File parser extracts rows, columns, row count
  β†’ Build analysis prompt with data sample (first 5 rows)
  β†’ OpenRouter API (GPT-4o-mini) generates structured JSON insights
  β†’ Store parsed data + AI insights in MongoDB (Item collection)
  β†’ Return item with summary, trends, KPIs, risks, chart data

AI Chat Flow (Streaming)

User sends message
  β†’ Create or load existing ChatSession
  β†’ Add user message to session history
  β†’ Send full history to OpenRouter (GPT-4o-mini) with streaming
  β†’ Server-Sent Events (SSE) stream tokens to frontend
  β†’ Parse AI response for follow-up suggestions (JSON array)
  β†’ Save assistant message to session
  β†’ Display streaming text + suggestion buttons

AI Content Generation Flow

User enters topic, selects type/tone/length
  β†’ Select prompt template (blog/social/product/docs)
  β†’ Replace placeholders with user input
  β†’ OpenRouter API call (GPT-4o-mini, max_tokens based on length)
  β†’ Save to GeneratedContent collection
  β†’ Return generated text to frontend

Image Analysis Flow

User uploads image (base64)
  β†’ Optional: user provides custom prompt
  β†’ OpenRouter Vision API (GPT-4o) with image + prompt
  β†’ Save analysis to ImageAnalysis collection
  β†’ Display analysis text, tags, dimensions, palette

Authentication Flow

Login/Register
  β†’ Zod validation
  β†’ bcrypt hash (register) or compare (login)
  β†’ Sign JWT (7-day expiry)
  β†’ Store token in localStorage
  β†’ Attach Bearer token to all API requests
  β†’ protect middleware verifies token on protected routes

Google OAuth Flow

Google Sign-In button
  β†’ Google One-Tap returns credential
  β†’ Decode Google JWT β†’ extract name, email, googleId, avatar
  β†’ POST /api/auth/google (auto-creates user if new)
  β†’ Receive MindAgent JWT + user data
  β†’ Store in auth context

API Endpoints

Public Endpoints

Method Route Description
GET /api/health Health check
GET /api/agents List all agents
GET /api/agents/:id Get agent by ID
GET /api/items Browse items (paginated, searchable, filterable)
GET /api/items/:id Get item detail + related items
POST /api/contact Submit contact form

Auth Endpoints

Method Route Description
POST /api/auth/register Create account (email/password)
POST /api/auth/login Login (email/password)
POST /api/auth/demo-login Auto-login as demo user
POST /api/auth/google Google OAuth login/register

Protected Endpoints (JWT Required)

Method Route Description
GET /api/auth/me Get current user profile
PUT /api/auth/me Update profile (name, avatar)
PUT /api/auth/password Change password (email accounts only)
POST /api/ai/generate-content Generate AI content (blog/social/product/docs)
POST /api/ai/analyze-image Analyze uploaded image
GET /api/ai/image-history List user's image analyses
DELETE /api/ai/image-history/:id Delete image analysis
POST /api/ai/chat Send chat message (SSE streaming response)
GET /api/ai/sessions List user's chat sessions
DELETE /api/ai/sessions/:id Delete chat session
GET /api/ai/history List user's generated content
DELETE /api/ai/history/:id Delete generated content
GET /api/items/my List user's uploaded items
POST /api/items Upload & analyze file (CSV/XLSX/JSON)
DELETE /api/items/:id Delete item
GET /api/items/:id/report Download item as XLSX report
GET /api/recommendations AI-powered agent recommendations

Security Considerations

  1. Authentication: JWT tokens with 7-day expiry, bcrypt password hashing (12 rounds)
  2. Protected Routes: Express middleware (protect) verifies Bearer token on all protected endpoints
  3. Input Validation: Zod schemas validate all request bodies (auth, AI, contact)
  4. Rate Limiting: AI endpoints limited to 10 requests/minute; auth endpoints limited to 20 requests/15 minutes
  5. File Upload Security: Multer restricts to CSV/XLSX/JSON only, 5MB max size, memory storage (no disk writes)
  6. HTTP Security: Helmet middleware sets secure HTTP headers
  7. CORS: Configured to allow only the client origin with credentials
  8. Password Protection: Password field excluded from all default Mongoose queries via select: false
  9. Data Isolation: All user-scoped queries filter by userId / ownerId to prevent cross-user data access
  10. Environment Variables: All API keys and secrets stored in .env / .env.local (gitignored)

User Roles & Permissions

Feature Visitor User
Browse Home Page βœ… βœ…
Browse Agent Catalog βœ… βœ…
View Agent Details βœ… βœ…
View Public Items βœ… βœ…
Read Blog / About / Pricing βœ… βœ…
Submit Contact Form βœ… βœ…
Login / Register βœ… βœ…
AI Chat Assistant ❌ βœ…
AI Content Generation ❌ βœ…
AI Image Analysis ❌ βœ…
Upload & Analyze Data Files ❌ βœ…
View Item Detail + Charts ❌ βœ…
Download XLSX Reports ❌ βœ…
Manage Own Items ❌ βœ…
View Profile & Dashboard ❌ βœ…
Edit Profile / Change Password ❌ βœ…
Delete Own Account ❌ βœ…
Get AI Recommendations ❌ βœ…

Project Pages

Route Access Description
/ Public Home β€” Hero swiper, features, agent categories, how it works, testimonials, FAQ, newsletter
/explore Public Agent/tool catalog with search and filters
/pricing Public Pricing plans
/about Public About page
/blog Public Blog listing
/contact Public Contact form
/login Public Login + demo login
/register Public User registration
/ai-chat Protected Streaming AI chat assistant with session history
/content-generator Protected AI content generation (blog, social, product, docs)
/image-analyzer Protected Upload image β†’ AI-powered analysis with tags
/data-analyzer Protected CSV/XLSX/JSON data analysis with AI insights
/items/add Protected Upload data file for AI analysis
/items/manage Protected Manage uploaded data items
/items/[id] Public Item detail with charts, insights, related items
/profile Protected User profile with sidebar, stats, donut charts, settings

Performance & Scalability

  • Server-Side Pagination: Items endpoint supports page/limit/sort/search/filter for efficient data loading
  • Skeleton Loaders: Loading states on all pages for improved perceived performance
  • Streaming Responses: AI chat uses Server-Sent Events (SSE) for real-time token delivery
  • Memory Storage: Multer uses memory storage (no disk I/O) for fast file processing
  • Database Indexing: Unique indexes on email, compound indexes on userId + timestamps
  • Rate Limiting: Prevents API abuse (10 AI req/min, 20 auth req/15min)
  • Code Splitting: Next.js App Router enables automatic route-based code splitting
  • Responsive Design: Mobile-first layout works across all device sizes
  • Dark Mode: Built-in theme switching with next-themes
  • Request Validation: Zod schemas validate inputs early, preventing unnecessary DB/API calls

Setup

Prerequisites

  • Node.js 18+
  • MongoDB (local or Atlas)
  • OpenRouter API key

Client Setup

cd client
npm install
cp .env.example .env.local
# Fill in NEXT_PUBLIC_API_URL, NEXT_PUBLIC_GOOGLE_CLIENT_ID
npm run dev

Server Setup

cd server
npm install
cp .env.example .env
# Fill in MONGO_URI, JWT_SECRET, OPENROUTER_API_KEY
npm run dev

Seed Database (Optional)

cd server
npm run seed

Creates a demo user (demo@mindagent.ai / demo123) with 4 sample data analysis reports.

Environment Variables

Client (.env.local)

Variable Required Description
NEXT_PUBLIC_API_URL Yes Backend API URL (e.g. http://localhost:5000/api)
NEXT_PUBLIC_GOOGLE_CLIENT_ID Yes Google OAuth client ID

Server (.env)

Variable Required Description
MONGO_URI Yes MongoDB connection string
JWT_SECRET Yes Secret key for JWT signing
OPENROUTER_API_KEY Yes OpenRouter API key
PORT No Server port (default: 5000)

Future Enhancement Opportunities

  • Multi-Provider AI: Add Groq, Gemini, Anthropic, or OpenAI as alternative providers via the AIProvider interface
  • RAG (Retrieval-Augmented Generation): Vector search over user's uploaded documents for context-aware responses
  • Agent Tool Calling: Enable AI agents to invoke external tools (web search, calculator, database queries)
  • Conversation Branching: Allow users to branch chat conversations from any point
  • Collaborative Workspaces: Share items and chat sessions with team members
  • Export Formats: PDF, Markdown, and HTML report exports in addition to XLSX
  • Real-Time Notifications: WebSocket-based alerts for completed analyses
  • Advanced Data Visualization: Interactive charts with drill-down, filtering, and custom dashboard builder
  • User Analytics Dashboard: Usage statistics, token consumption tracking, and productivity metrics
  • API Key Management: Allow users to bring their own API keys for higher rate limits
  • Webhooks: Notify external services when analyses complete
  • Mobile App: Native iOS/Android apps for on-the-go AI assistance

About

A multi-agent AI productivity platform powered by Next.js 15, Express, MongoDB, and OpenRouter. Features specialized agents for content writing, file/data analysis, image vision, and persistent chats.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages