Skip to content

davidspiv/transaction-backend

Repository files navigation

DESCRIPTION

JSON API for a simplified, double-entry finance app similar to GNUCash, MoneyDance or Quickbooks for small businesses.

The Frontend currently exists as an SPA using Vue's Composition API. Currently not very usable; would recommend interacting with this API using Postman or equivalent.

GETTING STARTED

Hosting the API Locally

  1. SQLite (database engine) and pnpm (package manager) should be installed on your local machine.
  2. This project utilizes Biome in lieu of ESLint / Prettier. If using VS Code, ensure the Biome extension is installed and your workspace settings enable Biome as the default formatter.
  3. Remove the “.example” from the .env file title and change relevant parameters.
  4. pnpm install - Install dependencies.
  5. pnpm run db - Build the SQLite database using existing CSV data in the “testInputs” directory.
  6. pnpm run dev - Run the API and have typescript transpiler watch for any changes.
  7. To test, URI is “http://localhost:{PORT}/api” + path found in the “routes” directory.

Building the Database

  1. pnpm run db calls “database.ts”. Schema and relevant scripts are located in the “src/dev” directory.
  2. The database schema and seed are parsed into individual SQL commands.
  3. The database is created, tables are built from the schema, and base seed data inputted.
  4. CSV data is read and parsed from the local “/testInputs” directory.
  5. Data is written to the database.

Request / Response Data Flow

  1. Entry point is “src/index.ts”. Using the Express framework - The HTTP request is converted to JSON, logged, and sent to the relevant route via the “routes” directory.
  2. Each route accesses the relevant function in the “controller” directory. This function connects the HTTP request to the relevant database action.
  3. Data access functions reside in the “db” directory and are named identically to their controller counterparts. These functions perform CRUD operations on the SQLite database, format the data if necessary, and return objects.
  4. Data objects are returned from the data-access layer back to the controller function where a HTTP response is created.
  5. The request is returned from the controller layer back to “src.index.ts”. Any errors are caught and/or the HTTP response is sent.

About

API in Node w/Express and SQLite

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published