# cryptokitchen23/fengshui_agent architecture

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

- Interactive diagram: https://gitdiagram.com/cryptokitchen23/fengshui_agent
- Repository: https://github.com/cryptokitchen23/fengshui_agent

## Overview

##### Recognize the Main Project Components
- Web Application (Rails MVC): The core application is built using Ruby on Rails. Identify the MVC layers:
- Controllers: In app/controllers (e.g., PumpFunPromptsController, SystemPromptsController)
- Views: In app/views (with layouts and specific views for prompts)
- Models: In app/models (e.g., Message, Prompt)
- Frontend Assets: JavaScript and CSS managed in app/assets and app/javascript, supporting interactivity in the browser.
- Database: Managed via ActiveRecord with migrations found in db/migrate and overall schema in db/schema.rb.
- Background Job Processing: Located in app/jobs (e.g., telegram_bot_worker_job, twitter_bot_worker_job) to handle asynchronous tasks for messaging bots.
- Service Layer: Contains integrations with external APIs and business logic (e.g., openai_service, telegram_botter, twitter_botter, cmc_pump_fun_service, etc.).
- External Services: The README mentions using external API keys for services like OpenAI, Telegram, and CoinMarketCap. These services should be represented as distinct external components interfaced via the service layer.

##### Out the Relationships and Interaction Flow
- Client (Browser/User): Initiates requests that hit the Rails controllers.
- Controllers then coordinate between Models (database operations), Services (external API calls), and Views (to render responses).
- Background Jobs: Triggered either by controllers or scheduled tasks, they run asynchronously to interact with external platforms (bots) and process responses.
- The Database component (usually an SQL database, as indicated by ActiveRecord migrations) has a bidirectional relationship with models, maintaining persistent data.

##### Architectural Patterns and Design Principles
- MVC (Model-View-Controller): Clearly separate each major application layer.
- Service-Oriented Architecture: The “app/services” folder indicates encapsulated business logic for interfacing with external services and handling domain-specific tasks.
- Asynchronous Job Processing: Use of background jobs (e.g., Telegram and Twitter bot workers) introduces the aspect of event-driven processing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser["Browser/Client"]:::frontend

    subgraph "Rails Application"
        Controllers["Controllers"]:::rails
        Models["Models"]:::rails
        Views["Views"]:::rails
        Services["Services"]:::rails
    end

    subgraph "Frontend Assets"
        AssetsCSS["CSS & Static Assets"]:::assets
        AssetsJS["JavaScript Assets"]:::assets
    end

    Database["Database (ActiveRecord)"]:::database
    Background["Background Jobs"]:::jobs
    Config["Integrations Config"]:::config

    subgraph "External APIs"
        OpenAI["OpenAI API"]:::external
        Telegram["Telegram API"]:::external
        Twitter["Twitter API"]:::external
        CMC["CoinMarketCap API"]:::external
    end

    Browser -->|"UserRequest"| Controllers
    Controllers -->|"RenderViews"| Views
    Controllers -->|"DataOps"| Models
    Controllers -->|"InvokeLogic"| Services
    Views -->|"LoadAssets"| AssetsCSS
    Views -->|"LoadAssets"| AssetsJS
    Models <-->|"DBOperations"| Database

    Services -->|"Call"| OpenAI
    Services -->|"Call"| Telegram
    Services -->|"Call"| Twitter
    Services -->|"Call"| CMC

    Controllers -->|"TriggerJobs"| Background
    Background -->|"ProcessTelegram"| Telegram
    Background -->|"ProcessTwitter"| Twitter

    Config -.->|"Configure"| Services
    Config -.->|"Configure"| Background

    click Controllers "https://github.com/cryptokitchen23/fengshui_agent/tree/main/app/controllers"
    click Models "https://github.com/cryptokitchen23/fengshui_agent/tree/main/app/models"
    click Views "https://github.com/cryptokitchen23/fengshui_agent/tree/main/app/views"
    click AssetsCSS "https://github.com/cryptokitchen23/fengshui_agent/tree/main/app/assets"
    click AssetsJS "https://github.com/cryptokitchen23/fengshui_agent/tree/main/app/javascript"
    click Background "https://github.com/cryptokitchen23/fengshui_agent/tree/main/app/jobs"
    click Services "https://github.com/cryptokitchen23/fengshui_agent/tree/main/app/services"
    click Config "https://github.com/cryptokitchen23/fengshui_agent/tree/main/config/initializers"
    click Database "https://github.com/cryptokitchen23/fengshui_agent/tree/main/db/migrate"

    classDef frontend fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef rails fill:#E8DAEF,stroke:#6C3483,stroke-width:2px;
    classDef assets fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef database fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef jobs fill:#FDEBD0,stroke:#D35400,stroke-width:2px;
    classDef config fill:#F5CBA7,stroke:#A04000,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
```
