Dr. Aria is a highly sophisticated, AI-driven psychological chat application. It provides real-time, clinically informed therapeutic conversations using a dual-model LLM architecture. Designed with strict privacy in mind, the platform supports both server-side and end-to-end encryption.
- Real-Time Therapy Chat: Low-latency, token-by-token streaming responses using Server-Sent Events (SSE).
- Dual-Model AI Architecture:
- Uses a heavy model (e.g.,
gpt-4o) for high-quality, empathetic primary responses. - Uses a lighter model (e.g.,
gpt-4o-mini) for asynchronous background tasks.
- Uses a heavy model (e.g.,
- Asynchronous Clinical Subsystems:
- Observer: Silently analyzes conversations to extract clinical insights, emotional states, and behavioral patterns.
- Compressor: Summarizes past conversational chapters to prevent context window overflow.
- Synthesizer: Builds and maintains a longitudinal profile of the user's mental health journey.
- Dual-Mode Privacy:
- Mode A (Server-Side Encryption): The server securely encrypts and decrypts messages in RAM.
- Mode B (End-to-End Encryption): The client encrypts messages locally. The server only sees ciphertext for storage and transient plaintext in RAM strictly during the request lifecycle.
- Built-in CLI Tool: Includes a powerful
chat.jsCLI script for interacting directly with the backend without needing the frontend.
- Frontend: Next.js 16, React 19, Tailwind CSS (Found in the
Frontend/folder). - Backend: Node.js, Express.js.
- Database: MongoDB (Mongoose).
- AI Integration: OpenAI SDK.
- Security: JWT for stateless auth, bcrypt for password hashing, AES for message encryption.
├── Frontend/ # Next.js 16 Client Application
├── ai/ # AI prompt builders, wrappers, and asynchronous processors
│ ├── groq.js # OpenAI API bindings & streaming logic
│ ├── observer.js # Silent clinical insights generator
│ ├── chapterCompressor.js # Context summarization
│ └── profileSynthesizer.js # Longitudinal user profiling
├── config/ # DB & environmental config
├── controllers/ # Express route handlers (Auth, Chat, Privacy)
├── middlewares/ # JWT Authentication and Route Protection
├── models/ # Mongoose schemas (User, Message, Profile, etc.)
├── routes/ # Express API routing and rate limiting
├── utils/ # Encryption utilities, mailing, and cron jobs
├── chat.js # Interactive CLI client for local testing
└── index.js # Main backend Express server entry point
- Node.js (v18+)
- MongoDB instance (local or Atlas)
- OpenAI API Key
- Clone the repository and navigate to the project root.
- Install dependencies:
npm install
- Create a
.envfile in the root directory:PORT=4000 FRONTEND_URL=http://localhost:3000 MONGODB_URL=mongodb+srv://<user>:<password>@cluster.mongodb.net/dr-aria SECRET_KEY=your_super_secret_jwt_key OPENAI_API_KEY=sk-proj-... # Optional: Model overrides OPENAI_MAIN_MODEL=gpt-4o OPENAI_FAST_MODEL=gpt-4o-mini
- Start the backend server:
npm run dev # or node index.js
- Navigate to the frontend directory:
cd Frontend - Install dependencies:
npm install
- Copy the example
.envvariables (ensure it points to the backend API):NEXT_PUBLIC_API_URL=http://localhost:4000/api/v1
- Start the Next.js development server:
npm run dev
- Access the app at
http://localhost:3000.
You can test the AI logic, SSE streams, and authentication locally without starting the frontend using the built-in CLI tool.
Ensure the backend server is running, then run:
node chat.jsCLI Options:
node chat.js [email protected](Login with specific email)node chat.js --signup(Force a fresh user creation)node chat.js --verbose(Show full error stack traces and JWT debug info)
In-Chat Commands:
/history- Show your last 6 messages/me- View current user statistics and encryption mode/clear- Refresh session JWT/quit- Exit the CLI
The application uses multiple strict limiters to prevent abuse:
- OTP Limiter: Protects SMS/Email gateways.
- Auth Limiter: Prevents brute forcing on
/loginand/signup. - Chat Limiter: Limits users to a strict conversational pace (e.g., 20 requests per minute) to protect OpenAI API quotas.
- Weekly Reporter (
utils/weeklyReportCron.js): A cron job runs every Sunday to compile insights and longitudinal profiles generated by the observer into structured weekly summaries.
Disclaimer: Dr. Aria is an AI tool designed for psychological support simulation and is not a replacement for professional human psychiatric or medical help.