Spaces:
Sleeping
Sleeping
metadata
title: FinanceBackend
emoji: π°
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
Above credentials are for huggingface deployment
Finance Data Processing and Access Control Backend
A backend system for managing financial records with role-based access control. Built with FastAPI and SQLite.
Tech Stack
- Framework: FastAPI (Python)
- Database: SQLite via SQLAlchemy ORM
- Authentication: JWT (JSON Web Tokens)
- Password Hashing: bcrypt via passlib
- API Docs: Swagger UI (auto-generated)
Project Structure
finance-backend/
β
βββ main.py β FastAPI app entry point
βββ database.py β SQLite connection and session
βββ requirements.txt β Dependencies
βββ finance.db β Auto-generated SQLite database
β
βββ models/
β βββ user.py β User table
β βββ record.py β Financial Record table
β
βββ schemas/
β βββ user.py β User request/response schemas
β βββ record.py β Record request/response schemas
β
βββ routes/
β βββ auth.py β /auth endpoints
β βββ users.py β /users endpoints
β βββ records.py β /records endpoints
β βββ dashboard.py β /dashboard endpoints
β
βββ services/
β βββ auth_service.py β Auth business logic
β βββ user_service.py β User business logic
β βββ record_service.py β Record business logic
β βββ dashboard_service.py β Summary and analytics logic
β
βββ core/
βββ dependencies.py β JWT auth and role checker
βββ security.py β Password hashing and JWT utils
Deployed
- Base URL:
https://krrishsinha-financebackend.hf.space - Swagger UI For Testing The Backend:
https://krrishsinha-financebackend.hf.space/docs
Setup Instructions
In the terminal
1. Clone the repository
git clone https://github.com/krrishsinha20/FinanceBackend.git
cd FinanceBackend
2. Create virtual environment
python -m venv venv
3. Activate virtual environment
Windows:
venv\Scripts\activate
Mac/Linux:
source venv/bin/activate
4. Install dependencies
pip install -r requirements.txt
5. Run the server
uvicorn main:app --reload
6. Open Swagger UI
After this you will get a url in the terminal running on local host
Put that url in the browser and then on the local host url just put /docs at the end of url to see the backend endpoints and hencefurther for testing and using them
http://localhost:8000/docs
Note: The SQLite database (finance.db) is created automatically on first run. No manual database setup required.
How to Test
Step 1 β Register users
Use POST /auth/register to create users with different roles:
{ "name": "Admin User", "email": "admin@zorvyn.com", "password": "admin123", "role": "admin" }
{ "name": "Analyst User", "email": "analyst@zorvyn.com", "password": "analyst123", "role": "analyst" }
{ "name": "Viewer User", "email": "viewer@zorvyn.com", "password": "viewer123", "role": "viewer" }
Step 2 β Login
Use POST /auth/login or click Authorize on Swagger UI and enter credentials directly.
Step 3 β Add transactions (Admin only)
Use POST /records/ to add income and expense entries.
Step 4 β Test role restrictions
Switch between users in Authorize and verify access control behavior.
Roles and Permissions
| Feature | Viewer | Analyst | Admin |
|---|---|---|---|
| View records | Yes | Yes | Yes |
| View summary | Yes | Yes | Yes |
| View recent activity | Yes | Yes | Yes |
| View category wise breakdown | No | Yes | Yes |
| View monthly trends | No | Yes | Yes |
| Create/Edit/Delete records | No | No | Yes |
| Manage users | No | No | Yes |
API Endpoints
Auth
| Method | Endpoint | Description | Access |
|---|---|---|---|
| POST | /auth/register |
Register new user | Public |
| POST | /auth/login |
Login and get JWT token | Public |
Users
| Method | Endpoint | Description | Access |
|---|---|---|---|
| GET | /users/ |
Get all users | Admin |
| GET | /users/me |
Get current user info | All |
| GET | /users/{id} |
Get user by ID | Admin |
| PUT | /users/{id} |
Update user role or status | Admin |
| DELETE | /users/{id} |
Deactivate user (soft delete) | Admin |
Note: type field in records must be
incomeorexpense
Financial Records
| Method | Endpoint | Description | Access |
|---|---|---|---|
| POST | /records/ |
Create new transaction | Admin |
| GET | /records/ |
Get all transactions with filters | All |
| GET | /records/{id} |
Get single transaction | All |
| PUT | /records/{id} |
Update transaction | Admin |
| DELETE | /records/{id} |
Soft delete transaction | Admin |
Dashboard
| Method | Endpoint | Description | Access |
|---|---|---|---|
| GET | /dashboard/summary |
Total income, expense, net balance | All |
| GET | /dashboard/category-wise |
Category wise breakdown | Analyst + Admin |
| GET | /dashboard/monthly-trends |
Monthly income and expense trends | Analyst + Admin |
| GET | /dashboard/recent-activity |
Last 10 transactions | All |
Filtering Records
GET /records/ supports query parameters:
/records/?type=income
/records/?type=expense
/records/?category=salaries
/records/?start_date=2026-01-01&end_date=2026-04-01
Assumptions Made
- Roles are limited to three types:
viewer,analyst,admin - Only admins can create, update, or delete financial records
- Soft delete is used for both users and records β data is never permanently removed
- JWT tokens expire after 24 hours
- Password must be between 6 and 72 characters
- SQLite is used for simplicity as this is an assessment project
Tradeoffs Considered
- SQLite over PostgreSQL β easier setup for evaluators, no external DB server needed
- Passlib + bcrypt β industry standard password hashing, minor version compatibility resolved by pinning bcrypt==4.0.1
- Soft delete β records and users are never permanently deleted, maintains data integrity
- JWT over sessions β stateless authentication, better suited for API based systems
Author
Krrish Sinha Backend Developer Intern Assignment Zorvyn FinTech Pvt. Ltd.