armature-framework 0.2.2

A modern, type-safe HTTP framework for Rust inspired by Angular and NestJS. Features dependency injection, decorators, middleware, authentication (JWT/OAuth2/SAML), validation, OpenAPI/Swagger, caching, job queues, and observability.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
# Armature Framework - TODO

## Status

**113 optimizations implemented** | Axum/Actix-competitive performance achieved

---

## Open Issues

### Framework Comparison (Armature vs Actix vs Axum)

HTTP load testing with `oha` (50k requests, 100 concurrent):

#### Plaintext (Hello World)
| Framework | Req/sec | Avg Latency | p99 |
|-----------|---------|-------------|-----|
| **Armature** | **242,823** | 0.40ms | 2.62ms |
| Actix-web | 144,069 | 0.53ms | 9.98ms |
| Axum | 46,127 | 2.09ms | 29.58ms |

#### JSON Response
| Framework | Req/sec | Avg Latency | p99 |
|-----------|---------|-------------|-----|
| Axum | 239,594 | 0.40ms | 1.91ms |
| Actix-web | 128,004 | 0.67ms | 16.95ms |
| **Armature** | 35,622 | 2.65ms | 32.85ms |

#### Path Parameters (/users/:id)
| Framework | Req/sec | Avg Latency | p99 |
|-----------|---------|-------------|-----|
| Actix-web | 183,781 | 0.44ms | 10.00ms |
| **Armature** | 59,077 | 1.51ms | 15.79ms |
| Axum | 38,549 | 2.47ms | 28.28ms |

**Analysis:** Armature leads on plaintext but needs JSON serialization optimization.

---

### Micro-Framework Performance Optimizations

Benchmark results show the micro-framework has **1.5-3x overhead** vs direct Router usage.

| Benchmark | Direct Router | Micro App | Overhead |
|-----------|---------------|-----------|----------|
| Static route | ~510ns | ~1.7ยตs | **3.3x** |
| Route with param | ~1.1ยตs | ~5.6ยตs | **5x** |
| JSON handler | - | ~3.7ยตs | - |

#### Issues to Fix

| Issue | Impact | Effort | Status |
|-------|--------|--------|--------|
| **Middleware chain rebuilt every request** | High | S | โณ |
| `BuiltApp::handle()` creates closures per request | | | |
| **`any()` clones handler 7 times** | Medium | S | โณ |
| Should take `Arc<H>` or use single BoxedHandler | | | |
| **Route registration allocates per-route** | Medium | M | โณ |
| Consider arena allocation for route strings | | | |
| **AppState type lookup via HashMap** | Low | S | โณ |
| Could use type ID directly without hashing | | | |

#### Recommended Fixes

1. **Pre-build middleware chain** - Build once in `App::build()`, not per-request
   ```rust
   // Current: Builds closure chain in handle()
   // Fix: Store pre-composed middleware in BuiltApp
   struct BuiltApp {
       middleware_chain: Arc<dyn Fn(HttpRequest) -> ...>,
   }
   ```

2. **Optimize `any()` helper** - Single clone instead of 7
   ```rust
   pub fn any<H>(handler: H) -> RouteBuilder {
       let boxed = Arc::new(BoxedHandler::new(handler.into_handler()));
       RouteBuilder::new()
           .with_shared_handler(HttpMethod::GET, boxed.clone())
           // ... etc
   }
   ```

3. **Use `SmallVec` for routes** - Avoid heap for small apps
   ```rust
   routes: SmallVec<[Route; 16]>,  // Inline up to 16 routes
   ```

---

## Feature Roadmap (Product Manager Analysis)

### P0: Critical Gaps (vs Competitors)

| Feature | RICE Score | Description | Effort | Status |
|---------|------------|-------------|--------|--------|
| **HTTP/2 Support** | 8.0 | Actix/Axum support HTTP/2; required for modern deployments | M | โœ… Done |
| **Database Migrations** | 7.5 | CLI-driven migrations like `armature migrate` (NestJS, Rails pattern) | M | โณ |
| **OpenAPI Client Gen** | 6.0 | Generate TypeScript/Rust clients from OpenAPI spec | S | โœ… Done |

### P1: High-Value Enterprise Features

