CoolFace
Apppublic

adel-creative/invoice_api

sourceHugging Facemitupdated 11mo agoView on Hugging Face
0likes
App README

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)

bash
# 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

bash
# 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

bash
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

bash
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 user
  • โ€”POST /auth/login - Login and get JWT

Invoices

  • โ€”POST /invoices/generate - Create new invoice
  • โ€”GET /invoices/{id} - Get invoice by ID
  • โ€”GET /invoices/ - List all invoices
  • โ€”GET /invoices/{id}/download - Download PDF
  • โ€”POST /invoices/{id}/send-email - Send via email
  • โ€”PUT /invoices/{id} - Update invoice
  • โ€”DELETE /invoices/{id} - Delete invoice

Users

  • โ€”GET /users/me - Get user profile
  • โ€”PUT /users/me - Update profile
  • โ€”GET /users/me/stats - Get statistics

๐Ÿ” Environment Variables

env
# 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

bash
# Build and run
docker-compose up -d

# View logs
docker-compose logs -f

# Stop
docker-compose down

๐Ÿงช Testing

bash
# 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)

TierInvoices/MonthPriceEmail Sending
Free10\$05/day
Basic100\$9.9950/day
Pro500\$29.99200/day
EnterpriseUnlimitedCustomUnlimited

๐Ÿค Contributing

Contributions are welcome! Please follow these steps:

  1. 1.Fork the repository
  2. 2.Create feature branch (git checkout -b feature/AmazingFeature)
  3. 3.Commit changes (git commit -m 'Add AmazingFeature')
  4. 4.Push to branch (git push origin feature/AmazingFeature)
  5. 5.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


๐ŸŒŸ 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

bash
# 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.txt

2. Configuration

bash
# Copy environment template
cp .env.example .env

# Edit .env with your settings
nano .env

3. Database Setup

bash
# Initialize database
alembic upgrade head

4. Run the API

bash
# 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 4

5. Access API Documentation

  • โ€”Swagger UI: http://localhost:8000/docs
  • โ€”ReDoc: http://localhost:8000/redoc

๐Ÿ”‘ Environment Variables

env
# 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 user
  • โ€”POST /auth/login - Login and get JWT token
  • โ€”POST /auth/refresh - Refresh access token

Invoices

  • โ€”POST /invoices/generate - Create new invoice
  • โ€”GET /invoices/{invoice_id} - Get invoice by ID
  • โ€”GET /invoices/ - List all user invoices
  • โ€”GET /invoices/{invoice_id}/download - Download PDF
  • โ€”POST /invoices/{invoice_id}/send-email - Send invoice via email

Users

  • โ€”GET /users/me - Get current user info
  • โ€”PUT /users/me - Update user profile

๐Ÿงช Testing

bash
# Run all tests
pytest

# Run with coverage
pytest --cov=app tests/

# Run specific test file
pytest tests/test_invoices.py -v

๐Ÿณ Docker Deployment

bash
# 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

  1. 1.Fork the repository
  2. 2.Create feature branch (git checkout -b feature/AmazingFeature)
  3. 3.Commit changes (git commit -m 'Add some AmazingFeature')
  4. 4.Push to branch (git push origin feature/AmazingFeature)
  5. 5.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