adel-creative/invoice_api
Professional bilingual invoice generator for freelancers and businesses
๐ Features
โ Bilingual PDF Generation - Professional invoices in Arabic and English โ JWT Authentication - Secure user authentication โ Email Sending - Send invoices directly to clients โ QR Code Integration - Generate QR codes for easy payment โ Multi-Currency Support - MAD, USD, EUR, SAR, AED โ Payment Links - Unique payment links per user โ RESTful API - Clean and documented API โ RapidAPI Ready - Ready to publish on RapidAPI
๐ Quick Start
Prerequisites
- Python 3.11+
- pip
Installation (2 minutes)
# Clone repository
git clone https://github.com/yourusername/invoice-api.git
cd invoice-api
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Configure environment
cp .env.example .env
# Edit .env with your settings
# Initialize database
python -c "from app.database import init_db; init_db()"
# Run the API
uvicorn app.main:app --reload๐ API is running at: http://localhost:8000 ๐ Documentation: http://localhost:8000/docs
๐ Documentation
- [Quick Start Guide](QUICK_START.md) - Get started in 10 minutes
- [API Documentation](API_DOCUMENTATION.md) - Complete API reference
- [Deployment Guide](DEPLOYMENT.md) - Production deployment
- [Postman Collection](Invoice_API.postman_collection.json) - Import and test
๐ฏ Example Usage
1. Register & Login
# Register
curl -X POST http://localhost:8000/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "john@example.com",
"username": "john_doe",
"password": "securepass123",
"company_name": "John Consulting"
}'
# Login
curl -X POST http://localhost:8000/auth/login \
-H "Content-Type: application/json" \
-d '{
"username": "john_doe",
"password": "securepass123"
}'2. Create Invoice
TOKEN="your_jwt_token"
curl -X POST http://localhost:8000/invoices/generate \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"client_name": "ACME Corp",
"client_email": "billing@acme.com",
"language": "ar",
"currency": "MAD",
"items": [
{
"name": "Web Development",
"quantity": 1,
"price": 15000
}
],
"tax_rate": 20
}'3. Send Invoice via Email
curl -X POST http://localhost:8000/invoices/1/send-email \
-H "Authorization: Bearer $TOKEN"๐ Project Structure
invoice-api/
โโโ app/
โ โโโ main.py # FastAPI application
โ โโโ config.py # Configuration
โ โโโ database.py # Database setup
โ โโโ models/ # SQLAlchemy models
โ โโโ schemas/ # Pydantic schemas
โ โโโ api/ # API endpoints
โ โโโ services/ # Business logic
โ โโโ templates/ # Invoice templates
โ โโโ utils/ # Helper functions
โโโ tests/ # Unit tests
โโโ static/ # Generated files
โโโ requirements.txt # Dependencies
โโโ .env.example # Environment template
โโโ docker-compose.yml # Docker configuration๐ ๏ธ Tech Stack
- Framework: FastAPI 0.109.0
- Database: SQLAlchemy + SQLite/PostgreSQL
- PDF Generation: WeasyPrint + Jinja2
- QR Codes: qrcode + segno
- Email: aiosmtplib
- Authentication: JWT (python-jose)
- Validation: Pydantic
๐ API Endpoints
Authentication
POST /auth/register- Register new userPOST /auth/login- Login and get JWT
Invoices
POST /invoices/generate- Create new invoiceGET /invoices/{id}- Get invoice by IDGET /invoices/- List all invoicesGET /invoices/{id}/download- Download PDFPOST /invoices/{id}/send-email- Send via emailPUT /invoices/{id}- Update invoiceDELETE /invoices/{id}- Delete invoice
Users
GET /users/me- Get user profilePUT /users/me- Update profileGET /users/me/stats- Get statistics
๐ Environment Variables
# Database
DATABASE_URL=sqlite:///./invoices.db
# Security
SECRET_KEY=your-super-secret-key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
# Email (SendGrid example)
EMAIL_HOST=smtp.sendgrid.net
EMAIL_PORT=587
EMAIL_USERNAME=apikey
EMAIL_PASSWORD=your-api-key
EMAIL_FROM=noreply@yourdomain.com
# App
DEBUG=true
ALLOWED_ORIGINS=http://localhost:3000๐ณ Docker Deployment
# Build and run
docker-compose up -d
# View logs
docker-compose logs -f
# Stop
docker-compose down๐งช Testing
# Run all tests
pytest
# With coverage
pytest --cov=app tests/
# Specific test file
pytest tests/test_invoices.py -v๐ Features Roadmap
โ MVP (Current)
- [x] Bilingual PDF generation
- [x] JWT authentication
- [x] Email sending
- [x] QR codes
- [x] Multi-currency
๐ Phase 2
- [ ] Payment gateway integration (Stripe, PayPal)
- [ ] Webhook notifications
- [ ] Recurring invoices
- [ ] Invoice templates customization
- [ ] Multi-language expansion
๐ฎ Phase 3
- [ ] Mobile SDK
- [ ] Advanced analytics
- [ ] Team collaboration
- [ ] API rate limiting tiers
- [ ] White-label solution
๐ฐ Pricing Tiers (Suggested)
๐ค Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- FastAPI for the amazing framework
- WeasyPrint for PDF generation
- The open-source community
๐ Support
- Documentation: Full Docs
- Email: support@yourdomain.com
- Issues: GitHub Issues
- Discord: Join our community
๐ Show Your Support
If this project helped you, give it a โญ๏ธ on GitHub!
Made with โค๏ธ for freelancers and small businesses in MENA
Get Started | API Docs | Deploy
invoice-api/
โโโ app/
โ โโโ __init__.py
โ โโโ main.py # FastAPI app entry point
โ โโโ config.py # Configuration & environment variables
โ โโโ database.py # Database connection
โ โ
โ โโโ models/
โ โ โโโ __init__.py
โ โ โโโ user.py # User database model
โ โ โโโ invoice.py # Invoice database model
โ โ
โ โโโ schemas/
โ โ โโโ __init__.py
โ โ โโโ user.py # User Pydantic schemas
โ โ โโโ invoice.py # Invoice Pydantic schemas
โ โ โโโ auth.py # Authentication schemas
โ โ
โ โโโ api/
โ โ โโโ __init__.py
โ โ โโโ auth.py # Authentication endpoints
โ โ โโโ invoices.py # Invoice CRUD endpoints
โ โ โโโ users.py # User management endpoints
โ โ
โ โโโ services/
โ โ โโโ __init__.py
โ โ โโโ auth_service.py # JWT & password handling
โ โ โโโ pdf_service.py # PDF generation
โ โ โโโ qr_service.py # QR code generation
โ โ โโโ email_service.py # Email sending
โ โ
โ โโโ templates/
โ โ โโโ invoice_ar.html # Arabic invoice template
โ โ โโโ invoice_en.html # English invoice template
โ โ
โ โโโ utils/
โ โโโ __init__.py
โ โโโ dependencies.py # FastAPI dependencies
โ โโโ helpers.py # Helper functions
โ
โโโ tests/
โ โโโ __init__.py
โ โโโ test_auth.py
โ โโโ test_invoices.py
โ โโโ test_services.py
โ
โโโ alembic/ # Database migrations
โ โโโ versions/
โ โโโ env.py
โ
โโโ static/ # Generated PDFs & QR codes
โ โโโ invoices/
โ โโโ qr_codes/
โ
โโโ .env.example # Environment variables template
โโโ .gitignore
โโโ requirements.txt
โโโ alembic.ini
โโโ README.md
โโโ docker-compose.yml # Optional: for deployment๐ Quick Start
1. Installation
# Clone the repository
git clone <your-repo-url>
cd invoice-api
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt2. Configuration
# Copy environment template
cp .env.example .env
# Edit .env with your settings
nano .env3. Database Setup
# Initialize database
alembic upgrade head4. Run the API
# Development mode
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
# Production mode
uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 45. Access API Documentation
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
๐ Environment Variables
# Database
DATABASE_URL=sqlite:///./invoices.db
# For PostgreSQL: postgresql://user:password@localhost/dbname
# Security
SECRET_KEY=your-super-secret-key-change-this-in-production
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
# Email (SendGrid example)
EMAIL_HOST=smtp.sendgrid.net
EMAIL_PORT=587
EMAIL_USERNAME=apikey
EMAIL_PASSWORD=your-sendgrid-api-key
EMAIL_FROM=noreply@yourdomain.com
# App Settings
APP_NAME=Invoice Generator API
APP_VERSION=1.0.0
DEBUG=true๐ API Endpoints
Authentication
POST /auth/register- Register new userPOST /auth/login- Login and get JWT tokenPOST /auth/refresh- Refresh access token
Invoices
POST /invoices/generate- Create new invoiceGET /invoices/{invoice_id}- Get invoice by IDGET /invoices/- List all user invoicesGET /invoices/{invoice_id}/download- Download PDFPOST /invoices/{invoice_id}/send-email- Send invoice via email
Users
GET /users/me- Get current user infoPUT /users/me- Update user profile
๐งช Testing
# Run all tests
pytest
# Run with coverage
pytest --cov=app tests/
# Run specific test file
pytest tests/test_invoices.py -v๐ณ Docker Deployment
# Build and run with Docker Compose
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down๐ Features
โ MVP Features (Stage 1)
- [x] Bilingual PDF generation (Arabic + English)
- [x] JWT Authentication
- [x] Invoice CRUD operations
- [x] QR Code generation
- [x] Unique payment links
- [x] Email sending capability
- [x] PDF download
- [x] RapidAPI ready
๐ฎ Future Features
- [ ] Payment gateway integration (Stripe, PayPal)
- [ ] Multi-language support
- [ ] Subscription tiers
- [ ] Advanced analytics
- [ ] Webhook notifications
๐ค Contributing
- Fork the repository
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add some AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open Pull Request
๐ License
MIT License - feel free to use for commercial projects
๐ฌ Support
- Documentation:
/docs - Email: support@yourdomain.com
- Issues: GitHub Issues
Made with โค๏ธ for freelancers and small businesses in MENA
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
