Skip to content

nova728/health-platform-backend

Repository files navigation

Smart Health Platform - Backend

中文文档 | English Document


English Document

Technology Stack

Java 17 Spring Boot MySQL MyBatis-Plus JWT WebSocket Maven Aliyun

Project Overview

Smart Health Platform is an intelligent health management system that integrates health data management, diet tracking, medication reminders, exercise monitoring, and community interaction. The backend is built with Spring Boot 3.2.0 and follows a clean three-layer architecture (Controller-Service-Mapper).

Key Features:

  • Comprehensive health data tracking (BMI, weight, blood pressure, heart rate, sleep, steps)
  • AI-powered health analysis and personalized recommendations
  • Real-time medication reminders via WebSocket
  • Nutrition tracking with external API integration (FatSecret)
  • FDA drug information database integration
  • Community forum with rich text support
  • Smart health report generation

System Screenshots

🏠 Dashboard - System Overview

系统概览



📊 Health Data Analytics

健康数据分析

实时追踪 BMI、血压、心率、睡眠质量等多项健康指标



🤖 AI Health Assistant

AI健康助手



💊 Medication Reminder Interface

用药提醒



💬 Community Forum

社区论坛



🍎 Diet & Nutrition Tracking

饮食记录

饮食记录

营养分析

营养分析


🏃 Exercise Monitoring

运动监测

Project Structure

healthplatform/
├── src/main/java/com/health/healthplatform/
│   ├── config/                    # Configuration classes
│   │   ├── CorsConfig.java       # CORS configuration
│   │   ├── JwtConfig.java        # JWT authentication
│   │   ├── WebSocketConfig.java  # WebSocket setup
│   │   └── OAuth2Config.java     # OAuth2 configuration
│   │
│   ├── controller/                # REST API controllers
│   │   ├── AuthController.java
│   │   ├── UserController.java
│   │   ├── HealthDataController.java
│   │   ├── AIAnalysisController.java
│   │   ├── ArticleController.java
│   │   ├── DietRecord/
│   │   ├── MedicineReminder/
│   │   └── ExerciseRecord/
│   │
│   ├── service/                   # Business logic layer
│   │   ├── UserService.java
│   │   ├── AuthService.java
│   │   ├── health_data/          # Health metrics services
│   │   ├── DietRecord/           # Diet management
│   │   ├── MedicineReminder/     # Medication management
│   │   ├── HealthReport/         # Report generation
│   │   ├── DeepSeekService.java  # AI integration
│   │   ├── FdaDrugApiService.java
│   │   └── FileService.java      # OSS file upload
│   │
│   ├── mapper/                    # Data access layer
│   │   ├── UserMapper.java
│   │   ├── HealthDataMapper.java
│   │   └── ...
│   │
│   ├── entity/                    # Database entities
│   │   ├── User.java
│   │   ├── HealthData.java
│   │   ├── MedicineReminder.java
│   │   └── ...
│   │
│   ├── DTO/                       # Data transfer objects
│   ├── vo/                        # View objects
│   ├── websocket/                 # WebSocket handlers
│   ├── handler/                   # Exception handlers
│   ├── interceptor/               # JWT interceptor
│   └── util/                      # Utility classes
│
├── src/main/resources/
│   ├── application.properties     # Application configuration
│   ├── mapper/                    # MyBatis XML mappings
│   └── sql/                       # Database scripts
│
└── pom.xml                        # Maven dependencies

Core Features Implementation

1. Health Data Management

  • Real-time tracking of multiple health metrics
  • Historical trend analysis with date range queries
  • Automatic BMI calculation
  • Health status assessment based on medical standards

2. AI Health Analysis

  • Integration with DeepSeek AI service
  • Personalized health recommendations
  • Context-aware health Q&A
  • Multi-dimensional health score calculation

3. Medication Management

  • Medicine record tracking
  • Smart reminder scheduling
  • FDA drug information integration
  • Real-time push notifications via WebSocket

4. Diet & Nutrition

  • Meal recording with nutrition details
  • Daily nutrition summary
  • Goal setting and achievement tracking
  • FatSecret API integration for food data

5. Community Forum

  • Article publishing with rich text editor
  • Multi-level comment system
  • Social features (likes, favorites, shares)
  • Image upload to Aliyun OSS

6. Real-time Communication

  • WebSocket for instant notifications
  • Automatic reconnection mechanism
  • Session management for multiple users
  • Support for various notification types

Quick Start

