Implementation-ready feature blueprints, bug fix plans, and security audits for Claude Code and Gemini CLI. Enforced quality gates — edge cases, correctness properties, 12-domain security reviews — 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
Every blueprint enforces a set of quality gates before it is considered complete. These are what eliminate the revision cycle typical of AI-generated specs.
The generator validates every blueprint against 29 checks before finalizing. Key categories:
# ... 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 |
| /build <name> | Task & Mark |
Autonomously execute blueprint |
| /spec <name> | progress |
Read existing blueprint + progress |
| /review <file> | fixes |
Review code against conventions |
| /test <feature> | *.test.ts |
Scaffold Vitest tests from spec |
| /audit <file> | audit.md |
Run 29 Quality Gates audit |
| /bridge <path> | atlas/*.md |
Sync external API/Backend context |
| /history <topic> | memory |
Search past blueprints for patterns |
| /security-review [mode] | 12 domains |
OWASP, UU PDP, ISO 27001 security audit |
| /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.
Security Review Agent
Comprehensive security audits covering OWASP Top 10, Indonesian UU PDP compliance, ISO 27001, multi-tenant isolation, AI/LLM security, and infrastructure hardening.
JWT validation, RBAC, session management, token security, privilege escalation
OWASP A01
SQL injection, command injection, template injection, path traversal
OWASP A03
PII handling, encryption at rest/transit, UU PDP compliance, GCS security
OWASP A02 + UU PDP
DB queries, API scope, storage paths, AI/LLM context, Redis keys, background jobs
Project-specific — Always Critical
Rate limiting, CORS, security headers, error handling, debug endpoints
OWASP A01/A05/A07
Docker security, secrets management, database hardening, network config
OWASP A05
Prompt injection, data leakage, cost abuse, output validation, tool call safety
OWASP LLM Top 10
Secure storage, HTTPS enforcement, biometric auth, code protection
OWASP Mobile Top 10
Input validation, dependency audit, business logic/payment, logging & monitoring
OWASP A03/A04/A06/A09
# Full codebase audit — all 12 domains
claude> /security-review full
# Targeted AI/LLM security review
claude> /security-review ai
# UU PDP compliance check
claude> /security-review compliance uupdp
# Infrastructure security (Docker, secrets, network)
claude> /security-review infra
Choose your agent and get your first implementation-ready spec.
Auto-installs to .claude/
$ npx amanah-blueprint
claude> /setup
claude> /blueprint feature
Global user-level skills
$ gemini skills install blueprint.skill --scope user
gemini> /setup
gemini> /blueprint feature
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.