Skip to content

hibeefrosh/Expense-Management-API

Repository files navigation

Expense Management API

A robust RESTful API for managing company expenses, built with Laravel 12.

Features

  • Multi-tenancy: Each company has its own isolated data environment
  • Role-based Access Control: Admin, Manager, and Employee roles with different permissions
  • Expense Management: Create, read, update, and delete expense records
  • User Management: Admin can manage users within their company
  • Audit Logging: Track all changes to expenses for accountability
  • Caching: Improved performance with database caching
  • Weekly Reports: Automated expense reports sent to company admins
  • API Authentication: Secure token-based authentication with Laravel Sanctum

Requirements

  • PHP 8.2+
  • MySQL 8.0+
  • Composer

Installation

  1. Clone the repository:

    
    cd expense-management-api
    
  2. Install dependencies:

    composer install
    
  3. Create and configure your environment file:

    cp .env.example .env
    
  4. Configure your database in the .env file:

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=expense_management
    DB_USERNAME=root
    DB_PASSWORD=
    
  5. Generate application key:

    php artisan key:generate
    
  6. Run migrations and seed the database:

    php artisan migrate --seed
    
  7. Start the development server:

    php artisan serve
    

API Endpoints

Authentication

  • POST /api/register - Register a new company and admin
  • POST /api/login - Login and get authentication token
  • POST /api/logout - Logout and invalidate token

Users

  • GET /api/users - List all users (Admin only)
  • GET /api/users/{id} - Get user details (Admin only)
  • POST /api/users - Create new user (Admin only)
  • PUT /api/users/{id} - Update user (Admin only)
  • DELETE /api/users/{id} - Delete user (Admin only)

Expenses

  • GET /api/expenses - List all expenses
  • GET /api/expenses/{id} - Get expense details
  • POST /api/expenses - Create new expense
  • PUT /api/expenses/{id} - Update expense (Admin/Manager only)
  • DELETE /api/expenses/{id} - Delete expense (Admin only)

Testing

Use Postman or any API client to test the endpoints. Sample requests are included in the documentation.

Scheduled Tasks

The application includes a scheduled task to send weekly expense reports to company admins every Monday at 8:00 AM.

To test this functionality manually, run:

php artisan expenses:send-weekly-report

php artisan queue:work

Security

This API implements:

  • Token-based authentication
  • Role-based access control
  • Cross-company data isolation
  • Input validation
  • Audit logging

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages