How tsffarias/docstream works
Project Type and Purpose
• DocStream is a full-stack data-engineering pipeline for automating PDF data extraction, transformation, storage, and visualization.
• Purpose: Ingest PDFs into AWS S3, trigger processing via SQS, extract tables/text with Python, land raw data in PostgreSQL, transform via DBT (bronze→silver→gold), and present KPIs through a Streamlit dashboard.
File Structure
• Top-level:
• docker/: Dockerfile, docker-compose for containerizing services
• src/: core Python code, configs, dbt project, file-stores, frontend
• src/configs/: extraction/queue/database rules and AWS tool wrappers (boto3)
• src/dbt_dw/: DBT project with models (bronze/silver/gold layers), macros, tests
• src/files/: sample CSV/PDF data organized by “jornada” and “redrex”
• src/frontend/: Streamlit app (app.py)
• extractor scripts at project root: pdf_viz.py, table_pdf_extractor.py, text_pdf_extractor.py
• Patterns:
• Event-driven ETL: S3 → SQS → worker
• Layered data transformations (DBT bronze/silver/gold)
• Separation of concerns: extraction logic, config, storage, analytics.
Extracted Insights from README
• Describes AWS services: S3 (storage), SQS (messaging), EC2 (compute)
• Postgres as OLTP/analytical store
• DBT for SQL-based transformations and data modeling
• Streamlit for interactive frontend
Main Components & Their Interactions
a. Components
1. Client/User: accesses Streamlit UI to upload PDFs or view dashboards
2. AWS S3 Bucket: stores incoming PDF files
3. AWS SQS Queue: receives S3-object-created events
4. EC2 Worker (or container):
• Polls SQS every 2 minutes via Python script (src/__init__.py)
• Downloads PDF from S3
• Invokes extraction modules:
• table_pdf_extractor.py (Camelot/Tabula)
• text_pdf_extractor.py (PyPDF2/Regex)
• Writes raw records to PostgreSQL
5. PostgreSQL Database: initial landing (raw tables) and final store
6. DBT Transformation Engine:
• Bronze layer (raw staging models)
• Silver layer (cleaned, joined models)
• Gold layer (analytics-ready tables)
7. Streamlit Frontend:
• src/frontend/app.py reads from Postgres via SQLAlchemy
• Displays KPIs, allows file upload (direct to S3 or local tests)
b. Data Flow
• User → Streamlit UI → (direct S3 upload or local file drop)
• S3 upload → S3 emits event → SQS queue
• Worker polls SQS → fetch message → download PDF → extract → write to Postgres
• DBT processes raw tables → transforms → loads gold tables
• Streamlit queries Postgres gold tables → renders dashboards
Architectural Patterns & Principles
• Event-Driven Architecture: decouples ingestion (S3) from processing (worker via SQS)
• Layered ETL/ELT: raw staging → curated → analytics
• Modular Design: separate configs, extraction logic, transformation models, UI
• Infrastructure as Code: Docker + Makefile + docker-compose for local dev parity
• Scalability: AWS managed services (S3/SQS), containerizable worker and DBT tasks