# pakira-56a/aruaru-game architecture

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

- Interactive diagram: https://gitdiagram.com/pakira-56a/aruaru-game
- Repository: https://github.com/pakira-56a/aruaru-game

## Overview

##### Project’s Main Nature and Purpose
- This is a full-stack web application built on Rails 7.1.3, combining a game (memory matching game) with social posting and content sharing features.
- Its primary function is to serve as a communication tool where users post “あるある” (common quirks or typical features associated with various “界隈” or communities) and play a memory (神経衰弱) game based on these posts. It further supports social sharing (e.g., via X/Twitter) and integrates with external APIs like OpenAI.

##### Primary Components
— User Interface / Frontend:
- Web Pages: Views, layouts, JavaScript controllers, and assets (managed with TailwindCSS, DaisyUI, and Stimulus).
- Responsive design elements for mobile priority.
— Backend / Application Server (Rails):
- Controllers, Models, and Views following the MVC pattern.
- Service objects (e.g., OpenAIService) and custom modules (e.g., ogp_creator, custom_authentication_failure).
- Middleware for authentication (using Devise, OmniAuth for Google sign-in).
- Jobs, mailers, and channels (for real-time communication if used).
— Database:
- PostgreSQL for persistent storage, including tables for users, posts, tags, likes, and the specific columns for “あるある” entries (aruaru_one to aruaru_five).
— External Service Integrations:
- OpenAI API for AI-generated content.
- Google Analytics for tracking.
- AWS S3 (through CarrierWave configuration) for image storage.
- Render.com for deployment infrastructure.
- External sharing via X (Twitter) for social features.
- Cookie-based session management to limit certain features (e.g., one AI generation per day).
— Development & Deployment:
- Docker (Dockerfile, Dockerfile.dev) for containerization.
- Configuration files (Procfile.dev, GitHub workflows, Uptime Robot usage) for deployment and continuous integration.

##### Relationships and Interactions
- Web clients (browsers on mobile/desktop) interact with the Rails application server via HTTP(S).
- The controllers render views and respond to user interactions (game play, posting, and searching).
- The business logic (models, services) manages data transformations, game rules, and interaction with the OpenAI API.
- Persistent state is maintained in PostgreSQL.
- Uploaded images (for posts, ogp generation) are handled via CarrierWave and stored on AWS S3.
- When a request for AI generation is made, the application invokes the OpenAIService which communicates directly with the OpenAI API. Cookie-based session limits are checked before the API call is allowed.
- External redirects: After game completion or share actions, users are directed to X (Twitter) for social interaction.

##### Architectural Patterns and Technologies
- The organization follows the MVC design pattern, with clear separation between presentation (views/assets), business logic (controllers/models/services), and persistence (database).
- Frontend enhancements employ modern JavaScript patterns (Stimulus controllers) with TailwindCSS for styling.
- Authentication is managed with Devise and OmniAuth.
- For asynchronous or background tasks, Rails jobs are used.
- Infrastructure and deployment leverage Docker, Render.com, and GitHub Actions workflows for testing.

