You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LUMOS provides deep integration with the [Anchor framework](https://www.anchor-lang.com/), allowing you to generate complete Solana programs with account contexts, IDL, and TypeScript clients.
7
7
8
+
## LUMOS + Anchor: Better Together
9
+
10
+
:::tip[Key Point]
11
+
**LUMOS complements Anchor, it doesn't replace it.** LUMOS generates Anchor-compatible code from a schema, giving you a single source of truth for your data structures.
12
+
:::
13
+
14
+
Think of it this way:
15
+
-**Anchor** = The framework that runs your Solana program
16
+
-**LUMOS** = The tool that generates Anchor code from a schema
17
+
18
+
**Why use both?**
19
+
20
+
| Without LUMOS | With LUMOS |
21
+
|---------------|------------|
22
+
| Manually write Rust structs | Define once in `.lumos` schema |
| Calculate account space by hand | Auto-calculated `LEN` constants |
26
+
| Write IDL manually or extract | Auto-generate IDL from schema |
27
+
28
+
**LUMOS generates standard Anchor code** - your program still uses `anchor_lang`, `#[account]`, `#[program]`, and everything else you know. The difference is you define your types once and generate the rest.
29
+
30
+
---
31
+
32
+
## When to Use LUMOS vs Anchor Alone
33
+
34
+
| Scenario | Recommendation |
35
+
|----------|----------------|
36
+
| Starting a new Anchor project | ✅ Use LUMOS - define schema first, generate code |
37
+
| Existing Anchor project, want type sync | ✅ Use LUMOS - adopt gradually for new types |
38
+
| Simple program, few account types | ⚠️ Either works - Anchor alone is fine |
39
+
| Complex program, many shared types | ✅ Use LUMOS - prevents drift between Rust/TS |
40
+
| Need custom IDL modifications | ⚠️ Start with LUMOS, customize after |
41
+
| Team with mixed Rust/TS developers | ✅ Use LUMOS - schema is readable by all |
42
+
43
+
**Bottom line:** If you're writing TypeScript clients that interact with your Anchor program, LUMOS saves you from maintaining duplicate type definitions.
44
+
45
+
---
46
+
8
47
## Overview
9
48
10
49
When your schema uses `#[account]` attributes, LUMOS automatically generates Anchor-compatible code:
@@ -477,12 +516,148 @@ struct Stake {
477
516
478
517
---
479
518
519
+
## Common Patterns
520
+
521
+
### PDA (Program Derived Address) Accounts
522
+
523
+
PDAs are accounts whose address is derived from seeds. Define the account structure in LUMOS, derive the PDA in your Anchor code:
524
+
525
+
```rust
526
+
// schema.lumos
527
+
#[solana]
528
+
#[account]
529
+
structUserProfile {
530
+
authority:PublicKey,
531
+
username:String,
532
+
reputation:u64,
533
+
created_at:i64,
534
+
}
535
+
```
536
+
537
+
```rust
538
+
// In your Anchor program
539
+
#[derive(Accounts)]
540
+
#[instruction(username:String)]
541
+
pubstructCreateProfile<'info> {
542
+
#[account(
543
+
init,
544
+
payer = authority,
545
+
space = 8 +UserProfile::LEN,
546
+
seeds = [b"profile", authority.key().as_ref()],
547
+
bump
548
+
)]
549
+
pubprofile:Account<'info, UserProfile>,
550
+
#[account(mut)]
551
+
pubauthority:Signer<'info>,
552
+
pubsystem_program:Program<'info, System>,
553
+
}
554
+
```
555
+
556
+
### One-to-Many Relationships
557
+
558
+
Model relationships using PublicKey references:
559
+
560
+
```rust
561
+
// schema.lumos
562
+
#[solana]
563
+
#[account]
564
+
structCollection {
565
+
authority:PublicKey,
566
+
name:String,
567
+
item_count:u32,
568
+
}
569
+
570
+
#[solana]
571
+
#[account]
572
+
structItem {
573
+
collection:PublicKey, // Reference to parent
574
+
owner:PublicKey,
575
+
name:String,
576
+
attributes:Vec<u8>,
577
+
}
578
+
```
579
+
580
+
### Token Account Integration
581
+
582
+
When working with SPL tokens alongside LUMOS-generated accounts:
0 commit comments