How cassio-tieres/validacrp works
Project Type and Purpose
• ValidaCRP is a Python-based Telegram bot (an AI agent) that lets Secretariat users or psychologists validate a CRP number via a chat interface.
• It uses OCR (Pytesseract), audio processing, LangChain for AI orchestration, and MongoDB to store or cache request data.
File Structure
• Top-level scripts & configs:
• main.py → bot entrypoint
• .env-exemplo / requirements.txt → environment & deps
• readme.md → project overview
• Directories:
• functions/ → business logic modules (genAI setup, OCR, audio processing, Telegram config)
• database/ → db.py (MongoDB connection and data access)
• prompt/ → Markdown instructions passed to the LLM
• No heavy front-end; it’s a single service (microservice) that integrates APIs and external scraping.
README for Additional Insights
• Tech stack: Python, LangChain, MongoDB, Pytesseract, Telegram API
• Use cases: Text and audio validation requests (audio support is planned/backlog)
• External dependency: scrapes https://cadastro.crp.org.br for CRP data.
a. Main Components to Represent
1. Telegram Client (User)
2. Telegram Bot API (external service)
3. Bot Application (your code):
• Entrypoint (main.py)
• Telegram Config Module
• Request Router / Controller
• Business Logic Modules (OCR, audio processor, text handler)
• LangChain Orchestrator (genai_config + prompt templates)
• Database Layer (MongoDB via database/db.py)
4. External CRP Website (HTTP scraper)
5. Data Store: MongoDB
6. Auxiliary: Tesseract Engine
b. Relationships & Data Flows
• User → Telegram API → Bot Application (Webhook or Polling)
• Bot App:
– Routes incoming message to either text handler, OCR pipeline, or audio pipeline
– OCR Pipeline calls Tesseract engine → extracts text → passes to LangChain
– Audio Pipeline calls speech-to-text → passes to LangChain
– LangChain orchestrates prompt (from prompt/*.md) + extracted text → generates validation request
– Bot App scrapes CRP site (HTTP client) → receives raw CRP data
– Bot App stores/fetches previous lookups in MongoDB
– Bot App aggregates results → Telegram API → returns message to User
c. Architectural Patterns & Principles
• Single Responsibility: each module in functions/ handles one concern
• Pipeline/Chain of Responsibility: text, OCR, audio pipelines feed into a common AI orchestrator
• External Integration Layer: clear boundary between your code and external services (Telegram, CRP Website, Tesseract, MongoDB)
d. Relevant Technologies & Libraries
• Python runtime
• python-telegram-bot (or equivalent wrapper)
• LangChain for prompt management
• Pytesseract + Tesseract engine for OCR
• Speech-to-text library (for future audio)
• Requests or HTTPX for web scraping
• pymongo for MongoDB access
Final Advice
• Be as granular as your audience needs—showing each function module is fine if they care about low-level plumbing. Otherwise, group them into “OCR Service,” “Audio Service,” etc.
• Flow from user input to final Telegram message is unbroken and clearly annotated.