How shreyasjha03/drhp_automator-s45- works
1. What this repository is
- A batch CLI pipeline for extracting authorised share capital changes from corporate filing documents and producing DRHP-style capital structure outputs.
- It is not a web app; the main entry point is app/main.py, which orchestrates a file-based processing flow.
2. Primary data source and sink
- Inputs come from data/sample_docs/ containing .md documents that represent filings such as SH-7, board resolutions, EGM documents, and MOA amendments.
- Outputs are written to data/outputs/ as:
- result.csv for tabular event summaries
- CAPITAL_STRUCTURE.md for detailed traceable event narratives
3. Ingestion boundary
- app/ingestion/loader.py is the first subsystem.
- Its job is to discover and load document files from disk into the pipeline as raw text records, preserving file identity for later traceability.
4. Document classification
- app/classification/classifier.py assigns each loaded document a type such as SH7, PAS3, BOARD_RESOLUTION, EGM, or MOA.
- The README indicates this is primarily rule-based keyword matching, with an LLM fallback when the document is ambiguous.
5. Extraction layer
- app/extraction/extractor.py converts classified documents into structured capital-change fields.
- app/extraction/prompts.py holds the prompt templates used when the system needs to ask the LLM to interpret weaker or less structured text.
- The architecture is intentionally hybrid:
- deterministic parsing for structured documents
- Groq LLM fallback for harder cases
6. LLM integration
- app/utils/llm_client.py encapsulates the external LLM dependency.
- The repository uses Groq with llama-3.1-8b-instant when enabled by environment variables.
- This is an optional dependency; the pipeline still runs without the API key, but with reduced fallback capability.
7. Core data model
- app/models/schemas.py defines the shared structured schema used across the pipeline.
- This is the main contract boundary between ingestion, extraction, processing, and output, keeping document-specific parsing logic separate from event-level business logic.
8. Event reconstruction
- app/processing/event_builder.py groups extracted document facts into capital-change events, using the README’s event-centric approach.
- The repository’s key merge key is effectively (date, event_type), with multiple documents rolled into one event when they describe the same capital change.
9. Validation and conflict handling
- app/processing/validator.py checks for:
- missing fields
- conflicting values across sources
- confidence level assignment
- The system explicitly avoids guessing: if sources disagree, it preserves the conflict and lowers confidence rather than silently reconciling it.
10. Timeline and output shaping
- app/processing/timeline.py appears to organize events into a chronological capital history.
- app/output/generator.py turns validated events into the two final deliverables: CSV and markdown.
- This is the final presentation boundary of the pipeline.
11. Repository-level flow
- The end-to-end flow is:
- load documents
- classify them
- extract structured values
- build events from multiple documents
- validate/score confidence
- generate outputs
- The central architectural principle is traceability: every output row or narrative should be explainable back to specific source documents.
12. Operational characteristics
- The project is a single-process, offline analysis tool rather than a distributed system.
- Dependencies are managed through requirements.txt.
- Environment-based config is used for the LLM backend, which means the architecture can degrade gracefully if external inference is unavailable.
13. Testing and quality signal
- tests/test_env.py and tests/test_llm.py suggest the current test coverage focuses on environment setup and LLM connectivity/behavior rather than broad pipeline unit tests.
- That matches the repository’s emphasis on integration of extraction and external model fallback.
14. How to diagram it
- A good architecture diagram would show:
- File input layer (data/sample_docs)
- Pipeline orchestrator (app/main.py)
- Classification / Extraction / Processing / Output as separate stages
- Groq LLM as an optional external service used only by extraction/classification fallback
- File outputs (result.csv, CAPITAL_STRUCTURE.md)
- Schema/model boundary shared across stages to enforce consistent event structure
Main entry points: extractor.py Extractor · main.py Main · classifier.py Classifier · generator.py Generator
Components 15
Inputs
Source documents and raw filing files
- Sample Docs · Markdown filing documents used as pipeline input
data/sample_docs
Pipeline
Core batch processing stages
- Main · Entry point that runs the batch pipeline
app/main.py - Loader · Discovers and loads filing documents from disk
app/ingestion/loader.py - Classifier · Assigns document types using rules with LLM fallback
app/classification/classifier.py - Extractor · Derives structured capital-change fields from classified documents
app/extraction/extractor.py - Prompts · LLM prompt templates for ambiguous documents
app/extraction/prompts.py - LLM Client · Encapsulates optional Groq model access
app/utils/llm_client.py - Schemas · Common structured schema used across stages
app/models/schemas.py - Event Builder · Merges document facts into capital-change events
app/processing/event_builder.py - Validator · Checks missing fields, conflicts, and confidence
app/processing/validator.py - Timeline · Orders validated events into capital history
app/processing/timeline.py - Generator · Builds CSV and markdown deliverables
app/output/generator.py
Outputs
Generated deliverables
- Result CSV · Final event summary table
data/outputs/result.csv - Capital MD · Traceable capital-structure narrative
data/outputs/CAPITAL_STRUCTURE.md
External
Optional model dependency
- Groq · Optional external LLM used for fallback interpretation
Connections 21
- Sample Docs → Loader: documents · Raw filing markdown files are discovered and loaded
- Loader → Main: records · Loaded document records enter the orchestrated flow
- Main → Classifier: route · Main pipeline sends records to document classification
- Classifier → Extractor: typed docs · Classified documents are passed to extraction
- Classifier → Groq: fallback · Ambiguous classifications may use the LLM
- Extractor → Prompts: templates · Extraction uses prompt templates for weaker documents
- Extractor → Groq: fallback · Hard cases are interpreted by the external model
- Extractor → Schemas: structured fields · Extracted values are normalized to the shared schema
- Schemas → Event Builder: contract · Shared model shapes event reconstruction
- Event Builder → Validator: events · Built events are checked for completeness and conflicts
- Validator → Timeline: validated events · Validated events are ordered into a chronology
- Timeline → Generator: history · Chronological capital history is formatted for output
- Generator → Result CSV: write · Tabular event summary is emitted to CSV
- Generator → Capital MD: write · Narrative capital structure report is emitted as markdown
- Main → Generator: finalize · The orchestrator hands validated results to output generation
- Main → Schemas: shared model · Pipeline stages share the common data contract
- Validator → Schemas: check · Validation is performed against the shared schema
- LLM Client → Groq: api · Client encapsulates optional Groq backend access
- Classifier → LLM Client: model call · Classifier can invoke the shared LLM client
- Extractor → LLM Client: model call · Extractor can invoke the shared LLM client
- Prompts → Extractor: instructions · Prompt templates support extraction logic