Rafiq is a desktop application built with Electron + React that serves as an "Agent of all Agents" to help managers with their work. It features AI-powered assistance, team communication, document management, and productivity tools. Working Demo
| Layer | Technology | Purpose |
|---|---|---|
| Desktop Framework | Electron 33+ | Cross-platform desktop app |
| Frontend | React 18 + TypeScript | UI components |
| Build Tool | Vite 6 | Fast development/build |
| State Management | Zustand | Lightweight state |
| Styling | Tailwind CSS | Utility-first CSS |
| Database | PostgreSQL + Prisma | Primary data store |
| AI Gateway | OpenRouter API | Multi-LLM access |
| Voice (Offline) | Whisper (@xenova/transformers) | Speech-to-text |
| Real-time | Socket.IO | WebSocket communication |
| Nodemailer + ImapFlow | Email integration | |
| Slack | @slack/web-api | Slack integration |
| Discord | discord.js | Discord integration |
| Auth | JWT (jose) + Argon2 | Authentication |
D:\Rafiq\
├── package.json # Dependencies and npm scripts
├── tsconfig.json # Base TypeScript config
├── tsconfig.main.json # Electron main process TS config
├── tsconfig.renderer.json # React renderer TS config
├── vite.config.ts # Vite bundler configuration
├── tailwind.config.js # Tailwind CSS with custom theme
├── postcss.config.js # PostCSS for Tailwind
├── docker-compose.yml # Docker: PostgreSQL + pgAdmin + Redis
├── Dockerfile # Multi-stage build for CI/packaging
├── start.bat # Windows quick start (checks Docker, starts containers, installs deps)
├── start.sh # Linux/Mac quick start (same as above)
├── .env.example # Environment variables template
├── .env # Local environment config
│
├── prisma/
│ └── schema.prisma # Database schema (25+ models)
│
├── scripts/
│ └── init-db.sql # Database initialization SQL
│
└── src/
├── main/ # ELECTRON MAIN PROCESS
│ ├── index.ts # App entry, creates window, registers IPC
│ ├── app/
│ │ ├── WindowManager.ts # Creates BrowserWindow, handles lifecycle
│ │ └── TrayManager.ts # System tray with context menu
│ ├── ipc/
│ │ └── index.ts # IPC handlers for all channels (auth, agent, chat, etc.)
│ └── services/
│ └── ai/
│ └── OpenRouterClient.ts # OpenRouter API client with streaming
│
├── preload/
│ └── index.ts # Context bridge exposing safe API to renderer
│ # Exposes: api.auth, api.agent, api.chat, api.team,
│ # api.documents, api.meetings, api.voice, api.integrations,
│ # api.settings, api.analytics, api.notifications, api.system
│
├── renderer/ # REACT FRONTEND
│ ├── index.html # HTML entry with CSP headers
│ ├── index.tsx # React entry, mounts App with BrowserRouter
│ ├── App.tsx # Root component with routes and theme
│ │
│ ├── components/
│ │ └── common/
│ │ ├── Layout.tsx # Main layout with Sidebar + Header + content
│ │ ├── Sidebar.tsx # Navigation sidebar with user info
│ │ ├── Header.tsx # Top bar with search, notifications, window controls
│ │ └── ThemeToggle.tsx # Light/Dark/System theme switcher
│ │
│ ├── pages/
│ │ ├── LoginPage.tsx # Auth page with login/register forms
│ │ ├── DashboardPage.tsx # Overview with stats, suggestions, quick actions
│ │ ├── AgentPage.tsx # AI chat interface with voice input
│ │ ├── ChatPage.tsx # Team messaging with channels
│ │ ├── TeamPage.tsx # Task management (Kanban/List views)
│ │ ├── DocumentsPage.tsx # File management with AI summarization
│ │ ├── MeetingsPage.tsx # Calendar and meeting scheduler
│ │ ├── AnalyticsPage.tsx # Performance metrics and charts
│ │ └── SettingsPage.tsx # Profile, Agent, Integrations, Notifications, Security
│ │
│ ├── store/ # ZUSTAND STATE MANAGEMENT
│ │ ├── authStore.ts # User auth state, login/logout, session
│ │ ├── themeStore.ts # Theme preference (light/dark/system)
│ │ └── agentStore.ts # AI chat messages, suggestions, context
│ │
│ └── styles/
│ └── globals.css # Tailwind imports + custom components
│ # Defines: .card, .btn-*, .input, .badge-*, .nav-item, etc.
│
├── shared/ # SHARED BETWEEN MAIN & RENDERER
│ ├── constants/
│ │ └── channels.ts # IPC_CHANNELS and WS_EVENTS constants
│ └── types/
│ ├── agent.types.ts # Agent, OpenRouter, conversation types
│ └── api.types.ts # API responses, user, team, task, meeting types
│
└── types/
└── global.d.ts # Global Window.api type declaration
- Central AI assistant that understands user's job role
- Routes requests to specialized sub-agents
- Provides actionable recommendations
- Reviews team reports and task outputs
- Web search for best practices
- Find common mistakes to avoid
- Evidence-based recommendations
- Built-in chat system with channels
- Email integration (IMAP/SMTP)
- Slack integration
- Discord integration
- Upload and organize files
- AI-powered summarization
- Knowledge base for reference materials
- Calendar view (month/week/day)
- AI-suggested optimal meeting times
- Auto-generated meeting notes
- Task completion metrics
- Team performance tracking
- Risk assessment with AI
- English voice input
- Whisper for offline speech-to-text
- Command parsing
Key models in prisma/schema.prisma:
- User - Users with roles (ADMIN, MANAGER, MEMBER, GUEST)
- Session - JWT sessions with refresh tokens
- Team - Teams with owner and members
- TeamMember - User-Team relationship with roles
- Channel - Chat channels (PUBLIC, PRIVATE, DIRECT, AGENT)
- Message - Chat messages with threading
- Task - Tasks with status, priority, assignments, subtasks
- Report - Team reports with AI summaries
- Document - Files with metadata, tags, AI summaries
- Folder - Hierarchical folder structure
- Meeting - Meetings with attendees, agenda, notes
- MeetingAttendee - User-Meeting relationship
- AgentContext - User context for AI personalization
- AgentConversation - AI conversation history
- Integration - Email, Slack, Discord configs
- EmailMessage - Cached email messages
- Notification - User notifications
- AnalyticsEvent - Event tracking
- SyncQueue - Offline sync queue
The app uses Electron IPC for main-renderer communication.
IPC_CHANNELS.AUTH.*- Login, logout, session managementIPC_CHANNELS.AGENT.*- AI chat, suggestions, contextIPC_CHANNELS.CHAT.*- Messages, channelsIPC_CHANNELS.TEAM.*- Teams, members, tasks, reportsIPC_CHANNELS.DOCUMENTS.*- Files, summarization, searchIPC_CHANNELS.MEETINGS.*- Schedule, notes, invitesIPC_CHANNELS.VOICE.*- Speech recognitionIPC_CHANNELS.INTEGRATIONS.*- Email, Slack, DiscordIPC_CHANNELS.SETTINGS.*- User preferences, themeIPC_CHANNELS.ANALYTICS.*- Metrics, dashboardsIPC_CHANNELS.NOTIFICATIONS.*- AlertsIPC_CHANNELS.SYSTEM.*- Window controls, status
window.api.auth.login(email, password)
window.api.agent.sendMessage(message, context)
window.api.chat.getChannels()
window.api.team.getTasks(teamId)
window.api.documents.summarize(documentId)
window.api.meetings.create(meeting)
window.api.voice.startRecognition()
window.api.settings.setTheme('dark')
window.api.system.minimize()
// ... and moreThe OpenRouterClient class (src/main/services/ai/OpenRouterClient.ts) handles AI:
// Available models
OpenRouterClient.MODELS = {
FAST: 'openai/gpt-4o-mini',
BALANCED: 'openai/gpt-4o',
POWERFUL: 'anthropic/claude-3.5-sonnet',
CODE: 'anthropic/claude-3.5-sonnet',
CHEAP: 'meta-llama/llama-3.1-70b-instruct',
}
// Usage
const client = new OpenRouterClient(apiKey);
const response = await client.chat({ model, messages });
// Or streaming:
for await (const chunk of client.chatStream({ model, messages, stream: true })) {
// Handle chunk
}.card- White/dark card with border and shadow.btn-primary- Blue primary button.btn-secondary- Gray secondary button.btn-ghost- Transparent button.btn-danger- Red danger button.input- Styled text input.label- Form label.badge-*- Status badges (primary, success, warning, error).nav-item- Sidebar navigation item.nav-item-active- Active nav state.message-bubble-user- User chat bubble (blue, right).message-bubble-assistant- AI chat bubble (gray, left).app-drag- Electron window drag region.app-no-drag- Non-draggable area within drag region
- Supports Light, Dark, and System themes
- Uses Tailwind's
dark:variant - Theme stored in Zustand with localStorage persistence
- Applied via
document.documentElement.classList.add('dark')
The .env file is pre-configured for local Docker development:
# Database (matches docker-compose.yml)
DATABASE_URL="postgresql://smartlink:smartlink_secure_password_2024@localhost:5432/smartlink?schema=public"
# OpenRouter API (required for AI features)
# Get your API key from https://openrouter.ai/keys
OPENROUTER_API_KEY=""
# Redis (matches docker-compose.yml)
REDIS_URL="redis://localhost:6379"
# Email Integration (IMAP/SMTP)
EMAIL_IMAP_HOST="imap.gmail.com"
EMAIL_IMAP_PORT="993"
EMAIL_SMTP_HOST="smtp.gmail.com"
EMAIL_SMTP_PORT="587"
EMAIL_USER=""
EMAIL_PASSWORD=""
# Slack Integration
SLACK_BOT_TOKEN=""
SLACK_APP_TOKEN=""
# Discord Integration
DISCORD_BOT_TOKEN=""
# Security (change in production!)
JWT_SECRET="smartlink-jwt-secret-change-in-production-2024"
ENCRYPTION_KEY="smartlink-32char-encrypt-key!!"
# App Settings
NODE_ENV="development"Note: The DATABASE_URL and REDIS_URL are pre-configured to work with the Docker containers out of the box.
npm run dev # Start Vite + Electron in development
npm run build # Build for production
npm run package # Package as distributable
npm run db:generate # Generate Prisma client
npm run db:push # Push schema to database
npm run db:migrate # Run migrations
npm run db:studio # Open Prisma Studio
npm run lint # Run ESLint
npm run test # Run VitestThe project includes a complete Docker setup with PostgreSQL, pgAdmin, and Redis.
| Service | Container Name | Port | Purpose |
|---|---|---|---|
| PostgreSQL 16 | smartlink-db | 5432 | Primary database |
| pgAdmin 4 | smartlink-pgadmin | 5050 | Database GUI |
| Redis 7 | smartlink-redis | 6379 | Caching & real-time |
PostgreSQL:
Host: localhost:5432
User: smartlink
Password: smartlink_secure_password_2024
Database: smartlink
pgAdmin:
URL: http://localhost:5050
Email: admin@smartlink.local
Password: admin123
The Dockerfile uses multi-stage build:
- Builder stage - Installs deps, generates Prisma, builds app
- Production stage - Minimal image for packaging
Note: Electron apps run natively, not in Docker. The Dockerfile is for building/CI.
Windows:
start.batLinux/Mac:
chmod +x start.sh
./start.shThe start script automatically:
- Checks if Docker is running
- Starts PostgreSQL, pgAdmin, Redis containers
- Waits for PostgreSQL to be ready
- Installs npm dependencies (if needed)
- Generates Prisma client
- Pushes database schema
- Shows connection info
Then run:
npm run dev-
Start Docker containers:
docker-compose up -d
-
Wait for PostgreSQL to be healthy:
docker-compose ps # Check status -
Install dependencies:
npm install
-
Set up environment:
cp .env.example .env # Edit .env with your configuration (or use defaults for local dev) -
Initialize database:
npm run db:generate # Generate Prisma client npm run db:push # Push schema to database
-
Run in development:
npm run dev
# Start all services
docker-compose up -d
# Stop all services
docker-compose down
# View logs
docker-compose logs -f postgres
# Reset database (delete all data)
docker-compose down -v
docker-compose up -d
# Check service health
docker-compose ps| Service | URL/Port |
|---|---|
| SmartLink App | Electron window (npm run dev) |
| PostgreSQL | localhost:5432 |
| pgAdmin | http://localhost:5050 |
| Redis | localhost:6379 |
- Electron with Context Isolation - Secure IPC via preload script
- Vite for Renderer - Fast HMR and build
- Zustand over Redux - Simpler state management
- Prisma ORM - Type-safe database access
- OpenRouter - Access to multiple LLMs with single API
- Custom Titlebar - Frameless window with custom controls
- Tailwind CSS - Rapid UI development with dark mode
-
Agent Services - Implement actual agent logic in
src/main/services/agents/AgentOrchestrator.ts- Route requests to sub-agentsMainAgent.ts- Primary assistantResearchAgent.ts- Web search capabilitiesDocumentAgent.ts- SummarizationRiskAgent.ts- Risk assessmentMeetingAgent.ts- Scheduling optimization
-
Voice Recognition - Implement Whisper integration in
src/main/services/voice/ -
Communication Services - Implement in
src/main/services/communication/EmailService.ts- IMAP/SMTPSlackService.ts- Slack APIDiscordService.ts- Discord.jsChatService.ts- Real-time chat
-
WebSocket Server - Real-time updates via Socket.IO
-
Offline Support - SQLite cache and sync queue
Key files by size (for context on complexity):
prisma/schema.prisma- 11KB (complete database schema)src/preload/index.ts- 11KB (full IPC API bridge)src/renderer/pages/SettingsPage.tsx- 15KB (most complex page)src/renderer/pages/AgentPage.tsx- 11KB (AI chat interface)src/renderer/pages/DashboardPage.tsx- 11KB (overview page)src/renderer/components/common/Sidebar.tsx- 7KB (navigation)src/shared/types/api.types.ts- 6KB (API type definitions)src/renderer/styles/globals.css- 6KB (all custom styles)src/shared/constants/channels.ts- 5KB (IPC channels)
This is a private project created for management assistance.