Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/JReyna217/PharmaVault/llms.txt

Use this file to discover all available pages before exploring further.

PharmaVault stores all data in a PostgreSQL database called pharmavault_db, consisting of five tables that are created by two SQL scripts in the sql/ directory. The schema uses identity columns for all primary keys, UUID generation for incident tracking, and explicit foreign key constraints to maintain referential integrity between users, their inventory, and the error log.
Always run the scripts in numeric order — 00-CreateDataBase.sql before 01-InitSchema.sql. The second script creates tables inside the database that the first script creates, so running them out of order will produce a “database does not exist” error.

Schema Initialization

1

Run 00-CreateDataBase.sql

Creates the pharmavault_db database. Run this script as a PostgreSQL superuser or a role with CREATEDB privileges.
sql/00-CreateDataBase.sql
CREATE DATABASE pharmavault_db;
2

Connect to pharmavault_db

Switch your psql session (or client connection) to the newly created database before running the next script.
\c pharmavault_db
3

Run 01-InitSchema.sql

Creates all five tables with their columns, constraints, defaults, and foreign keys.
sql/01-InitSchema.sql
CREATE TABLE users ( ... );
CREATE TABLE medicine_catalog ( ... );
CREATE TABLE inventory ( ... );
CREATE TABLE system_responses ( ... );
CREATE TABLE error_logs ( ... );
See the Tables section below for the full DDL of each table.

Tables

