> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sphyre.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# Fortro Engine

> Rust Axum backend powering Sphyre identity, credential, consent, and verification flows

# Fortro Engine

Fortro Engine is the central backend for the Sphyre ecosystem. It exposes the REST API used by Sphyre ALV, Sphyre Issuers, and Sphyre Verifier, then coordinates MongoDB persistence, IPFS storage, cryptographic operations, and Base Sepolia smart-contract calls.

<CardGroup cols={2}>
  <Card title="Runtime" icon="server">
    **Language:** Rust 2021<br />
    **Framework:** Axum `0.7.5`<br />
    **Async runtime:** Tokio `1.32.0`
  </Card>

  <Card title="Primary Responsibilities" icon="shield">
    DID authentication<br />
    Credential issuance<br />
    Presentation verification<br />
    Consent and blockchain anchoring
  </Card>
</CardGroup>

## Implemented Route Groups

Routes are mounted in `src/api/mod.rs` under `/api`.

| Module                    | Base path                | What it handles                                                                        |
| ------------------------- | ------------------------ | -------------------------------------------------------------------------------------- |
| `auth.rs`                 | `/api/auth`              | Register, login, challenge verification, DID generation, profile, wallet auth          |
| `wallet.rs`               | `/api/wallet`            | Holder credentials, wallet profile, evidence upload, sharing, consents, activities     |
| `credential_request.rs`   | `/api/wallet`            | Holder credential requests and issuer-side approval/rejection endpoints                |
| `presentation_request.rs` | `/api/wallet`            | Presentation request approval/rejection and holder pending request polling             |
| `issuer.rs`               | `/api/issuer`            | Issuer profile, auth hash, schemas, templates, offers, issuance, revocation, stats     |
| `verifier.rs`             | `/api/verifier`          | Verifier profile, presentation requests, presentations, presets, consent checks, stats |
| `domain.rs`               | `/api/domain`            | Issuer/verifier domain challenge and verification status                               |
| `did.rs`                  | `/api/did`               | DID resolution                                                                         |
| `qr.rs`                   | `/api/qr`                | Short URL resolution and QR payload creation                                           |
| `admin.rs`                | `/api/admin`             | DID generation, key migration, holder DID registration                                 |
| `blockchain_new.rs`       | `/api/blockchain`        | Current credential, schema, and consent contract helpers                               |
| `blockchain.rs`           | `/api/blockchain-legacy` | Legacy blockchain helpers retained for compatibility                                   |
| `health.rs`               | `/api/health`            | Health checks                                                                          |

## Key Endpoints

```text theme={null}
POST /api/auth/register
POST /api/auth/login
POST /api/auth/challenge
POST /api/auth/verify-challenge
POST /api/auth/wallet/encrypted-seed
POST /api/auth/wallet/encrypted-seed/get

GET  /api/wallet/:did/credentials
GET  /api/wallet/:did/activities
GET  /api/wallet/:did/statistics
POST /api/wallet/:did/credentials/share
GET  /api/wallet/:did/consents
POST /api/wallet/:did/consents
POST /api/wallet/:did/consents/:consent_id/revoke
POST /api/wallet/credential-request
GET  /api/wallet/:did/credential-requests
POST /api/wallet/presentation-requests
POST /api/wallet/presentation-requests/:request_id/approve
GET  /api/wallet/presentation-requests/:request_id/status

POST /api/issuer/:did/schemas
GET  /api/issuer/:did/schemas
POST /api/issuer/:did/templates
POST /api/issuer/:did/issue
POST /api/issuer/:did/credentials/:credential_id/revoke
POST /api/issuer/:did/offers

POST /api/verifier/requests
GET  /api/verifier/requests/:id
POST /api/verifier/presentations
GET  /api/verifier/:did/presentations
POST /api/verifier/presentations/:id/verify
GET  /api/verifier/verify/ipfs/:ipfs_hash
GET  /api/verifier/:did/presets
POST /api/verifier/:did/presets

POST /api/blockchain/credential/register
POST /api/blockchain/credential/revoke
GET  /api/blockchain/credential/check/:did/:credential_hash
POST /api/blockchain/schema/register
POST /api/blockchain/consent/grant
POST /api/blockchain/consent/revoke
GET  /api/blockchain/status
```

## Dependencies

```toml theme={null}
axum = { version = "0.7.5", features = ["multipart", "macros"] }
mongodb = "3.0.0"
ipfs-api-backend-hyper = "0.6.0"
ethers = { version = "2.0.8", features = ["legacy"] }
jsonwebtoken = "8.3.0"
ed25519-dalek = "1.0.1"
bbs = "0.4.1"
bulletproofs = "4.0.0"
pqc_kyber = { version = "0.7.1", features = ["kyber768"] }
crystals-dilithium = "1.0.0"
```

## Project Structure

```text theme={null}
fortro-engine/
├── src/
│   ├── main.rs
│   ├── api/
│   ├── blockchain/
│   ├── middleware/
│   ├── services/
│   ├── utils/
│   ├── models.rs
│   ├── db.rs
│   ├── config.rs
│   └── error.rs
├── Cargo.toml
└── Cargo.lock
```

## Data Model Notes

Schemas use an `attributes` array, not a generic `fields` array. Credential records include BBS signature metadata, Kyber encryption state, optional anonymous credential data, evidence attachments, extensions, IPFS references, and blockchain transaction references.

```json theme={null}
{
  "credential_type": "NationalID",
  "schema_id": "schema-uuid",
  "subject_did": "did:alyra:holder...",
  "attributes": {
    "full_name": "Alice Smith"
  },
  "evidence_required": ["photo_id"],
  "extensions": []
}
```

## Smart Contracts

The backend integrates with the contracts in `fortro-contract-dev/hardhat/contracts`, including `CredentialRegistry`, `SchemaRegistry`, `ConsentRegistry`, `SSIRegistry`, `SSIRegistryFactory`, `SphyreAccessControl` (`AccessControl.sol`), `ERC2771Context`, and `MinimalForwarder`.

<Card title="Smart Contract Layer" icon="file-contract" href="/components/smart-contracts">
  Review contract inventory, roles, on-chain operations, and blockchain API routes.
</Card>
