An AI-powered regulatory guidance system for pharmaceutical regulations in Saudi Arabia, built with Flask, Supabase, and modern web technologies.
- AI-Powered Chat Interface: Get intelligent answers about SFDA regulations
- Comprehensive FAQ System: Browse categorized regulatory guidelines
- User Authentication: Secure login/signup with Supabase
- Profile Management: User profiles with theme preferences
- Dark/Light Theme: Accessible theme toggle with system preference detection
- Responsive Design: Works seamlessly across desktop and mobile devices
- Real-time Updates: Live chat with typing indicators and suggested questions
The SFDA Copilot application uses an HTML-first approach for theme toggles, ensuring better accessibility and maintainability.
- β Light/dark theme support
- β System preference detection
- β User preference persistence
- β Accessible toggle buttons with ARIA labels
- β
Bootstrap 5 integration with
data-bs-theme - β Keyboard navigation support
- β Screen reader compatibility
Theme toggle buttons are defined directly in the HTML with proper accessibility attributes:
<!-- Landing page theme toggle -->
<button
id="landing-theme-toggle"
class="theme-toggle-btn btn btn-outline-secondary btn-sm ms-2"
aria-label="Toggle theme between light and dark"
title="Toggle theme between light and dark"
>
<i class="bi bi-moon-fill"></i>
</button>
<!-- Sidebar theme toggle -->
<button
id="sidebar-theme-toggle"
class="theme-toggle-btn btn btn-outline-secondary btn-sm ms-2"
aria-label="Toggle theme between light and dark"
title="Toggle theme between light and dark"
>
<i class="bi bi-moon-fill"></i>
</button>
<!-- Offcanvas theme toggle -->
<button
id="offcanvas-theme-toggle"
class="theme-toggle-btn btn btn-outline-secondary btn-sm ms-2"
aria-label="Toggle theme between light and dark"
title="Toggle theme between light and dark"
>
<i class="bi bi-moon-fill"></i>
</button>The theme system uses event delegation and DOMCache for optimal performance:
// Event delegation for better performance
document.addEventListener('click', (e) => {
if (e.target.closest('.theme-toggle-btn')) {
e.preventDefault();
toggleTheme();
}
});
// Keyboard navigation support
document.addEventListener('keydown', (e) => {
if (e.target.closest('.theme-toggle-btn') && (e.key === 'Enter' || e.key === ' ')) {
e.preventDefault();
toggleTheme();
}
});- Uses Bootstrap 5's native
data-bs-themeattribute - Stores preference in localStorage
- Respects system color scheme preference
- Synchronizes across all toggle buttons
- ARIA Labels: Clear descriptions for screen readers
- Keyboard Navigation: Full keyboard accessibility with Enter and Space keys
- Focus Management: Proper focus handling during theme changes
- Screen Reader Announcements: Theme change notifications
- High Contrast: Maintains readability in both themes
- Python 3.8+
- Node.js 16+
- Supabase account
-
Clone the repository
git clone https://github.com/your-username/sfda-copilot.git cd sfda-copilot -
Set up the backend
# Create virtual environment python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate # Install dependencies pip install -r requirements.txt # Set up environment variables cp .env.example .env # Edit .env with your Supabase credentials
-
Set up the frontend
# Install Node.js dependencies npm install # Build frontend assets (if needed) npm run build
-
Configure Supabase
- Create a new Supabase project
- Set up the database schema (see
web/migrations/) - Get your project URL and anon key
- Update
.envwith your credentials
-
Run the application
# Start Flask development server python web/app.py # Open your browser to http://localhost:5000
sfda-copilot/
βββ README.md # This file
βββ requirements.txt # Python dependencies
βββ package.json # Node.js dependencies
βββ .env.example # Environment variables template
βββ faq.yaml # FAQ data configuration
βββ static/ # Static frontend assets
β βββ css/
β β βββ style.css # Custom CSS styles
β βββ js/
β β βββ app.js # Main JavaScript application
β βββ images/ # Image assets
βββ web/ # Flask backend
β βββ app.py # Flask application entry point
β βββ api/ # API endpoints
β βββ services/ # Business logic services
β βββ utils/ # Utility functions
β βββ templates/ # HTML templates
β β βββ index.html # Main application template
β βββ tests/ # Test files
βββ data/ # Regulatory guideline data
β βββ regulatory/
β βββ pharmacovigilance/
β βββ Veterinary_Medicines/
β βββ Biological_Products_and_Quality_Control/
βββ memory-bank/ # Project documentation and notes
SearchEnginecomposes the index, query processor, semantic search, TF-IDF lexical search, and result combiner. Those search responsibilities remain separate by design.web.utils.embedding_helpersis the only embedding-provider factory. Provider initialization fails clearly rather than switching vector spaces behind an existing FAISS index.- Frontend
Servicesowns only Supabase and HTTP operations. Event handlers own user-facing recovery,state.jsowns runtime state, andauth-view.jsowns authenticated/unauthenticated view transitions.
python -m pip install -r requirements-dev.txt
python -m playwright install chromium# Fast backend suite
python -m pytest -m "not browser and not integration"
# Browser suite (pytest starts an ephemeral Flask test server)
python -m pytest -m browser --browser chromium
# Integration tests requiring generated artifacts or external services
python -m pytest -m integration
# Backend coverage
python -m pytest -m "not browser and not integration" --cov=webPlaywright starts an ephemeral Flask test server from web/tests/conftest.py.
GitHub Actions installs Chromium and runs the browser suite as a separate
merge gate.
- Theme Toggle Tests: Verify theme persistence, accessibility, and functionality
- Profile Integration Tests: Test theme preference synchronization with user profiles
- Authentication Tests: Test user authentication and session management
- API Tests: Test backend API endpoints
# Supabase Configuration
SUPABASE_URL=your_supabase_project_url
SUPABASE_ANON_KEY=your_supabase_anon_key
# Flask Configuration
FLASK_ENV=development
FLASK_DEBUG=True
SECRET_KEY=your_secret_key
# Database Configuration (if not using Supabase)
DATABASE_URL=your_database_urlEdit faq.yaml to customize the FAQ categories and questions:
regulatory:
title: "Regulatory Guidelines"
icon: "bi-shield-check"
questions:
- short: "Drug Registration"
text: "What are the requirements for drug registration in Saudi Arabia?"- Theme Toggle Refactoring Plan
- Detailed implementation plan and technical specifications
API endpoints are documented in the code with OpenAPI/Swagger annotations.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for new functionality
- Ensure all tests pass (
python -m pytest) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow the existing code style and patterns
- Write comprehensive tests for new features
- Update documentation for significant changes
- Ensure accessibility compliance
- Test across different browsers and devices
- Theme Toggle Refactoring: Implemented HTML-first approach with improved accessibility
- Profile Integration: Enhanced theme preference synchronization with user profiles
- Testing Suite: Added comprehensive tests for theme toggle functionality
- Documentation: Updated all documentation with new implementation details
- v2.0.0: Complete theme toggle refactoring with accessibility improvements
- v1.0.0: Initial release with basic functionality
Theme Toggle Not Working
- Check that JavaScript is enabled in your browser
- Clear browser cache and localStorage
- Verify that all theme toggle buttons have the correct
class="theme-toggle-btn"attribute - Check browser console for JavaScript errors
Authentication Issues
- Verify Supabase credentials in
.envfile - Ensure Supabase project is properly configured
- Check network connectivity to Supabase services
Mobile Responsiveness
- Test on actual devices, not just browser dev tools
- Check viewport meta tag settings
- Verify CSS media queries are working correctly
This project is licensed under the MIT License - see the LICENSE file for details.
- Mohamed Fouda - Lead Developer & Designer
- SFDA Copilot Team - Development & Testing
- Saudi Food and Drug Authority (SFDA) for regulatory guidelines
- Bootstrap team for the excellent UI framework
- Supabase team for the backend-as-a-service platform
- OpenAI for AI capabilities
For support, please open an issue in the GitHub repository or contact the development team.
Note: This is a documentation file for the SFDA Copilot project. For the most up-to-date information, please refer to the project's GitHub repository and the latest code commits.