
- Create FastAPI app structure - Set up SQLAlchemy with SQLite for database management - Implement invoice and invoice item models - Add Alembic for database migrations - Create invoice generation and retrieval API endpoints - Add health check endpoint - Set up Ruff for linting - Update README with project details
3.3 KiB
3.3 KiB
Invoice Generation Service
This is a FastAPI application for generating and managing invoices. It allows you to create, read, update, and delete invoices without requiring user signup.
Features
- Generate invoices with automatic invoice number generation
- Store invoice details in SQLite database
- Retrieve invoice information by ID or invoice number
- Update invoice details and status
- Delete invoices
- Health check endpoint
Technical Stack
- Framework: FastAPI
- Database: SQLite with SQLAlchemy ORM
- Migrations: Alembic
- Validation: Pydantic
- Linting: Ruff
Project Structure
.
├── alembic.ini # Alembic configuration file
├── app # Application package
│ ├── api # API routes
│ │ └── routes # API route modules
│ │ ├── __init__.py # Routes initialization
│ │ └── invoices.py # Invoice routes
│ ├── core # Core functionality
│ │ ├── config.py # Application settings
│ │ ├── database.py # Database connection setup
│ │ └── utils.py # Utility functions
│ ├── models # SQLAlchemy models
│ │ ├── __init__.py # Models initialization
│ │ └── invoice.py # Invoice and InvoiceItem models
│ └── schemas # Pydantic schemas
│ ├── __init__.py # Schemas initialization
│ └── invoice.py # Invoice-related schemas
├── main.py # Application entry point
├── migrations # Alembic migrations
│ ├── env.py # Alembic environment
│ ├── script.py.mako # Migration script template
│ └── versions # Migration scripts
│ └── ef0aaab3a275_initial_database_tables.py # Initial migration
├── requirements.txt # Project dependencies
└── pyproject.toml # Ruff configuration
API Endpoints
Health Check
GET /health
: Check if the service is running
Invoice Management
POST /api/v1/invoices
: Create a new invoiceGET /api/v1/invoices
: List all invoices (with pagination)GET /api/v1/invoices/{invoice_id}
: Get a specific invoice by IDPOST /api/v1/invoices/find
: Find an invoice by invoice numberPATCH /api/v1/invoices/{invoice_id}
: Update an invoicePATCH /api/v1/invoices/{invoice_id}/status
: Update invoice statusDELETE /api/v1/invoices/{invoice_id}
: Delete an invoice
Setup and Installation
- Clone the repository
- Install dependencies:
pip install -r requirements.txt
- Run migrations:
alembic upgrade head
- Start the application:
uvicorn main:app --reload
API Documentation
Once the application is running, you can access:
- Interactive API documentation at
/docs
(Swagger UI) - Alternative API documentation at
/redoc
(ReDoc)
Invoice Number Format
Invoices are automatically assigned a unique invoice number with the format:
INV-YYYYMM-XXXXXX
, where:INV
is a fixed prefixYYYYMM
is the year and month (e.g., 202307 for July 2023)XXXXXX
is a random alphanumeric string