Skip to content

About

Sistema com intuito de fazer o controle de gastos pessoais

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

202 Commits

Folders and files

Repository files navigation

💰 Inside Finances API

Personal finance management REST API — income, expenses, categories and monthly balances — built with NestJS, TypeScript, TypeORM and MySQL, containerized with Docker and deployed with CI/CD.

NestJS 9 TypeScript Node.js 16 MySQL Docker GitHub Actions CI/CD Last commit

🇧🇷 Read this README in Portuguese (pt-BR)

📖 About the project

Inside Finances is a backend for tracking personal finances: each user registers their income and expensesorganized by category, and the API provides monthly totals and balance with filters by period, category, type and payment status.

This project was born from a real use case: it replaces an Excel spreadsheet I used for years to control my own expenses — the script/ folder contains a Node.js script that reads that spreadsheet (.xlsx) and imports the history into the API, with consistency checks before importing.

It was built as a study of a production-grade backend: authentication with JWT, request validation with DTOs, relational modeling with TypeORM, documentation with Swagger/OpenAPI, multi-stage Docker images and automated deployment with GitHub Actions.

✨ Features

  • 🔐 Authentication — login with email/username + password (Passport local strategy) issuing a JWT access token, with JWT strategy and guard implemented for protected routes
  • 👥 Users — registration, listing, update and delete (password stored hashed and masked in queries)
  • 💸 Transactions — full CRUD of incomes and expenses, with description, value, date, paid status, bank and specification
  • 🏷 Categories — income/expense categories with icons, seeded via TypeORM migrations
  • 📊 Totalizers — income, expenses and available balance per user: overall, by month, by category, or only paid entries
  • 📃 API documentation — interactive with Swagger / OpenAPI
  • 🚦 Rate limiting — brute-force protection on the API
  • 🐳 Docker — multi-stage images (development with hot-reload and production) + orchestration with docker-compose
  • 🚀 CI/CD — GitHub Actions pipeline with build and automated deployment

🛠 Tech stack

Backend / API: Node.js 16, TypeScript, NestJS 9, REST API, TypeORM (repositories, migrations, entities, relations), MySQL Security: Passport, JWT authentication, hashed passwords, rate limiting Validation & docs: class-validator, class-transformer, DTOs, Swagger, OpenAPI Infra & tooling: Docker (multi-stage build), docker-compose, GitHub Actions (CI/CD, rsync deploy), Jest (unit and e2e), ESLint, Prettier

📂 Project structure

.
├── docker-compose.yml          # API + MySQL orchestration
├── server/src
│   ├── app/                    # Root module (TypeORM + feature modules)
│   ├── migrations/             # TypeORM migrations (seed of default categories)
│   ├── shared/                 # SharedModule + ApiConfigService (env validation, fail-fast)
│   └── modules/
│       ├── auth/               # Login, JWT and local strategies, guards
│       ├── users/              # Users CRUD, entity with hashed/masked password
│       ├── transactions/         # Transactions CRUD, filters and totalizers
│       └── transactionsCategory/ # Income/expense categories CRUD
└── script/                     # Script that imports an Excel spreadsheet into the API

🔌 API endpoints

Base path: /api — the full, interactive documentation is served by Swagger at /doc once the app is running.

Method Route Description
POST /api/auth/login Authenticates and returns a JWT access token
GET /api/users Lists users
POST /api/users Creates a user
GET PATCH DELETE /api/users/:id Fetches, updates or removes a user
GET /api/transactions/user/:userId Lists the user's transactions. Filters via query: categoryId, date=YYYY-MM, type (+ or -), isPaid
GET /api/transactions/user/:userId/last 10 most recent paid transactions
GET /api/transactions/user/:userId/totalizers Total income, expenses and balance up to today
GET /api/transactions/user/:userId/totalizer Totalizers filtered by categoryId, date and type (paid only)
GET PATCH DELETE /api/transactions/:id Fetches, updates or removes a transaction
POST /api/transactions Creates a transaction
GET /api/category Lists categories (ordered)
POST /api/category Creates a category
PATCH DELETE /api/category/:id Updates or removes a category

🚀 Getting started

1. Clone the repository

git clone https://github.com/thiagorcode/inside-finances-be.git
cd inside-finances-be

2. Run with Docker (recommended)

The local image reads server/.env.docker, so create it first:

cp server/.env.docker.example server/.env.docker

Suggested values (they match docker-compose.yml):

DB_HOST=mysql
DB_USERNAME=finances
DB_PASSWORD=finances
DB_DATABASE=finances
DB_PORT=3306
PORT=8080
ENVIRONMENT=local
ENABLE_ORM_LOGS=false

Then start the whole stack:

docker-compose up -d --build

3. Or run locally

Prerequisites: Node.js 16, Yarn and a MySQL instance.

cd server
cp .env.example .env # set DB_*, PORT, ENVIRONMENT=local, ENABLE_ORM_LOGS and JWT_KEY
yarn
yarn typeorm migration:run -d ormconfig.ts # optional: seeds the default categories
yarn start:dev

Useful scripts (server/)

yarn start:dev # watch mode
yarn lint     # ESLint (with --fix)
yarn format   # Prettier
yarn test     # Jest unit tests
yarn test:e2e # Jest e2e tests

🗺 Roadmap

  • 🔐 Activate the JWT guard on all protected routes, taking the user id from the token instead of route params
  • 🔑 Migrate password hashing from SHA-256 to bcrypt
  • 📧 Forgot / reset password flow (temporary password by email)
  • ✅ Global request validation pipe with DTO whitelist
  • 📄 Pagination on transaction listings
  • 📊 Monthly summary report endpoint

👨‍💻 Author

Thiago Rodrigues — backend developer

GitHub E-mail

About

Sistema com intuito de fazer o controle de gastos pessoais

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages