# ankushgitrepo/pharmacy-management-system architecture

> Architecture diagram of the GitHub repository ankushgitrepo/pharmacy-management-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ankushgitrepo/pharmacy-management-system
- Repository: https://github.com/ankushgitrepo/pharmacy-management-system

## Overview

##### Main Components
- Console UI / Main Application: Represented by the Main class and related command/menu handling.
- Drug Management Module: Components to add, update, delete, view drugs and list expired drugs (including the Drug class and associated audit/triggers indicated by the DBMS folder files).
- Customer Management Module: Handled by the Customer class and related functionalities – adding, updating, and deleting customer records.
- Cart and Order Processing: Modules for Cart (Cart and CartItem classes), Order, and OrderItems operations.
- Data Structures & Action Logging: Custom implementations like StackDSA for logging actions and LinkedListDSA for additional data handling.
- Database Handler: The DatabaseHandler class that manages connections and queries to the PostgreSQL database.
- Database and External Services: PostgreSQL database itself (and associated schema with Drugs, Customers, Cart, Orders, OrderItems, and Drugs_Audit tables) with integration via the postgresql-42.7.3.jar driver.

##### Relationships and Interactions
- The Main class initiates the application, directing control flows to the various management modules.
- For any operation (e.g., adding a drug or registering a customer), the respective module (Drug Management, Customer Management) validates input, processes business logic, and then calls the DatabaseHandler to execute SQL operations.
- The Cart Management module interacts with both Drug and Customer modules. It ensures that a customer's cart data is consistent with the inventory data.
- An action logging mechanism (the stack data structure) captures user commands or changes as they occur.
- The system relies on triggers in the database (log_drug_changes trigger) to audit drug data modifications.
- Data flows from the console UI to business logic, then to the database for persistence and back for confirmation/updates.

##### Architectural Patterns & Design Principles
- Separation of Concerns: The system divides responsibilities into distinct modules (UI, business logic, data access).
- Modular Design: Each module (Drug Management, Customer Management, Cart, and Orders) has its defined classes and interactions.
- Use of Custom Data Structures: Instead of standard collections, the application uses a Stack and LinkedList for specialized logging and data handling.
- Database Abstraction: All database interactions are centralized in the DatabaseHandler, ensuring maintainability and easier configuration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Main Application / CLI"]:::ui
    B["Drug Management"]:::module
    C["Customer Management"]:::module

    subgraph "Cart & Order Processing"
        D1["Cart"]:::module
        D2["CartItem"]:::module
        D3["Order"]:::module
    end

    subgraph "Action Logging"
        E1["StackDSA"]:::logging
        E2["LinkedListDSA"]:::logging
    end

    F["Database Handler"]:::dbaccess
    G["PostgreSQL Database<br/><small>Tables: Drugs, Customers, Cart, Orders, OrderItems, Drugs_Audit</small>"]:::database
    H["PostgreSQL JDBC Driver"]:::external
    I["DBMS Documentation"]:::docs

    A -->|"initiate"| B
    A -->|"initiate"| C
    A -->|"initiate"| D1
    A -->|"initiate"| D2
    A -->|"initiate"| D3

    B -->|"crud"| F
    C -->|"crud"| F
    D1 -->|"crud"| F
    D2 -->|"crud"| F
    D3 -->|"crud"| F

    B -->|"log_action"| E1
    C -->|"log_action"| E1
    D1 -->|"log_action"| E1
    D2 -->|"log_action"| E1
    D3 -->|"log_action"| E1

    F -->|"query"| G
    G -->|"response"| F

    B -->|"docs"| I
    I -->|"audit_trigger"| G

    H -->|"connects"| G

    click A "https://github.com/ankushgitrepo/pharmacy-management-system/blob/main/Pharmacy_Management_System/src/main/java/org/example/Main.java"
    click B "https://github.com/ankushgitrepo/pharmacy-management-system/blob/main/Pharmacy_Management_System/src/main/java/org/example/Drug.java"
    click I "https://github.com/ankushgitrepo/pharmacy-management-system/tree/main/Pharmacy_Management_System/src/main/java/org/example/DBMS/"
    click C "https://github.com/ankushgitrepo/pharmacy-management-system/blob/main/Pharmacy_Management_System/src/main/java/org/example/Customer.java"
    click D1 "https://github.com/ankushgitrepo/pharmacy-management-system/blob/main/Pharmacy_Management_System/src/main/java/org/example/Cart.java"
    click D2 "https://github.com/ankushgitrepo/pharmacy-management-system/blob/main/Pharmacy_Management_System/src/main/java/org/example/CartItem.java"
    click D3 "https://github.com/ankushgitrepo/pharmacy-management-system/blob/main/Pharmacy_Management_System/src/main/java/org/example/Order.java"
    click E1 "https://github.com/ankushgitrepo/pharmacy-management-system/blob/main/Pharmacy_Management_System/src/main/java/org/example/StackDSA.java"
    click E2 "https://github.com/ankushgitrepo/pharmacy-management-system/blob/main/Pharmacy_Management_System/src/main/java/org/example/LinkedListDSA.java"
    click F "https://github.com/ankushgitrepo/pharmacy-management-system/blob/main/Pharmacy_Management_System/src/main/java/org/example/DatabaseHandler.java"
    click H "https://github.com/ankushgitrepo/pharmacy-management-system/blob/main/postgresql-42.7.3.jar"

classDef ui fill:#ffcc00,stroke:#000,stroke-width:2px;
classDef module fill:#99ccff,stroke:#000,stroke-width:2px;
classDef logging fill:#ff99cc,stroke:#000,stroke-width:2px;
classDef dbaccess fill:#ccffcc,stroke:#000,stroke-width:2px;
classDef database fill:#ff9999,stroke:#000,stroke-width:2px;
classDef external fill:#ffff99,stroke:#000,stroke-width:2px;
classDef docs fill:#ccffff,stroke:#000,stroke-width:2px;
```
