A comprehensive healthcare management system connecting patients, healthcare providers, and administrators through a modern web platform.
- Quick Start
- Architecture
- Technology Stack
- Features
- Docker Setup
- Local Development
- Configuration
- Testing
- Troubleshooting
- Team
- Docker 20.10+
- Docker Compose 2.0+
- Git
# 1. Clone repository
git clone https://gitlab.com/manhnc2/g1-se1961-nj-swp391-fal25.git
cd g1-se1961-nj-swp391-fal25
# 2. Setup environment
cp .env.example .env
nano .env # Edit with your Firebase credentials
# 3. Create frontend production env
cat > medconnect-fe/.env.production << 'EOF'
NEXT_PUBLIC_FIREBASE_API_KEY=your_actual_api_key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your-project-id
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your-project.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=123456789
NEXT_PUBLIC_FIREBASE_APP_ID=1:123456789:web:abcdef
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=G-XXXXXXXXXX
NEXT_PUBLIC_API_URL=http://localhost:8080/api
EOF
# 4. Start application
docker-compose up -d --build
# 5. Access application
# Frontend: http://localhost:3000
# Backend: http://localhost:8080
# Database: localhost:1433 (sa/Toilakhoa1204!)Backend:
cd medconnect-be
./mvnw spring-boot:runFrontend:
cd medconnect-fe
npm install
npm run devmedconnect/
βββ medconnect-be/ # Spring Boot Backend
β βββ src/main/java/ # Java source code
β βββ src/main/resources/ # Configuration files
β βββ pom.xml # Maven dependencies
β
βββ medconnect-fe/ # Next.js Frontend
β βββ components/ # React components
β βββ features/ # Feature modules
β βββ pages/ # Next.js pages
β βββ package.json # npm dependencies
β
βββ docker-compose.yml # Docker orchestration
- Java 21 - Latest LTS version
- Spring Boot 3.5.6 - Enterprise framework
- SQL Server 2022 - Database
- Maven - Build tool
- Lombok - Code generation
- Next.js 15.3.1 - React framework
- React 18.3.1 - UI library
- TypeScript 5.6.3 - Type safety
- Tailwind CSS 4.1.11 - Styling
- HeroUI - Component library
- Framer Motion - Animations
- π₯ Patient Management - Registration, profiles, medical history
- π Appointment Scheduling - Booking and management system
- π Medical Records - Secure digital storage
- πΌ Provider Portal - Practice management tools
- π₯ Telemedicine - Virtual consultations
- π Admin Dashboard - Facility management
- Docker Desktop installed and running
- Docker Compose V2
- At least 4GB RAM available for containers
# 1. Start all services (DB creates database, Backend creates tables via Hibernate)
docker-compose up -d --build
# 2. Wait for backend to fully start (creates tables automatically)
# Check backend logs to confirm it's ready
docker-compose logs -f be
# 3. Load mock data (after backend is ready - wait ~60 seconds)
chmod +x load-mock-data.sh
./load-mock-data.shWhat happens:
- β
Database container starts and creates
MedConnectdatabase - β Backend starts and Hibernate auto-creates all tables from JPA entities
- β
Mock data script loads sample data:
- 2 Admin accounts
- 10 Doctors (various specialties)
- 10 Patients
- 10 Medical specialties
Test Login Accounts:
- Admin:
admin.system@medconnect.vn - Doctor:
doctor.an@medconnect.vn - Patient:
patient.mai@gmail.com
β οΈ Note: Firebase UIDs in mock data are placeholders. Update them after Firebase authentication setup.
If you need to reload mock data:
# Method 1: Using the script
./load-mock-data.sh
# Method 2: Direct command
docker exec -it medconnect-db /opt/mssql-tools18/bin/sqlcmd \
-S localhost -U sa -P "MedConnect@2025" \
-d MedConnect -i /scripts/mock-data.sql -C| Command | Description |
|---|---|
docker-compose up |
Start services |
docker-compose down |
Stop services |
docker-compose logs |
View logs |
docker-compose exec |
Execute command in a running container |
- Port conflicts: Ensure ports in
docker-compose.ymlare not used by other services. - Permission denied: Run commands with
sudoor adjust permissions. - Network issues: Ensure Docker Desktop or daemon is running.
- Use Docker Desktop for an easy-to-use interface and integration with your system.
- Ensure WSL 2 is enabled on Windows for better performance.
- Install Docker using your package manager (e.g.,
apt,yum). - Add your user to the
dockergroup to run commands withoutsudo.
For development, you can run the backend and frontend locally without Docker.
cd medconnect-be
./mvnw spring-boot:runcd medconnect-fe
npm install
npm run devCreate a .env file in the root directory:
Root .env file:
# Frontend Firebase Configuration (Web App)
NEXT_PUBLIC_FIREBASE_API_KEY=your_firebase_api_key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your_project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your_project_id
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your_project.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your_sender_id
NEXT_PUBLIC_FIREBASE_APP_ID=your_app_id
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=your_measurement_id
# Backend Firebase Admin SDK Configuration
# Download from: Firebase Console > Project Settings > Service Accounts > Generate New Private Key
FIREBASE_TYPE=service_account
FIREBASE_PRIVATE_KEY_ID=your_private_key_id
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nYOUR_KEY\n-----END PRIVATE KEY-----\n"
FIREBASE_CLIENT_EMAIL=firebase-adminsdk-xxxxx@your-project.iam.gserviceaccount.com
FIREBASE_CLIENT_ID=your_client_id
FIREBASE_CLIENT_X509_CERT_URL=https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-xxxxx%40your-project.iam.gserviceaccount.com
# Gemini API
NEXT_PUBLIC_GEMINI_API_KEY=your_gemini_api_key
# API URL
NEXT_PUBLIC_API_URL=http://be:8080/apiHow to get Firebase credentials:
-
Frontend Firebase Config (for web app):
- Go to Firebase Console
- Select your project
- Go to Project Settings (gear icon)
- Scroll down to "Your apps" section
- Click on the web app icon or "Add app"
- Copy the config values to your
.envfile
-
Backend Firebase Admin SDK (for server):
- Go to Firebase Console
- Select your project
- Go to Project Settings > Service Accounts
- Click "Generate New Private Key"
- Download the JSON file
- Copy values from JSON to your
.envfile:typeβFIREBASE_TYPEproject_idβUse NEXT_PUBLIC_FIREBASE_PROJECT_IDprivate_key_idβFIREBASE_PRIVATE_KEY_IDprivate_keyβFIREBASE_PRIVATE_KEY(keep the \n characters)client_emailβFIREBASE_CLIENT_EMAILclient_idβFIREBASE_CLIENT_IDclient_x509_cert_urlβFIREBASE_CLIENT_X509_CERT_URL
Backend:
SPRING_DATASOURCE_URL=jdbc:sqlserver://db:1433;databaseName=MedConnect;encrypt=false
SPRING_DATASOURCE_USERNAME=sa
SPRING_DATASOURCE_PASSWORD=Toilakhoa1204!
SPRING_PROFILES_ACTIVE=prodFrontend (local development):
NEXT_PUBLIC_API_URL=http://localhost:8080/api
NEXT_PUBLIC_FIREBASE_API_KEY=your_firebase_api_key
# ... other Firebase credentials# Backend
cd medconnect-be && ./mvnw test
# Frontend
cd medconnect-fe && npm testdocker-compose -f docker-compose.prod.yml build
docker-compose -f docker-compose.prod.yml up -d- Fork the repository
- Create feature branch:
git checkout -b feature/your-feature - Commit changes:
git commit -m 'feat: add feature' - Push to branch:
git push origin feature/your-feature - Submit merge request
- Java: Google Java Style Guide
- TypeScript: ESLint + Prettier
- Commits: Conventional Commits
- Documentation: Update README for new features
Missing environment variables:
# Create .env file from template
cp .env.example .env
# Edit with your Firebase credentials
nano .envPort 1433 already in use:
# Find what's using the port
lsof -i :1433
# Stop local SQL Server
brew services stop mssql-server # macOS
# or
sudo systemctl stop mssql-server # Linux
# Or change port in docker-compose.yml to "1434:1433"Database connection failed:
docker-compose logs dbPort already in use:
# Kill process on port
lsof -i :3000 | grep LISTEN | awk '{print $2}' | xargs kill -9Frontend build errors:
cd medconnect-fe
rm -rf .next node_modules
npm install && npm run buildFirebase authentication errors:
# Make sure your .env file has valid Firebase credentials
# Get credentials from: https://console.firebase.google.com/Docker build fails:
# Clean Docker cache and rebuild
docker-compose down -v
docker system prune -a
docker-compose up -d --buildDatabase 'MedConnect' does not exist:
# Option 1: Create database manually using sqlcmd (in SQL Server 2022)
docker exec -it g1-se1961-nj-swp391-fal25-db-1 /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P Toilakhoa1204! -C -Q "CREATE DATABASE MedConnect;"
# Option 2: Use Azure Data Studio or SQL Server Management Studio to connect and create database
# Host: localhost,1433
# Username: sa
# Password: Toilakhoa1204!
# Option 3: Let Spring Boot auto-create (remove databaseName from connection string)
# The connection string in docker-compose.yml will connect to master and create tables
# Option 4: Clean restart
docker-compose down -v
docker-compose up -d --buildSQL Server healthcheck failing:
# Check SQL Server logs
docker-compose logs db
# Check if SQL Server is accepting connections
docker exec -it g1-se1961-nj-swp391-fal25-db-1 /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P Toilakhoa1204! -C -Q "SELECT @@VERSION;"
# If sqlcmd not found, SQL Server 2022 uses /opt/mssql-tools18/bin/sqlcmdBackend connection failed:
# Check if database is ready
docker-compose logs db
# Check backend logs
docker-compose logs be
# Restart backend
docker-compose restart beFirebase configuration errors:
# Error: auth/api-key-not-valid or auth/invalid-api-key
# This means Firebase credentials are missing or incorrect
# Step 1: Get Firebase Web App credentials
# 1. Go to https://console.firebase.google.com/
# 2. Select your project
# 3. Click gear icon (βοΈ) > Project settings
# 4. Scroll to "Your apps" section
# 5. If no web app exists, click "Add app" > Web (</> icon)
# 6. Copy the firebaseConfig object values
# Step 2: Get Firebase Admin SDK credentials (for backend)
# 1. In Firebase Console, go to Project settings
# 2. Click "Service accounts" tab
# 3. Click "Generate new private key"
# 4. Download the JSON file
# 5. Extract values to .env file
# Step 3: Update .env file
nano .env
# Example of correct .env format:
# NEXT_PUBLIC_FIREBASE_API_KEY=AIzaSyC1a2b3c4d5e6f7g8h9i0j (NOT "your_firebase_api_key")
# NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=myproject-12345.firebaseapp.com
# NEXT_PUBLIC_FIREBASE_PROJECT_ID=myproject-12345
# Step 4: Restart containers
docker-compose down
docker-compose up -d --build
# Step 5: Check if credentials are loaded
docker-compose exec fe printenv | grep FIREBASE
docker-compose exec be printenv | grep FIREBASEFirebase login issues after updating .env:
# After updating .env file, you MUST rebuild containers with --no-cache
docker-compose down
docker-compose build --no-cache
docker-compose up -d
# Verify build args are passed correctly
docker-compose config | grep FIREBASE
# Check if env vars are available in container
docker-compose exec fe printenv | grep NEXT_PUBLIC_FIREBASE_API_KEY
# If the value shows correctly, test in browser console (F12):
# console.log(process.env.NEXT_PUBLIC_FIREBASE_API_KEY)Next.js environment variables in Docker:
# Next.js requires NEXT_PUBLIC_* vars to be available at BUILD time
# They are embedded into the JavaScript bundle during build
# Common mistake: Only setting runtime env vars
# β This won't work for NEXT_PUBLIC_* vars
environment:
NEXT_PUBLIC_FIREBASE_API_KEY: xxx
# β
Correct: Pass as build args AND runtime env
build:
args:
NEXT_PUBLIC_FIREBASE_API_KEY: xxx
environment:
NEXT_PUBLIC_FIREBASE_API_KEY: xxx
# Verify the build received the variables:
docker-compose build fe 2>&1 | grep FIREBASEDebug Firebase configuration in browser:
# 1. Open browser console (F12)
# 2. Run these commands:
console.log('Firebase API Key:', process.env.NEXT_PUBLIC_FIREBASE_API_KEY);
console.log('Firebase Auth Domain:', process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN);
# Should show:
# Firebase API Key: AIzaSyDVhKvRppmWjfg8RLylH6YE6G7Q1a0CPOM
# Firebase Auth Domain: medconnect-2eaff.firebaseapp.com
# If it shows "undefined", the build didn't include the env vars
# Solution: Rebuild with --no-cache
docker-compose down
docker-compose build --no-cache fe
docker-compose up -dComplete rebuild procedure:
# 1. Stop all containers
docker-compose down
# 2. Remove old images
docker rmi g1-se1961-nj-swp391-fal25-fe
# 3. Verify .env file is correct
cat .env | grep NEXT_PUBLIC_FIREBASE_API_KEY
# 4. Build with no cache (important!)
docker-compose build --no-cache fe
# 5. Start containers
docker-compose up -d
# 6. Check logs
docker-compose logs -f fe
# 7. Test login at http://localhost:3000Firebase "build-time-dummy" error (FINAL FIX):
# Error: projects/build-time-dummy/installations
# This means Next.js didn't receive Firebase credentials during build
# SOLUTION: Create .env.production file
# 1. Create the file with actual credentials
cat > medconnect-fe/.env.production << 'EOF'
NEXT_PUBLIC_FIREBASE_API_KEY=AIzaSyDVhKvRppmWjfg8RLylH6YE6G7Q1a0CPOM
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=medconnect-2eaff.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=medconnect-2eaff
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=medconnect-2eaff.firebasestorage.app
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=183795808131
NEXT_PUBLIC_FIREBASE_APP_ID=1:183795808131:web:f367eea401528b3bf168b6
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=G-LF9M9EJ4J8
NEXT_PUBLIC_API_URL=http://be:8080/api
EOF
# 2. Verify the file was created
cat medconnect-fe/.env.production
# 3. Complete rebuild (MUST remove old image)
docker-compose down
docker rmi g1-se1961-nj-swp391-fal25-fe 2>/dev/null || true
docker-compose build --no-cache fe
docker-compose up -d
# 4. Test in browser
# Open http://localhost:3000 and check Console (F12)
# Run: console.log(process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID)
# Should show: medconnect-2eaff (NOT build-time-dummy)Why .env.production is needed:
# Next.js in Docker needs .env.production because:
# 1. docker-compose build args don't work reliably with Next.js
# 2. NEXT_PUBLIC_* vars must be embedded at BUILD time
# 3. .env.production is the standard way for Next.js production builds
# The Dockerfile copies .env.production before npm run build
# Next.js automatically reads it and embeds values into the bundleVerify Firebase is working:
# After rebuild, check in browser console:
console.log({
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID
});
# Should show actual values, NOT:
# - undefined
# - build-time-dummy
# - nullBackend "Failed to fetch" error in Docker:
# Error: TypeError: Failed to fetch
# This happens when frontend tries to call http://be:8080/api from browser
# Browser cannot resolve Docker service name 'be'
# Only Docker internal network can resolve it
# Solution: Use localhost for browser API calls
# Update medconnect-fe/.env.production:
NEXT_PUBLIC_API_URL=http://localhost:8080/api
# Then rebuild:
docker-compose down
docker rmi g1-se1961-nj-swp391-fal25-fe
docker-compose build --no-cache fe
docker-compose up -d
# Verify in browser console:
# console.log(process.env.NEXT_PUBLIC_API_URL)
# Should show: http://localhost:8080/apiAPI URL configuration:
# Client-side (browser): http://localhost:8080/api
# Server-side (Docker): http://be:8080/api
# For apps with SSR, use dynamic API URL:
const API_URL = typeof window !== 'undefined'
? 'http://localhost:8080/api' // Browser
: 'http://be:8080/api'; // Server