Prerequisites

  • JDK 17 or higher
  • Maven 3.9.9 or higher
  • MySQL 8.0 or higher
  • Aliyun account (for OSS, SMS services)

Installation Steps

  1. Clone the repository
git clone https://github.com/nova728/health-platform-backend.git
cd health-platform-backend
  1. Configure database
# Create database
mysql -u root -p
CREATE DATABASE healthplatform CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

# Import database schema
mysql -u root -p healthplatform < src/main/resources/sql/schema.sql
  1. Configure application.properties
# Database configuration
spring.datasource.url=jdbc:mysql://localhost:3306/healthplatform
spring.datasource.username=your_username
spring.datasource.password=your_password

# Aliyun OSS configuration
aliyun.oss.endpoint=your_endpoint
aliyun.oss.accessKeyId=your_access_key
aliyun.oss.accessKeySecret=your_secret_key
aliyun.oss.bucketName=your_bucket_name

# JWT configuration
jwt.secret=your_jwt_secret_key
jwt.expiration=3600000

# DeepSeek AI configuration
deepseek.api.key=your_deepseek_api_key
deepseek.api.url=https://api.deepseek.com
  1. Build and run
# Build the project
mvn clean install

# Run the application
mvn spring-boot:run

# Or run the jar file
java -jar target/healthplatform-0.0.1-SNAPSHOT.jar
  1. Verify installation
# Check if the server is running
curl http://localhost:8088/actuator/health

The backend server will start on http://localhost:8088

API Documentation

Authentication APIs

  • POST /api/user/login - User login
  • POST /api/user/register - User registration
  • GET /api/user/{id} - Get user profile

Health Data APIs

  • GET /api/health/{userId}/history - Get health data history
  • POST /api/health/{userId}/data - Add health data record
  • GET /api/health/{userId}/bmi - Get BMI data
  • GET /api/health/{userId}/blood-pressure - Get blood pressure data

AI Analysis APIs

  • POST /api/ai/chat - AI health assistant chat
  • POST /api/ai/health-qa - Health knowledge Q&A
  • POST /api/health-reports/{userId}/generate - Generate health report

Medication APIs

  • GET /api/medicines/{userId}/medicine - Get medication history
  • POST /api/medicines/{userId}/medicine - Add medication record
  • POST /api/medicines/{userId}/medicine/{medicineId}/reminder - Set reminder

Community APIs

  • GET /api/articles - Get article list
  • POST /api/articles/{userId} - Create article
  • POST /api/articles/{userId}/{id}/comments - Add comment
  • POST /api/articles/{id}/{userId}/like - Like/unlike article

Database Design

Core Tables:

  • user - User information
  • health_data - Health metrics records
  • medicine_records - Medication records
  • medicine_reminders - Medication reminders
  • meal_records - Diet records
  • diet_goals - Nutrition goals
  • exercise_records - Exercise logs
  • articles - Community articles
  • comments - Article comments
  • health_reports - Generated health reports

For detailed database schema, see Database Design Document

Architecture Highlights

  1. Three-Layer Architecture: Clear separation of Controller, Service, and Mapper layers
  2. Dependency Injection: Extensive use of Spring's IoC container
  3. Exception Handling: Unified exception handling with custom error codes
  4. Logging: Comprehensive logging using Slf4j
  5. Security: JWT authentication, password encryption, SQL injection prevention
  6. Real-time Communication: WebSocket for instant notifications
  7. External Integration: Multiple third-party API integrations (FDA, FatSecret, AI services)

Development Guidelines

Code Style

  • Follow Java naming conventions
  • Use Lombok annotations to reduce boilerplate code
  • Write comprehensive JavaDoc comments
  • Keep methods focused and under 50 lines

Testing

# Run unit tests
mvn test

# Run integration tests
mvn verify

# Generate test coverage report
mvn jacoco:report

Performance Optimization

  • Database indexing on frequently queried columns
  • MyBatis-Plus pagination for large datasets
  • Caching for frequently accessed data
  • Async processing for time-consuming tasks

Deployment

Docker Deployment

# Build Docker image
docker build -t health-platform-backend .

# Run container
docker run -d -p 8088:8088 --name health-backend health-platform-backend

Cloud Deployment (Aliyun ECS)

  1. Deploy application to ECS instance
  2. Configure security groups and firewall
  3. Set up Nginx reverse proxy
  4. Configure SSL certificate for HTTPS

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

Project Link: https://github.com/nova728/health-platform-backend


About

health-platform-backend

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages