Skip to content

Commit e0cb8c7

Browse files
committed
fix: restructure architecture part
1 parent 981ae8c commit e0cb8c7

1 file changed

Lines changed: 80 additions & 77 deletions

File tree

README.md

Lines changed: 80 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -239,95 +239,98 @@ MatchFlow delivers real, measurable value by automating repetitive finance tasks
239239

240240

241241
<a id="architecture"></a>
242-
## Architecture
242+
## Architecture
243243

244-
[![Architecture Diagram](/frontend/public/architecture.svg)](/frontend/public/architecture.svg)
244+
MatchFlow’s architecture is described in two C4-style component views plus a layer breakdown:
245245

246-
[View on Eraser![](https://app.eraser.io/workspace/1wX2yEL4ckFloMZ5chjD/preview?elements=22osCHEEW3uJF1qCVzKzKQ&type=embed)](https://app.eraser.io/workspace/1wX2yEL4ckFloMZ5chjD?elements=22osCHEEW3uJF1qCVzKzKQ)
246+
1. **System Context & High-Level Components**
247+
2. **Detailed Clean-Architecture Components**
248+
3. **Layer-by-Layer Breakdown**
247249

248-
MatchFlow is built on Clean Architecture principles, with clear separation of concerns across six horizontal layers. Requests flow from left to right (and back), while dependencies always point inward toward the core Domain layer. Below is a breakdown of each layer, the major components within it, and the primary data flows.
250+
---
249251

250-
### 1. Client Layer
251-
- **Browser (React SPA)**
252-
- Contains ten page components:
253-
AuthPage, LandingPage, CreatePOPage, PurchaseOrdersPage, PurchaseOrderDetailsPage, DashboardPage, InvoicePage, AutoMatchPage, UploadInvoicePage, and UploadResultPage.
254-
- Sends and receives JWT-protected HTTPS calls to the Nginx proxy.
255-
256-
### 2. Presentation Layer
257-
- **Nginx Reverse Proxy** (Fly.io container “React+Nginx”)
258-
- Terminates TLS, serves the React bundle, and forwards API requests.
259-
- **API Gateway** (.NET 6 Web API, Fly.io container “Backend”)
260-
- Hosts all controllers and orchestrates application logic.
261-
- **Redirector** (Fly.io container)
262-
- Routes requests from `matchflow.app``www.matchflow.app`.
263-
264-
### 3. Controller Layer
265-
_All running inside the API Gateway container:_
266-
- **AuthController** (handles login, JWT issuance & validation)
267-
- **PurchaseOrderListController**
268-
- **InvoiceListController**
269-
- **InvoiceMatchController**
270-
- **InvoiceUploadController**
271-
272-
### 4. Application Layer
273-
- **Services** (use-case implementations):
274-
- `CreatePurchaseOrderService`
275-
- `MatchingService`
276-
- `UploadInvoiceService`
277-
- `JWT Issuance & Validation` (via UserService)
278-
- **Ports / Interfaces** (abstractions for infrastructure):
279-
- `IInvoiceRepository`, `IPurchaseOrderRepository`
280-
- `IFormRecognizer`, `IBlobStorage`
281-
- `IExceptionRecordRepository`, `IServiceBusClient`, `IUserService`
282-
- Dependencies are injected here, following the Dependency Inversion Principle.
283-
284-
### 5. Infrastructure Layer
285-
_Concrete implementations of all ports:_
286-
- **EF Core Repositories**: `InvoiceRepository`, `PurchaseOrderRepository`, `ExceptionRecordRepository`, backed by `AppDbContext`
287-
- **Azure Clients**: `BlobStorageService`, `FormRecognizerClient`, `ServiceBusClient`
288-
- **UserService** (JWT key management & refresh logic)
289-
290-
### 6. Domain Layer
291-
_Pure business entities with no external dependencies:_
292-
- `Invoice`, `PurchaseOrder`, `InvoiceLineItem`, `PurchaseOrderLineItem`, `ExceptionRecord`, `User`
293-
294-
### Cloud Services
295-
- **Azure Blob Storage** (PDF persistence)
296-
- **Azure Form Recognizer** (OCR)
297-
- **Azure SQL Database** (POs, invoices, audit logs)
298-
- **Azure Service Bus** (discrepancy messaging)
299-
- **Application Insights** (telemetry & logging)
300-
301-
### Local Development
302-
- **Docker Compose** spins up all containers (React+Nginx, API, SQL emulator, Blob emulator, etc.) for end-to-end testing without Azure.
252+
### 1. System Context & High-Level Components
253+
*Who uses the system and the major “boxes” it interacts with*
303254

304-
---
255+
![System Context Diagram](/frontend/public/context_diagram.png)
256+
![High-Level Component Diagram](/frontend/public/component_diagram.png)
305257

306-
### Primary Data Flows
307-
308-
1. **User Upload**
309-
Browser → Nginx (HTTPS + JWT) → API Gateway
310-
2. **Invoice Processing**
311-
`UploadInvoiceController` → UploadInvoiceService
312-
→ BlobStorageService → Azure Blob (POST PDF)
313-
→ FormRecognizerClient → Azure Form Recognizer (extract JSON)
314-
3. **Matching Logic**
315-
`UploadInvoiceService` → MatchingService → EF Repositories → Azure SQL
316-
4. **Discrepancy Handling**
317-
On mismatch, UploadInvoiceService → ServiceBusClient → Azure Service Bus
318-
Front-end polls/subscribes for results
319-
5. **Telemetry**
320-
All API calls and repository operations log to Application Insights
258+
- **Users** (Invoice Managers) in their browser
259+
- **React SPA + Nginx** (Fly.io container “React+Nginx”): serves UI, terminates TLS, forwards API calls
260+
- **.NET 6 API Gateway** (Fly.io container “Backend”): hosts all Controllers and Services
261+
- **Redirector** (Fly.io): 301-redirects `matchflow.app``www.matchflow.app`
262+
- **Azure Cloud Services**:
263+
- Blob Storage (PDF persistence)
264+
- Form Recognizer (OCR)
265+
- SQL Database (POs, invoices, audit logs)
266+
- Service Bus (discrepancy messaging)
267+
- Application Insights (telemetry & logging)
321268

322269
---
323270

324-
By following Clean Architecture, MatchFlow achieves high testability, clear module boundaries, and the ability to swap out or mock any external dependency (databases, cloud services, UI) without impacting the business core.
271+
### 2. Detailed Clean-Architecture Components
272+
*Internal layering and dependencies*
273+
274+
![Detailed Architecture Diagram](/frontend/public/architecture.svg)
275+
276+
- **Controllers**
277+
- AuthController, PurchaseOrderListController, InvoiceListController, InvoiceMatchController, InvoiceUploadController
278+
- **Application Services (Use-Cases)**
279+
- CreatePurchaseOrderService
280+
- MatchingService
281+
- UploadInvoiceService
282+
- JWT issuance & validation via UserService
283+
- **Ports / Interfaces**
284+
- IInvoiceRepository, IPurchaseOrderRepository
285+
- IFormRecognizer, IBlobStorage
286+
- IExceptionRecordRepository, IServiceBusClient, IUserService
287+
- **Infrastructure**
288+
- EF Core Repositories: InvoiceRepository, PurchaseOrderRepository, ExceptionRecordRepository (via AppDbContext)
289+
- Azure SDK Clients: BlobStorageService, FormRecognizerClient, ServiceBusClient
290+
- UserService (JWT key management & refresh logic)
291+
- **Domain Entities**
292+
- Invoice, PurchaseOrder, InvoiceLineItem, PurchaseOrderLineItem, ExceptionRecord, User
325293

294+
---
326295

327-
![Context Diagram](/frontend/public/context_diagram.png)
328-
![Context Diagram](/frontend/public/component_diagram.png)
329-
296+
### 3. Layer-by-Layer Breakdown
330297

298+
#### Client Layer
299+
- **Browser (React SPA)**
300+
- Pages: AuthPage, LandingPage, CreatePOPage, PurchaseOrdersPage, PurchaseOrderDetailsPage, DashboardPage, InvoicePage, AutoMatchPage, UploadInvoicePage, UploadResultPage
301+
- Communicates over HTTPS+JWT with Nginx
302+
303+
#### Presentation Layer
304+
- **Nginx Reverse Proxy**
305+
- TLS termination, static-file serving, API forwarding
306+
- **Redirector**
307+
- 301 redirects apex domain → `www`
308+
309+
#### Controller Layer
310+
_All inside the .NET API Gateway container_
311+
- AuthController
312+
- PurchaseOrderListController
313+
- InvoiceListController
314+
- InvoiceMatchController
315+
- InvoiceUploadController
316+
317+
#### Application Layer
318+
- **Use-Case Services**
319+
- CreatePurchaseOrderService
320+
- MatchingService
321+
- UploadInvoiceService
322+
- **Dependency-Inverted Ports**
323+
- IInvoiceRepository, IPurchaseOrderRepository, IFormRecognizer, IBlobStorage, IExceptionRecordRepository, IServiceBusClient, IUserService
324+
325+
#### Infrastructure Layer
326+
- **EF Core Repositories** (Invoice, PO, ExceptionRecord)
327+
- **Azure SDK Clients** (BlobStorage, FormRecognizer, ServiceBus)
328+
- **UserService** (JWT management)
329+
330+
#### Domain Layer
331+
- Plain C# business entities: Invoice, PurchaseOrder, InvoiceLineItem, PurchaseOrderLineItem, ExceptionRecord, User
332+
333+
331334

332335
## Screenshots
333336
### Authentication

0 commit comments

Comments
 (0)