# amitesh007z/stella architecture

> Architecture diagram of the GitHub repository amitesh007z/stella, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amitesh007z/stella
- Repository: https://github.com/amitesh007z/stella

## Overview

##### Project type and purpose
- Stella Protocol is a full-stack web application providing a routing intelligence engine for the Stellar network.
- The frontend is built with React (Vite), the backend with Fastify (Node.js), and it uses SQLite (WAL) for persistence.
- Key capabilities include anchor discovery, asset registry, in-memory route graph construction, pathfinding, quote generation, and execution planning.

##### File structure
- Monorepo root with two top-level folders:
- frontend/ – React code, pages, components, API client
- backend/ – Fastify server, configuration, database migrations, services, routes
- backend/src/services/ subdivides core domains: anchor crawler, asset registry, graph builder, route engine, execution engine
- Configuration files: .env examples, vercel.json, vite.config.js, DEPLOY.md
- README.md documents architecture, API, tech stack

##### README for architecture insights
- Core services listed: Anchor Crawler, Asset Registry, Route Graph, Route Resolver, Execution Engine, Quote Manager
- External dependencies: Horizon Testnet API, stellar.toml crawl, Freighter wallet

a. Main components (from top to bottom)
- User Interface (Browser/React SPA)
- API Layer (Fastify HTTP server)
- Core Services (vertically stacked):
1. Anchor Crawler
2. Asset Registry
3. Route Graph Builder
4. Route Discovery Engine (Pathfinder → Resolver → Cache)
5. Execution Engine (FeeCalc → Slippage → Planner → QuoteManager)
- Persistence & Cache: SQLite (WAL mode) + In-memory LRU cache
- External Systems: Stellar Horizon API, stellar.toml sources, Freighter Wallet
b. Relationships & interactions
- UI → REST API calls (/api/routes, /api/graph, /api/anchors, /api/quotes)
- API Layer delegates to Core Services, which read/write to SQLite or in-memory cache
- Anchor Crawler fetches stellar.toml (HTTP) and populates Asset Registry
- Graph Builder polls Asset Registry and Horizon for orderbook data to build weighted graph
- Route Discovery queries graph, applies algorithms, then Horizon validation
- Execution Engine uses Horizon SDK and Freighter to prepare transactions
c. Architectural patterns & design principles
- Layered architecture (presentation → API → domain services → data)
- Modular services (single responsibility for crawling, indexing, routing, execution)
- Two-layer cache: fast in-memory LRU + durable SQLite TTL cache
- Clean separation of concerns: routes vs. services vs. lib vs. plugins
- Graceful shutdown and health checks for reliability
d. Key technologies & libraries
- Frontend: React 19, Vite, React Router, Freighter API
- Backend: Node.js 20+, Fastify 5, better-sqlite3, @stellar/stellar-sdk, Pino
- Deployment: Vercel (frontend), Railway/Vercel (backend)

##### Detail without over-fragmentation
- Every major service from the file structure
- How migrations and config fit into the startup sequence (e.g., Fastify app init → migrate.js → service scheduling)
- “vertical” nature by ordering from top (user) down to bottom (network/deployment targets)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer"
        UI["User Interface (React SPA)"]:::ui
    end

    subgraph "API Layer"
        API["Fastify API Layer"]:::api
        Config["Configuration"]:::config
        Plugins["Error Handler Plugin"]:::plugin
        Startup["App Init & Migrations"]:::api
        Routes["HTTP Routes"]:::api
    end

    subgraph "Core Services"
        AC["Anchor Crawler"]:::core
        AR["Asset Registry"]:::core
        GB["Route Graph Builder"]:::core
        RE["Route Discovery Engine"]:::core
        EE["Execution Engine"]:::core
    end

    subgraph "Data Stores"
        DB["SQLite (WAL)"]:::db
        Cache["In-memory LRU Cache"]:::cache
    end

    subgraph "External Systems"
        STOML["stellar.toml Sources"]:::external
        HZN["Stellar Horizon API"]:::external
        FR["Freighter Wallet"]:::external
    end

    UI -->|"calls REST API"| API
    API --> Config
    API --> Plugins
    API --> Startup
    API --> Routes

    Routes --> AC
    Routes --> AR
    Routes --> GB
    Routes --> RE
    Routes --> EE

    AC -->|"fetches toml"| STOML
    AC --> AR
    AC --> DB

    AR --> DB

    GB -->|"polls horizon"| HZN
    GB --> AR
    GB --> DB

    RE --> GB
    RE --> DB
    RE -->|"stores results"| Cache
    Cache -->|"cached hits"| RE

    EE --> HZN
    EE --> FR
    EE --> DB
    EE --> AR

    %% Click Events
    click UI "https://github.com/amitesh007z/stella/tree/main/frontend/src"
    click API "https://github.com/amitesh007z/stella/blob/main/backend/src/index.js"
    click Config "https://github.com/amitesh007z/stella/blob/main/backend/src/config/index.js"
    click Plugins "https://github.com/amitesh007z/stella/blob/main/backend/src/plugins/errorHandler.js"
    click Startup "https://github.com/amitesh007z/stella/blob/main/backend/src/app.js"
    click Routes "https://github.com/amitesh007z/stella/tree/main/backend/src/routes"
    click AC "https://github.com/amitesh007z/stella/tree/main/backend/src/services/anchor"
    click AR "https://github.com/amitesh007z/stella/tree/main/backend/src/services/asset"
    click GB "https://github.com/amitesh007z/stella/tree/main/backend/src/services/graph"
    click RE "https://github.com/amitesh007z/stella/tree/main/backend/src/services/route"
    click EE "https://github.com/amitesh007z/stella/tree/main/backend/src/services/execution"
    click DB "https://github.com/amitesh007z/stella/tree/main/backend/src/db"
    click Cache "https://github.com/amitesh007z/stella/blob/main/backend/src/services/route/routeCache.js"
    click STOML "https://github.com/amitesh007z/stella/blob/main/backend/src/lib/horizon.js"
    click HZN "https://github.com/amitesh007z/stella/blob/main/backend/src/lib/horizon.js"
    click FR "https://github.com/amitesh007z/stella/blob/main/backend/src/lib/logger.js"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef api fill:#DFF7E0,stroke:#28A745,color:#28A745;
    classDef core fill:#FFE8B0,stroke:#E0A800,color:#E0A800;
    classDef db fill:#D1B48C,stroke:#8B4513,color:#8B4513,stroke-width:2px;
    classDef cache fill:#E0E0E0,stroke:#6C757D,color:#6C757D;
    classDef external fill:#E9D0FF,stroke:#6F42C1,color:#6F42C1,stroke-dasharray: 5 5;
    classDef config fill:#FFF5E6,stroke:#FF8C00,color:#FF8C00;
    classDef plugin fill:#FFECEC,stroke:#DC3545,color:#DC3545;
```
