Skip to content

mechimaher/qscrap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2,489 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

QScrap Platform - Enterprise Automotive Marketplace

Version: 2.0
Status: Production-Ready
License: Proprietary
Canonical Architecture: See BRAIN.MD for the single source of truth


πŸš€ Platform Overview

QScrap is Qatar's first enterprise-grade automotive spare parts marketplace offering:

  • Parts Marketplace: Spare parts bidding & delivery (βœ… Live)
  • Escrow & Buyer Protection: 7-day warranty hold with proof-of-condition (βœ… Live)
  • Partner Revenue: Analytics, Loyalty, Ads, Subscriptions (βœ… Live)
  • Quick Services: Battery, oil, wash, tire, AC, breakdown (πŸ”œ Phase 2)
  • Repair Services: Workshop bookings & mobile mechanics (πŸ”œ Phase 2)
  • Insurance Integration: MOI reports, pricing analytics (πŸ”œ Phase 3)

Revenue Potential: 295k QAR/year
Market Position: Leader in Qatar automotive sector


πŸ“Š Technical Stack

Backend:

  • Node.js 18+ with Express.js
  • TypeScript for type safety
  • PostgreSQL 14+ (primary database)
  • Redis for caching & real-time features
  • Socket.IO for WebSocket communication

Frontend:

  • React Native (Expo) for mobile apps
  • Vanilla HTML/CSS/JS for dashboards
  • Premium Qatar VVIP theme (Maroon & Gold)

Infrastructure:

  • VPS: Hetzner (Doha Region)
  • Nginx reverse proxy with TLS + Cloudflare
  • Docker Compose (Backend, PostgreSQL 14, Redis)
  • GitHub Actions CI/CD β†’ GHCR β†’ Docker pull on VPS

πŸ› οΈ Quick Start

Prerequisites

Node.js >= 18
PostgreSQL >= 14
Redis >= 6
npm or yarn

Installation

  1. Clone repository:
git clone https://github.com/mechimaher/qscrap.git
cd qscrap
  1. Install dependencies:
npm install
  1. Configure environment:
cp .env.example .env
# Edit .env with your credentials
  1. Run database migrations:
npm run migrate
  1. Start development server:
npm run dev

Server runs on http://localhost:3000


πŸ—‚οΈ Project Structure

qscrap/
β”œβ”€β”€ src/                    # Backend source code
β”‚   β”œβ”€β”€ config/            # Database, Redis, jobs
β”‚   β”œβ”€β”€ controllers/       # Request handlers
β”‚   β”œβ”€β”€ services/          # Business logic
β”‚   β”œβ”€β”€ routes/            # API endpoints
β”‚   β”œβ”€β”€ middleware/        # Auth, validation, rate limiting
β”‚   └── utils/             # Helper functions
β”œβ”€β”€ mobile/                # Customer mobile app
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ screens/      # App screens
β”‚   β”‚   β”œβ”€β”€ components/   # Reusable components
β”‚   β”‚   β”œβ”€β”€ services/     # API clients
β”‚   β”‚   └── navigation/   # App navigation
β”‚   └── build_customer_apk.sh
β”œβ”€β”€ driver-mobile/        # Driver mobile app
β”œβ”€β”€ public/               # Web dashboards & website
β”‚   β”œβ”€β”€ admin-dashboard.html
β”‚   β”œβ”€β”€ garage-dashboard.html
β”‚   β”œβ”€β”€ operations-dashboard.html
β”‚   β”œβ”€β”€ finance-dashboard.html
β”‚   β”œβ”€β”€ support-dashboard.html
β”‚   └── css/
β”œβ”€β”€ uploads/              # User uploads
└── tests/               # Automated tests


πŸ”‘ API Documentation

Authentication

Login:

POST /api/auth/login
Content-Type: application/json

{
  "phone_number": "+97412345678",
  "password": "password123"
}

Response:

{
  "success": true,
  "token": "eyJhbGciOiJIUzI1NiIs...",
  "user": {
    "user_id": "uuid",
    "full_name": "Ahmed Al-Mansoori",
    "role": "customer"
  }
}

Quick Services (πŸ”œ Phase 2 β€” Not Yet Implemented)

The following on-demand services are planned for Phase 2:

  • Battery replacement
  • Oil change
  • Home car wash
  • Tire service/repair
  • AC gas refill
  • Emergency breakdown assistance

Complete API Docs

Visit /api-docs when server is running for interactive Swagger documentation. See BRAIN.MD Section 3.5 for the full 345-endpoint API reference.


πŸ§ͺ Testing

Run all tests:

npm test

Run with coverage:

npm run test:coverage

Run specific test:

npm test -- loyalty.service.test

Coverage Targets (see COVERAGE-IMPROVEMENT-PLAN.md):

  • Current: ~24%
  • Target: 70% (branches, functions, lines, statements)
  • Priority: Payment/escrow flows, order state machine

πŸ“¦ Deployment

Production Build

# Backend
npm run build
npm start

# Mobile App
cd mobile
./build_customer_apk.sh

VPS Deployment (Docker Compose)

# SSH to server
ssh root@147.93.89.153

# Navigate to project
cd /opt/qscrap

# Pull latest and rebuild
git pull origin main
docker compose build --no-cache backend
docker compose up -d

# Run migrations
docker exec qscrap-backend node scripts/migrate.js