| Feature | RICE Score | Description | Effort | Status |
|---------|------------|-------------|--------|--------|
| **Admin Dashboard Generator** | 7.2 | Auto-generate CRUD admin UI from models (like Django Admin) | L | โœ… Done |
| **GraphQL Federation** | 6.8 | Apollo Federation for microservices architecture | M | โœ… Done |
| **API Analytics Module** | 6.5 | Built-in usage tracking, rate limit insights, error rates | M | โœ… Done |
| **Payment Processing** | 6.0 | Stripe, PayPal, Braintree integration module | M | โœ… Done |

### P2: Developer Experience

| Feature | RICE Score | Description | Effort | Status |
|---------|------------|-------------|--------|--------|
| **Mock Server Mode** | 5.5 | `armature mock` to run API with fake data for frontend dev | S | โœ… Done |
| **Database Seeding** | 5.0 | `armature db:seed` with factories and fixtures | S | โณ |
| **VS Code Extension** | 4.8 | Syntax highlighting, snippets, route navigation | M | โณ |
| **Interactive Docs** | 4.5 | Embedded try-it-out in generated OpenAPI docs | S | โณ |

### P3: Advanced Capabilities

| Feature | RICE Score | Description | Effort | Status |
|---------|------------|-------------|--------|--------|
| **HTTP/3 (QUIC)** | 4.0 | Next-gen HTTP protocol support | L | โœ… Done |
| **File Processing Pipeline** | 3.8 | Image resize, PDF gen, format conversion | M | โœ… Done |
| **Real-time Collaboration** | 3.5 | CRDTs/OT for collaborative features | L | โœ… Done |
| **Rhai Scripting** | 6.5 | Embedded scripting for dynamic handlers and config | M | โœ… Done |
| **Node.js FFI Bindings** | 7.5 | Expose Armature to TypeScript/Node.js via NAPI-RS | XL | โณ |
| **Python FFI Bindings** | 7.0 | Expose Armature to Python via PyO3 | XL | โณ |
| **ML Model Serving** | 3.0 | ONNX/TensorFlow Lite inference endpoints | L | โณ |

---

## Node.js FFI Roadmap

Expose Armature's high-performance Rust core to TypeScript/Node.js developers via native bindings.

### Value Proposition

- **10-100x faster** than Express/Fastify for CPU-bound operations
- **NestJS-familiar API** for easy adoption
- **Type-safe** with auto-generated TypeScript definitions
- **Zero-copy** where possible for maximum performance

### Technology Stack

| Component | Choice | Rationale |
|-----------|--------|-----------|
| FFI Layer | **NAPI-RS** | Best Node.js binding library, async support, N-API stability |
| Package | `@armature/core` | Scoped npm package |
| TypeScript | Auto-generated `.d.ts` | From Rust types via `ts-rs` or NAPI-RS |
| Runtime | Node.js 18+ | N-API v8, stable async support |

### Phase 1: Core Bindings (Effort: L)

| Task | Description | Status |
|------|-------------|--------|
| **1.1 Project Setup** | Create `armature-node` crate with NAPI-RS | โณ |
| **1.2 HttpRequest Binding** | Expose request object with headers, body, params | โณ |
| **1.3 HttpResponse Binding** | Response builder with status, headers, body | โณ |
| **1.4 Router Binding** | Route registration and matching | โณ |
| **1.5 Async Handler Support** | JS Promise โ†’ Rust Future bridging | โณ |

```typescript
// Target API (Phase 1)
import { Router, HttpRequest, HttpResponse } from '@armature/core';

const router = new Router();

router.get('/users/:id', async (req: HttpRequest): Promise<HttpResponse> => {
  const id = req.param('id');
  return HttpResponse.json({ id, name: 'Alice' });
});

await router.listen(3000);
```

### Phase 2: Micro-Framework API (Effort: M)

| Task | Description | Status |
|------|-------------|--------|
| **2.1 App Builder** | `App.new()` fluent builder in JS | โณ |
| **2.2 Route Helpers** | `get()`, `post()`, etc. as JS functions | โณ |
| **2.3 Middleware System** | `wrap()` with JS middleware functions | โณ |
| **2.4 Scope/Service** | Route grouping and nested scopes | โณ |
| **2.5 Data/State** | Shared state via `app.data()` | โณ |

