Skip to content

Commit 3f82e72

Browse files
committed
Readme - added arch & dfd diagrams + documentation stuff
1 parent 943fff7 commit 3f82e72

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,43 @@ A FastAPI-based KYC (Know Your Customer) system that automatically extracts stru
3838
│ └── models.py # SQLAlchemy models
3939
└── uploads/ # Local upload directory (for development)
4040
```
41+
## Architecture Overview
42+
- **Architecture Diagram**
43+
![Kyc-API Architecture](arch-images\kyc-arch.png)
44+
- **Data Flow Diagram**
45+
![Kyc-API DFD](arch-images\kyc-dfd.jpg)
46+
47+
## Engineering Decisions
48+
49+
**Why FastAPI?**
50+
- FastAPI is built from the ground up to support asynchronous programming (`async`/`await`), which is critical for I/O-bound operations like uploading images to S3 or querying databases. It also provides automatic validation via Pydantic and generates interactive OpenAPI documentation (`/docs`) out of the box, drastically speeding up development and frontend integration.
51+
- **Alternatives:**
52+
- *Flask:* Synchronous by default and requires third-party plugins for OpenAPI docs and validation.
53+
- *Django:* Too heavyweight for a microservice focused purely on providing a REST API.
54+
55+
**Why Celery?**
56+
- AWS Textract processing can take several seconds to complete. If we process the image synchronously, the HTTP request would hang and potentially timeout, creating a poor user experience. Celery allows us to immediately return a `202 Accepted` response with a `task_id`, offloading the heavy OCR processing to background worker nodes.
57+
- **Alternatives Considered:**
58+
- *RQ (Redis Queue):* Simpler to set up, but less robust than Celery for scaling and complex workflows.
59+
- *FastAPI BackgroundTasks:* Runs in the same process as the API, meaning a high volume of heavy tasks could crash the API server.
60+
61+
**Why Redis?**
62+
- Celery requires a message broker to pass task messages from the FastAPI web server to the background workers, and a result backend to store the immediate state of those tasks. Redis handles both roles incredibly fast because it is entirely in-memory.
63+
- **Alternatives:**
64+
- *RabbitMQ:* Excellent for complex message routing, but requires more overhead and setup than Redis.
65+
- *Amazon SQS:* A great serverless alternative, but introduces cloud vendor lock-in for the message broker and can be slower than in-memory Redis.
66+
67+
**Why PostgreSQL?**
68+
- We need relational integrity to tie Users to their specific KYC Tasks (a 1-to-many relationship). PostgreSQL handles concurrent connections beautifully in production and offers native `JSONB` column types, which is perfect for storing the highly variable, nested JSON structures returned by AWS Textract.
69+
- **Alternatives:**
70+
- *MongoDB (NoSQL):* Good for storing arbitrary JSON, but less ideal for strict user schema and relational querying.
71+
- *SQLite:* Used in our pytest environment for speed, but lacks the concurrency handling required for a production API.
72+
73+
**Why Textract instead of traditional OCR (like Tesseract)?**
74+
- Traditional open-source OCR engines (like Tesseract) simply extract raw text strings from an image. We would then have to write complex, error-prone Regex or NLP parsers to figure out which string is the "Name" vs the "Document Number". AWS Textract's `AnalyzeID` API uses machine learning specifically trained on ID documents to automatically return structured Key-Value pairs with confidence scores, eliminating the need for custom parsing logic.
75+
- **Alternatives**
76+
- *Tesseract OCR:* Free and open-source, but requires heavy image pre-processing (OpenCV) and custom data parsing.
77+
- *Google Cloud Vision API / Azure AI Document Intelligence:* Comparable managed cloud AI services, but AWS Textract integrates seamlessly with our existing AWS S3 infrastructure.
4178

4279
## Installation
4380

arch-images/kyc-arch.png

1.49 MB
Loading

arch-images/kyc-dfd.jpg

87.8 KB
Loading

0 commit comments

Comments
 (0)