🧠 Inspiration
MindFree.AI is a platform where users can get into therapy sessions with AI that can recognize the user's emotions from the camera. The AI interacts with the real-time emotion data gathered and gives insights to users. Then, Gemini-powered AI provides more than 10 meditation sounds and suggests the best meditation sound based on the user's emotion data. The emotion data are saved through blockchain technology using Midnight and smart contract. The platform also provides a dynamic graph of users' emotion data.
MindFree.AI is our response to this need: an intelligent, privacy-first AI therapy, meditation assistant.
✨ What it does
MindFree.AI is a secure AI-powered mental wellness platform that:
- 🎭 Detects real-time emotions from webcam input using face-api.js and expression models
- ✍️ Logs emotional snapshots with timestamps
- 🪙 Anchors hashed emotion data to the Midnight blockchain (privacy-first)
- 🔐 Stores metadata securely in MongoDB, simulating on-chain anchoring
- 💬 Provides therapeutic chat support using OpenAI (GPT-3.5)
- 🎧 Suggests meditation music using Gemini based on your mood
- 📈 Displays emotional trends and anchor logs in a visual dashboard
🛠️ How we built it
Frontend
- Next.js (React), Tailwind CSS, Chart.js
- Emotion trend graph, anchor history cards, audio player UI
Backend
- FastAPI (Python) — Emotion detection, AI chat, Gemini meditation
- Node.js — Middleware for Midnight mock smart contract anchoring
- MongoDB Atlas — For user accounts, emotion logs, and anchor records
- Docker — Midnight node simulation for development
🧩 Why two backend servers? FastAPI & Node.js
We implemented two backend servers to divide responsibilities and bridge the gap between AI processing and blockchain anchoring:
The emotion detection using face-api.js is handled entirely in the frontend (Next.js) using TensorFlow.js. It analyzes the user's facial expressions from the webcam and sends the parsed emotion probabilities (like happy, sad, neutral, etc.) to the FastAPI backend.
FastAPI (Python)
This server handles all AI-related functionality:- Logging emotion snapshots to MongoDB
- Generating AI responses via OpenAI (GPT-3.5)
- Getting meditation recommendations using Gemini
- Hashing and sending emotion data for anchoring
Node.js (Express)
This server is responsible for:- Connecting to the Midnight blockchain devnet
- Anchoring hashed emotion data using the Midnight SDK
- Storing anchor metadata and returning mock transaction IDs
- The Node.js backend plays a crucial role in connecting our app to the Midnight blockchain. While the AI services are powered by FastAPI, all blockchain-related logic lives in Node.js because Midnight's SDK and tooling are currently only available in the NPM ecosystem.
🛠️ The main reason for this separation is that Midnight's SDKs and smart contract tooling are only available in the Node.js (npm) ecosystem. Since FastAPI (Python) cannot directly interact with these tools, we spun up a lightweight Node.js service to handle the blockchain logic.
AI & Blockchain
- OpenAI (GPT-3.5) for therapeutic response generation
- Google Gemini for meditation track recommendations
- Midnight SDKs for blockchain integration and smart contract scaffolding
🧪 Development Environment Setup
| 🧱 Service | 🌐 URL | 📄 Description |
|---|---|---|
| Frontend (Next.js) | http://localhost:3000 | React-based UI for dashboard, emotion graph, meditation |
| FastAPI Server | http://localhost:8000 | Python backend for AI chat, Gemini recommendation, emotion logs |
| Node.js API | http://localhost:6300 | Express server handling smart contract anchoring and users |
| Midnight Node | http://localhost:9999 | Docker container running Midnight proof server (TestNet) |
🌘 Use of Midnight
We leveraged Midnight's privacy-first blockchain to anchor emotional data using hashed metadata — ensuring user privacy without storing raw information on-chain.
🔐 Wallet Info & Identity Management
To simulate a privacy-focused identity system, we used the @midnight-ntwrk/wallet SDK to generate wallet identities during user registration. These wallets are stored in the users MongoDB collection and serve as anonymous identifiers for anchoring emotion logs.
🧩 How It Works
- A random seed is generated using Midnight’s HD wallet library.
- The seed is used to derive a wallet using
WalletBuilder. - The resulting shielded wallet address and
seedHexare stored securely. - Emotion log hashes are later anchored with this identity using a simulated smart contract.
🔐 Wallet Info & Identity Management
To simulate a privacy-focused identity system for anchoring user data, we used Midnight's SDK to generate wallet identities using WalletBuilder and store them securely in MongoDB.
🧬 Wallet Generation Code (Node.js)
ts
import { WalletBuilder } from '@midnight-ntwrk/wallet';
import { NetworkId } from '@midnight-ntwrk/zswap';
import { generateRandomSeed } from '@midnight-ntwrk/wallet-sdk-hd';
function toHexString(buffer) {
return Array.from(buffer)
.map((b) => b.toString(16).padStart(2, '0'))
.join('');
}
async function generateWallet() {
const seedBytes = generateRandomSeed(); // Generate secure seed
const seedHex = toHexString(seedBytes); // Convert to hex for storage
const wallet = await WalletBuilder.build(
'https://indexer.testnet-02.midnight.network/api/v1/graphql',
'wss://indexer.testnet-02.midnight.network/api/v1/graphql/ws',
'http://localhost:9999',
'https://rpc.testnet-02.midnight.network',
seedHex,
NetworkId.TestNet,
'info'
);
await wallet.start();
const state = await new Promise((resolve) => {
wallet.state().subscribe(resolve);
});
console.log('🪪 Wallet Address:', state.address);
return { seedHex, address: state.address };
}
📄 Smart Contract – compact DSL
We designed a minimal smart contract in Midnight's domain-specific language (called compact) to simulate anchoring a hash:
compact
contract anchor_text {
private field text_hash: Field
def initialize(hash: Field):
text_hash = hash
def update_hash(new_hash: Field):
text_hash = new_hash
def get_hash(): Field
return text_hash
}
🔐 What the Smart Contract Represents
Although we're simulating it locally via the Node.js backend:
- The contract acts as a ledger proof that a specific emotional state existed at a specific time.
- Because we store only the hash (not the raw emotion data), user privacy is preserved.
- The contract's purpose is to hold and update a single hash value, offering a traceable anchoring mechanism that could later support ZK proofs or full on-chain verification.
By anchoring hashes, we're laying the foundation for verifiable mental health journaling — without ever exposing sensitive raw data.
🐳 Running the Midnight Node with Docker
docker pull midnightnetwork/proof-server:latest
docker run -p 9999:6300 midnightnetwork/proof-server -- 'midnight-proof-server --network testnet'
🗄️ Use of MongoDB
We used MongoDB Atlas as our backend database to store user data, emotional snapshots, and anchoring records. It allowed us to query, visualize, and simulate blockchain interactions securely and efficiently.
📦 Collections Overview
| Collection | Description |
|---|---|
users |
Stores user credentials and Midnight wallet info (seed + shielded address) |
emotions |
Stores detected emotion data per timestamp for each user |
anchors |
Stores hashed emotion metadata and mock transaction IDs after anchoring |
👤 users Collection
- Created on user signup.
- Includes:
email: User's loginpassword: Hashed password via bcryptwallet: Object storing generated Midnight wallet identity
json
{
"_id": "ObjectId",
"email": "[email protected]",
"password": "$2b$10$ESzY3O0/hPMti5jdoj5OYe...",
"wallet": {
"seedHex": "b2bd9f26c5a4df00...",
"address": "mn_shield-addr_test1y7vh2xx..."
}
}
🎭 emotions Collection
• Logged after each emotion detection via webcam.
• Used for:
• AI therapy context (OpenAI)
• Meditation recommendations (Gemini)
• Trend graph visualization
• Blockchain hash generation
{
"_id": "ObjectId",
"user_email": "[email protected]",
"emotions": {
"happy": 0.9999,
"neutral": 0.00002,
"sad": 0.00001
},
"timestamp": "2025-04-13T07:42:11.730Z"
}
🪙 anchors Collection
• Populated by Node.js backend after hashing and (mock) anchoring to Midnight.
• Includes:
• userId: Links to MongoDB users _id
• hash: SHA-256 hash of emotion data
• metadata: Metadata block for blockchain context
• txId: Simulated transaction ID
• createdAt: Timestamp of anchoring
{
"_id": "ObjectId",
"userId": "67fad34d236f44e5b9fc3a60",
"hash": "5bd2e2a7...",
"metadata": {
"type": "chat_anchor",
"timestamp": "2025-04-13T11:38:18.557Z",
"sha256": "5bd2e2a7..."
},
"txId": "tx-1744544298557",
"createdAt": "2025-04-13T11:38:18.557Z"
}
🧠 Why We Use Both MongoDB and Midnight Blockchain
MindFree.AI leverages the strengths of both MongoDB and the Midnight blockchain to provide a secure, verifiable, and intelligent mental health tracking system.
🔹 Blockchain = Trust & Verifiability
We use the Midnight blockchain to anchor each emotion log by saving a SHA-256 hash of the data. This proves the data:
- ✅ Existed at a specific time
- ✅ Was not tampered with
- ✅ Remains private, since only the hash is stored on-chain
This gives users confidence that their emotional records are secure and cryptographically verifiable without revealing sensitive details.
🔹 MongoDB = AI, Insights & Dashboards
We store the actual emotion data (user email, emotion probabilities, timestamp) in MongoDB, enabling:
- 📈 Real-time emotion trend analysis
- 💬 Personalized therapy sessions using AI (Gemini + GPT)
- 🧩 Custom dashboards and visualizations for mental wellness tracking
🔐 Why This Hybrid Model Works
| Purpose | Blockchain (Midnight) | MongoDB |
|---|---|---|
| Verifiability | ✅ Cryptographic proof | ❌ Not verifiable on its own |
| Data privacy | ✅ Hash only, no raw data | ✅ Secure and private |
| Real-time queries | ❌ Inefficient | ✅ Optimized for search & filtering |
| AI-driven features | ❌ Not directly usable | ✅ Feeds AI assistants |
| Storage cost | ✅ Minimal | ✅ Affordable and scalable |
By combining blockchain immutability with database flexibility, we ensure that users' mental health data is both secure and useful.
🚧 Challenges we ran into
- Setting up and syncing Midnight local devnet correctly
- Making sure the same hashed payload is used across both Python and Node.js servers
- Frontend issues with anchor data rendering due to user ID mismatches
- Ensuring accurate timestamp and emotion readings for analysis and anchoring
- Parsing JSON responses from Gemini consistently
- Finding the documentation for the use of Midnight
- Challenge of using python deepface because of the connection from backend python to next js frontend, emotion detection was directly done in the frontend using face-api.js
🏆 Accomplishments that we’re proud of
- ✅ Successfully anchored emotion hashes to the Midnight blockchain
- ✅ Integrated multi-modal AI (OpenAI + Gemini) in one seamless UX
- ✅ Built a cross-platform system with two backend servers working together
- ✅ Designed a full emotion-to-anchor pipeline that feels smooth and secure
- ✅ Created a polished UI with live emotion graphs and anchor history
📚 What we learned
- How to hash sensitive data and simulate secure anchoring on-chain
- How to interface with Midnight’s SDK and testnet tools
- Best practices for using DeepFace in a live emotion tracking context
- How to build multi-service architectures using Python and Node together
- The power of AI + blockchain in privacy-preserving applications
🔮 What’s next for MindFree.AI
- ✅ Implement true zero-knowledge proofs for real privacy guarantees
- ✅ Enable users to write encrypted journals and anchor those too
- ✅ Let users send/receive “Dust” tokens as self-care rewards or affirmations
- ✅ Add more dynamic AI tools like habit coaching or trauma debriefing
- ✅ Deploy on a live Midnight network when available
- ✅ Mobile version with emotion detection via front-facing camera

Log in or sign up for Devpost to join the conversation.