Skip to content

Latest commit

 

History

History
216 lines (164 loc) · 12.9 KB

reports.md

File metadata and controls

216 lines (164 loc) · 12.9 KB

Codebase Analysis Report: IRIS Protocol

1. Executive Summary

  • What this project does: IRIS is a decentralized, non-custodial AI protocol designed to assess portfolio risk, score tokens and wallets, and automatically protect digital assets using real-time on-chain signals.
  • Its overall purpose: To provide DeFi users on the Solana blockchain with dynamic risk scoring, auto-swap emergency actions, and claimable Insurance NFTs to autonomously cover and protect against losses.
  • Technology stack: The application utilizes a modern, multi-tiered stack including Next.js 15 / React 19 for the frontend interfaces, FastAPI / Python for the AI Risk Engine back-end, and Rust / Anchor for the Solana smart contracts.
  • Maturity level: Prototype / MVP Stage. The application is in a closed testing phase. The UI and waitlist are built, but the DevOps pipeline (Docker, CI/CD) and full test coverages are incomplete.
  • Key strengths: Excellent separation of concerns, utilization of cutting-edge frameworks, web3-native authentication via Civic/Supabase, and highly readable, modular smart contract definitions.
  • High-level risks: Completely empty Docker configuration files, zero configured CI/CD pipelines, reliance on a centralized oracle for risk score signatures, and missing frontend test coverage.

2. Project Structure Overview

Folder Structure

iris-protocol/
├── anchor/             # Solana smart contracts
│   ├── Anchor.toml     # Anchor workspace configuration
│   └── programs/
│       └── anchor/     # Rust smart contract source code
├── backend/            # AI Risk Engine API
│   ├── Dockerfile      # (Currently Empty)
│   ├── docker-compose.yml # (Currently Empty)
│   ├── requirements.txt
│   └── app/            # FastAPI source code (api, core, data, models, test)
├── frontend/           # Main Web Application
│   ├── package.json
│   └── src/            # Next.js App Router (app, components, hooks, services)
└── waitlist/           # Landing Page / Waitlist Service
    ├── package.json
    └── src/            # Next.js application

Explanation & Architectural Pattern

The system is built using a Microservices / Modular Monorepo Architecture:

  1. frontend/: The main user-facing decentralized application (dApp).
  2. waitlist/: A separate marketing and waitlist generation site.
  3. backend/: A centralized Python Microservice serving the AI Risk logic, likely interfacing with OpenAI and Helius RPC.
  4. anchor/: The decentralized on-chain engine executing state changes and enforcing insurance mechanics.

Entry Points

  • Frontend: frontend/src/app/page.tsx & frontend/src/app/layout.tsx
  • Backend API: backend/app/main.py
  • Smart Contract: anchor/programs/anchor/src/lib.rs

3. Technology Stack

Frontend & Waitlist

  • Framework: Next.js 15.3.1 (App Router)
  • Language: TypeScript / React 19.0.0
  • Styling: TailwindCSS 4, Radix UI primitives, Framer Motion
  • Web3: @solana/web3.js (^1.98.2), @solana/wallet-adapter-react, @civic/auth-web3
  • Backend-as-a-Service: Supabase (@supabase/supabase-js ^2.49.4)
  • Package Manager: npm

Backend (Risk Engine)

  • Framework: FastAPI (0.110.1)
  • Language: Python 3.x
  • Server: Uvicorn (0.29.0)
  • Validation: Pydantic (2.7.1)
  • Package Manager: pip (requirements.txt)

Smart Contracts (Anchor)

  • Framework: Anchor Framework
  • Language: Rust
  • Blockchain: Solana, SPL-Token
  • Tooling: ts-mocha for localnet testing, yarn as package manager for Anchor tooling.