# Health check
curl -s https://api.qscrap.qa/health | jq

Database Backup

# Manual backup
docker exec qscrap-postgres pg_dump -U postgres qscrap_db > backup.sql

# Automated backup (daily)
# See: /opt/scripts/backup.sh

πŸ”§ Configuration

Environment Variables

# Server
PORT=3000
NODE_ENV=production

# Database
DB_HOST=localhost
DB_PORT=5432
DB_NAME=qscrap_db
DB_USER=postgres
DB_PASSWORD=your_password

# Redis
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=your_password

# JWT
JWT_SECRET=your_secret_key
JWT_EXPIRES_IN=7d

# File Upload
UPLOAD_DIR=./uploads
MAX_FILE_SIZE=10485760  # 10MB

# Rate Limiting
RATE_LIMIT_WINDOW=15      # minutes
RATE_LIMIT_MAX_REQUESTS=100

# Monitoring
SENTRY_DSN=your_sentry_dsn (optional)

πŸ—οΈ Architecture

System Components

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Customers β”‚
β”‚  (Mobile App)β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚
β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   API Layer │◄───── Dashboardsβ”‚
β”‚  (Express)  β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚
β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Services   │◄─────  Cache   β”‚
β”‚   Layer     β”‚     β”‚  (Redis) β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
β”‚  Database   β”‚
β”‚ (PostgreSQL)β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Request Lifecycle

  1. Client Request β†’ API endpoint
  2. Authentication β†’ JWT validation
  3. Validation β†’ Zod schema check
  4. Rate Limiting β†’ Abuse prevention
  5. Business Logic β†’ Service layer
  6. Database β†’ Query execution
  7. Cache β†’ Redis for performance
  8. Response β†’ JSON to client

🎯 Key Features

For Customers (βœ… Live)

  • πŸ” Request spare parts (multi-garage bidding)
  • 🚚 Real-time delivery tracking
  • 🎁 Loyalty rewards (4-tier system)
  • ⭐ Ratings & reviews
  • πŸ”„ 30-second undo for accidental orders
  • πŸ’¬ In-app chat with garages

For Partners / Garages (βœ… Live)

  • πŸ“Š Analytics dashboard
  • πŸ’° Revenue management & payout tracking
  • πŸ’³ Premium subscriptions (5 tiers: Demo β†’ Platinum)
  • πŸ“¦ Inventory & showcase management
  • 🀝 3-round negotiation system

For Operations (βœ… Live)

  • πŸ‘₯ User management
  • πŸ’΅ Payout processing (2-way confirmation)
  • 🎫 Support tickets with SLA tracking
  • πŸ“ˆ Platform analytics
  • βš™οΈ System configuration

Planned Features (πŸ”œ Phase 2-3)

  • ⚑ Quick services (battery, oil, wash, tire, AC, breakdown)
  • πŸ”§ Workshop bookings & mobile mechanics
  • πŸ“„ Insurance integration (MOI reports, pricing benchmarks)
  • πŸ“’ Ad campaigns for garages

πŸ“ˆ Performance Metrics

Current Performance:

  • API Response Time: ~50ms (p95)
  • Database Query Time: ~20ms (p95)
  • Socket.IO Latency: <50ms
  • Cache Hit Rate: 80%+
  • Test Coverage: ~24% (target: 70%)
  • Uptime: 99.9%+

πŸ” Security

Implemented:

  • βœ… JWT authentication (15m access + 7d refresh tokens)
  • βœ… Input validation (Zod + express-validator)
  • βœ… Rate limiting (express-rate-limit per endpoint)
  • βœ… SQL injection prevention (parameterized queries)
  • βœ… XSS protection (Helmet + request sanitization)
  • βœ… CORS configuration (origin whitelist)
  • βœ… Helmet security headers (HSTS, CSP, X-Frame-Options)
  • βœ… Password hashing (bcrypt, 12 rounds)
  • βœ… CSRF protection (double-submit cookie)
  • βœ… Audit logging (audit_logs, admin_audit_log tables)
  • βœ… Idempotency keys (payment deduplication)
  • βœ… Stripe webhook signature verification

Planned:

  • Two-factor authentication
  • IP whitelisting (admin)
  • Penetration testing
  • CSP nonce migration (remove unsafe-inline)

πŸ› Troubleshooting

Common Issues

Database Connection Failed:

# Check PostgreSQL is running
docker ps | grep postgres

# Restart container
docker restart qscrap-postgres

Redis Not Connected:

# Check Redis is running
docker ps | grep redis

# Test connection
redis-cli -h localhost -p 6379 ping

Port Already in Use:

# Find process using port 3000
lsof -i :3000

# Kill process
kill -9 <PID>

Migration Errors:

# Roll back last migration
npm run migrate:rollback

# Re-run migrations
npm run migrate

πŸ“ž Support

Technical Issues:

Business Inquiries:


πŸ“„ License

Copyright Β© 2026 QScrap. All rights reserved.

Proprietary software - Not for redistribution.


πŸ™ Acknowledgments

Built with exceptional execution and enterprise-grade standards for Qatar's automotive market.

Technology Partners:

  • Node.js Foundation
  • PostgreSQL Community
  • React Native Team
  • Expo Framework

Status: Production-Ready | Market-Leading Platform

About

B2B/B2C platform in Qatar

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors