A complete Hybrid Web + Desktop Application for analyzing and visualizing chemical equipment parameters from CSV files.
- Production URL: https://chemical-backend-production-dd2c.up.railway.app/
- Production URL: https://chemical-frontend-production-974b.up.railway.app/
Username: testuser
Password: testpass123
- Backend: Django 5.2 + Django REST Framework (Production: Railway)
- Database: SQLite3 (file-based, production-ready)
- Frontend (Web): React 19 + Chart.js (Production: Railway)
- Frontend (Desktop): PyQt5 + Matplotlib (Planned)
- Data Processing: Pandas
- Authentication: JWT (Simple JWT)
- PDF Generation: ReportLab
βββββββββββββββββββββββββββββββββββββββββββββββ
β React Web App (Frontend) β
β https://chemical-frontend-production-974b.up.railway.app/ β
βββββββββββββββββ¬ββββββββββββββββββββββββββββββ
β REST API
β
βββββββββββββββββ΄ββββββββββββββββββββββββββββββ
β Django Backend (API) β
β https://chemical-backend-production-dd2c.up.railway.app/ β
β β’ REST APIs β’ Pandas β’ ReportLab β
βββββββββββββββββ¬ββββββββββββββββββββββββββββββ
β
βββββββββββββββββ΄ββββββββββββββββ
β SQLite Database β
β (db.sqlite3) β
βββββββββββββββββββββββββββββββββ
/app/
βββ django_backend/ # Django Backend
β βββ chemical_visualizer/ # Django Project
β β βββ settings.py
β β βββ urls.py
β β βββ wsgi.py
β βββ api/ # Django App
β β βββ models.py # Dataset model
β β βββ serializers.py # DRF serializers
β β βββ views.py # API views
β β βββ urls.py # API routes
β βββ uploads/ # CSV file storage
β βββ db.sqlite3 # SQLite database
β βββ manage.py
β βββ venv/ # Python virtual env
β βββ sample_data.csv # Test CSV file
β
βββ frontend/ # React Frontend
βββ src/
β βββ components/
β β βββ Login.jsx
β β βββ Register.jsx
β β βββ Dashboard.jsx
β βββ App.js
β βββ App.css
β βββ index.js
βββ package.json
βββ .env
-
CSV Upload & Processing
- Validates CSV structure (required columns)
- Parses CSV using Pandas
- Computes summary statistics
- Stores metadata in SQLite
-
Dataset Management
- Automatically maintains last 5 datasets
- Auto-deletes older datasets
- Tracks upload timestamp and user
-
Summary Statistics
- Total equipment count
- Average flowrate, pressure, temperature
- Equipment type distribution (JSON)
-
REST APIs
POST /api/upload/- Upload CSVGET /api/summary/latest/- Get latest dataset summaryGET /api/history/- Get last 5 datasetsGET /api/export/csv/- Export dataset as CSVGET /api/report/pdf/- Generate PDF reportPOST /api/register/- User registrationPOST /api/token/- JWT login
-
Authentication
- JWT-based authentication
- Token-based API access
- User registration and login
-
PDF Report Generation
- Professional PDF reports using ReportLab
- Summary statistics tables
- Equipment type distribution
-
Authentication Pages
- Login page
- Registration page
- JWT token management
-
Dashboard
- CSV file upload form
- Summary statistics cards
- Interactive charts (Chart.js)
- Pie chart: Equipment type distribution
- Bar chart: Parameter comparison
- Data table (first 50 rows)
- Export CSV and PDF buttons
-
Visualizations
- Equipment type distribution (Pie chart)
- Parameter comparison (Bar chart)
- Responsive design
- Dark theme with glassmorphism
- Navigate to Django backend
cd /app/django_backend- Activate virtual environment
source venv/bin/activate
# Resolve project venv site-packages
$proj_site = Resolve-Path .\.venv\Lib\site-packages
# Conda base site-packages (adjust only if your path differs)
$mlbase_site = "D:\program\conda\Lib\site-packages"
# Create a .pth file that points to Conda base packages
"$mlbase_site" | Out-File -FilePath (Join-Path $proj_site "conda_mlbase.pth") -Encoding ascii
- Install dependencies (Already done)
pip install django djangorestframework djangorestframework-simplejwt pandas reportlab Pillow django-cors-headers- Run migrations (Already done)
python manage.py makemigrations
python manage.py migrate- Create superuser (Already created: admin/admin123)
python manage.py createsuperuser- Start Django server
python manage.py runserver 0.0.0.0:8002Or use supervisor:
sudo supervisorctl restart django_backend- Navigate to frontend
cd /app/frontend- Install dependencies (Already done)
yarn add chart.js react-chartjs-2- Start React app
yarn startOr use supervisor:
sudo supervisorctl restart frontendPOST /api/register/
Content-Type: application/json
{
"username": "testuser",
"password": "password123",
"email": "test@example.com"
}
Response: 201 Created
{
"message": "User registered successfully",
"user": {
"id": 1,
"username": "testuser",
"email": "test@example.com"
}
}POST /api/token/
Content-Type: application/json
{
"username": "testuser",
"password": "password123"
}
Response: 200 OK
{
"access": "eyJ0eXAiOiJKV1QiLCJhbGciOi...",
"refresh": "eyJ0eXAiOiJKV1QiLCJhbGciOi..."
}All requests must include:
Authorization: Bearer <access_token>
POST /api/upload/
Content-Type: multipart/form-data
Authorization: Bearer <token>
Form Data:
file: <csv_file>
name: "My Dataset" (optional)
Response: 201 Created
{
"message": "File uploaded successfully",
"dataset": {
"id": 1,
"name": "sample_data.csv",
"upload_timestamp": "2025-01-28T10:30:00Z",
"total_equipment_count": 20,
"avg_flowrate": 188.55,
"avg_pressure": 58.73,
"avg_temperature": 104.32,
"equipment_type_distribution": {
"Reactor": 4,
"Pump": 5,
"Heat Exchanger": 5,
"Distillation Column": 2,
"Compressor": 2,
"Mixer": 2,
"Separator": 2
}
},
"raw_data": [ ... ] // First 100 rows
}GET /api/summary/latest/
Authorization: Bearer <token>
Response: 200 OK
{
"summary": {
"id": 1,
"name": "sample_data.csv",
"upload_timestamp": "2025-01-28T10:30:00Z",
"total_equipment_count": 20,
"avg_flowrate": 188.55,
"avg_pressure": 58.73,
"avg_temperature": 104.32,
"equipment_type_distribution": { ... }
},
"raw_data": [ ... ] // All rows
}GET /api/history/
Authorization: Bearer <token>
Response: 200 OK
{
"history": [
{ ... dataset 1 ... },
{ ... dataset 2 ... },
...
]
}GET /api/export/csv/
GET /api/export/csv/<dataset_id>/
Authorization: Bearer <token>
Response: 200 OK (CSV file download)GET /api/report/pdf/
GET /api/report/pdf/<dataset_id>/
Authorization: Bearer <token>
Response: 200 OK (PDF file download)Required columns:
Equipment Name,Equipment Type,Flowrate,Pressure,Temperature
Example:
Equipment Name,Equipment Type,Flowrate,Pressure,Temperature
Reactor-A1,Reactor,150.5,45.2,120.3
Pump-B2,Pump,200.0,60.5,85.7
Heat Exchanger-C3,Heat Exchanger,180.3,55.0,95.2Sample file available at: /app/django_backend/sample_data.csv
Admin User:
- Username:
admin - Password:
admin123
Test User (Production):
- Username:
testuser - Password:
testpass123
Login and get token:
curl -X POST http://localhost:8002/api/token/ \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"admin123"}'Upload CSV:
TOKEN="<your_access_token>"
curl -X POST http://localhost:8002/api/upload/ \
-H "Authorization: Bearer $TOKEN" \
-F "file=@/app/django_backend/sample_data.csv" \
-F "name=Sample Dataset"Get latest summary:
curl -X GET http://localhost:8002/api/summary/latest/ \
-H "Authorization: Bearer $TOKEN"- Open browser: Production Frontend
- Login with:
- Username:
testuser - Password:
testpass123(Or register a new user)
- Username:
- Upload the sample CSV file
- View statistics, charts, and data table
- Export CSV or PDF report
Key Dependencies:
django==5.2.10- Web frameworkdjangorestframework==3.16.1- REST API frameworkdjangorestframework-simplejwt==5.5.1- JWT authenticationpandas==3.0.0- Data processingreportlab==4.4.9- PDF generationdjango-cors-headers==4.9.0- CORS support
Database Model:
class Dataset(models.Model):
name = CharField(max_length=255)
upload_timestamp = DateTimeField(auto_now_add=True)
total_equipment_count = IntegerField()
avg_flowrate = FloatField()
avg_pressure = FloatField()
avg_temperature = FloatField()
equipment_type_distribution = JSONField()
file_path = CharField(max_length=500)
uploaded_by = ForeignKey(User)Key Dependencies:
react==19.0.0- UI frameworkreact-router-dom==7.5.1- Routingchart.js==4.5.1- Charting libraryreact-chartjs-2==5.3.1- React wrapper for Chart.jsaxios==1.8.4- HTTP client
Chart Types:
- Pie Chart - Equipment type distribution
- Bar Chart - Parameter comparison (Flowrate, Pressure, Temperature)
-
JWT Authentication
- Secure token-based auth
- 24-hour access token lifetime
- 7-day refresh token lifetime
-
Protected Routes
- All data endpoints require authentication
- Frontend route protection
-
CORS Configuration
- Configured for development (allow all origins)
- Should be restricted in production
-
Password Validation
- Django built-in validators
- Minimum length, complexity checks
- PyQt5 desktop interface
- File upload dialog
- Data table with QTableWidget
- Matplotlib charts integration
- Same REST API integration
- Local settings storage
- Real-time data streaming
- Advanced filtering and search
- Custom report templates
- Email notifications
- Data export to Excel
- Chart customization options
- Multi-user collaboration
- Historical trend analysis
- Anomaly detection using ML
Database locked error:
cd /app/django_backend
rm db.sqlite3
python manage.py migrateCheck Django logs:
tail -f /var/log/supervisor/django_backend.*.logRestart Django:
sudo supervisorctl restart django_backendClear cache and restart:
cd /app/frontend
rm -rf node_modules/.cache
sudo supervisorctl restart frontendCheck frontend logs:
tail -f /var/log/supervisor/frontend.*.log-
Clean Code Structure
- Modular Django app design
- Reusable React components
- Separation of concerns
-
RESTful API Design
- Standard HTTP methods
- Proper status codes
- Consistent response format
-
Error Handling
- Validation errors
- Authentication errors
- User-friendly error messages
-
Data Validation
- CSV structure validation
- Required column checks
- Data type validation
-
Responsive Design
- Mobile-friendly interface
- Flexible grid layouts
- Adaptive components
-
Performance
- Efficient Pandas operations
- Pagination for large datasets
- Optimized queries
For issues or questions:
- Check logs in
/var/log/supervisor/ - Review API responses for error details
- Verify authentication tokens
- Ensure CSV format is correct
Completed:
- β Django backend with DRF
- β SQLite database
- β CSV upload and processing
- β Summary statistics calculation
- β REST APIs (all endpoints)
- β JWT authentication
- β PDF report generation
- β React web frontend
- β Chart.js visualizations
- β Data table display
- β Export functionality
- β Responsive design
Pending:
- β³ PyQt5 desktop application
- β³ Matplotlib desktop charts
Built with β€οΈ using Django REST Framework + React + Chart.js