# aijarvis0x/jarvis-api architecture

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

- Interactive diagram: https://gitdiagram.com/aijarvis0x/jarvis-api
- Repository: https://github.com/aijarvis0x/jarvis-api

## Overview

##### Main Components
- API Server: At the core is the server entry point (src/server.ts and src/app.ts). This component includes the HTTP server that initializes the routing and other middleware.
- Routing Layer: Represented by the “src/routes” directory which includes endpoints such as admin, auth, bot, category, chat, market, metadata, user, etc.
- Database: Prisma is used for database management. Indicate “prisma/schema.prisma” and migration folders as the backend relational database, keeping in mind that Prisma abstracts the actual DB.
- Job Processing/Task Scheduler: Highlight “src/lib/job-queue.ts” and the cron-like jobs (such as those in core-ai and scan) that handle background tasks.
- Blockchain/Smart Contract Integration: Using the “src/monad” folder with ABI files (e.g., market.abi.ts, mint-nft.abi.ts), include a component that connects to blockchain networks or smart contracts.
- Configurations and Environment: Illustrate config modules (e.g., in src/config) that set up environment variables, keys, and other runtime settings.
- Deployment/Containerization: Include Docker components (Dockerfile, docker-compose, ecosystem configs, and nginx.conf) that indicate how the project is containerized and may be fronted by Nginx as a reverse proxy.

##### Relationships and Interactions
- Service Layer making calls to the Database (Prisma) to perform queries and/or migrations.
- How middleware (plugins) wraps around the routes to enforce security (auth, CSRF, rate limiting, verification) and any validation.
- If applicable, highlight the integration with blockchain smart contracts (via the monad modules) as external service calls.

##### Architectural Patterns and Technologies
- Clearly label components with technologies: TypeScript for the codebase, Prisma as the ORM, PostgreSQL (or another DB backend) as the database engine, Redis as the caching/message queue layer, and Docker for containerization.
- Mention the use of middleware (fastify-zod, security-headers, etc.) to enforce validation and security.
- Micro/module separation where each route/service encapsulates a specific domain (admin, auth, market, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Backend Service"
        subgraph "API Server Layer"
            API_Server["API Server"]:::api
        end

        subgraph "Routing & Middleware Layer"
            Middleware["Middleware/Plugins"]:::middleware
            Routes["Routing Layer"]:::api
        end

        subgraph "Service Layer"
            Service["Service Layer"]:::service
        end

        subgraph "Data Management"
            Database["Prisma/Database"]:::database
        end

        subgraph "Job Processing & Background Tasks"
            Job["Job Processing/Task Scheduler"]:::job
        end

        subgraph "External Integrations"
            Storage["External Storage/Cache"]:::external
            Blockchain["Blockchain Integration"]:::blockchain
        end

        subgraph "Configurations & Environment"
            Config["Configurations & Environment"]:::config
        end

        subgraph "Deployment & Containerization"
            Deployment["Deployment/Containerization"]:::deployment
        end
    end

    API_Server -->|"HTTP_Request"| Middleware
    Middleware -->|"After_Middleware"| Routes
    Routes -->|"Calls"| Service
    Service -->|"DB_Query"| Database
    Service -->|"Async_Job"| Job
    Service -->|"Upload"| Storage
    Service -->|"Smart_Contract"| Blockchain
    Job -->|"DB_Update"| Database
    Job -->|"S3_Request"| Storage
    Config -->|"Provides_Config"| API_Server
    Config -->|"Provides_Config"| Service
    Deployment -->|"Containers"| API_Server

    classDef api fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef middleware fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef service fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef database fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef job fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef external fill:#DDA0DD,stroke:#333,stroke-width:2px;
    classDef blockchain fill:#87CEEB,stroke:#333,stroke-width:2px;
    classDef config fill:#F5DEB3,stroke:#333,stroke-width:2px;
    classDef deployment fill:#D3D3D3,stroke:#333,stroke-width:2px;

    click API_Server "https://github.com/aijarvis0x/jarvis-api/blob/main/src/server.ts"
    click API_Server "https://github.com/aijarvis0x/jarvis-api/blob/main/src/app.ts"
    click Routes "https://github.com/aijarvis0x/jarvis-api/tree/main/src/routes"
    click Middleware "https://github.com/aijarvis0x/jarvis-api/tree/main/src/plugins"
    click Service "https://github.com/aijarvis0x/jarvis-api/tree/main/src/services"
    click Database "https://github.com/aijarvis0x/jarvis-api/blob/main/prisma/schema.prisma"
    click Database "https://github.com/aijarvis0x/jarvis-api/tree/main/prisma/migrations"
    click Job "https://github.com/aijarvis0x/jarvis-api/blob/main/src/lib/job-queue.ts"
    click Job "https://github.com/aijarvis0x/jarvis-api/blob/main/src/core-ai/start-ai-generate.job.ts"
    click Job "https://github.com/aijarvis0x/jarvis-api/blob/main/src/scan/scan.ts"
    click Job "https://github.com/aijarvis0x/jarvis-api/blob/main/src/scan/rescan.ts"
    click Storage "https://github.com/aijarvis0x/jarvis-api/blob/main/src/config/s3-config.ts"
    click Storage "https://github.com/aijarvis0x/jarvis-api/blob/main/src/lib/redis.ts"
    click Storage "https://github.com/aijarvis0x/jarvis-api/blob/main/src/lib/redis-instances.ts"
    click Storage "https://github.com/aijarvis0x/jarvis-api/blob/main/src/utils/s3.ts"
    click Storage "https://github.com/aijarvis0x/jarvis-api/blob/main/src/utils/upload-image.ts"
    click Blockchain "https://github.com/aijarvis0x/jarvis-api/tree/main/src/monad"
    click Config "https://github.com/aijarvis0x/jarvis-api/tree/main/src/config"
    click Config "https://github.com/aijarvis0x/jarvis-api/blob/main/src/env.ts"
    click Deployment "https://github.com/aijarvis0x/jarvis-api/tree/main/Dockerfile"
    click Deployment "https://github.com/aijarvis0x/jarvis-api/blob/main/docker-compose.yml"
    click Deployment "https://github.com/aijarvis0x/jarvis-api/blob/main/docker-compose.prod.yml"
    click Deployment "https://github.com/aijarvis0x/jarvis-api/blob/main/ecosystem.config.cjs"
    click Deployment "https://github.com/aijarvis0x/jarvis-api/blob/main/nginx.conf"
```
