Templates/Finance

Loan servicing database schema

Borrowers, loan products, loans with repayment schedules and payments.

5 tables, 4 relationships

Opens as a new diagram you can change. Free.

Tables

borrowers

  • iduuid not null
  • full_nametext not null
  • emailtext not null
  • credit_scoreinteger
  • created_attimestamptz not null

loan_products

  • iduuid not null
  • nametext not null
  • annual_ratenumeric(5,2) not null
  • term_monthsinteger not null
  • created_attimestamptz not null

loans

  • iduuid not null
  • borrower_id> borrowersuuid not null
  • product_id> loan_productsuuid not null
  • principalnumeric(14,2) not null
  • disbursed_ondate
  • statustext not null
  • created_attimestamptz not null

repayment_schedule

  • iduuid not null
  • loan_id> loansuuid not null
  • due_ondate not null
  • principal_duenumeric(14,2) not null
  • interest_duenumeric(14,2) not null
  • created_attimestamptz not null

loan_payments

  • iduuid not null
  • loan_id> loansuuid not null
  • amountnumeric(14,2) not null
  • paid_ondate not null
  • created_attimestamptz not null

As PostgreSQL

The same diagram exports to MySQL, MariaDB, SQLite, SQL Server and Oracle, and to Prisma, Drizzle, SQLAlchemy and Convex models.

CREATE TABLE "borrowers" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "full_name" TEXT NOT NULL,
  "email" TEXT NOT NULL UNIQUE,
  "credit_score" INTEGER,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "loan_payments" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "loan_id" UUID NOT NULL,
  "amount" NUMERIC(14,2) NOT NULL,
  "paid_on" DATE NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "loan_products" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "name" TEXT NOT NULL,
  "annual_rate" NUMERIC(5,2) NOT NULL,
  "term_months" INTEGER NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "loans" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "borrower_id" UUID NOT NULL,
  "product_id" UUID NOT NULL,
  "principal" NUMERIC(14,2) NOT NULL,
  "disbursed_on" DATE,
  "status" TEXT DEFAULT 'applied' NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "repayment_schedule" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "loan_id" UUID NOT NULL,
  "due_on" DATE NOT NULL,
  "principal_due" NUMERIC(14,2) NOT NULL,
  "interest_due" NUMERIC(14,2) NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

ALTER TABLE "loans" ADD CONSTRAINT "fk_loans_borrower_id" FOREIGN KEY ("borrower_id") REFERENCES "borrowers" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "loans" ADD CONSTRAINT "fk_loans_product_id" FOREIGN KEY ("product_id") REFERENCES "loan_products" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "repayment_schedule" ADD CONSTRAINT "fk_repayment_schedule_loan_id" FOREIGN KEY ("loan_id") REFERENCES "loans" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "loan_payments" ADD CONSTRAINT "fk_loan_payments_loan_id" FOREIGN KEY ("loan_id") REFERENCES "loans" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

More Finance templates

Start with one diagram, free

One diagram with two branches, no card needed. Upgrade when your team needs more.