Chapter 4: System Design
4.1 Class Diagrams
Backend (FastAPI, SQLAlchemy)
The backend is designed using SQLAlchemy ORM models to represent the core entities of
the system. The two main entities are User and Specialist, with a one-to-one
relationship. This design allows for flexible user management and easy extension for future
roles (e.g., admin, patient).
+-------------------+ 1 +----------------------+
| User |-----------------| Specialist |
+-------------------+ +----------------------+
| id (PK) | | id (PK) |
| username | | user_id (FK) |
| email | | name |
| hashed_password | | phone_number |
| user_type | | license_number |
| status | | specialization |
| is_active | | hospital |
| is_superuser | | bio |
+-------------------+ | is_approved |
| license_file |
| profile_image |
+----------------------+
• User: Represents all users in the system, including specialists and admins. Contains
authentication and status fields.
• Specialist: Extends the user with medical and professional information, such as
license, specialization, and hospital affiliation.
Other Entities: - DashboardStats: Used for admin analytics and system monitoring. -
Token: Handles authentication tokens for secure API access. - SpecialistRegistration:
Manages the registration workflow for new specialists, including file uploads and approval
status.
ML Microservice
The machine learning microservice is built using PyTorch and FastAPI. The core class is
SkinDiseaseModel, which uses the EfficientNet-B2 architecture for image classification.
The microservice exposes endpoints for prediction and model management.
• SkinDiseaseModel: Inherits from [Link], encapsulates the neural network
architecture.
• DataLoader, Trainer, Predictor: Utility classes and functions for training, evaluating,
and serving the model.
4.2 Database Schema Design
The database schema is designed for extensibility and normalization. The main tables are:
• users
– Fields: id (PK), username, email, hashed_password, user_type, status,
is_active, is_superuser
– Purpose: Stores authentication and role information for all users.
• specialists
– Fields: id (PK), user_id (FK), name, phone_number, license_number,
specialization, hospital, bio, is_approved, license_file, profile_image
– Purpose: Stores additional information for users who are healthcare
specialists.
• (Other tables as needed for dashboard, admin, etc.)
– These can include tables for appointments, logs, or educational content in
future expansions.
Relationships: - One-to-one: Each specialist is also a user, linked via user_id. - Admins
are users with user_type = ADMIN, allowing for role-based access control.
This schema supports efficient queries for user management, specialist search, and future
features like appointments or messaging.
4.3 UI/UX Interface Design
The frontend is built with Flutter, following Material 3 design principles for a modern,
accessible, and responsive user experience.
• Main Screens:
– Splash Screen: Provides branding and a smooth entry into the app,
improving perceived performance.
– Home Screen: Central hub for users, offering quick access to diagnosis,
specialist search, and educational content.
– Image Upload: Allows users to capture or select images for diagnosis, with
real-time feedback and error handling.
– Diagnosis Result: Displays AI predictions, confidence scores, and actionable
health advice, encouraging users to consult specialists.
– Specialist Search: Enables users to find and filter specialists by name,
specialization, or hospital, with detailed profile views.
– Specialist Registration: Multi-step form for healthcare professionals to join
the platform, including secure file uploads for credentials.
– Settings: Lets users toggle between light/dark mode, switch environments
(dev/prod), and view app configuration.
– About/Disclaimer: Clearly communicates the app’s purpose, limitations,
and legal disclaimers.
• Navigation:
The app uses a bottom navigation bar for primary sections (Home, Learn, Find
Specialist, Join Us), ensuring intuitive access. Additional settings and information
are accessible via a drawer or dedicated settings screen.
• Design Language:
The UI uses a teal accent color, rounded corners, and accessible font sizes. All forms
include validation and helpful error messages. The app supports both light and dark
themes, adapting to user preferences and device settings.
Chapter 5: System Implementation
5.1 Tech Stack and Tools Used
• Frontend:
– Flutter: Enables cross-platform development for Android, iOS, web, and
desktop.
– Dart: The primary language for Flutter apps.
– Provider: State management for authentication and user data.
– SharedPreferences: Persistent storage for user settings (e.g., theme).
– Material 3: Modern UI components and theming.
• Backend:
– FastAPI: High-performance Python web framework for building APIs.
– SQLAlchemy: ORM for database management and migrations.
– SQLite: Lightweight database for development and testing (can be replaced
with PostgreSQL/MySQL).
– JWT: Secure, stateless authentication.
– CORS: Allows cross-origin requests from the Flutter frontend.
• ML Microservice:
– PyTorch: Deep learning framework for model development and inference.
– EfficientNet: State-of-the-art CNN architecture for image classification.
– TorchScript: For model serialization and deployment.
– FastAPI: Serves the model as a REST API.
• DevOps:
– Uvicorn: ASGI server for FastAPI.
– pip: Python package management.
– [Link]: Dependency management for reproducible
environments.
– Modular directory structure: Ensures maintainability and scalability.
5.2 Key Code Snippets
Flutter: Main App Routing
MaterialApp(
title: [Link],
theme: [Link],
darkTheme: [Link],
themeMode: _isDarkMode ? [Link] : [Link],
initialRoute: '/',
routes: {
'/': (context) => const SplashScreen(),
'/login': (context) => const LoginScreen(),
'/home': (context) => HomeScreen(onThemeToggle: _toggleTheme),
// ...other routes
},
);
This snippet shows how the app initializes routes and themes, providing a seamless user
experience across different devices and preferences.
Backend: FastAPI Main
app = FastAPI(title="Dr. Skin API", description="API for skin
specialist management system", version="1.0.0")
app.include_router(specialist_routes.router)
app.include_router(auth_routes.router)
app.include_router(dashboard_routes.router)
app.include_router(diagnosis_routes.router)
The backend is modular, with each feature (auth, specialists, dashboard, diagnosis) in its
own router, making the codebase easy to maintain and extend.
ML API: Prediction Endpoint
@[Link]("/predict")
async def predict(file: UploadFile = File(...)):
image = [Link]([Link](await [Link]())).convert('RGB')
image_tensor = transform(image).unsqueeze(0)
with torch.no_grad():
outputs = model(image_tensor)
probabilities = [Link](outputs, dim=1)[0]
top3_prob, top3_indices = [Link](probabilities, 3)
predictions = [{"class": class_names[[Link]()],
"confidence": float([Link]())} for prob, idx in zip(top3_prob,
top3_indices)]
return {"predictions": predictions, "top_prediction":
predictions[0]}
This endpoint receives an image, processes it with the trained model, and returns the top 3
predictions with confidence scores.
5.3 Sample API Endpoints or Service Logic
• POST /auth/register – Registers a new user or specialist, validating input and
storing credentials securely.
• POST /auth/token – Authenticates users and returns a JWT for secure, stateless
sessions.
• GET /specialists/ – Lists and filters specialists based on query parameters.
• POST /specialists/{id}/approve – Allows admins to approve specialist
registrations.
• POST /diagnosis/ – Accepts an image and returns AI-based diagnosis (currently
returns static data for testing).
Example: Specialist Registration Flow 1. The specialist fills out the registration form and
uploads required documents. 2. The backend validates the data, checks for duplicates, and
stores files securely. 3. The specialist’s account is created with a pending status. 4. An
admin reviews the application and approves or rejects it. 5. Upon approval, the specialist
gains access to additional features.
5.4 Implementation Highlights
• EfficientNet-B2 is chosen for its balance of accuracy and efficiency, enabling high-
quality predictions even on modest hardware.
• JWT Authentication ensures secure, stateless sessions, reducing server load and
improving scalability.
• Role-based Access Control restricts sensitive operations (like specialist approval)
to authorized users.
• Advanced Data Augmentation during training increases model robustness and
generalization.
• Responsive Flutter UI adapts to different screen sizes and accessibility needs.
• Environment Switcher in the app allows for easy toggling between development
and production backends, aiding testing and deployment.
Chapter 6: Conclusion and Future Work
Summary of Goals Achieved
The Dr. Skin project successfully delivers a full-stack, AI-powered platform for skin health.
The system enables users to receive instant, AI-driven skin disease predictions, search for
healthcare specialists, and access educational content—all through a modern, cross-
platform Flutter app. The backend is secure, modular, and scalable, supporting robust user
management and specialist workflows. The machine learning microservice achieves high
accuracy using state-of-the-art deep learning techniques.
Suggested Improvements or Next Steps
• Appointment Booking & Teleconsultation: Integrate real-time booking and video
consultation features to connect users with specialists directly.
• Expanded ML Coverage: Train the model on more skin conditions and diverse
datasets to improve accuracy and inclusivity.
• Production Database: Migrate from SQLite to PostgreSQL or MySQL for better
performance and reliability in production.
• Push Notifications & Real-Time Chat: Enhance user engagement and support with
notifications and secure messaging.
• Continuous Integration/Deployment: Automate testing and deployment pipelines
for faster, safer releases.
• Clinical Validation: Partner with healthcare providers to validate the system in
real-world settings and ensure regulatory compliance.
• User Studies: Conduct usability studies to gather feedback and improve the user
experience.
References
1. Tschandl, P., et al. “The HAM10000 dataset, a large collection of multi-source
dermatoscopic images of common pigmented skin lesions.” Scientific data 5 (2018):
180161.
2. Tan, M., & Le, Q. V. “EfficientNet: Rethinking model scaling for convolutional neural
networks.” ICML 2019.
3. FastAPI Documentation: [Link]
4. Flutter Documentation: [Link]
5. PyTorch Documentation: [Link]
6. [Add more as needed]
Appendix
A. Screenshots
(Insert screenshots of the app: Home, Upload, Diagnosis, Specialist Search, Registration, etc.
Here you can describe each screenshot and its purpose in the user journey.)
B. Extra Code
• [Link] for backend and ML microservice, listing all dependencies for
reproducibility.
• Example configuration files for environment variables, database connections, and
deployment.
• Test scripts for API endpoints and model inference.
End of Report