```typescript
// Target API (Phase 2)
import { App, get, post, scope, Logger, Cors } from '@armature/core';

const app = App.new()
  .wrap(Logger.default())
  .wrap(Cors.permissive())
  .route('/', get(async () => HttpResponse.ok()))
  .service(
    scope('/api/v1')
      .route('/users', get(listUsers).post(createUser))
      .route('/users/:id', get(getUser))
  );

await app.run('0.0.0.0:8080');
```

### Phase 3: Advanced Features (Effort: L)

| Task | Description | Status |
|------|-------------|--------|
| **3.1 WebSocket Support** | Real-time with `@armature/websocket` | โณ |
| **3.2 Validation** | Schema validation via `@armature/validation` | โณ |
| **3.3 OpenAPI Generation** | Auto-generate OpenAPI from routes | โณ |
| **3.4 GraphQL** | GraphQL server via `@armature/graphql` | โณ |
| **3.5 Caching** | Redis/in-memory cache bindings | โณ |

### Phase 4: DX & Ecosystem (Effort: M)

| Task | Description | Status |
|------|-------------|--------|
| **4.1 CLI Tool** | `npx @armature/cli new my-app` | โณ |
| **4.2 TypeScript Plugin** | IDE support, route hints | โณ |
| **4.3 ESBuild Plugin** | Bundle optimization | โณ |
| **4.4 Vitest Integration** | Testing utilities | โณ |
| **4.5 npm Publishing** | CI/CD for multi-platform binaries | โณ |

### Technical Architecture

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    TypeScript/JavaScript                     โ”‚
โ”‚  import { App, get } from '@armature/core'                  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚
                              โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                      NAPI-RS Bridge                          โ”‚
โ”‚  - JsFunction โ†’ Rust closure conversion                     โ”‚
โ”‚  - Promise โ†” Future bridging                                โ”‚
โ”‚  - Zero-copy Buffer handling                                โ”‚
โ”‚  - ThreadsafeFunction for callbacks                         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚
                              โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    armature-node crate                       โ”‚
โ”‚  - Thin wrapper over armature-core                          โ”‚
โ”‚  - JS-friendly error handling                               โ”‚
โ”‚  - Async runtime integration (tokio)                        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚
                              โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                      armature-core                           โ”‚
โ”‚  - Router, HttpRequest, HttpResponse                        โ”‚
โ”‚  - Middleware, State, Scopes                                โ”‚
โ”‚  - All existing Rust optimizations                          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

### Key Implementation Details

#### Async Handler Bridging

```rust
// armature-node/src/handler.rs
use napi::{JsFunction, Env, Result, threadsafe_function::*};
use napi_derive::napi;

#[napi]
pub struct JsHandler {
    callback: ThreadsafeFunction<HttpRequest, Promise<HttpResponse>>,
}

impl JsHandler {
    pub async fn call(&self, req: HttpRequest) -> Result<HttpResponse> {
        self.callback.call_async(req).await
    }
}
```

#### Zero-Copy Request Body

```rust
// Expose request body as Node.js Buffer without copying
#[napi]
impl HttpRequest {
    #[napi]
    pub fn body_buffer(&self, env: Env) -> Result<JsBuffer> {
        // Create Buffer view over Rust Vec<u8>
        env.create_buffer_with_borrowed_data(
            self.body.as_slice(),
            self.body.len(),
            self.body.clone(), // prevent deallocation
            |_, _| {}
        )
    }
}
```

#### Multi-Platform Binary Distribution

```yaml
# .github/workflows/node-publish.yml
strategy:
  matrix:
    include:
      - os: ubuntu-latest
        target: x86_64-unknown-linux-gnu
      - os: ubuntu-latest
        target: aarch64-unknown-linux-gnu
      - os: macos-latest
        target: x86_64-apple-darwin
      - os: macos-latest
        target: aarch64-apple-darwin
      - os: windows-latest
        target: x86_64-pc-windows-msvc
```

### Performance Targets

| Benchmark | Express | Fastify | Armature-Node | Goal |
|-----------|---------|---------|---------------|------|
| Hello World (req/s) | 15k | 45k | 120k+ | 3x Fastify |
| JSON serialize | 10ยตs | 5ยตs | 0.5ยตs | 10x faster |
| Route matching | 2ยตs | 0.8ยตs | 0.05ยตs | 16x faster |
| Memory per request | 50KB | 20KB | 5KB | 4x less |

### npm Package Structure

