Project Workshop — DocuMind AI Platform
This is a portfolio submission, not a copy-and-run tutorial. A reviewer must be able to clone it, configure it without guessing, execute the critical path, observe a deliberate failure, run the tests, and understand the most important…
- What you are building
- Architecture
- Acceptance criteria
- Suggested repository structure
- Build plan: vertical slices
FastAPI · LangGraph · pgvector · Kafka · Redis · Kubernetes · React · RAGAS
Expected effort: 15–24 focused hours · Minimum meaningful tests: 24What you are building
This is a portfolio submission, not a copy-and-run tutorial. A reviewer must be able to clone it, configure it without guessing, execute the critical path, observe a deliberate failure, run the tests, and understand the most important design decision from the README.
Architecture
Critical interaction
Ownership table
| Boundary | Owns | Must not own |
|---|---|---|
| Interface | Parsing, protocol validation, identity extraction, status or presentation mapping | Core business invariants |
| Application/domain | Authorization inputs, state transitions, orchestration, transaction intent | Framework globals or raw transport objects |
| Repository/gateway | One persistence or external protocol, bounded retries, error translation | Product policy |
| Background/UI projection | Recoverable derived state and delivery progress | Hidden authoritative truth |
| Operations | Configuration, health, deployment, telemetry, recovery | Business decisions encoded only in dashboards |
Acceptance criteria
| ID | Required behavior | Evidence |
|---|---|---|
| AC-1.1 | FastAPI async + lifespan (DB pool/Redis/ML models) produces the specified behavior inside Sprint 1: Core RAG backend | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.2 | PDF/DOCX/TXT upload → Celery → chunking → embeddings → pgvector produces the specified behavior inside Sprint 1: Core RAG backend | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.3 | hybrid search + BGE reranker + GPT-4o streaming produces the specified behavior inside Sprint 1: Core RAG backend | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.4 | Redis idempotency keys for uploads produces the specified behavior inside Sprint 1: Core RAG backend | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.1 | Multi-document reasoning StateGraph (5 nodes) produces the specified behavior inside Sprint 2: LangGraph agent | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.2 | query_analyzer→retriever→reranker→synthesizer→citation_formatter produces the specified behavior inside Sprint 2: LangGraph agent | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.3 | conditional routing: single vs multi-doc vs no-context produces the specified behavior inside Sprint 2: LangGraph agent | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.4 | PostgreSQL checkpointer + Kafka ingest events produces the specified behavior inside Sprint 2: LangGraph agent | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.1 | RAGAS eval pipeline in CI produces the specified behavior inside Sprint 3: Production | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.2 | Kubernetes: HPA on FastAPI pods produces the specified behavior inside Sprint 3: Production | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.3 | Prometheus: query latency/retrieval precision/token cost produces the specified behavior inside Sprint 3: Production | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.4 | React frontend: drag-drop/streaming chat/citation highlighting produces the specified behavior inside Sprint 3: Production | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
Suggested repository structure
1documind/2├── backend/3│ ├── app/{api,domain,repositories,schemas}/4│ ├── ingestion/{extractors,chunking,embeddings}/5│ ├── retrieval/{lexical,vector,fusion,reranker}/6│ └── agent/{state,nodes,routes,checkpoints}/7├── frontend/{app,components,hooks,lib,state}/8├── workers/{celery,kafka_consumers}/9├── contracts/{openapi,events,evaluation}/10├── infra/{compose,helm,observability}/11├── tests/{unit,integration,contract,e2e,rag-eval,load}/12└── docs/{adrs,runbooks,threat-model.md}Build plan: vertical slices
| Milestone | Capability | First implementation | Exit condition |
|---|---|---|---|
| 1 | Sprint 1: Core RAG backend | FastAPI async + lifespan (DB pool/Redis/ML models); PDF/DOCX/TXT upload → Celery → chunking → embeddings → pgvector; hybrid search + BGE reranker + GPT-4o streaming | Demonstration plus focused tests |
| 2 | Sprint 2: LangGraph agent | Multi-document reasoning StateGraph (5 nodes); query_analyzer→retriever→reranker→synthesizer→citation_formatter; conditional routing: single vs multi-doc vs no-context | Demonstration plus focused tests |
| 3 | Sprint 3: Production | RAGAS eval pipeline in CI; Kubernetes: HPA on FastAPI pods; Prometheus: query latency/retrieval precision/token cost | Demonstration plus focused tests |
| 4 | Hardening and delivery | Security, recovery, telemetry, performance, documentation | Full acceptance suite and recorded demonstration |
For each milestone, first create a failing acceptance test or a reproducible command. Implement the thinnest path to an observable result, add the nearest durable invariant, inject one expected failure, and refactor only after evidence protects the behavior.
Reference vertical slice
1@router.post("/documents", status_code=202)2async def upload(file: UploadFile, key: str = Header(alias="Idempotency-Key"), user=Depends(current_user)):3 digest = await stream_to_object_storage(file, owner=user.id)4 document, created = await documents.create_once(owner=user.id, key=key, digest=digest)5 if created:6 await outbox.append("document.uploaded.v1", key=str(document.id), payload={"document_id": str(document.id)})7 return {"document_id": document.id, "status": document.status}8
9async def ingest(event):10 chunks = split_with_provenance(await extract(event.document_id))11 vectors = await embed_in_batches(chunks)12 await index.replace_document(event.document_id, chunks, vectors)Expected result
1Repeated upload keys return the same document; committed outbox delivery starts a replace-safe ingestion pipeline.Code reading
| Line | Code | Explanation |
|---|---|---|
| 1 | @router.post("/documents", status_code=202) | Applies a decorator or framework annotation before the following definition is bound. |
| 2 | async def upload(file: UploadFile, key: str = Header(alias="Idempotency-Key"), user=Depends(current_user)): | Defines a coroutine function; calling it creates a coroutine object and await drives its execution. |
| 3 | digest = await stream_to_object_storage(file, owner=user.id) | Starts or resumes asynchronous I/O and yields control until the awaited operation completes. |
| 4 | document, created = await documents.create_once(owner=user.id, key=key, digest=digest) | Starts or resumes asynchronous I/O and yields control until the awaited operation completes. |
| 5 | if created: | Evaluates the condition and enters this branch only when it is truthy. |
| 6 | await outbox.append("document.uploaded.v1", key=str(document.id), payload={"document_id": str(document.id)}) | Starts or resumes asynchronous I/O and yields control until the awaited operation completes. |
| 7 | return {"document_id": document.id, "status": document.status} | Returns the observable result to the caller and ends this invocation. |
| 9 | async def ingest(event): | Defines a coroutine function; calling it creates a coroutine object and await drives its execution. |
| 10 | chunks = split_with_provenance(await extract(event.document_id)) | Starts or resumes asynchronous I/O and yields control until the awaited operation completes. |
| 11 | vectors = await embed_in_batches(chunks) | Starts or resumes asynchronous I/O and yields control until the awaited operation completes. |
| 12 | await index.replace_document(event.document_id, chunks, vectors) | Starts or resumes asynchronous I/O and yields control until the awaited operation completes. |
Risk register
| Area | Failure to reproduce | Required design response |
|---|---|---|
| Sprint 1: Core RAG backend | Publishing work before the document transaction commits or mixing embedding versions creates phantom jobs and inconsistent retrieval. | Keep upload status explicit, version every parser/splitter/model, and make reprocessing replace-safe. |
| Sprint 2: LangGraph agent | A no-context route is not GraphQL resolver context; letting generated prose silently decide state transitions makes the graph untestable. | Keep routing predicates deterministic, cap cycles and tool calls, and record node-level inputs, outputs, latency, and error state. |
| Sprint 3: Production | Appending untrusted HTML, losing stream identity after reconnect, or highlighting by mutable character offsets can create XSS, duplicate text, or incorrect evidence. | Use progressive states, accessible drop alternatives, reconnect/resume behavior, and citation focus that works with keyboard and screen readers. |
Engineering checklist for this stack
- To do: deliver reviewable vertical slices
- To do: keep authoritative and derived state distinct
- To do: make every external effect retry-safe
- To do: integrate security and observability before the final sprint
- To do: publish reproducible demo and failure evidence
Test strategy
Implement at least 24 meaningful cases. A long list of shallow happy-path tests does not satisfy the requirement.
| Risk class | Minimum | Examples |
|---|---|---|
| Happy path and contract | 2 | Correct output, status/schema, durable state |
| Validation and boundaries | 2 | Empty, malformed, extreme, unsupported transition |
| Authorization or trust boundary | 1 | Missing identity, wrong tenant/role, injection or unsafe content |
| Failure and recovery | 2 | Timeout, retry, rollback, reconnect, dependency outage |
| Duplicate or concurrency | 1 | Same identity twice, racing update, redelivery |
| Performance and operations | 16 | Query bound, lag, p95, resource limit, telemetry |
Representative test scaffold
1@pytest.mark.anyio2async def test_duplicate_upload_is_replace_safe_and_cited(harness):3 first = await harness.upload("contract.pdf", key="upload-42")4 second = await harness.upload("contract.pdf", key="upload-42")5 assert second.document_id == first.document_id6
7 await harness.drain_ingestion()8 answer = await harness.ask(first.document_id, "What is the termination period?")9 assert answer.citations10 assert all(c.document_id == first.document_id for c in answer.citations)11 assert harness.indexed_chunk_versions(first.document_id) == {"bge-v1"}Failure drills
- Stop the primary external dependency during the critical path. Capture the failure, cleanup, telemetry, and recovery.
- Repeat the same operation with the same stable identity. Prove one logical outcome or document why repetition is forbidden.
- Crash after durable state changes but before the response, acknowledgement, or projection. Re-run and reconcile.
- Submit the largest supported input and one slightly larger input.
- Remove one permission and prove denial without state change or information leakage.
- Roll back the change or restore the dependency, then run a smoke test and reconciliation check.
Performance experiment
State the dataset, payload distribution, concurrency, rate, duration, cache state, and resource limits before measuring. Publish p50, p95, p99, throughput, error rate, and the technology-specific correctness signal such as query count, consumer lag, duplicate effects, rendered updates, token cost, or recall. Change one variable at a time and retain raw output.
Submission package
- Complete source with a locked/reproducible environment.
- README.md with problem, architecture, setup, commands, configuration, assumptions, and trade-offs.
- Acceptance and risk-focused tests with a short explanation of what mocks intentionally do not cover.
- One design record explaining the most consequential choice and a rejected alternative.
- Security notes, sample non-secret configuration, and cleanup commands.
- A demonstration record: terminal transcript, screenshots, trace, query plan, or metrics dashboard.
- A 5–8 minute walkthrough following input → validation → state → failure → evidence.
Grading rubric
| Dimension | Weight | Full-credit evidence |
|---|---|---|
| Product behavior | 25 | Acceptance criteria pass through real public boundaries |
| Architecture and ownership | 20 | Responsibilities and state authority are explicit |
| Tests and recovery | 20 | Important negative, duplicate, concurrent, and outage cases pass |
| Security and data correctness | 15 | Least privilege, validation, constraints, and secret handling are demonstrated |
| Performance and operations | 10 | Reproducible measurement, useful telemetry, and rollback/recovery |
| Documentation and explanation | 10 | A new reviewer can reproduce and defend the result |
Mastery check
How well can you recall this?
Finished this lesson?