A personal finance management API built with Ruby on Rails. Track accounts, transactions, and manage your finances with ease.
- π User Authentication - Secure session-based and token-based authentication
- π€ User Profiles - Manage personal information and preferences
- πΌ Multi-Owner Support - Create and manage multiple financial entities
- π¦ Account Management - Track multiple bank accounts per owner
- πΈ Transaction Tracking - Record income, expenses, and transfers
- π Transaction Categorization - Internal vs external transactions
- π Advanced Querying - Filter transactions by date, account, and type
- π API Documentation - Auto-generated OpenAPI documentation
- Framework: Ruby on Rails 8.1.2
- Database: PostgreSQL
- Authentication: BCrypt with has_secure_password
- API Documentation: OasRails (OpenAPI/Swagger)
- Testing: Minitest
- Deployment: Kamal with Docker
- Job Queue: Solid Queue
- Cable: Solid Cable
- Cache: Solid Cache
- Ruby 3.4+ (or the version specified in
.ruby-version) - PostgreSQL
- Bundler
- Clone the repository:
git clone https://github.com/jovialen/nokroner-backend.git
cd nokroner-backend- Install dependencies:
bundle install- Set up the database:
bin/rails db:create
bin/rails db:migrate- Start the server:
bin/rails serverThe application will be available at http://localhost:3000.
Run the full test suite:
bin/rails testRun specific test files:
bin/rails test test/controllers/api/v1/user_controller_test.rbRun RuboCop for style checking:
bin/rubocopRun Brakeman for security analysis:
bin/brakemanRun Bundler Audit for dependency security:
bin/bundler-auditRun all CI checks:
bin/ciInteractive API documentation is available at /docs when the server is running.
Visit http://localhost:3000/docs to explore the API endpoints.
The API supports two authentication methods:
-
Bearer Token: Include the token in the Authorization header
Authorization: Bearer <your_token> -
Encrypted Cookie: Automatically set when logging in through the web interface
POST /api/v1/register- Create a new user accountPOST /api/v1/login- Authenticate and get session tokenDELETE /api/v1/logout- End current sessionGET /api/v1/me- Get current user informationDELETE /api/v1/me- Delete user account
GET /api/v1/me/profile- Get user profilePATCH /api/v1/me/profile- Update user profile
GET /api/v1/owners- List all ownersPOST /api/v1/owners- Create new ownerGET /api/v1/owners/:id- Get owner detailsPATCH /api/v1/owners/:id- Update ownerDELETE /api/v1/owners/:id- Delete owner
GET /api/v1/accounts- List all accountsGET /api/v1/owners/:owner_id/accounts- List accounts for specific ownerPOST /api/v1/accounts- Create new accountGET /api/v1/accounts/:id- Get account detailsPATCH /api/v1/accounts/:id- Update accountDELETE /api/v1/accounts/:id- Delete account
GET /api/v1/transactions- List all transactionsPOST /api/v1/transactions- Create new transactionGET /api/v1/transactions/:id- Get transaction detailsPATCH /api/v1/transactions/:id- Update transactionDELETE /api/v1/transactions/:id- Delete transaction
- User: User accounts with authentication
- Profile: User profile information (name, date of birth)
- Session: User authentication sessions
- Owner: Financial entities (user can have multiple)
- Account: Bank accounts belonging to owners
- Transaction: Financial transactions between accounts
- Users have one Profile and one Owner (as themselves)
- Users can create multiple additional Owners
- Owners have multiple Accounts
- Accounts have many sent and received Transactions
- Transactions belong to a User (creator)
Transactions automatically update account balances:
- Internal Transfer: Between two accounts owned by same owner
- External Transfer: Between accounts with different owners
- Income: Money coming into an account (from_account is nil)
- Expense: Money leaving an account (to_account is nil)
Account balances are automatically maintained through transaction callbacks.
Configure your environment variables in .env or through your deployment system:
POSTGRES_HOST- PostgreSQL host (default: localhost)POSTGRES_PORT- PostgreSQL port (default: 5432)POSTGRES_USER- PostgreSQL usernamePOSTGRES_PASSWORD- PostgreSQL passwordRAILS_MASTER_KEY- Rails master key for credentials
The application uses PostgreSQL with multiple databases in production:
- Primary database for main data
- Cache database for Rails cache
- Queue database for job queue
- Cable database for Action Cable
The application is configured for deployment with Kamal:
# Setup deployment
kamal setup
# Deploy
kamal deploy
# View logs
kamal logs -fSee config/deploy.yml for deployment configuration.
- Follow the Ruby style guide enforced by RuboCop
- Write tests for new features
- Ensure all tests pass before submitting PR
- Keep test coverage high
- Passwords are hashed using BCrypt
- Sessions use secure tokens
- CORS is configured for cross-origin requests
- API supports both cookie and bearer token authentication
- Regular security audits with Brakeman and Bundler Audit
This project is licensed under the GNU General Public License version 3 - see the LICENSE file for details.
Nicolai Frigaard - nicofri@pm.me
Project Link: https://github.com/jovialen/nokroner-backend