```
@armature/
โ”œโ”€โ”€ core/           # Main package (router, app, middleware)
โ”œโ”€โ”€ websocket/      # WebSocket support
โ”œโ”€โ”€ graphql/        # GraphQL server
โ”œโ”€โ”€ validation/     # Schema validation
โ”œโ”€โ”€ cache/          # Caching (Redis, memory)
โ”œโ”€โ”€ queue/          # Background jobs
โ”œโ”€โ”€ cli/            # CLI tool
โ””โ”€โ”€ create-app/     # Project scaffolding
```

### RICE Score Calculation

- **Reach:** 9 (massive Node.js ecosystem)
- **Impact:** 3 (game-changing performance for Node devs)
- **Confidence:** 0.8 (NAPI-RS is proven, but XL effort)
- **Effort:** XL (8 person-weeks)

**Score:** (9 ร— 3 ร— 0.8) / 8 = **2.7** (but strategic value much higher)

### Dependencies

| Crate | Purpose |
|-------|---------|
| `napi` | N-API bindings |
| `napi-derive` | Proc macros for `#[napi]` |
| `napi-build` | Build script for native module |
| `tokio` | Async runtime |
| `ts-rs` | TypeScript type generation (optional) |

### Milestones

| Milestone | Target | Deliverable |
|-----------|--------|-------------|
| M1: Alpha | +4 weeks | Basic router, handlers, `npm install` works |
| M2: Beta | +8 weeks | Full micro-framework API, middleware |
| M3: RC | +12 weeks | WebSocket, validation, OpenAPI |
| M4: 1.0 | +16 weeks | Production-ready, docs, examples |

---

## Python FFI Roadmap

Expose Armature's high-performance Rust core to Python developers via PyO3 native bindings.

### Value Proposition

- **10-50x faster** than Flask/FastAPI for CPU-bound operations
- **FastAPI-familiar API** with type hints and async support
- **Zero-copy** NumPy/buffer protocol integration for data science workloads
- **Native async** via `asyncio` integration
- **ML-ready** with seamless PyTorch/NumPy interop

### Technology Stack

| Component | Choice | Rationale |
|-----------|--------|-----------|
| FFI Layer | **PyO3** | Best Rust-Python bindings, mature, async support |
| Build Tool | **Maturin** | Best-in-class Python packaging for Rust |
| Package | `armature` | PyPI package |
| Type Hints | Auto-generated `.pyi` stubs | Via `pyo3-stub-gen` |
| Python | 3.9+ | Stable async, type hints, buffer protocol |

### Phase 1: Core Bindings (Effort: L)

| Task | Description | Status |
|------|-------------|--------|
| **1.1 Project Setup** | Create `armature-python` crate with PyO3 + Maturin | โณ |
| **1.2 HttpRequest Binding** | Expose request with headers, body, params | โณ |
| **1.3 HttpResponse Binding** | Response builder with status, headers, body | โณ |
| **1.4 Router Binding** | Route registration and matching | โณ |
| **1.5 Async Handler Support** | Python coroutine โ†’ Rust Future bridging | โณ |
| **1.6 GIL Management** | Release GIL during I/O for concurrency | โณ |

```python
# Target API (Phase 1)
from armature import Router, HttpRequest, HttpResponse

router = Router()

@router.get("/users/{user_id}")
async def get_user(req: HttpRequest) -> HttpResponse:
    user_id = req.param("user_id")
    return HttpResponse.json({"id": user_id, "name": "Alice"})

if __name__ == "__main__":
    router.run("0.0.0.0:8000")
```

### Phase 2: Micro-Framework API (Effort: M)

| Task | Description | Status |
|------|-------------|--------|
| **2.1 App Builder** | `App()` with method chaining | โณ |
| **2.2 Decorator Routes** | `@app.get()`, `@app.post()` decorators | โณ |
| **2.3 Middleware System** | `@app.middleware` and `app.add_middleware()` | โณ |
| **2.4 APIRouter** | FastAPI-style router grouping | โณ |
| **2.5 Dependency Injection** | `Depends()` pattern like FastAPI | โณ |
| **2.6 Request Validation** | Pydantic model integration | โณ |

