# amineladrem/lotus-ncshack architecture

> Architecture diagram of the GitHub repository amineladrem/lotus-ncshack, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amineladrem/lotus-ncshack
- Repository: https://github.com/amineladrem/lotus-ncshack

## Overview

##### Project Type and Purpose
- Lotus is a full-stack, client-server healthcare platform:
- A Next.js dashboard (“lotusweb-master”) for pharmacies
- A Flutter mobile app (“Patient-App-Mob”) for patients
- A backend API (“BACKEND” folder—with Django REST or Node.js/Express)
- A relational database (SQLite in DEV, PostgreSQL in PROD)
- External AI service (Google Gemini via the Flutter package)

##### File Structure
- Top-level directories: BACKEND, Patient-App-Mob, lotusweb-master
- Backend: Django project (manage.py, apps, models, serializers, views, urls)
- Mobile: Flutter project (lib/, assets/, android/, ios/, linux/, macos/, windows/)
- Web: Next.js app (app/, components/, public/, config, Tailwind config)
- Config files: Django settings.py, Flutter pubspec.yaml, Next.js package.json

##### README for Additional Insights
- RESTful endpoints for login, suppliers count, meds sold, list meds, list suppliers
- Next.js uses fetch()/useEffect for real-time data
- Flutter calls HTTP APIs and directly integrates with an AI service
- Tech stack: Node.js/Express (or Django REST), PostgreSQL (or SQLite), Next.js/Tailwind, Flutter

##### Main Components & Their Relationships
A. Clients
1. Web Dashboard
– Next.js front end (React pages, Tailwind UI)
– Fetches JSON over HTTPS from the API server
2. Mobile App
– Flutter UI (Dart code)
– State managed via setState
– Calls backend REST endpoints for schedules, login, data
– Integrates directly with Google Gemini API for chatbot
B. API Server
– REST API (Django REST Framework or Express.js)
– Exposes endpoints (/login, /numsup, /medsold, /listmeds, /listsups)
– Handles business logic, authentication, data validation
C. Database
– DEV: SQLite (db.sqlite3)
– PROD: PostgreSQL (host: 127.0.0.1:5432)
– Stores Patients, Suppliers, Drugs, Inventory, Sales
D. External Services
– Google Gemini (via generative_model package in Flutter)
– (Optional) Firebase integrations if using firebase.py
– Geolocation/Pharmacy locator APIs

Flow:
[Web/Mobile Clients] ←HTTPS/JSON→ [API Server] ←SQL Queries→ [Database]
↕
[External AI Service]

