156 lines
5.0 KiB
Markdown
156 lines
5.0 KiB
Markdown
# SaaS Invoicing Application
|
|
|
|
A SaaS invoicing application backend built with FastAPI and SQLite. This application provides a complete solution for managing customers, products/services, invoices, and payments with user authentication and authorization.
|
|
|
|
## Features
|
|
|
|
- **User Management**: Registration, authentication, and profile management
|
|
- **Customer Management**: Store and manage customer information
|
|
- **Product/Service Catalog**: Manage your products and services with pricing
|
|
- **Invoice Management**: Create, update, and manage invoices
|
|
- **PDF Invoice Generation**: Generate professional PDF invoices
|
|
- **Payment Tracking**: Record and track payments for invoices
|
|
- **Multi-tenant Architecture**: Each user has their own isolated data
|
|
|
|
## Technology Stack
|
|
|
|
- **Backend**: FastAPI
|
|
- **Database**: SQLite with SQLAlchemy ORM
|
|
- **Authentication**: JWT tokens
|
|
- **PDF Generation**: WeasyPrint
|
|
- **Migrations**: Alembic
|
|
- **Validation**: Pydantic
|
|
|
|
## Getting Started
|
|
|
|
### Prerequisites
|
|
|
|
- Python 3.8+
|
|
- Pip package manager
|
|
|
|
### Installation
|
|
|
|
1. Clone the repository:
|
|
|
|
```bash
|
|
git clone <repository-url>
|
|
cd saasinvoicingapplication
|
|
```
|
|
|
|
2. Set up a virtual environment:
|
|
|
|
```bash
|
|
python -m venv venv
|
|
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
```
|
|
|
|
3. Install dependencies:
|
|
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
4. Set up environment variables (or create a `.env` file):
|
|
|
|
```
|
|
SECRET_KEY=your-secret-key # Change this in production!
|
|
```
|
|
|
|
5. Run database migrations:
|
|
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
|
|
### Running the Application
|
|
|
|
Start the application with Uvicorn:
|
|
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
The API will be available at [http://localhost:8000](http://localhost:8000), and the interactive documentation at [http://localhost:8000/docs](http://localhost:8000/docs).
|
|
|
|
## API Documentation
|
|
|
|
The API is fully documented with OpenAPI and is available at the `/docs` endpoint. The main endpoints include:
|
|
|
|
- **Authentication**: `/api/v1/auth/*`
|
|
- Register: POST `/api/v1/auth/register`
|
|
- Login: POST `/api/v1/auth/login`
|
|
- JSON Login: POST `/api/v1/auth/login/json`
|
|
|
|
- **Users**: `/api/v1/users/*`
|
|
- Get current user: GET `/api/v1/users/me`
|
|
- Update current user: PATCH `/api/v1/users/me`
|
|
|
|
- **Customers**: `/api/v1/customers/*`
|
|
- List customers: GET `/api/v1/customers`
|
|
- Create customer: POST `/api/v1/customers`
|
|
- Get customer: GET `/api/v1/customers/{customer_id}`
|
|
- Update customer: PATCH `/api/v1/customers/{customer_id}`
|
|
- Delete customer: DELETE `/api/v1/customers/{customer_id}`
|
|
|
|
- **Products**: `/api/v1/products/*`
|
|
- List products: GET `/api/v1/products`
|
|
- Create product: POST `/api/v1/products`
|
|
- Get product: GET `/api/v1/products/{product_id}`
|
|
- Update product: PATCH `/api/v1/products/{product_id}`
|
|
- Delete product: DELETE `/api/v1/products/{product_id}`
|
|
|
|
- **Invoices**: `/api/v1/invoices/*`
|
|
- List invoices: GET `/api/v1/invoices`
|
|
- Create invoice: POST `/api/v1/invoices`
|
|
- Get invoice: GET `/api/v1/invoices/{invoice_id}`
|
|
- Update invoice: PATCH `/api/v1/invoices/{invoice_id}`
|
|
- Delete invoice: DELETE `/api/v1/invoices/{invoice_id}`
|
|
- Update status: PATCH `/api/v1/invoices/{invoice_id}/status`
|
|
- Generate PDF: GET `/api/v1/invoices/{invoice_id}/pdf`
|
|
|
|
- **Payments**: `/api/v1/payments/*`
|
|
- List payments: GET `/api/v1/payments`
|
|
- List invoice payments: GET `/api/v1/payments/invoice/{invoice_id}`
|
|
- Create payment: POST `/api/v1/payments`
|
|
- Get payment: GET `/api/v1/payments/{payment_id}`
|
|
- Update payment: PATCH `/api/v1/payments/{payment_id}`
|
|
- Delete payment: DELETE `/api/v1/payments/{payment_id}`
|
|
|
|
## Environment Variables
|
|
|
|
The following environment variables can be configured:
|
|
|
|
- `SECRET_KEY`: Secret key for JWT token encryption (required)
|
|
- `ACCESS_TOKEN_EXPIRE_MINUTES`: Token expiration time in minutes (default: 60 * 24 * 7)
|
|
- `PROJECT_NAME`: Application name (default: "SaaS Invoicing Application")
|
|
- `BACKEND_CORS_ORIGINS`: CORS origins allowed (default: "*")
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
├── alembic.ini # Alembic configuration
|
|
├── app/ # Application package
|
|
│ ├── api/ # API endpoints
|
|
│ │ └── v1/ # API version 1
|
|
│ ├── core/ # Core functionality
|
|
│ ├── crud/ # CRUD operations
|
|
│ ├── db/ # Database setup
|
|
│ ├── models/ # SQLAlchemy models
|
|
│ ├── schemas/ # Pydantic schemas
|
|
│ ├── services/ # Business logic services
|
|
│ ├── templates/ # HTML templates for PDF generation
|
|
│ └── utils/ # Utility functions
|
|
├── migrations/ # Alembic migrations
|
|
│ ├── versions/ # Migration scripts
|
|
│ └── env.py # Migration environment
|
|
├── main.py # Application entry point
|
|
└── requirements.txt # Project dependencies
|
|
```
|
|
|
|
## License
|
|
|
|
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
|
|
## Contributing
|
|
|
|
Contributions are welcome! Please feel free to submit a Pull Request. |