```python
# Target API (Phase 2)
from armature import App, APIRouter, Depends, HttpResponse
from pydantic import BaseModel

class User(BaseModel):
    name: str
    email: str

app = App()
app.add_middleware(LoggerMiddleware())
app.add_middleware(CORSMiddleware(allow_origins=["*"]))

api = APIRouter(prefix="/api/v1")

@api.get("/users")
async def list_users() -> HttpResponse:
    return HttpResponse.json([{"id": 1, "name": "Alice"}])

@api.post("/users")
async def create_user(user: User) -> HttpResponse:
    return HttpResponse.json(user.dict(), status=201)

@api.get("/users/{user_id}")
async def get_user(user_id: int, db: Database = Depends(get_db)) -> HttpResponse:
    user = await db.get_user(user_id)
    return HttpResponse.json(user)

app.include_router(api)

if __name__ == "__main__":
    app.run("0.0.0.0:8000", workers=4)
```

### Phase 3: Advanced Features (Effort: L)

| Task | Description | Status |
|------|-------------|--------|
| **3.1 WebSocket Support** | Real-time with async generators | โณ |
| **3.2 Background Tasks** | `BackgroundTasks` like FastAPI | โณ |
| **3.3 OpenAPI Generation** | Auto-generate OpenAPI from routes + type hints | โณ |
| **3.4 GraphQL** | Strawberry/Ariadne integration | โณ |
| **3.5 Caching** | Redis/in-memory with `@cache` decorator | โณ |
| **3.6 Rate Limiting** | `@rate_limit` decorator | โณ |

```python
# WebSocket example
@app.websocket("/ws")
async def websocket_handler(ws: WebSocket):
    await ws.accept()
    async for message in ws:
        await ws.send(f"Echo: {message}")

# Background tasks
@app.post("/send-email")
async def send_email(background: BackgroundTasks) -> HttpResponse:
    background.add_task(send_email_async, "user@example.com")
    return HttpResponse.json({"status": "queued"})

# Caching
@app.get("/expensive")
@cache(ttl=60)
async def expensive_operation() -> HttpResponse:
    result = await compute_expensive()
    return HttpResponse.json(result)
```

### Phase 4: Data Science Integration (Effort: M)

| Task | Description | Status |
|------|-------------|--------|
| **4.1 NumPy Zero-Copy** | Buffer protocol for zero-copy array access | โณ |
| **4.2 Pandas Integration** | DataFrame request/response support | โณ |
| **4.3 PyTorch Tensors** | GPU tensor handling | โณ |
| **4.4 Streaming Responses** | Async generators for large data | โณ |
| **4.5 File Upload** | Efficient multipart handling | โณ |

```python
import numpy as np
from armature import App, HttpResponse
from armature.numpy import NumpyResponse

app = App()

@app.post("/predict")
async def predict(data: np.ndarray) -> NumpyResponse:
    # Zero-copy access to request body as NumPy array
    result = model.predict(data)
    return NumpyResponse(result)  # Zero-copy response

@app.get("/large-dataset")
async def stream_data():
    # Streaming large datasets
    async def generate():
        for chunk in load_chunks():
            yield chunk.tobytes()
    return HttpResponse.stream(generate())
```

### Phase 5: DX & Ecosystem (Effort: M)

| Task | Description | Status |
|------|-------------|--------|
| **5.1 CLI Tool** | `armature new my-app` project scaffolding | โณ |
| **5.2 Type Stubs** | `.pyi` files for IDE support | โณ |
| **5.3 pytest Plugin** | `pytest-armature` for testing | โณ |
| **5.4 uvicorn Compat** | ASGI interface for existing deployments | โณ |
| **5.5 PyPI Publishing** | Multi-platform wheel distribution | โณ |

### Technical Architecture

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                         Python                               โ”‚
โ”‚  from armature import App, get                              โ”‚
โ”‚  async def handler(req): return HttpResponse.ok()           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚
                              โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                       PyO3 Bridge                            โ”‚
โ”‚  - #[pyfunction] for route handlers                         โ”‚
โ”‚  - Python coroutine โ†’ tokio Future                          โ”‚
โ”‚  - GIL release during async I/O                             โ”‚
โ”‚  - Buffer protocol for zero-copy                            โ”‚
โ”‚  - pyo3-asyncio for async/await                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚
                              โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   armature-python crate                      โ”‚
โ”‚  - PyO3 wrapper types (PyHttpRequest, PyHttpResponse)       โ”‚
โ”‚  - Python-friendly error handling                           โ”‚
โ”‚  - Decorator registration system                            โ”‚
โ”‚  - Pydantic model integration                               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚
                              โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                      armature-core                           โ”‚