The users table stores account credentials and profile information for every registered PharmaVault user. Passwords are never stored in plain text — the application always stores a BCrypt hash in password_hash.
ColumnTypeConstraintsNotes
user_idINTPK, IDENTITY, NOT NULLAuto-generated surrogate key
emailVARCHAR(255)UNIQUE, NOT NULLUsed as the login identifier
password_hashVARCHAR(255)NOT NULLBCrypt hash of the user’s password
full_nameVARCHAR(100)NOT NULLDisplay name
registration_dateTIMESTAMPDEFAULT CURRENT_TIMESTAMPSet automatically on insert
CREATE TABLE users (
    user_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    email VARCHAR(255) UNIQUE NOT NULL,
    password_hash VARCHAR(255) NOT NULL,
    full_name VARCHAR(100) NOT NULL,
    registration_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
C# model: PharmaVault.Core.Models.User
The medicine_catalog table is a shared, admin-managed reference list of medicines that users can add to their personal inventory. Individual catalog entries can be soft-deleted by toggling is_active rather than physically removing them.
ColumnTypeConstraintsNotes
catalog_idINTPK, IDENTITY, NOT NULLAuto-generated surrogate key
nameVARCHAR(250)NOT NULLMedicine name
pharmaceutical_formVARCHAR(50)NOT NULLe.g., tablet, capsule, syrup
dosageVARCHAR(50)nullablee.g., 500 mg, 10 mg/5 mL
is_activeBOOLEANDEFAULT TRUESoft-delete flag
CREATE TABLE medicine_catalog (
    catalog_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    name VARCHAR(250) NOT NULL,
    pharmaceutical_form VARCHAR(50) NOT NULL,
    dosage VARCHAR(50),
    is_active BOOLEAN DEFAULT TRUE
);
C# model: PharmaVault.Core.Models.MedicineCatalog
The inventory table represents each user’s personal medication stock. Every row links a user to a catalog entry and records quantity, purchase date, expiration date, and optional prescription notes.
ColumnTypeConstraintsNotes
inventory_idINTPK, IDENTITY, NOT NULLAuto-generated surrogate key
user_idINTFK → users.user_id, NOT NULL, CASCADE DELETEOwner of this inventory row
catalog_idINTFK → medicine_catalog.catalog_id, NOT NULLWhich medicine this entry is for
quantityINTNOT NULL, DEFAULT 0Current stock count
purchase_dateDATEnullableOptional purchase record
expiration_dateDATENOT NULLMandatory expiry — used for expiry alerts
prescription_notesTEXTnullableFree-text dosage or prescription notes (max 500 chars enforced in C#)
date_addedTIMESTAMPDEFAULT CURRENT_TIMESTAMPSet automatically on insert
CREATE TABLE inventory (
    inventory_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    user_id INT NOT NULL REFERENCES users(user_id) ON DELETE CASCADE,
    catalog_id INT NOT NULL REFERENCES medicine_catalog(catalog_id),
    quantity INT NOT NULL DEFAULT 0,
    purchase_date DATE,
    expiration_date DATE NOT NULL,
    prescription_notes TEXT,
    date_added TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
C# model: PharmaVault.Core.Models.Inventory
The system_responses table is a lookup table that stores localized response messages for operation outcomes. The code column acts as a short, human-readable key (up to 6 characters) that application code uses to look up the appropriate translated message.
ColumnTypeConstraintsNotes
codeVARCHAR(6)PK, NOT NULLShort response code (e.g., OK, ERR01)
message_esTEXTNOT NULLSpanish message text
message_enTEXTNOT NULLEnglish message text
CREATE TABLE system_responses (
    code VARCHAR(6) PRIMARY KEY,
    message_es TEXT NOT NULL,
    message_en TEXT NOT NULL
);
C# model: PharmaVault.Core.Models.SystemResponse
The error_logs table records all application exceptions captured by ExceptionHandlingMiddleware and routed through IErrorLogDao.LogErrorAsync. Each row is assigned a UUID incident number, making it easy to cross-reference a user-visible error reference with the server-side log record.
ColumnTypeConstraintsNotes
log_idINTPK, IDENTITY, NOT NULLAuto-generated surrogate key
origin_layerVARCHAR(15)NOT NULLe.g., Web, Data, Core
main_objectVARCHAR(50)NOT NULLClass or component where the error originated
method_nameVARCHAR(50)NOT NULLMethod where the error was thrown
descriptionVARCHAR(4000)nullableOptional additional context
error_messageVARCHAR(4000)NOT NULLException message text
error_dateTIMESTAMPDEFAULT CURRENT_TIMESTAMPSet automatically on insert
user_idINTFK → users.user_id, nullable, SET NULLNull if the error occurred before authentication
incident_numberUUIDNOT NULL, DEFAULT gen_random_uuid()Unique incident identifier shown to users
CREATE TABLE error_logs (
    log_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    origin_layer VARCHAR(15) NOT NULL,
    main_object VARCHAR(50) NOT NULL,
    method_name VARCHAR(50) NOT NULL,
    description VARCHAR(4000),
    error_message VARCHAR(4000) NOT NULL,
    error_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    user_id INT REFERENCES users(user_id) ON DELETE SET NULL,
    incident_number UUID DEFAULT gen_random_uuid() NOT NULL
);
C# model: PharmaVault.Core.Models.ErrorLog

Relationships

PharmaVault’s foreign key constraints encode important data-lifecycle decisions directly in the schema.
users ──────────────────────────────────────┐
  │  (CASCADE DELETE)                        │  (SET NULL)
  ▼                                          ▼
inventory                               error_logs

  │  (RESTRICT — no action on delete)

medicine_catalog

inventory.user_id → users.user_id

ON DELETE CASCADE. When a user account is deleted, all of that user’s inventory rows are automatically removed. There is no orphaned inventory data after account deletion.

inventory.catalog_id → medicine_catalog.catalog_id

No explicit ON DELETE action (defaults to RESTRICT). A catalog entry cannot be deleted while inventory rows reference it. Use the is_active flag to soft-delete catalog entries instead.

error_logs.user_id → users.user_id

ON DELETE SET NULL. Error log records are preserved even after the associated user is deleted. The user_id column is set to NULL, keeping the full audit trail intact while removing the personal data link.

Complete Schema SQL

CREATE DATABASE pharmavault_db;

Build docs developers (and LLMs) love