OAI is a graduation thesis project that implements a web-based invoice processing system using OCR and AI-assisted information extraction.
The system allows users to upload invoice images, extract text using OCR, parse invoice information into structured data, validate invoice consistency, manually review or correct extracted data, approve or reject invoices, and track all important changes through audit logs.
English: Design and implementation of an invoice processing system using OCR and AI-assisted information extraction.
Vietnamese: Xây dựng hệ thống xử lý hóa đơn ứng dụng OCR và AI hỗ trợ trích xuất, kiểm tra và quản lý dữ liệu hóa đơn.
- Reduce manual invoice data entry.
- Convert invoice images into structured invoice data.
- Compare rule-based extraction with AI-assisted extraction.
- Keep humans in the review and approval loop.
- Provide auditability for invoice operations.
- Build a maintainable layered .NET web application suitable for a real business workflow.
- .NET 10
- Blazor Web App with Interactive Server rendering
- ASP.NET Core Identity
- Entity Framework Core
- SQL Server
- Tesseract OCR
- OpenAI API for LLM-based invoice parsing
- Bootstrap 5
- xUnit for unit tests
OAI/
├── OAI.Domain
├── OAI.Application
├── OAI.Infrastructure
└── OAI.WebContains core business models and rules.
Main concepts:
VendorInvoiceInvoiceLineItemValidationIssueInvoiceExtractionResultAuditLogEntryMoneyvalue objectInvoiceStatusValidationSeverity
Responsibilities:
- Invoice amount calculation.
- Invoice consistency validation.
- Invoice status transitions.
- Domain-level business rules.
Contains use cases, DTOs, and application abstractions.
Main use cases:
- Create invoice
- Update invoice
- Validate invoice
- Approve invoice
- Reject invoice
- Move invoice back to pending review
- Get invoice list/detail
- Compare OCR/rule-based extraction with OCR/AI extraction
- Get dashboard summary
- Get validation issues
- Get audit logs
- Get system settings
- Manage vendors
Contains technical implementations.
Main components:
- EF Core
OaiDbContext - SQL Server repositories
- ASP.NET Core Identity persistence
- File storage service
- Tesseract OCR service
- Rule-based invoice text parser
- OpenAI invoice text parser
- Hybrid invoice text parser
- Invoice extraction comparison service
- Audit trail interceptor
- Demo data seeder
- System health service
Contains the Blazor UI.
Main screens:
- Login / logout
- Dashboard
- Upload invoice
- Invoice list
- Invoice detail
- Edit invoice
- OCR vs AI comparison
- Validation issues
- Vendor management
- Audit logs
- Settings
- Demo data tools in Development
- System health tools in Development
Upload invoice image
→ Save file
→ Run OCR with Tesseract
→ Parse OCR text
├── OpenAI parser if enabled and available
└── Rule-based parser fallback
→ Create invoice record
→ Validate consistency
→ PendingReview
→ Human review/edit
→ Approve or reject
→ Audit trackingThe system supports a hybrid extraction pipeline:
- Tesseract converts invoice image files into raw text.
- OpenAI parser attempts to convert raw OCR text into structured invoice data.
- Rule-based parser is used as fallback when AI is disabled, unavailable, or fails.
- Extraction results are stored with raw text, structured JSON, engine name, confidence score, attempt number, and status.
The system does not fully trust OCR or AI output. Extracted data is stored for review, then users with the correct permissions can edit normalized invoice data and re-run consistency validation.
PendingReview → Approved
PendingReview → Rejected
Approved → PendingReview
Approved → RejectedExported invoices are protected from invalid state transitions according to domain rules.
The system validates invoice consistency by comparing declared amounts with calculated amounts from line items.
Examples:
- Missing line items
- Subtotal mismatch
- Tax amount mismatch
- Total amount mismatch
- Unresolved error-level issues blocking approval
The system uses ASP.NET Core Identity with role-based and permission-based authorization.
Default roles:
AdministratorAccountantAuditorViewer
Permission examples:
dashboard.viewinvoices.viewinvoices.uploadinvoices.editinvoices.approveinvoices.rejectvendors.manageaudit_logs.viewsettings.view
The UI supports English and Vietnamese using .resx resource files.
- Default language: English
- Supported languages: English, Vietnamese
- Language switcher is available in the top bar
The system supports filters for operational screens.
Invoice list filters:
- Keyword
- Status
- Vendor
- Issue date from/to
- Paging
Dashboard filters:
- Issue date from/to
Audit log filters:
- Keyword
- Entity
- Action type
- Source
- User name
- Occurred date from/to
- Paging
Important data changes are captured through an EF Core SaveChanges interceptor.
Audit logs include:
- Entity name
- Entity ID
- Action type
- Old values
- New values
- User ID
- User name
- Source
- Occurred time
Audit detail is displayed through a dialog to keep the audit log list readable.
In Development environment, the system exposes tools for:
- Seeding demo data
- Resetting demo data
- Checking system health
System health checks include:
- Database connectivity
- Pending migrations
- Vendor count
- Invoice count
- Demo invoice count
- Audit log count
- Identity user count
- Identity role count
- File storage configuration
- OCR configuration
- LLM provider/model configuration
- .NET 10 SDK
- SQL Server
- Tesseract OCR language data files in
OAI/OAI.Web/tessdata - Optional: OpenAI API key for AI-assisted extraction
Development settings are stored in:
OAI/OAI.Web/appsettings.Development.jsonImportant configuration sections:
{
"ConnectionStrings": {
"DefaultConnection": "Server=.;Database=OaiDB;Trusted_Connection=True;TrustServerCertificate=True"
},
"FileStorage": {
"RootPath": "storage",
"InvoiceFolder": "invoices",
"MaxFileSizeBytes": 20971520
},
"Ocr": {
"TessDataPath": "tessdata",
"Languages": "eng+vie"
},
"Llm": {
"Enabled": true,
"Provider": "OpenAI",
"Model": "gpt-4.1-mini",
"MaxInputCharacters": 12000
}
}Do not commit real API keys to source control. Use user secrets or environment variables.
Example:
cd OAI
dotnet user-secrets set "Llm:ApiKey" "sk-..." --project OAI.Web/OAI.Web.csprojTo disable AI parsing and use rule-based extraction only:
"Llm": {
"Enabled": false
}Run these commands from the repository root:
cd OAI
dotnet ef database update --project OAI.Infrastructure/OAI.Infrastructure.csproj --startup-project OAI.Web/OAI.Web.csprojTo create a new migration:
cd OAI
dotnet ef migrations add MigrationName --project OAI.Infrastructure/OAI.Infrastructure.csproj --startup-project OAI.Web/OAI.Web.csproj --context OaiDbContextFrom the repository root:
cd OAI
dotnet run --project OAI.Web/OAI.Web.csprojThen open the local URL printed by the application.
The Development configuration can seed these users:
| Role | Password | |
|---|---|---|
| Administrator | admin@oai.local |
Admin@123456 |
| Accountant | accountant@oai.local |
Accountant@123456 |
| Auditor | auditor@oai.local |
Auditor@123456 |
| Viewer | viewer@oai.local |
Viewer@123456 |
These accounts are for local development and demonstration only. Change or remove them before production use.
Run all tests:
cd OAI
dotnet testRun a specific test project:
cd OAI
dotnet test OAI.Domain.Tests/OAI.Domain.Tests.csproj
dotnet test OAI.Application.Tests/OAI.Application.Tests.csprojA recommended demo flow:
- Log in as Administrator or Accountant.
- Open Dashboard and show date range filters.
- Upload a sample invoice image.
- Open Invoice List and use filters.
- Open Invoice Detail.
- Show Overview, Line Items, Validation, and Extraction History tabs.
- Open extraction result detail to show raw OCR text and structured JSON.
- Edit invoice data and revalidate.
- Approve or reject the invoice.
- Open Audit Logs and view audit detail dialog.
- Switch language between English and Vietnamese.
- Open system settings or health tools in Development.
This project demonstrates:
- A practical invoice processing workflow using OCR and AI.
- A layered .NET implementation with separation of concerns.
- Hybrid extraction using rule-based and AI-assisted parsing.
- Validation logic for invoice consistency.
- Human-in-the-loop correction and approval.
- Authentication and role/permission-based authorization.
- Audit logging for traceability.
- Localization using
.resx. - Filtering, paging, demo data, and system health support.
- The project currently focuses on image invoices. PDF support can be added in a later phase.
- OpenAI API billing is separate from ChatGPT Plus.
- If OpenAI fails or quota is insufficient, the system can fall back to rule-based parsing.
- Keep secrets out of
appsettings.json.