# mahi-kumari/medikart architecture

> Architecture diagram of the GitHub repository mahi-kumari/medikart, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mahi-kumari/medikart
- Repository: https://github.com/mahi-kumari/medikart

## Overview

##### Project Type and Purpose
- This is a full-stack web application called “medikart” for online medicine ordering and doctor consultations.
- The front end is a static HTML/CSS/JS client. The back end is a Node.js/Express REST API that handles user authentication, prescription uploads (with OCR), consultation requests, medicine search, orders, and payments.

##### File Structure
Top‐level:
· README.md – project overview and feature list
· index.html, login.html, consultation.html, prescription.html, payment.html – static UI pages
· script.js, style.css, variables.scss – front-end logic and styling
· addressRoutes.js, authRoutes.js, consultationRoutes.js, prescriptionRoutes.js, server.js, db.js – root‐level server files (potentially legacy or alternative entrypoint)
· /uploads – storage for uploaded prescriptions
· /image – static assets

backend/
· backend/server.js – main Express application entrypoint
· backend/db.js – MySQL connection logic
· backend/routes/*Routes.js – Express route definitions for address, auth, consultation, prescription
· backend/uploads – nested storage for uploaded files
· backend/google-credentials.json.json – Google Cloud Vision credentials

Observations: MVC-style separation (routes vs. DB config), file upload middleware, nested back-end folder for isolation.

##### README for Additional Insights
- Uses MySQL to store users, prescriptions, consultation records, orders, locations.
- OCR via Google Cloud Vision API called from the prescription upload endpoint.
- OTP login/signup via Firebase Authentication.
- Real-time medicine search with filters.
- Doctor suggestions using an AI service (could be internal logic or external AI API).
- Payment options: UPI (QR scan), Card (secure entry), COD.
- Location integration saved to DB; delivery charges vary by location.
- WhatsApp integration for support (deep link).

##### Main Components & Their Interactions
a. Frontend (Client)
- Static pages + script.js call REST endpoints over HTTPS.
- Firebase SDK for OTP login.
- File input for prescription uploads.
- UI for browsing medicines, filling consultation form, making payments, and contacting via WhatsApp.
b. Backend (Node.js/Express)
- API Gateway: server.js
- Route Handlers: /auth, /address, /consultation, /prescription
- Business Logic: calls to Firebase Admin SDK, Google Cloud Vision client, AI suggestion engine, and payment gateway SDKs.
- File Upload Middleware: stores in /uploads.
c. Database (MySQL)
- Tables: Users, Prescriptions, Medicines, Orders, Consultations, Locations, etc.
- db.js encapsulates connection pooling and query methods.
d. External Services
- Firebase Auth for OTP verification
- Google Cloud Vision API for OCR
- Payment Gateway (UPI QR service, Card processing API)
- AI service for doctor suggestion (could be an internal microservice or external API)
- WhatsApp Business deep-link URL

##### Architectural Patterns & Design Principles
- Separation of Concerns: static front end vs. Express REST API vs. DB layer.
- MVC–Lite: routes (controllers) ≠ db.js (models) ≠ static UI (views).
- Modular Routing: each resource (auth, address, prescription, consultation) has its own router.
- Middleware for cross‐cutting concerns: authentication, file uploads, error handling.
- Externalization of credentials and config (google-credentials.json.json).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Client"
        direction TB
        F1["index.html"]:::frontend
        F2["login.html"]:::frontend
        F3["consultation.html"]:::frontend
        F4["prescription.html"]:::frontend
        F5["payment.html"]:::frontend
        F6["script.js"]:::frontend
        F7["style.css"]:::frontend
        F8["variables.scss"]:::frontend
        F9["image/*"]:::frontend
    end

    subgraph "Express API Server"
        direction TB
        subgraph "Server Entry"
            BE1["backend/server.js"]:::backend
            RE1["server.js"]:::backend
        end
        subgraph "Database Config"
            BE2["backend/db.js"]:::backend
            RE2["db.js"]:::backend
        end
        subgraph "Route Handlers"
            R1["backend/routes/authRoutes.js"]:::backend
            R2["authRoutes.js"]:::backend
            R3["backend/routes/addressRoutes.js"]:::backend
            R4["addressRoutes.js"]:::backend
            R5["backend/routes/consultationRoutes.js"]:::backend
            R6["consultationRoutes.js"]:::backend
            R7["backend/routes/prescriptionRoutes.js"]:::backend
            R8["prescriptionRoutes.js"]:::backend
        end
        MIDDLE["File Upload Middleware"]:::backend
        CRED["Credentials Store\n(google-credentials.json.json)"]:::backend
    end

    DB["MySQL Database\n(medikart)"]:::datastore
    FS["File Storage\n/uploads"]:::datastore

    subgraph "External Services"
        direction TB
        E1["Firebase Auth"]:::external
        E2["Google Cloud Vision"]:::external
        E3["Payment Gateway"]:::external
        E4["AI Suggestion Service"]:::external
        E5["WhatsApp Deep Link"]:::external
    end

    subgraph "Documentation & Misc"
        direction TB
        D1["README.md"]:::external
        D2["package.json"]:::external
        D3["package-lock.json"]:::external
        D4["medikart_dump.sql"]:::external
    end

    %% Connections
    F6 -->|HTTPS Requests| BE1
    BE1 -->|SQL Queries| DB
    BE1 -->|Store/Retrieve| FS
    BE1 -->|OTP Verification| E1
    BE1 -->|OCR Request| E2
    BE1 -->|Payment Processing| E3
    BE1 -->|Doctor Suggestions| E4
    F1 -->|Support Chat| E5

    %% Click Events
    click F1 "https://github.com/mahi-kumari/medikart/blob/main/index.html"
    click F2 "https://github.com/mahi-kumari/medikart/blob/main/login.html"
    click F3 "https://github.com/mahi-kumari/medikart/blob/main/consultation.html"
    click F4 "https://github.com/mahi-kumari/medikart/blob/main/prescription.html"
    click F5 "https://github.com/mahi-kumari/medikart/blob/main/payment.html"
    click F6 "https://github.com/mahi-kumari/medikart/blob/main/script.js"
    click F7 "https://github.com/mahi-kumari/medikart/blob/main/style.css"
    click F8 "https://github.com/mahi-kumari/medikart/blob/main/variables.scss"
    click F9 "https://github.com/mahi-kumari/medikart/tree/main/image/"
    click BE1 "https://github.com/mahi-kumari/medikart/blob/main/backend/server.js"
    click RE1 "https://github.com/mahi-kumari/medikart/blob/main/server.js"
    click BE2 "https://github.com/mahi-kumari/medikart/blob/main/backend/db.js"
    click RE2 "https://github.com/mahi-kumari/medikart/blob/main/db.js"
    click R1 "https://github.com/mahi-kumari/medikart/blob/main/backend/routes/authRoutes.js"
    click R2 "https://github.com/mahi-kumari/medikart/blob/main/authRoutes.js"
    click R3 "https://github.com/mahi-kumari/medikart/blob/main/backend/routes/addressRoutes.js"
    click R4 "https://github.com/mahi-kumari/medikart/blob/main/addressRoutes.js"
    click R5 "https://github.com/mahi-kumari/medikart/blob/main/backend/routes/consultationRoutes.js"
    click R6 "https://github.com/mahi-kumari/medikart/blob/main/consultationRoutes.js"
    click R7 "https://github.com/mahi-kumari/medikart/blob/main/backend/routes/prescriptionRoutes.js"
    click R8 "https://github.com/mahi-kumari/medikart/blob/main/prescriptionRoutes.js"
    click FS "https://github.com/mahi-kumari/medikart/tree/main/uploads/"
    click CRED "https://github.com/mahi-kumari/medikart/blob/main/google-credentials.json.json"
    click D1 "https://github.com/mahi-kumari/medikart/blob/main/README.md"
    click D2 "https://github.com/mahi-kumari/medikart/blob/main/package.json"
    click D3 "https://github.com/mahi-kumari/medikart/blob/main/package-lock.json"
    click D4 "https://github.com/mahi-kumari/medikart/blob/main/medikart_dump.sql"

    %% Styles
    classDef frontend fill:#e0f7e9,stroke:#333,stroke-width:1px
    classDef backend fill:#e0f4ff,stroke:#333,stroke-width:1px
    classDef datastore fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef external fill:#f0f0f0,stroke:#333,stroke-width:1px
```
