An open API service indexing awesome lists of open source software.

https://github.com/mth-ribeiro-dev/finance-api-go

REST API in Go for personal finance tracking with local JSON storage.
https://github.com/mth-ribeiro-dev/finance-api-go

backend gin go json-api personal-finance rest-api

Last synced: 4 months ago
JSON representation

REST API in Go for personal finance tracking with local JSON storage.

Awesome Lists containing this project

README

          

πŸ“˜ Read this documentation in [PortuguΓͺs πŸ‡§πŸ‡·](./README.pt-BR.md)

# πŸ“Š Finance API - Personal Finance Management in Go

This project is a REST API for managing personal finances developed in Go. It allows recording income and expenses, automatic balance calculation, local data persistence using a JSON file, and includes user management features.

## Features

- Transaction recording (income and expenses)
- Automatic balance calculation
- Local data persistence using JSON file
- User management (registration, authentication, and deletion)
- Transactions linked to specific users
- API documentation with Swagger
- Email sending functionality

## Technologies Used

- Go (Golang)
- Gin Gonic (web framework)
- Encoding/JSON for data persistence
- Modular architecture
- Swagger for API documentation
- SMTP for email sending

## Project Structure

The project follows a modular structure, organized as follows:

```
finance-api/
β”œβ”€β”€ cmd/
β”‚ └── server/
β”‚ └── main.go
β”œβ”€β”€ internal/
β”‚ β”œβ”€β”€ handler/
β”‚ β”‚ β”œβ”€β”€ finance.go
β”‚ β”‚ └── user.go
β”‚ β”œβ”€β”€ model/
β”‚ β”‚ β”œβ”€β”€ dateOnly.go
β”‚ β”‚ β”œβ”€β”€ transaction.go
β”‚ β”‚ └── user.go
β”‚ β”œβ”€β”€ service/
β”‚ β”‚ β”œβ”€β”€ finance.go
β”‚ β”‚ β”œβ”€β”€ finance_test.go
β”‚ β”‚ β”œβ”€β”€ user.go
β”‚ β”‚ └── user_test.go
β”‚ └── storage/
β”‚ β”œβ”€β”€ commonStorage.go
β”‚ β”œβ”€β”€ financesStorage.go
β”‚ └── usersStorage.go
β”œβ”€β”€ go.mod
β”œβ”€β”€ go.sum
β”œβ”€β”€ .gitignore
β”œβ”€β”€ README.md
└── README.pt-BR.md
```
## How to Run

1. Clone the repository:

```bash
git clone https://github.com/mth-ribeiro-dev/finance-api.git
```

2. Navigate to the project directory:

```bash
cd finance-api
```

3. Install dependencies:

```bash
go get -v ./...
```

4. Run the application:

```bash
go run cmd/server/main.go
```

5. Access the Swagger documentation:

Open your browser and go to `http://localhost:8081/swagger/index.html`

## Configuration

Create a `config.yaml` file in the project root with the following structure:

```yaml
smtp:
host: your_smtp_host
port: your_smtp_port
username: your_smtp_username
password: your_smtp_password
```

## API Endpoints

For a detailed and interactive documentation of all API endpoints, please refer to the Swagger UI available at `http://localhost:8081/swagger/index.html` when the application is running.

### Users
- `POST /api/v1/user/register`: Registers a new user
- `POST /api/v1/user/login`: Authenticates a user
- `DELETE /api/v1/user/:id`: Deactivates a user

### Financial Transactions
- `POST /api/v1/finance/transaction`: Adds a new transaction
- `GET /api/v1/finance/transactions/:userId`: Returns all transactions for a user
- `GET /api/v1/finance/balance/:userId`: Returns a user's current balance
- `PUT /api/v1/finance/:id`: Update an existing transaction
- `DELETE /api/v1/finance/:id`: Delete a transaction

### Email
- `POST /api/v1/send-email`: Send an email

## Testing

The project includes comprehensive unit tests for the service layer. To run the tests:
```bash
go test ./...
```

## Documentation

This project uses Swagger for API documentation. The documentation includes detailed information about all endpoints, request/response models, and allows for interactive API testing.

To view the Swagger documentation:
1. Start the application
2. Open your web browser
3. Navigate to `http://localhost:8081/swagger/index.html`

The code also includes comprehensive comments, enhancing readability and maintainability.

## Best Practices Applied

- Modular code organization
- Use of `go.mod` for dependency management
- Implementation of unit tests
- Use of interfaces for decoupling (e.g., storage)
- Robust input validation

## License

This project is licensed under the [Creative Commons BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/) license for educational and non-commercial purposes.

## Author

Developed by Matheus Ribeiro
- Email: matheus.junio159@gmail.com
- GitHub: [https://github.com/mth-ribeiro-dev](https://github.com/mth-ribeiro-dev)