4. Dependency Analysis

  • Major Dependencies: Next.js, React, FastAPI, Supabase, Solana Web3.js.
  • Outdated Packages: No severely outdated packages. The project aggressively relies on bleeding-edge versions (Next.js 15, React 19, TailwindCSS 4).
  • Unused Dependencies: Cannot statically determine unused packages without a full install, however, waitlist includes @wallet-ui/react canary builds which are experimental.
  • Security Risk Assessment: Heavy reliance on beta/canary versions (e.g., Next 15) could introduce unstable behaviors or undiscovered zero-day vulnerabilities in the Node framework.
  • Large/Heavy Dependencies: @solana/web3.js and framer-motion add significant bundle weight.

5. Code Quality Review

  • Code Organization: Excellent. The domain logic is tightly scoped within respective service directories. FastAPI uses clean architecture (api, core, models, data).
  • Naming Conventions: Consistent PascalCase for React components and snake_case for Python / Rust implementations.
  • Modularity / Separation of Concerns: Very high. The separation of the waitlist from the main app ensures the heavy main frontend bundle doesn't impact marketing SEO.
  • Complexity Hotspots:
    • backend/app/models/llm.py: Contains heavy logic for prompt engineering and OpenAI interactions.
    • anchor/programs/anchor/src/lib.rs: Manages multiple interdependent states (Subscriptions, Insurance NFTs, Governance Actions).
  • Overall Code Quality Score: 8/10.
  • Justification: The code is thoughtfully structured and uses best-in-class tools. However, points are deducted for empty DevOps configurations, lack of frontend testing, and some brittle env variable implementations (e.g., non-null assertions !).

6. Architecture Analysis

High-Level Architecture Diagram

[ DeFi User ] 
      │ 
      ├──> (Web3 Auth via Civic) ──> [ Next.js Frontend ]
      │                                     │
      │                                     ├──> (REST API) ──> [ FastAPI Risk Engine ]
      │                                     │                         └──> [ OpenAI / Helius RPC ]
      │                                     │
      └──> (Wallet Signature) ──────────────┴──> [ Solana Blockchain (Anchor Contract) ]

Data Flow & State Management

  • State Management: Frontend utilizes React Contexts, Hooks, and likely Jotai for the waitlist. Server-state is cached via @tanstack/react-query.
  • API Structure: Python backend exposes standard REST endpoints (/api/v1/evaluate, /api/v1/explain).
  • Design Patterns:
    • Dependency Injection: Used heavily within FastAPI routes.
    • Provider Pattern: Standard in Next.js for Solana Wallet injection and Theme management.
  • Coupling: The system is loosely coupled via API boundaries, which is an excellent architectural choice for scalability.

7. Security Assessment

Checks Performed

  • Hardcoded secrets: 🟢 None found. Proper usage of os.getenv() and process.env.
  • API Keys: 🟢 Safely retrieved from environment variables.
  • Unsafe environment handling: 🔴 Detected in frontend/src/app/api/supabase-notification/route.ts via process.env.RESEND_API_KEY!. If this variable is missing in deployment, the Node instance will throw an unhandled exception.
  • Authentication: 🟢 Securely handled utilizing Civic web3 authentication passing JWTs to Supabase.
  • Oracle Centralization: 🟡 anchor contract relies heavily on verify_iris_signature to trust off-chain risk scores. If the IRIS server is compromised, malicious scores can be injected.

Severity Levels

  • High: Lack of Docker/Deployment configurations prevents secure, reproducible deployments in production environments.
  • Medium: Centralized Risk Oracle architecture in the Smart Contract.
  • Low: Non-null assertions (!) on environment variables.

8. Performance Considerations

  • Potential Bottlenecks: Synchronous AI inference delays. The evaluate endpoint in FastAPI relies on LLM models which can take several seconds to stream/return, potentially causing frontend timeout issues.
  • Memory Concerns: Python ML modeling (if loaded in memory dynamically instead of purely via external openAI calls) could bloat the Uvicorn workers.
  • Unoptimized Assets: Next.js automatically optimizes images, but framer-motion animations should be lazily loaded where possible.
  • Async Handling Quality: The Python backend correctly implements async def for endpoints wrapper logic call_next(request) middleware, ensuring Uvicorn can efficiently handle concurrent connections.

