# ukparliament/written-answer-bots architecture

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

- Interactive diagram: https://gitdiagram.com/ukparliament/written-answer-bots
- Repository: https://github.com/ukparliament/written-answer-bots

## Overview

##### Main Components
- External Data Sources/API: Since the app imports data (questions, written statements, etc.), add a component for “Data APIs” or “External Data Sources” where the application pulls information from.
- Social Media Integrations: There are specific libraries and tasks under lib/post (directories for Mastodon and Bluesky). Represent these as “Mastodon API” and “Bluesky API” components. Indicate that the application uses these APIs to post content.
- Background or Scheduled Tasks: Numerous Rake tasks (in lib/tasks) related to importing data and posting tweets (e.g., task_import_members.rake, tweet-bluesky.rake, tweet-mastodon.rake, etc.) indicate scheduled jobs that run separately from the main web server. Represent these tasks as a “Task Scheduler / Background Jobs” component.

##### Relationships and Interactions
- The Application Server (Rails MVC) receives HTTP requests via controllers, interacts with the models to fetch or persist data in the Database, and renders views to users.
- It also triggers background tasks (either via scheduled Rake tasks or cron jobs) that handle importing data from external APIs.
- Once imported, or based on certain conditions, the application posts content to Mastodon and Bluesky via the specific integration modules found in lib/post.

##### Architectural Patterns
- Using the standard Rails MVC design is a key pattern in this project.
- The separation between the web-facing part of the application (handling user interactions, controllers and views) and background tasks (executing Rake jobs for importing and posting) should be visually emphasized.
- The integration with external APIs (both to import content and to post content) is an important aspect.

##### Technologies and Design Principles
- Ruby on Rails: Mark the main application as a Ruby on Rails-based server.
- Rake Tasks: Highlight that periodic task execution (for importing and tweeting) is based on Rake tasks.
- API Integrations: Note that the project integrates with Mastodon and Bluesky endpoints.
- Versioning/Deployment: Include elements such as the Procfile that indicates usage on platforms like Heroku, hinting at deployment practices.

##### Final Advice and Details
- Document any relationships or dependencies, especially focusing on how data travels through the system—from importation, persistence, to content posting on social networks.

## Diagram (Mermaid)

```mermaid
flowchart TD
    client["Clients"]:::client

    subgraph "Rails Application Server (MVC)"
        controllers["Controllers"]:::rails
        models["Models"]:::rails
        views["Views"]:::rails
    end

    database["(Database)"]:::database
    background["Background Tasks / Scheduled Jobs"]:::background
    external["External Data APIs"]:::external
    mastodon["Mastodon API Integration"]:::social
    bluesky["Bluesky API Integration"]:::social

    client -->|"HTTP"| controllers
    controllers -->|"process"| models
    models -->|"CRUD"| database
    controllers -->|"trigger"| background
    external -->|"import"| background
    controllers -->|"post"| mastodon
    controllers -->|"post"| bluesky
    background -->|"post"| mastodon
    background -->|"post"| bluesky

    click controllers "https://github.com/ukparliament/written-answer-bots/tree/main/app/controllers"
    click models "https://github.com/ukparliament/written-answer-bots/tree/main/app/models"
    click views "https://github.com/ukparliament/written-answer-bots/tree/main/app/views"
    click external "https://github.com/ukparliament/written-answer-bots/tree/main/lib/import"
    click mastodon "https://github.com/ukparliament/written-answer-bots/blob/main/lib/post/mastodon/written_statements.rb"
    click bluesky "https://github.com/ukparliament/written-answer-bots/blob/main/lib/post/bluesky/written_statements.rb"
    click background "https://github.com/ukparliament/written-answer-bots/tree/main/lib/tasks"
    click database "https://github.com/ukparliament/written-answer-bots/tree/main/db"

    classDef rails fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef background fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef external fill:#D5F5E3,stroke:#239B56,stroke-width:2px;
    classDef social fill:#FADBD8,stroke:#C0392B,stroke-width:2px;
    classDef database fill:#D6EAF8,stroke:#2874A6,stroke-width:2px;
    classDef client fill:#F5EEF8,stroke:#8E44AD,stroke-width:2px;
```