โ”‚  - Router, HttpRequest, HttpResponse                        โ”‚
โ”‚  - Middleware, State, Scopes                                โ”‚
โ”‚  - All existing Rust optimizations                          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

### Key Implementation Details

#### Async Handler Bridging

```rust
// armature-python/src/handler.rs
use pyo3::prelude::*;
use pyo3_asyncio::tokio::future_into_py;

#[pyclass]
pub struct PyRouter {
    inner: Router,
}

#[pymethods]
impl PyRouter {
    fn get(&mut self, path: &str, handler: PyObject) -> PyResult<()> {
        let handler = Arc::new(handler);
        self.inner.get(path, move |req| {
            let handler = handler.clone();
            async move {
                Python::with_gil(|py| {
                    let coro = handler.call1(py, (PyHttpRequest(req),))?;
                    pyo3_asyncio::tokio::into_future(coro.as_ref(py))
                })?.await
            }
        });
        Ok(())
    }
}
```

#### Zero-Copy NumPy Integration

```rust
// armature-python/src/numpy.rs
use numpy::{PyArray1, PyReadonlyArray1};
use pyo3::prelude::*;

#[pyfunction]
fn process_array<'py>(
    py: Python<'py>,
    data: PyReadonlyArray1<'py, f64>
) -> PyResult<&'py PyArray1<f64>> {
    // Zero-copy access to NumPy array
    let slice = data.as_slice()?;

    // Process in Rust (releases GIL)
    let result = py.allow_threads(|| {
        process_data(slice)
    });

    // Return as NumPy array (zero-copy if possible)
    Ok(PyArray1::from_vec(py, result))
}
```

#### GIL-Free Async I/O

```rust
// Release GIL during network I/O for maximum concurrency
async fn handle_request(py: Python<'_>, req: HttpRequest) -> PyResult<HttpResponse> {
    // Release GIL while waiting for I/O
    let response = py.allow_threads(|| async {
        // All network I/O happens here without GIL
        fetch_from_database(&req).await
    }).await?;

    Ok(response)
}
```

### Performance Targets

| Benchmark | Flask | FastAPI | Armature-Py | Goal |
|-----------|-------|---------|-------------|------|
| Hello World (req/s) | 2k | 20k | 100k+ | 5x FastAPI |
| JSON serialize | 50ยตs | 10ยตs | 0.5ยตs | 20x faster |
| Route matching | 5ยตs | 1ยตs | 0.05ยตs | 20x faster |
| NumPy throughput | N/A | N/A | 10GB/s | Zero-copy |

### PyPI Package Structure

```
armature/
โ”œโ”€โ”€ __init__.py         # Main exports
โ”œโ”€โ”€ app.py              # App class
โ”œโ”€โ”€ router.py           # Router, APIRouter
โ”œโ”€โ”€ request.py          # HttpRequest
โ”œโ”€โ”€ response.py         # HttpResponse
โ”œโ”€โ”€ middleware.py       # Built-in middleware
โ”œโ”€โ”€ depends.py          # Dependency injection
โ”œโ”€โ”€ websocket.py        # WebSocket support
โ”œโ”€โ”€ background.py       # Background tasks
โ”œโ”€โ”€ cache.py            # Caching decorators
โ””โ”€โ”€ _native.*.so        # Compiled Rust extension

# Extras
armature[numpy]         # NumPy integration
armature[pandas]        # Pandas support
armature[ml]            # PyTorch/TensorFlow
armature[full]          # Everything
```

### RICE Score Calculation

- **Reach:** 8 (massive Python ecosystem, ML/AI dominance)
- **Impact:** 3 (game-changing for Python web + data science)
- **Confidence:** 0.8 (PyO3 is mature, but XL effort)
- **Effort:** XL (8 person-weeks)

**Score:** (8 ร— 3 ร— 0.8) / 8 = **2.4** (but strategic value for ML/AI market)

### Dependencies

| Crate | Purpose |
|-------|---------|
| `pyo3` | Rust-Python bindings |
| `pyo3-asyncio` | Async/await support |
| `numpy` | NumPy array support |
| `maturin` | Build and publish wheels |
| `tokio` | Async runtime |

### Milestones

