
- Add project root to Python path in migrations/env.py - Change database URL configuration to ensure database directory exists - Update alembic.ini to use relative database path - Make database URL configuration more resilient
SaaS Invoicing Application
A comprehensive SaaS invoicing application built with FastAPI and SQLite, designed for businesses to manage organizations, clients, and invoices efficiently.
Features
- Multi-tenant Architecture: Supports multiple organizations with user management
- User Authentication: Secure JWT-based authentication and role-based permissions
- Organization Management: Create and manage organizations with detailed information
- Client Management: Maintain a database of clients for each organization
- Invoice Management: Create, update, and delete invoices with line items
- PDF Generation: Generate professional PDF invoices for sharing with clients
- API Documentation: Interactive API documentation with Swagger UI and ReDoc
Prerequisites
- Python 3.8+
- pip (Python package manager)
Environment Variables
The application uses the following environment variables:
Variable | Description | Default Value |
---|---|---|
SECRET_KEY | Secret key for JWT token generation | CHANGE_ME_TO_A_SECURE_RANDOM_STRING |
ACCESS_TOKEN_EXPIRE_MINUTES | Access token expiration time in minutes | 30 |
SERVER_HOST | Host URL for the server | http://localhost:8000 |
Installation
- Clone the repository:
git clone https://github.com/yourusername/saasinvoicingapplication.git
cd saasinvoicingapplication
- Create a virtual environment (optional but recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Create a
.env
file with your environment variables:
SECRET_KEY=your-secure-secret-key
ACCESS_TOKEN_EXPIRE_MINUTES=30
SERVER_HOST=http://localhost:8000
- Initialize the database:
mkdir -p /app/storage/db
python -c "from app.db.base import Base; from app.db.session import engine; Base.metadata.create_all(bind=engine)"
alembic upgrade head
Running the Application
Start the application using uvicorn:
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
The API will be available at:
- API: http://localhost:8000
- Swagger UI Documentation: http://localhost:8000/docs
- ReDoc Documentation: http://localhost:8000/redoc
API Structure
The API follows a RESTful design and is structured as follows:
Authentication Endpoints
POST /api/v1/auth/token
- Get access tokenPOST /api/v1/auth/test-token
- Test token validity
User Management
GET /api/v1/users/
- List users (admin only)POST /api/v1/users/
- Create user (admin only)GET /api/v1/users/me
- Get current user infoPUT /api/v1/users/me
- Update current userGET /api/v1/users/{user_id}
- Get user by IDPUT /api/v1/users/{user_id}
- Update user (admin only)
Organization Management
GET /api/v1/organizations/
- List organizationsPOST /api/v1/organizations/
- Create organization (admin only)GET /api/v1/organizations/{id}
- Get organization by IDPUT /api/v1/organizations/{id}
- Update organizationDELETE /api/v1/organizations/{id}
- Delete organization (admin only)
Client Management
GET /api/v1/clients/
- List clientsPOST /api/v1/clients/
- Create clientGET /api/v1/clients/{id}
- Get client by IDPUT /api/v1/clients/{id}
- Update clientDELETE /api/v1/clients/{id}
- Delete client
Invoice Management
GET /api/v1/invoices/
- List invoicesPOST /api/v1/invoices/
- Create invoiceGET /api/v1/invoices/{id}
- Get invoice by IDPUT /api/v1/invoices/{id}
- Update invoiceDELETE /api/v1/invoices/{id}
- Delete invoiceGET /api/v1/invoices/{id}/pdf
- Generate PDF for invoice
Data Models
User
id
: Unique identifieremail
: Email address (unique)full_name
: Full namehashed_password
: Hashed passwordis_active
: User statusis_superuser
: Admin statusorganization_id
: Associated organization
Organization
id
: Unique identifiername
: Organization nameaddress
,city
,state
,postal_code
,country
: Address informationphone
,email
,website
: Contact informationtax_id
: Tax identification numberlogo_url
: URL to organization logo
Client
id
: Unique identifiername
: Client namecontact_name
: Primary contactemail
,phone
: Contact informationaddress
,city
,state
,postal_code
,country
: Address informationtax_id
: Tax identification numbernotes
: Additional notesorganization_id
: Associated organizationcreated_by_id
: User who created the client
Invoice
id
: Unique identifierinvoice_number
: Invoice reference numberstatus
: Invoice status (draft, sent, paid, overdue, cancelled)issue_date
,due_date
: Invoice datessubtotal
,tax_rate
,tax_amount
,discount
,total
: Financial informationnotes
,terms
: Additional informationis_recurring
,recurring_interval
: Recurring invoice detailsclient_id
: Associated clientorganization_id
: Associated organizationcreated_by_id
: User who created the invoice
InvoiceItem
id
: Unique identifierdescription
: Item descriptionquantity
,unit_price
,amount
: Item detailsinvoice_id
: Associated invoice
Development
Running Tests
Run tests using pytest:
pytest
Database Migrations
Generate a new migration after model changes:
alembic revision --autogenerate -m "Description of changes"
Apply migrations:
alembic upgrade head
License
This project is licensed under the MIT License - see the LICENSE file for details.
Description
Languages
Python
99.2%
Mako
0.8%