
Weekend Annoying Task Challenge: ClearDoc
Describes an AWS solution that reads and audits the documentation vs the implemented code
Vision & What the App Does:
The annoying truth: nobody updates the architecture docs.
Every team has a Confluence page or a README describing how the system works. It was accurate the day it was written. Then someone swapped Aurora for DynamoDB, renamed three endpoints, and moved auth to Cognito — and the doc kept confidently describing a system that no longer exists. The doc doesn't just go stale; it becomes actively misleading, which is worse than having no doc at all. New joiners trust it. Incident responders trust it. Both get burned.
Writing that documentation by hand is tedious. Keeping it current is relentlessly tedious. So it doesn't happen.
ClearDoc reads your code and writes the documentation for you — and when your existing docs disagree with your code, the code wins.
Point it at a GitHub repo (and optionally a Confluence space) and it produces a solution document: executive summary, component breakdown, data stores, external integrations, deployment topology, configuration. Every non-trivial claim carries a citation to a specific file and line range.
The part I actually care about is Appendix B: Documentation Drift. Every claim in your existing docs gets classified against the code:
On a real AWS sample repo it caught three README claims the code contradicts, including an endpoint list that no longer matched the actual API surface. That's the output I want: not "here's a doc," but "here are the three specific sentences in your README that are lying to your team, and here's the code that proves it."
Start with a design, then cut it
I wrote a full architecture design first, then deliberately scoped it down to what could be built and verified in a weekend:
Cut | Why |
|---|---|
Local-folder input | Browsers can't read a path; needs a CLI. GitHub URL covers the demo. |
PDF export | Needs headless Chromium in a container Lambda. Markdown proves the pipeline. |
Multi-tenancy | Single-tenant means the AWS account is the isolation boundary — a large security simplification, not just less code. |
Languages beyond TS/JS + Python | Three tree-sitter grammars fit a Lambda layer; a wide grammar set forces container images. |
Diagram generation | Genuinely the next thing I'd build. |
Cutting PDF and the wide grammar set had a compounding effect I didn't anticipate: they were the only two things requiring container images. Dropping them made every Lambda a plain zip package — faster builds, faster cold starts, no ECR.
Key architectural decisions
Map/reduce, not RAG. Bedrock Knowledge Bases is tuned for top-k retrieval answering chat questions. Documenting a system requires visiting every module. So: symbol-aware chunking (a chunk is a function or IaC resource with its line range attached), a Map state over modules on Sonnet, then a single Opus reduce. Vector retrieval is a supporting lookup for the drift classifier, not the primary mechanism.
Model tiering by task, which is where the cost comes from:
Stage | Model | Calls/job | Why |
|---|---|---|---|
Map (per-module) | Claude Sonnet 4.6 | ~1 per module | Volume driver |
Reduce (synthesis) | Claude Opus 4.6 | 1 | Most-read output, one call |
Drift classification | Claude Haiku 4.5 | ~1 per claim | Cheap, high-volume, simple decision |
Embeddings | Titan Text v2 | 1 per chunk | 1024-dim |
Architecture from IaC, not from the LLM. CloudFormation/SAM parses into a resource graph — real resources, real
Ref / GetAtt edges. That's ground truth about what's deployed. The LLM never invents infrastructure.Challenges — the interesting part
Every one of these was found by running the thing, not by reading the code.
- A CDK cross-stack dependency cycle that blocked all deploys. Secret.grantRead() and Bucket.grantRead() don't just add identity policy — they also mutate the shared KMS key's resource policy to name the grantee's role ARN. With the key in the storage stack and every Lambda in another stack, that created a reference back from storage, and CDK refused to synth. Fix: grant identity-side IAM only, relying on the key's default account-root trust.
- A 180-second timeout with zero log output — my own bug. First real pipeline run failed in the reduce stage. No logs at all. Opus answered a realistic prompt in 10s, and a direct Lambda invoke succeeded in 11s — so neither the model nor the code was at fault.
- IaC detection by filename doesn't work on real repos. The generated doc for an all-SAM repo said "No infrastructure-as-code resources detected." My inventory matched a hardcoded basename list — template.yaml, serverless.yml. The repo names its templates auth.yaml, product-mock.yaml, shoppingcart-service.yaml. Only sam init scaffolds produce template.yaml; real repos name templates after what they deploy.
Filename matching can't fix this. Detection is now by content signature (AWSTemplateFormatVersion, Transform: AWS::Serverless, Resources: + Type: AWS::). I tested it against the real files first, including the negative case — amplify.yml is CI config and must not match, since a false positive pollutes the deployment section with junk.
- An AWS CLI flag that broke my polling loop. aws stepfunctions ... --max-items 1 is the CLI's pagination flag — it appends a NextToken line to --output text. My wait loop compared against "RUNNING" and got "RUNNING\nNone", so it exited instantly. The API-level flag is --max-results.
AWS Services Used / Architecture Overview
Service | Role |
|---|---|
Amazon Bedrock | Claude Sonnet 4.6 (map), Opus 4.6 (reduce), Haiku 4.5 (drift classification), Titan Text v2 (embeddings) — via inference profiles |
AWS Step Functions | Standard workflow orchestrating 11 stages; execution history doubles as the per-job audit log |
AWS Lambda | 15 functions — 2 API, 13 pipeline stages (Node 22, ARM64, zip) |
Amazon S3 | Three buckets: raw ingest (7d), normalized (30d), output (90d, versioned) |
Amazon DynamoDB | Single-table: jobs, per-stage progress, drift findings, artifacts. On-demand + TTL |
Amazon API Gateway | HTTP API with JWT authorizer |
Amazon Cognito | User pool; no self-signup |
Amazon EventBridge | Decouples the API from the pipeline — this is the agent trigger |
AWS Secrets Manager | GitHub App key, Confluence token — KMS-encrypted, ingest-role-only |
AWS KMS | One customer-managed key across S3, DynamoDB, Secrets |
AWS CDK | 3 stacks (Storage / API / Pipeline), TypeScript |
How the agent is triggered
POST /jobs writes a job record and emits a JobCreated event to EventBridge. An EventBridge rule targets the Step Functions state machine. The API never invokes the pipeline directly — it returns 202 immediately, and the rule starts the execution asynchronously. That decoupling means a slow or failing pipeline can never make the API hang.Solution Diagram

What I Learned
Inference profiles have a two-hop IAM model. This was the single least obvious thing. A
us.anthropic.* profile isn't just an alias — it routes to a foundation model in some US region, and both hops are authorized. Granting the profile ARN alone produces AccessDenied naming the foundation model, which sends you debugging the wrong resource.An unlogged retry loop is an observability hole, not just missing nice-to-have logs. My reduce stage looked hung for 180 seconds with no output. It was working the whole time — retrying a throttled Bedrock call. Any bounded retry needs to emit a line per attempt, or "retrying" and "hung" are indistinguishable in CloudWatch. This generalizes well beyond Bedrock.
Filename heuristics break on real repositories.
template.yaml felt like a reasonable IaC signal because it's what tutorials produce. Real repos name templates after what they deploy. Detect by content when the content is cheap to read — and always test the negative case, or you trade false negatives for false positives.Scope cuts compound in useful ways. Dropping PDF and the wide grammar set removed the only two reasons for container images, which simplified packaging across all 15 functions. But cuts also create obligations: narrowing languages required coverage reporting and the
UNVERIFIABLE verdict, or the output would have been confidently wrong about code it never read.Smoking Gun
Found this discrepancy between the existing readme and the actual code:

This is the complete audit result: https://github.com/manumaan/cleardoc/blob/main/out/shopping-cart.md
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article