##### Detailed Elements
- Annotations for security measures (cookie session management for daily limits, CSRF/XSS protection in the configuration).

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    UB("User Browser"):::client

    %% Frontend (UI)
    subgraph "Frontend (UI)"
        FE1("Views (HTML/CSS/JS)"):::frontend
        FE2("JavaScript Controllers"):::frontend
        FE3("Stylesheets"):::frontend
    end

    %% Backend (Rails)
    subgraph "Backend (Rails)"
        BE1("Controllers (MVC)"):::backend
        BE2("Models (ORM)"):::backend
        BE3("Service Objects"):::backend
        BE4("Custom Modules"):::backend
        BE5("Jobs"):::backend
        BE6("Mailers"):::backend

        %% Authentication & Authorization (within Backend)
        subgraph "Authentication & Authorization"
            AU1("Devise & OmniAuth"):::auth
            AU2("Custom Authentication Failure"):::auth
        end
    end

    %% Database
    subgraph "Database"
        DB1("PostgreSQL Database"):::db
        DB2("Migration Scripts"):::db
    end

    %% External Services
    subgraph "External Services"
        EX1("OpenAI API"):::external
        EX2("AWS S3 Storage"):::external
        EX3("Google Analytics"):::external
        EX4("Social Sharing (X/Twitter)"):::external
    end

    %% Development & Deployment
    subgraph "Development & Deployment"
        DEP1("Containerization"):::deploy
        DEP2("Deployment Configuration"):::deploy
        DEP3("CI/CD Workflows"):::deploy
    end

    %% Connections
    UB -->|"HTTP"| FE1
    FE1 -->|"HTTP"| BE1
    %% Frontend internal components (implicit grouping)
    FE1 --- FE2
    FE1 --- FE3

    %% Backend interactions
    BE1 -->|"invokes"| BE2
    BE1 -->|"enqueues"| BE5
    BE1 -->|"triggers"| BE6
    BE1 -->|"authenticates"| AU1
    BE2 -->|"stores data"| DB1
    BE1 -->|"persists"| DB1

    BE3 -->|"calls"| EX1
    BE1 -->|"uploads"| EX2
    BE1 -->|"shares"| EX4

    %% Frontend external link
    FE1 -->|"loads"| EX3

    %% Database migration scripts
    DB2 --- DB1

    %% Deployment connection (dotted arrow)
    BE1 -. "deployed" .-> DEP1
    DEP1 --> DEP2
    DEP1 --> DEP3

    %% Styles
    classDef client fill:#aaf,stroke:#333,stroke-width:2px;
    classDef frontend fill:#f9f,stroke:#333,stroke-width:2px;
    classDef backend fill:#ccf,stroke:#333,stroke-width:2px;
    classDef db fill:#cfc,stroke:#333,stroke-width:2px;
    classDef external fill:#fc9,stroke:#333,stroke-width:2px;
    classDef auth fill:#ff9,stroke:#333,stroke-width:2px;
    classDef deploy fill:#9cf,stroke:#333,stroke-width:2px;

    %% Click Events for Frontend / User Interface
    click FE1 "https://github.com/pakira-56a/aruaru-game/tree/main/app/views"
    click FE2 "https://github.com/pakira-56a/aruaru-game/tree/main/app/javascript/controllers"
    click FE3 "https://github.com/pakira-56a/aruaru-game/tree/main/app/assets/stylesheets"

    %% Click Events for Backend / Application Server
    click BE1 "https://github.com/pakira-56a/aruaru-game/tree/main/app/controllers"
    click BE2 "https://github.com/pakira-56a/aruaru-game/tree/main/app/models"
    click BE3 "https://github.com/pakira-56a/aruaru-game/blob/main/app/services/openai_service.rb"
    click BE4 "https://github.com/pakira-56a/aruaru-game/blob/main/app/controllers/concerns/ogp_creator.rb"
    click BE5 "https://github.com/pakira-56a/aruaru-game/tree/main/app/jobs"
    click BE6 "https://github.com/pakira-56a/aruaru-game/tree/main/app/mailers"

    %% Click Events for Authentication & Authorization
    click AU1 "https://github.com/pakira-56a/aruaru-game/blob/main/app/controllers/users/omniauth_callbacks_controller.rb"
    click AU2 "https://github.com/pakira-56a/aruaru-game/blob/main/lib/custom_authentication_failure.rb"

    %% Click Events for Database
    click DB1 "https://github.com/pakira-56a/aruaru-game/blob/main/db/schema.rb"
    click DB2 "https://github.com/pakira-56a/aruaru-game/tree/main/db/migrate"

    %% Click Events for External Services
    click EX1 "https://github.com/pakira-56a/aruaru-game/blob/main/config/initializers/openai.rb"
    click EX2 "https://github.com/pakira-56a/aruaru-game/blob/main/config/initializers/carrierwave.rb"
    click EX3 "https://github.com/pakira-56a/aruaru-game/blob/main/app/views/layouts/_google_analytics.html.erb"
    click EX4 "https://github.com/pakira-56a/aruaru-game/blob/main/app/views/shared/_xshare_button.html.erb"

    %% Click Events for Development & Deployment
    click DEP1 "https://github.com/pakira-56a/aruaru-game/tree/main/Dockerfile"
    click DEP2 "https://github.com/pakira-56a/aruaru-game/blob/main/Procfile.dev"
    click DEP3 "https://github.com/pakira-56a/aruaru-game/blob/main/.github"
```
