Implementation-ready feature blueprints and bug fix plans for Claude Code. Enforced quality gates — edge cases, correctness properties, security checks — traced end-to-end.
$ npx amanah-blueprint
See it in action
You describe a feature to an AI (or a developer). They build something. It's 80% right. Missing edge cases. Vague error handling. No tests for the tricky parts.
Features
WHEN/IF/THEN SHALL language with concrete input/output examples for every criterion.
Minimum 5 per feature with exact expected behavior, traced to correctness properties and tests.
Formal statements bridging requirements and tests. Every property validates at least one must-have.
Existing services, utilities, and models identified before designing new components. Reuse before build.
Security, performance, traceability, and code quality checks enforced on every blueprint before finalizing.
- [x] marks in now.md.
Resume after interrupt. Audit trail built in.
How It Works
One file at a time, with user review between each step. Errors caught early don't compound.
flowchart LR
A["Research
Codebase"] --> B["what.md
Requirements"]
B --> C["how.md
Design"]
C --> D["now.md
Action Items"]
D --> E["Implement"]
style A fill:#18181b,stroke:#71717a,stroke-width:2px,color:#f4f4f5
style B fill:#18181b,stroke:#34d399,stroke-width:2px,color:#f4f4f5
style C fill:#18181b,stroke:#34d399,stroke-width:2px,color:#f4f4f5
style D fill:#18181b,stroke:#34d399,stroke-width:2px,color:#f4f4f5
style E fill:#18181b,stroke:#f59e0b,stroke-width:2px,color:#f4f4f5
Run in your project directory.
$ npx amanah-blueprint
In Claude Code, generate atlas.
claude> /setup
Create your first blueprint.
claude> /blueprint my-feature
See a Blueprint
This is what gets generated for a payment integration feature. Click a tab to switch between files.
# Credit Billing — What
## Overview
Credit-based billing for AI features. Users purchase credits,
each AI action costs a specific amount.
## Glossary
- **Credit**: Virtual currency, 1 credit = $0.01
- **Cost Map**: Lookup table mapping AI actions to credit costs
## Must-Haves
### M-1: Credit Deduction on AI Action
- **Priority**: P0 (must)
- **User Story:** As a user, I want to see exactly how many
credits each AI action costs before it runs.
#### Acceptance Criteria
1. WHEN an AI action is requested, THE system SHALL check
the user's credit balance against the action's cost.
- Example: balance=50, cost=10 → allow, new balance=40
2. IF balance < cost, THEN THE system SHALL reject with HTTP 402.
- Example: balance=3, cost=10 → HTTP 402
{required: 10, current: 3}
## Edge Cases
| Scenario | Expected Behavior |
|----------|-------------------|
| balance = 0 | Block, show purchase prompt |
| Concurrent requests | Serialize via SELECT FOR UPDATE |
| Webhook timeout | Don't add credits, log for reconcile |
| Cost map changes mid-flight | Use cost at request start time |
# Credit Billing — How
## Overview
Credit check and deduction via dedicated service layer.
Uses database row-level locking (SELECT FOR UPDATE).
**Key Design Decisions:**
- Row-level locking over mutexes (survives crashes)
- Immutable ledger (balance derived from ledger sum)
- Cost map cached in Redis (admin updates without deploys)
## Architecture
```mermaid
sequenceDiagram
participant C as Client
participant A as API
participant S as CreditService
participant D as Database
C->>A: POST /api/v1/generate-report
A->>S: check_and_deduct(user_id, action)
S->>D: SELECT FOR UPDATE balance
D-->>S: balance = 50
alt balance >= cost
S->>D: INSERT ledger + UPDATE balance
S-->>A: {success: true, balance_after: 40}
else balance < cost
S-->>A: {success: false, required: 10}
end
```
## Existing Code to Reuse
| What | File Path | How to Reuse |
|------|-----------|-------------|
| StripeWebhookHandler | services/payment/stripe.py | Add credit top-up |
| UserModel | models/user.py | Add credit_balance |
## Correctness Properties
### Property 1: Balance Never Negative
*For any* sequence of concurrent deductions, balance SHALL
never go below 0.
**Validates: M-1, Q-2**
# Credit Billing — Now
## Action Items
- [ ] 1. Database: Create ledger table
- [ ] 1.1 Create Alembic migration `add_credit_billing`
- Add `credit_balance INTEGER DEFAULT 0` to users
- Create `credit_ledger` table
- _Ref: M-1.3_
- [ ] 2. Checkpoint — Database ready
- Run `alembic upgrade head`
- [ ] 3. Service layer
- [ ] 3.1 Create `services/billing/credit_service.py`
- `CreditService.check_and_deduct(db, user_id, action)`
- Use SELECT FOR UPDATE for row locking
- _Ref: M-1.1_
- [ ] 4. Checkpoint — Service layer ready
- Unit test: check_and_deduct() with mock DB
- [ ] 5. API
- [ ] 5.1 Add credit check to AI endpoints
- _Ref: M-1.1_
- [ ] 6. Tests
- [ ] 6.1 Unit tests
- [ ] 6.2 Property tests (Hypothesis)
- [ ] 6.3 Integration tests
- [ ] 7. Final checkpoint — All tests pass
## Dependency Graph
```json
{
"waves": [
{ "id": 0, "tasks": ["1.1"] },
{ "id": 1, "tasks": ["3.1"] },
{ "id": 2, "tasks": ["5.1"] },
{ "id": 3, "tasks": ["6.1", "6.2", "6.3"] }
]
}
```
Cross-Referencing
Every artifact is numbered and linked. Requirements trace to properties, properties trace to tests, edge cases trace through the full chain.
graph LR
M1["M-1.2
Requirement"] -->|"validated by"| P1["Property 3
Speed-Up Bounded"]
E1["Edge Case
TTS 10s audio"] -->|"covered by"| P1
P1 -->|"tested by"| T1["Test 5.2
test_speed_factor_bounds"]
M1 -->|"traced to"| T1
style M1 fill:#18181b,stroke:#34d399,stroke-width:2px,color:#f4f4f5
style P1 fill:#18181b,stroke:#a78bfa,stroke-width:2px,color:#f4f4f5
style E1 fill:#18181b,stroke:#f59e0b,stroke-width:2px,color:#f4f4f5
style T1 fill:#18181b,stroke:#34d399,stroke-width:2px,color:#f4f4f5
Two Modes
flowchart TD
A["User Request"] --> B{"Detect Intent"}
B -->|"/blueprint, plan feature"| C["Full Mode
what + how + now"]
B -->|"/fix, hotfix, why"| D["Lite Mode
fix.md only"]
style A fill:#18181b,stroke:#71717a,stroke-width:2px,color:#f4f4f5
style B fill:#18181b,stroke:#a78bfa,stroke-width:2px,color:#f4f4f5
style C fill:#18181b,stroke:#34d399,stroke-width:2px,color:#f4f4f5
style D fill:#18181b,stroke:#f59e0b,stroke-width:2px,color:#f4f4f5
For new features and multi-component work.
Sequential review — pause after each file.
For bug fixes, hotfixes, and small changes.
Root cause → fix steps → edge cases → tests
Auto-escalates to Full Mode if >5 files affected.
Quality Gates
Click a category to see the individual checks. These run before a blueprint is finalized.
# ... same as current ...)get_event_loop())asyncio.to_thread()Atlas
Atlas is persistent project context — 5 files that tell the generator about your codebase. Blueprints use your actual imports, file paths, and conventions.
Slash Commands
| Command | Output | Purpose |
|---|---|---|
| /setup | atlas/*.md |
One-time project initialization |
| /blueprint <name> | what + how + now |
Generate full feature blueprint |
| /fix <name> | fix.md |
Generate bug fix plan |
| /spec <name> | progress |
Read existing blueprint + progress |
| /atlas | atlas/*.md |
Regenerate atlas from codebase |
Token Optimization
Blueprints are token-intensive by nature. The framework includes optimizations to minimize cost.
| Task | Tokens | When |
|---|---|---|
1 Lite fix (fix.md) |
~5-8K | Bug fix, small change |
| 1 Full blueprint (what + how + now) | ~20-30K | New feature |
| 2 Full blueprints (same session) | ~40K | Batched |
| Atlas regeneration | ~15K | First-time setup |
Tip: Batch blueprints in one session to save ~5K tokens per additional blueprint. Atlas stays in context.
Three commands to your first implementation-ready spec.
$ npx amanah-blueprint
Install the framework in your project directory.
claude> /setup
In Claude Code — generates atlas, installs skills, updates CLAUDE.md.
claude> /blueprint my-first-feature
Generates what.md, pauses for review, then how.md, then now.md.
FAQ
CLAUDE.md, package.json, requirements.txt, or similar files. Code examples and conventions are adapted to the detected stack.
.amanah/, .claude/commands/, .claude/skills/, and .claude/agents/. Your source code is never touched.
SKILL.md and AGENT.md in your project's .amanah/ directory to add project-specific rules or modify generation behavior.