A comprehensive, role-based knowledge management system for pediatric psychiatry with advanced AI personalization, BYOK support, and multi-tenant architecture.
- Node.js 18+
- npm or yarn
- Cloudflare account (for deployment)
- Wrangler CLI
-
Clone the repository
git clone <repository-url> cd pedi-psych-kb
-
Install dependencies
npm install
-
Set up Cloudflare D1 database
# Create database cd database npm run db:create # Run migrations npm run db:migrate # Seed demo data npm run db:seed
-
Configure environment
cp wrangler.toml.example wrangler.toml # Edit wrangler.toml with your Cloudflare credentials -
Start development servers
# Terminal 1: Start API server cd apps/app-api npm run dev # Terminal 2: Start frontend cd apps/frontend npm run dev
-
Access the application
- Frontend: http://localhost:3000
- API: http://localhost:8787
- Demo login:
admin@example.com/password123
- ✅ Role-Based Access Control: 5 user roles with appropriate content access
- ✅ Advanced AI Search: BYOK-powered personalization with medical accuracy boundaries
- ✅ Comprehensive Knowledge Base: 9 chapters covering pediatric behavioral health
- ✅ Multi-Language Support: English and Arabic content
- ✅ Professional Tools: Teleprompters, handouts, intervention plans
- ✅ License Management: Flexible licensing with individual and organization tiers
- 👑 Admin/CTO: Full system access, user management, content administration
- 👨⚕️ Doctor: Complete clinical access, all content categories, patient resources
- 👩⚕️ Therapist: Therapeutic focus, session tools, intervention planning
- 👨🏫 Educator: Educational content, classroom strategies, student support
- 👨👩👧👦 Parent: Family-focused guidance, practical home strategies
apps/app-api/
├── src/
│ ├── index.ts # Main application entry
│ ├── middleware/
│ │ ├── license.ts # Simplified role-based middleware
│ │ └── api-usage.ts # Optional usage tracking
│ └── routes/
│ ├── content.ts # Knowledge base & AI search
│ ├── admin.ts # User management
│ └── licenses.ts # License management
apps/frontend/
├── src/
│ ├── components/ # Reusable UI components
│ ├── pages/ # Route-specific pages
│ ├── contexts/ # React contexts (Auth, etc.)
│ └── i18n.ts # Internationalization
database/
├── schema.sql # Core tables (users, cards, tenants)
├── license_schema.sql # License management tables
└── seed.sql # Demo data
# Login
POST /api/auth/login
{
"email": "admin@example.com",
"password": "password123"
}# Browse knowledge base structure
GET /api/content/book-structure
# Basic search
POST /api/content/search
{
"query": "anxiety management",
"limit": 10
}
# Advanced AI-powered search
POST /api/content/advanced-search
{
"query": "My child has meltdowns at bedtime",
"context": {
"user_role": "parent",
"child_age": 8,
"conditions": ["behavioral"],
"severity": "moderate"
},
"response_type": "handout"
}# Configure AI provider
POST /api/content/byok-config
{
"provider": "gemini",
"api_key": "your-api-key",
"model_preferences": {
"model": "gemini-pro",
"temperature": 0.7
}
}
# Get configurations
GET /api/content/byok-config# Create user
POST /api/users
{
"email": "doctor@hospital.com",
"name": "Dr. Smith",
"role": "doctor"
}
# List users
GET /api/admin/users
# System health
GET /api/healthAdvantages:
- ✅ Serverless, global CDN
- ✅ Automatic scaling
- ✅ Built-in D1 database
- ✅ Cost-effective for most use cases
Setup:
# 1. Configure Cloudflare
npm install -g wrangler
wrangler login
# 2. Create D1 database
wrangler d1 create pedi-psych-kb-prod
# 3. Update wrangler.toml with database ID
# 4. Deploy
npm run deployAdvantages:
- ✅ Self-hosted control
- ✅ Custom infrastructure
- ✅ Enterprise compliance
Setup:
# 1. Build Docker image
docker build -t pedi-psych-kb .
# 2. Run with environment variables
docker run -p 8787:8787 \
-e JWT_SECRET=your-secret \
-e DATABASE_URL=your-db-url \
pedi-psych-kbAdvantages:
- ✅ Full server control
- ✅ Custom database setup
- ✅ Predictable costs
Setup:
# 1. Install Node.js 18+
# 2. Clone repository
# 3. Install dependencies
# 4. Configure database
# 5. Start with PM2
pm2 start ecosystem.config.js- Database Method (Initial Setup):
INSERT INTO users (email, password_hash, name, role, tenant_id, created_at, updated_at)
VALUES (
'cto@yourorg.com',
'password123', -- Use proper hashing in production
'CTO Name',
'admin',
1,
datetime('now'),
datetime('now')
);- API Method (After Initial Setup):
curl -X POST -H "Authorization: Bearer ADMIN_JWT" \
-H "Content-Type: application/json" \
-d '{
"email": "newadmin@yourorg.com",
"name": "New Admin",
"role": "admin"
}' \
"https://your-domain.com/api/users"Via Web Interface:
- Login as admin
- Navigate to Admin Panel → Users
- Click "Add New User"
- Fill in user details:
- Email address
- Full name
- Role (doctor, therapist, educator, parent)
- Organization/tenant
- Send credentials to user
Via API:
# Create doctor
curl -X POST -H "Authorization: Bearer ADMIN_JWT" \
-H "Content-Type: application/json" \
-d '{
"email": "doctor@hospital.com",
"name": "Dr. Jane Smith",
"role": "doctor",
"tenant_id": 1
}' \
"https://your-domain.com/api/users"
# Create parent
curl -X POST -H "Authorization: Bearer ADMIN_JWT" \
-H "Content-Type: application/json" \
-d '{
"email": "parent@family.com",
"name": "John Parent",
"role": "parent",
"tenant_id": 1
}' \
"https://your-domain.com/api/users"The system comes with pre-seeded demo users:
# Admin User
Email: admin@example.com
Password: password123
Role: admin
Access: Full system administration
# Doctor User
Email: doctor@example.com
Password: password123
Role: doctor
Access: All clinical content + AI features
# Therapist User
Email: therapist@example.com
Password: password123
Role: therapist
Access: Therapeutic content + session tools
# Educator User
Email: educator@example.com
Password: password123
Role: educator
Access: Educational content + classroom strategies
# Parent User
Email: parent@example.com
Password: password123
Role: parent
Access: Family-focused guidance-
Admin Testing:
- Login as admin
- Create new users
- View system analytics
- Manage content
-
Professional Testing:
- Login as doctor/therapist
- Configure BYOK (optional)
- Test advanced search
- Generate handouts/teleprompters
-
Parent Testing:
- Login as parent
- Browse educational content
- Use basic search
- Access family resources
# Required
JWT_SECRET=your-super-secure-jwt-secret-key
DATABASE_URL=your-database-connection-string
# Optional
GOOGLE_CLIENT_ID=your-google-oauth-client-id
GOOGLE_CLIENT_SECRET=your-google-oauth-secret- Change default passwords
- Use strong JWT secrets
- Enable HTTPS/SSL
- Configure CORS properly
- Implement rate limiting
- Set up monitoring and logging
- Regular security updates
# System health
curl https://your-domain.com/api/health
# Response
{
"status": "healthy",
"database": "connected",
"timestamp": "2025-10-28T12:00:00Z"
}- User activity tracking
- Content engagement metrics
- Search query analysis
- AI usage statistics
- Performance monitoring
# 1. Start API server
cd apps/app-api
npm run dev
# 2. Start frontend (new terminal)
cd apps/frontend
npm run dev
# 3. Access application
# Frontend: http://localhost:3000
# API: http://localhost:8787# Reset database
npm run db:reset
# Add new migration
npm run db:migrate
# Seed with fresh data
npm run db:seed# Run tests
npm run test
# Type checking
npm run type-check
# Linting
npm run lint- User Manual: Comprehensive guide for all user roles
- Deployment Guide: Detailed deployment instructions
- API Documentation: Complete API reference
- Admin Guide: System administration manual
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: docs/
- Issues: GitHub Issues
- Email: support@your-domain.com
- ✅ Role-based access control
- ✅ Advanced AI search with BYOK
- ✅ Comprehensive knowledge base
- ✅ Multi-language support
- ✅ Professional tools (teleprompters, handouts)
- Mobile applications (iOS/Android)
- Real-time collaboration features
- Advanced analytics dashboard
- Video content support
- Third-party integrations
- Advanced personalization algorithms
- Offline mode support
- Custom branding for organizations
- Advanced reporting and analytics
- Integration with EHR systems
Built with ❤️ for pediatric mental health professionals and families
Last Updated: October 2025