Skip to content

GenieWizards/finance-management-api

Repository files navigation

Finance Management API

A backend repository for the finance management system.

Table of Contents

Tech Stack

  • Language: TypeScript TypeScript
  • Runtime: Bun Bun
  • Package Manager: Bun Bun
  • Auth: Lucia Auth Lucia Auth
  • Database: PostgreSQL PostgreSQL
  • ORM/ODM: Drizzle Drizzle
  • Testing: Bun Bun
  • Documentation: OpenAPI/Scalar OpenAPI Scalar
  • Containerization: Docker Docker Docker Compose Docker Compose

To Setup Locally

  • This project uses Bun as its package manager. You need to have Bun installed on your system.
  • To install Bun, follow the official guide at bun.sh.
git clone https://github.com/GenieWizards/finance-management-api.git # Clone the repo
cd finance-management-api # Navigate to the cloned folder
bun install # Install necessary dependencies using Bun package manager
bun dev # Start the server in development mode

🐳 Docker Development Setup

This project uses Docker for both development and production environments. Below are the instructions to get started.

Prerequisites

  • Docker and Docker Compose installed on your machine
  • Make (usually pre-installed on macOS/Linux)

Available Make Commands

# Show all available commands
make help

# Development Commands
make dev-build    # Build development environment
make dev-up       # Start development environment
make dev-down     # Stop development environment

# Production Commands
make build        # Build production environment
make up           # Start production environment
make down         # Stop production environment
make restart      # Restart the application

# Utility Commands
make logs         # View logs from all containers
make ps           # List running containers
make shell        # Open a shell in the API container
make migrate      # Run database migrations
make clean        # Stop containers, remove volumes, and prune system

Quick Start (Development)

  1. Clone the repository

  2. Copy the environment file:

    cp .env.example .env
  3. Start the development environment:

    make dev-build
    make dev-up

The application will be available at http://localhost:8998

Development Notes

  • The development environment includes hot reloading. Any changes to the source code will automatically reflect in the running application.
  • When adding new dependencies (bun add <package>), you'll need to rebuild the containers:
    make dev-down
    make dev-build
    make dev-up

Database

  • PostgreSQL is available at localhost:5432
  • Default credentials (development):
    User: root
    Password: root
    Database: finance-management-api-dev
    
  • Migrations are run automatically when the container starts

Troubleshooting

If you encounter any issues:

  1. Clean Docker resources:

    make clean
  2. Rebuild everything:

    make rebuild
  3. Check logs:

    make logs

Test Environment Setup

  1. Create a test environment file:

    cp .env.example .env.test
  2. Update the .env.test file with the following configurations:

    LOG_LEVEL=silent
    DATABASE_URL=postgres://root:root@localhost:5432/finance-management-api-test
  3. When running tests, the application will automatically use .env.test configuration:

    bun run test

Note: The test database will be automatically created and migrated when running tests.

Production Deployment

For production deployment:

make build
make up

Note: Make sure to set appropriate environment variables for production use.

Check API Documentation

  • The API documentation is available at {{API_URL}}/reference

Database Migrations

If the schema is added/updated, you need to generate and apply the migrations:

bun db:generate # Generates the migration
bun db:migrate # Applies the migration

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

License

This project is licensed under the MIT License - see the LICENSE file for details.