9. Testing Evaluation

  • Test coverage estimate: ~15% overall.
  • Backend Tests: Standard pytest configurations found (test_api.py, test_data.py, test_models.py). Good baseline.
  • Frontend & Waitlist Tests: No comprehensive unit testing (Jest/Vitest) or E2E testing (Cypress/Playwright) suites could be located.
  • Smart Contract Tests: Anchor.toml defines a ts-mocha testing command, but extensive test directories are not populated.
  • Quality: The existing python tests check logical API validations, but system-wide integration tests are missing.

10. DevOps & Deployment

  • CI/CD setup: Missing. .github/workflows does not exist.
  • Docker configuration: Critically Deficient. Both Dockerfile and docker-compose.yml in the backend/ directory are entirely empty (0 bytes).
  • Production readiness: Not Ready. The application cannot be safely built or deployed to a cloud environment without functional containerization and CI validations.
  • Environment variables: Reliant on local .env files. Ensure secrets managers (AWS Secrets, Vercel Env) are used in production.

11. Documentation Review

  • README quality: Exceptionally high. The core README.md details context, architecture, team, use of funds, and links effectively.
  • Setup instructions: Minimal local environment setup instructions (e.g., missing "how to run the python server" in the root README).
  • Code comments quality: Very clean. lib.rs has strong docstring-equivalent comments above instructions (// Trigger a protection action...).

12. Maintainability Assessment

  • Ease of onboarding: High. The boundaries between backend, frontend, and smart contract are clearly delineated. A developer can work on the UI without understanding Rust.
  • Scalability potential: Very high. The backend can be scaled horizontally via Docker (once implemented) and the frontend deployed effectively on Vercel/CDN.
  • Technical debt level: Low, though "DevOps Debt" is currently the system's largest hurdle.

13. Risk Assessment Matrix

Risk Impact Likelihood Severity Recommendation
Empty Docker/DevOps Files High High Critical Immediately construct Dockerfile and docker-compose.yml for reproducible environments.
Missing CI/CD Pipelines Medium High High Implement GitHub Actions to run linters, type checks, and Python tests on every PR.
Brittle Env Handling Medium Low Medium Remove ! assertions in Next.js. Validate environment variables at startup (e.g., using zod).
Oracle Centralization High Low Medium Research decentralized consensus for reporting Risk Scores to the smart contract for V2.
No Frontend Tests Low High Low Introduce Cypress or Playwright to test the Web3 connection and swap user flows.

14. Refactoring & Improvement Roadmap

Immediate Fixes (Critical)

  1. Write the Dockerfile for the Python backend with uvicorn startup instructions.
  2. Fill out docker-compose.yml to orchestrate local development (e.g., pulling a local postgres/redis if needed).
  3. Validate all environment variables in both Node and Python environments securely on startup rather than at runtime.

Short-term Improvements

  1. Implement a GitHub Action (.github/workflows/main.yml) that runs npm run lint and pytest.
  2. Add end-to-end (E2E) testing for the critical Web3 wallet connection workflows.
  3. Write test cases for the Rust Smart Contracts (tests/iris.ts) to validate trigger protections logic limit checks.

Long-term Architectural Improvements

  1. Evolve the anchored Python signature verification to a decentralized validator network or existing decentralized Oracle (like Switchboard) for higher trustlessness.
  2. Separate the UI-Kit into an independent monorepo workspace to share components between the waitlist and main application avoiding duplicate dependencies.

15. Final Codebase Health Score

  • Overall Score: 78 / 100
  • Justification: The project shows incredible promise with clean architecture, modern tooling across a vast tech stack, and clear macro-scale design. It loses 22 points entirely on operational maturity: the lack of Docker configurations, automated deployment pipelines, and comprehensive end-to-end tests prevent it from being a production-ready system.
  • Summary Verdict: A beautifully designed and architected MVP that needs a heavy dose of DevOps and Testing attention before Mainnet launch.