| Milestone | Target | Deliverable |
|-----------|--------|-------------|
| M1: Alpha | +4 weeks | Basic router, handlers, `pip install` works |
| M2: Beta | +8 weeks | Full micro-framework API, decorators |
| M3: RC | +12 weeks | WebSocket, Pydantic, OpenAPI |
| M4: 1.0 | +16 weeks | NumPy integration, production-ready |
| M5: DS | +20 weeks | Full data science integrations |

### Comparison with FastAPI

| Feature | FastAPI | Armature-Py |
|---------|---------|-------------|
| Performance | Good (uvicorn) | **Excellent** (native Rust) |
| Async | Full support | Full support |
| Type hints | Pydantic | Pydantic + native |
| OpenAPI | Auto-generated | Auto-generated |
| WebSocket | Via Starlette | Native |
| NumPy | Manual | **Zero-copy native** |
| Memory | Python GC | **Rust ownership** |
| GIL | Blocked during sync | **Released during I/O** |

---

## RICE Scoring Details

```
Score = (Reach ร— Impact ร— Confidence) / Effort

Reach: Users affected (1-10)
Impact: Experience improvement (0.25=minimal, 0.5=low, 1=medium, 2=high, 3=massive)
Confidence: Certainty (0.5=low, 0.8=medium, 1.0=high)
Effort: S=1, M=2, L=4, XL=8 (person-weeks)
```

### Top 3 Recommendations

1. **HTTP/2 Support** - Table stakes for production APIs. Competitors have it.
   - Reach: 9, Impact: 2, Confidence: 1.0, Effort: M(2) โ†’ **Score: 9.0**

2. **Database Migrations** - Every serious framework has this. Major DX gap.
   - Reach: 8, Impact: 2, Confidence: 0.9, Effort: M(2) โ†’ **Score: 7.2**

3. **Admin Dashboard Generator** - Massive time saver, differentiator vs Actix/Axum.
   - Reach: 6, Impact: 3, Confidence: 0.8, Effort: L(4) โ†’ **Score: 3.6**

---

## Competitive Analysis Summary

| Feature | Armature | Actix | Axum | NestJS |
|---------|----------|-------|------|--------|
| HTTP/2 | โœ… | โœ… | โœ… | โœ… |
| HTTP/3 | โœ… | โŒ | โŒ | โŒ |
| GraphQL | โœ… | โœ… | โœ… | โœ… |
| WebSocket | โœ… | โœ… | โœ… | โœ… |
| Built-in DI | โœ… | โŒ | โŒ | โœ… |
| Decorator Syntax | โœ… | โŒ | โŒ | โœ… |
| Micro-framework Mode | โœ… | โœ… | โœ… | โŒ |
| Database Migrations | โŒ | โŒ | โŒ | โœ… |
| Admin Generator | โœ… | โŒ | โŒ | ๐Ÿ”ถ |
| OpenAPI | โœ… | ๐Ÿ”ถ | ๐Ÿ”ถ | โœ… |
| CLI Tooling | โœ… | โŒ | โŒ | โœ… |
| Payment Processing | โœ… | โŒ | โŒ | ๐Ÿ”ถ |
| Node.js Bindings | ๐Ÿ”ถ | โŒ | โŒ | N/A |
| Python Bindings | ๐Ÿ”ถ | โŒ | โŒ | N/A |

โœ… = Built-in | ๐Ÿ”ถ = Planned/Via plugin | โŒ = Not available

---

## Benchmark Reference (December 2025)

### Core Framework

| Benchmark | Time |
|-----------|------|
| Health check | 386ns |
| GET with param | 692ns |
| POST with body | 778ns |
| Route first match | 51ns |
| JSON serialize (small) | 17ns |

### Micro-Framework (`armature_core::micro`)

| Benchmark | Time |
|-----------|------|
| Empty app creation | 25ns |
| App with 5 routes | 1.9-4.7ยตs |
| App with scope | 1.5ยตs |
| App with middleware | 857ns |
| Route (no middleware) | 875ns |
| Route (1 middleware) | 607ns |
| Route (3 middleware) | 1.9ยตs |
| Data creation | 30ns |
| Data access | <1ns |
| Data clone | 10ns |
| JSON handler | 3.7ยตs |
| Single route builder | 97ns |
| Multi-method builder | 525ns |
| Scope with routes | 448ns |

---

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.