PDF Extractor Docs

Code structure

Low-level design

Module map

PathResponsibility
api/routesMaps HTTP requests to use cases.
api/dependencies.pyCreates request dependencies.
services/job_service.pyRuns job use cases.
services/contracts.pyDefines the extraction provider port.
services/llama_cloud.pyImplements the LlamaCloud adapter.
repositories/jobs.pyReads and writes job rows.
models/extraction_job.pyDefines job state and table columns.
staticContains the browser form and polling code.

Job state

PENDING → PROCESSING → COMPLETED
↘ FAILED
↘ CANCELLED

A final state is terminal. The service does not check LlamaCloud again after a final state.

Design patterns

Layered architecture

Each layer has one responsibility. Routes handle HTTP. Services handle use cases. Repositories handle persistence.

Ports and adapters

ExtractionProvider is a port. LlamaCloudExtractionProvider is an adapter. The job service depends on the port. The job service does not depend on the LlamaCloud SDK.

Repository pattern

JobRepository contains database operations. The service does not contain SQL queries.

Dependency injection

FastAPI creates the database session and service for each request. Tests can replace these dependencies.

Anti-corruption layer

The provider adapter changes external result fields and states into local values. Provider details do not enter the public API.

State machine

The status enum limits valid job states. Terminal jobs do not run more provider status checks.

Data model

ColumnUse
idPublic local job ID.
filenameOriginal file name.
llama_file_idInternal external file ID.
llama_job_idInternal external job ID.
result_jsonExtracted data.
metadata_jsonConfidence and source data.
error_messageSafe error message.