##### Architectural Patterns & Design Principles
- Separation of concerns:
- Presentation (Next.js, Flutter)
- API/business logic (Django/Express)
- Data persistence (SQL)
- External integrations (AI, geolocation)
- RESTful design: clear resource-based endpoints
- MVC (in Django) or layered architecture
- Server-side rendering vs. client-side state for web

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Web Dashboard
    subgraph "Web Dashboard (Next.js)" 
        direction TB
        NextPage["app/page.tsx"]:::frontend
        Layout["app/layout.tsx"]:::frontend
        DashboardMain["app/dashboard/page.tsx"]:::frontend
        Inventory["app/dashboard/inventory/page.tsx"]:::frontend
        Medicines["app/dashboard/medecines/page.tsx"]:::frontend
        Suppliers["app/dashboard/suppliers/page.tsx"]:::frontend
        UIComponents["components/ui/"]:::frontend
        GlobalsCSS["app/globals.css"]:::frontend
        TailwindConfig["tailwind.config.ts"]:::frontend
        ConfigTS["app/config/config.ts"]:::frontend
        Utils["lib/utils.ts"]:::frontend
    end

    %% Mobile App
    subgraph "Mobile App (Flutter)" 
        direction TB
        Main["lib/main.dart"]:::mobile
        Login["lib/login.dart"]:::mobile
        APIClient["lib/api.dart"]:::mobile
        MedsScreen["lib/pages/meds.dart"]:::mobile
        PharmacyScreen["lib/pages/pharmacy.dart"]:::mobile
        ProfileScreen["lib/pages/profile.dart"]:::mobile
        AIChat["lib/pages/ai.dart"]:::mobile
        Widgets["lib/widgets.dart"]:::mobile
        Colors["lib/colors.dart"]:::mobile
        Pubspec["pubspec.yaml"]:::mobile
        Assets["assets/"]:::mobile
    end

    %% API Server
    subgraph "API Server (Django REST)" 
        direction TB
        Manage["manage.py"]:::backend
        Settings["myproject/settings.py"]:::backend
        URLsConf["myproject/urls.py"]:::backend
        ASGI["myproject/asgi.py"]:::backend
        WSGI["myproject/wsgi.py"]:::backend
        Models["lotus/models.py"]:::backend
        Serializers["lotus/serializers.py"]:::backend
        Views["lotus/views.py"]:::backend
        AppURLs["lotus/urls.py"]:::backend
        Admin["lotus/admin.py"]:::backend
        Migrations["lotus/migrations/"]:::backend
        Tests["lotus/tests.py"]:::backend
        FirebaseUtil["firebase.py.save"]:::backend
        DBFile["db.sqlite3"]:::backend
    end

    %% Database
    DB["PostgreSQL / SQLite"]:::db

    %% External AI Service
    Gemini["Google Gemini API"]:::external

    %% Connections
    NextPage -->|"HTTPS/JSON"| Manage
    Layout -->|"HTTPS/JSON"| Manage
    DashboardMain -->|"HTTPS/JSON"| Manage
    Inventory -->|"HTTPS/JSON"| Manage
    Medicines -->|"HTTPS/JSON"| Manage
    Suppliers -->|"HTTPS/JSON"| Manage
    UIComponents -->|"Uses"| DashboardMain
    ConfigTS -->|"Config"| NextPage
    Utils -->|"Utils"| DashboardMain

    Main -->|"HTTPS/JSON"| Manage
    Login -->|"HTTPS/JSON"| Manage
    APIClient -->|"HTTPS/JSON"| Manage
    MedsScreen -->|"HTTPS/JSON"| Manage
    PharmacyScreen -->|"HTTPS/JSON"| Manage
    ProfileScreen -->|"HTTPS/JSON"| Manage
    AIChat -->|"API Call"| Gemini
    Widgets -->|"UI Widgets"| Main
    Colors -->|"Theming"| Main

    Manage -->|"SQL Queries"| DB
    Settings -->|"DB Config"| DB
    Models -->|"ORM"| DB
    Migrations -->|"Schema"| DB
    FirebaseUtil -->|"Optional"| Manage

    %% Styling and relationships
    classDef frontend fill:#ADD8E6,stroke:#000,color:#000
    classDef mobile fill:#87CEFA,stroke:#000,color:#000
    classDef backend fill:#F2A65A,stroke:#000,color:#000
    classDef db fill:#A9D18E,stroke:#000,color:#000
    classDef external fill:#D6A4F1,stroke:#000,color:#000

    %% Click Events
    click NextPage "https://github.com/amineladrem/lotus-ncshack/blob/main/lotusweb-master/app/page.tsx"
    click Layout "https://github.com/amineladrem/lotus-ncshack/blob/main/lotusweb-master/app/layout.tsx"
    click DashboardMain "https://github.com/amineladrem/lotus-ncshack/blob/main/lotusweb-master/app/dashboard/page.tsx"
    click Inventory "https://github.com/amineladrem/lotus-ncshack/blob/main/lotusweb-master/app/dashboard/inventory/page.tsx"
    click Medicines "https://github.com/amineladrem/lotus-ncshack/blob/main/lotusweb-master/app/dashboard/medecines/page.tsx"
    click Suppliers "https://github.com/amineladrem/lotus-ncshack/blob/main/lotusweb-master/app/dashboard/suppliers/page.tsx"
    click UIComponents "https://github.com/amineladrem/lotus-ncshack/tree/main/lotusweb-master/components/ui/"
    click GlobalsCSS "https://github.com/amineladrem/lotus-ncshack/blob/main/lotusweb-master/app/globals.css"
    click TailwindConfig "https://github.com/amineladrem/lotus-ncshack/blob/main/lotusweb-master/tailwind.config.ts"
    click ConfigTS "https://github.com/amineladrem/lotus-ncshack/blob/main/lotusweb-master/app/config/config.ts"
    click Utils "https://github.com/amineladrem/lotus-ncshack/blob/main/lotusweb-master/lib/utils.ts"

    click Main "https://github.com/amineladrem/lotus-ncshack/blob/main/Patient-App-Mob/lib/main.dart"
    click Login "https://github.com/amineladrem/lotus-ncshack/blob/main/Patient-App-Mob/lib/login.dart"
    click APIClient "https://github.com/amineladrem/lotus-ncshack/blob/main/Patient-App-Mob/lib/api.dart"
    click MedsScreen "https://github.com/amineladrem/lotus-ncshack/blob/main/Patient-App-Mob/lib/pages/meds.dart"
    click PharmacyScreen "https://github.com/amineladrem/lotus-ncshack/blob/main/Patient-App-Mob/lib/pages/pharmacy.dart"
    click ProfileScreen "https://github.com/amineladrem/lotus-ncshack/blob/main/Patient-App-Mob/lib/pages/profile.dart"
    click AIChat "https://github.com/amineladrem/lotus-ncshack/blob/main/Patient-App-Mob/lib/pages/ai.dart"
    click Widgets "https://github.com/amineladrem/lotus-ncshack/blob/main/Patient-App-Mob/lib/widgets.dart"
    click Colors "https://github.com/amineladrem/lotus-ncshack/blob/main/Patient-App-Mob/lib/colors.dart"
    click Pubspec "https://github.com/amineladrem/lotus-ncshack/blob/main/Patient-App-Mob/pubspec.yaml"
    click Assets "https://github.com/amineladrem/lotus-ncshack/tree/main/Patient-App-Mob/assets/"

    click Manage "https://github.com/amineladrem/lotus-ncshack/blob/main/BACKEND/manage.py"
    click Settings "https://github.com/amineladrem/lotus-ncshack/blob/main/BACKEND/myproject/settings.py"
    click URLsConf "https://github.com/amineladrem/lotus-ncshack/blob/main/BACKEND/myproject/urls.py"
    click ASGI "https://github.com/amineladrem/lotus-ncshack/blob/main/BACKEND/myproject/asgi.py"
    click WSGI "https://github.com/amineladrem/lotus-ncshack/blob/main/BACKEND/myproject/wsgi.py"
    click Models "https://github.com/amineladrem/lotus-ncshack/blob/main/BACKEND/lotus/models.py"
    click Serializers "https://github.com/amineladrem/lotus-ncshack/blob/main/BACKEND/lotus/serializers.py"
    click Views "https://github.com/amineladrem/lotus-ncshack/blob/main/BACKEND/lotus/views.py"
    click AppURLs "https://github.com/amineladrem/lotus-ncshack/blob/main/BACKEND/lotus/urls.py"
    click Admin "https://github.com/amineladrem/lotus-ncshack/blob/main/BACKEND/lotus/admin.py"
    click Migrations "https://github.com/amineladrem/lotus-ncshack/tree/main/BACKEND/lotus/migrations/"
    click Tests "https://github.com/amineladrem/lotus-ncshack/blob/main/BACKEND/lotus/tests.py"
    click FirebaseUtil "https://github.com/amineladrem/lotus-ncshack/blob/main/BACKEND/firebase.py.save"
    click DBFile "https://github.com/amineladrem/lotus-ncshack/blob/main/BACKEND/db.sqlite3"
```
