
- Implemented complete authentication system with JWT tokens - Created user management with registration and profile endpoints - Built client management with full CRUD operations - Developed invoice system with line items and automatic calculations - Set up SQLite database with proper migrations using Alembic - Added health monitoring and API documentation - Configured CORS for cross-origin requests - Included comprehensive README with usage examples
SaaS Invoicing Application
A comprehensive invoicing solution for businesses built with FastAPI and SQLite.
Features
- User Authentication: JWT-based authentication system
- Client Management: Create, read, update, and delete clients
- Invoice Management: Full CRUD operations for invoices with line items
- Health Monitoring: Built-in health check endpoint
- API Documentation: Interactive API docs with Swagger UI
Tech Stack
- Backend: FastAPI
- Database: SQLite with SQLAlchemy ORM
- Authentication: JWT tokens with bcrypt password hashing
- Migrations: Alembic
- Code Quality: Ruff for linting and formatting
Project Structure
├── main.py # FastAPI application entry point
├── requirements.txt # Python dependencies
├── alembic.ini # Alembic configuration
├── migrations/ # Database migrations
├── app/
│ ├── core/ # Core functionality (auth, config)
│ ├── db/ # Database configuration
│ ├── models/ # SQLAlchemy models
│ ├── routers/ # API route handlers
│ └── schemas/ # Pydantic schemas
Installation
- Install dependencies:
pip install -r requirements.txt
- Set up environment variables:
export SECRET_KEY="your-secret-key-here"
- Run database migrations:
alembic upgrade head
- Start the application:
uvicorn main:app --reload
Environment Variables
SECRET_KEY
: JWT secret key for token signing (required)
API Endpoints
Authentication
POST /auth/login
- User login
Users
POST /users/register
- Register new userGET /users/me
- Get current user profile
Clients
POST /clients/
- Create new clientGET /clients/
- List all clientsGET /clients/{id}
- Get specific clientPUT /clients/{id}
- Update clientDELETE /clients/{id}
- Delete client
Invoices
POST /invoices/
- Create new invoiceGET /invoices/
- List all invoicesGET /invoices/{id}
- Get specific invoicePUT /invoices/{id}
- Update invoiceDELETE /invoices/{id}
- Delete invoice
Health
GET /health
- Application health check
API Documentation
Once the application is running, you can access:
- Interactive API docs: http://localhost:8000/docs
- ReDoc documentation: http://localhost:8000/redoc
- OpenAPI JSON: http://localhost:8000/openapi.json
Database
The application uses SQLite database stored at /app/storage/db/db.sqlite
. The database includes tables for:
- Users (authentication and profile data)
- Clients (customer information)
- Invoices (invoice headers)
- Invoice Items (line items for invoices)
Development
Code Quality
# Run linting and formatting
ruff check .
ruff format .
Database Migrations
# Create new migration
alembic revision --autogenerate -m "Description"
# Apply migrations
alembic upgrade head
Usage Example
- Register a new user:
curl -X POST "http://localhost:8000/users/register" \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "password123",
"full_name": "John Doe",
"company_name": "ACME Corp"
}'
- Login to get access token:
curl -X POST "http://localhost:8000/auth/login" \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "password123"
}'
- Create a client (use the token from step 2):
curl -X POST "http://localhost:8000/clients/" \
-H "Authorization: Bearer YOUR_TOKEN_HERE" \
-H "Content-Type: application/json" \
-d '{
"name": "Client Company",
"email": "client@example.com",
"phone": "+1234567890",
"address": "123 Main St, City, State 12345"
}'
- Create an invoice:
curl -X POST "http://localhost:8000/invoices/" \
-H "Authorization: Bearer YOUR_TOKEN_HERE" \
-H "Content-Type: application/json" \
-d '{
"invoice_number": "INV-001",
"client_id": 1,
"due_date": "2024-02-01T00:00:00",
"tax_rate": 8.5,
"items": [
{
"description": "Web Development Services",
"quantity": 40,
"unit_price": 75.00
}
]
}'
License
This project is licensed under the MIT License.
Description
Languages
Python
98.2%
Mako
1.8%