Skip to content

renanzitoo/FinancialAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’° FinancialAPI

.NET C# MySQL License

A RESTful API for personal finance management with JWT authentication, transaction tracking, and category organization.


πŸ“‹ About the Project

FinancialAPI allows users to register, authenticate, and manage their personal finances by creating income and expense transactions organized into custom categories. Each user's data is fully isolated.

🎯 Features

  • πŸ” JWT Authentication β€” secure registration and login
  • πŸ—‚οΈ Categories β€” create and manage custom transaction categories
  • πŸ’Έ Transactions β€” record income and expenses in cents
  • πŸ“Š Summaries β€” overall and monthly financial summaries
  • πŸ” Filters β€” query transactions by date range or category
  • πŸ“– Swagger/OpenAPI β€” interactive API documentation

πŸ› οΈ Technologies Used

  • .NET 8.0 β€” Web framework
  • ASP.NET Core Web API β€” RESTful API construction
  • Entity Framework Core 8.0 β€” ORM for data access
  • Pomelo MySQL 8.0 β€” MySQL EF Core provider
  • AutoMapper 12.0 β€” Object-to-object mapping
  • FluentValidation 11 β€” Input validation
  • JWT Bearer β€” Stateless authentication
  • Swagger/OpenAPI β€” API documentation

πŸ“ Project Structure

FinancialAPI/
β”œβ”€β”€ Controllers/
β”‚   β”œβ”€β”€ AuthController.cs         # Register & login
β”‚   β”œβ”€β”€ CategoryController.cs     # Category CRUD
β”‚   └── TransactionController.cs  # Transaction CRUD & summaries
β”œβ”€β”€ Services/
β”‚   β”œβ”€β”€ CategoryService.cs
β”‚   β”œβ”€β”€ TransactionService.cs
β”‚   β”œβ”€β”€ JwtService.cs
β”‚   β”œβ”€β”€ PasswordService.cs
β”‚   └── CurrentUserService.cs
β”œβ”€β”€ Entities/
β”‚   β”œβ”€β”€ User.cs
β”‚   β”œβ”€β”€ Category.cs
β”‚   └── Transaction.cs            # TransactionType enum (Income/Expense)
β”œβ”€β”€ DTOs/
β”‚   β”œβ”€β”€ Requests/                 # Auth, Category, Transaction DTOs
β”‚   └── Responses/
β”œβ”€β”€ Interfaces/
β”‚   β”œβ”€β”€ ICategoryService.cs
β”‚   β”œβ”€β”€ ITransactionService.cs
β”‚   └── ICurrentUserService.cs
β”œβ”€β”€ Context/
β”‚   └── AppDbContext.cs
β”œβ”€β”€ Mappings/
β”‚   β”œβ”€β”€ CategoryMapping.cs
β”‚   └── TransactionMapping.cs
└── Migrations/

πŸ’» Requirements

  • .NET SDK 8 or higher
  • MySQL 8.0 or Docker
  • Git
  • IDE: JetBrains Rider, Visual Studio 2022, or VS Code

πŸš€ Running the Project

1️⃣ Clone the repository

git clone https://github.com/renanzitoo/FinancialAPI.git
cd FinancialAPI

2️⃣ Configure the database and JWT secret

Edit FinancialAPI/appsettings.json:

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=localhost;Port=3306;Database=financialapi;User=root;Password=your-password;"
  },
  "Jwt": {
    "Secret": "your-secret-key-at-least-32-characters-long"
  }
}

Option: MySQL via Docker

docker run --name mysql-financialapi -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=financialapi -p 3306:3306 -d mysql:8.0

3️⃣ Run the migrations

dotnet ef database update --project FinancialAPI

4️⃣ Restore and run

dotnet restore
dotnet run --project FinancialAPI

API available at: https://localhost:7000 or http://localhost:5000


πŸ“Œ API Endpoints

All endpoints except Auth require a Bearer token in the Authorization header.

πŸ” Auth

Method Endpoint Description
POST /api/auth/register Create a new account
POST /api/auth/login Authenticate and receive a JWT

πŸ—‚οΈ Categories

Method Endpoint Description
POST /api/categories Create a category
GET /api/categories List all user categories
GET /api/categories/{id} Get a category by ID
PUT /api/categories/{id} Update a category
DELETE /api/categories/{id} Delete a category

πŸ’Έ Transactions

Method Endpoint Description
POST /api/transactions Create a transaction
GET /api/transactions List all user transactions
GET /api/transactions/{id} Get a transaction by ID
PUT /api/transactions/{id} Update a transaction
DELETE /api/transactions/{id} Delete a transaction
GET /api/transactions/by-date Filter by date range (?startDate=&endDate=)
GET /api/transactions/by-category/{categoryId} Filter by category
GET /api/transactions/summary Overall financial summary
GET /api/transactions/summary/{year}/{month} Monthly financial summary

πŸ“ Example Requests

Register

POST /api/auth/register
{
  "name": "John Doe",
  "email": "john@example.com",
  "password": "P@ssw0rd!"
}

Create Transaction

POST /api/transactions
Authorization: Bearer <token>
{
  "title": "Salary",
  "categoryId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "amountInCents": 500000,
  "type": 1,
  "description": "Monthly salary",
  "date": "2026-03-16T00:00:00Z"
}

type: 1 = Income, 2 = Expense. amountInCents: amount in the smallest currency unit (e.g. 500000 = $5,000.00).


πŸ—„οΈ Data Model

Users

Column Type
Id GUID
Name VARCHAR
Email VARCHAR(100)
PasswordHash VARCHAR
CreatedAt DATETIME

Categories

Column Type
Id GUID
Name VARCHAR
UserId GUID (FK)

Transactions

Column Type
Id GUID
UserId GUID (FK)
CategoryId GUID (FK)
Title VARCHAR
AmountInCents BIGINT
Description VARCHAR
Date DATETIME
Type INT (1=Income, 2=Expense)

πŸ—οΈ Architecture

Implemented Patterns

  1. Service Layer β€” Business logic isolated in service classes
  2. DTO Pattern β€” Separation of entities and API models
  3. Interface Segregation β€” Services registered via interfaces
  4. Dependency Injection β€” Native ASP.NET Core DI
  5. AutoMapper Profiles β€” Clean entity ↔ DTO conversion

🧠 Concepts Practiced

  • βœ… External API consumption with HttpClient
  • βœ… Resilience and error handling
  • βœ… Local caching for optimization
  • βœ… Async/Await patterns
  • βœ… Entity Framework Core with MySQL
  • βœ… AutoMapper for DTOs
  • βœ… Data validation
  • βœ… Call auditing
  • βœ… RESTful patterns
  • βœ… Dependency injection

πŸ“ Future Improvements

  • Add ILogger for structured observability
  • Implement Circuit Breaker with Polly
  • Create unit tests (xUnit)
  • Integration tests
  • Health checks
  • Metrics (Prometheus)
  • Containerize the application
  • CI/CD with GitHub Actions
  • Rate limiting

πŸ‘¨β€πŸ’» Author

Renan Costa
GitHub: renanzitoo


⭐ If this project was useful to you, consider giving it a star!

About

ASP.NET Core API for personal finance management with JWT authentication, MySQL, transaction tracking, and financial summaries.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages