How 1068haruto/scenapla works
Project Type and Purpose
• This is a full-stack web application built with Ruby on Rails that serves as an economic simulation and life planning tool. It provides users with visualization of economic scenarios (such as “資産寿命”, “現実的シナリオ”, “理想的シナリオ”, “運用資産シナリオ”), AI-generated advice via OpenAI, and live economic news via the GNews API.
• The README emphasizes core use cases: inputting current economic data and life events, simulating future states, and offering AI advice plus news for informed decision-making.
File Structure
• The structure follows the conventional Rails MVC pattern. Notice:
– The “app” folder contains subdirectories for controllers, models, views, channels, jobs, and services.
– “app/services/” includes logic for external API integration (e.g., OpenAIAdviceService and GNewsService).
– Assets (including JavaScript, SCSS, and images) and views for both desktop and mobile are provided.
– Configuration files in “config” and migration files in “db” confirm database setup (PostgreSQL) and environmental configurations.
• CI/CD configurations are evident under “.github/workflows” (for GitHub Actions) and deployment-related files (Dockerfile, Procfile.dev) assure containerization and deployment (Heroku).
a. Main Components to Include:
– Frontend/Client:
◦ Represent the users’ browsers on PC, tablet, and mobile devices.
◦ Highlight user interfaces where economic data is input and simulation results (graphs for various scenarios) are displayed.
– Rails Application (Server-Side):
◦ MVC Components:
• Controllers handling requests (e.g., dashboard, users, simulation controllers).
• Models for business logic (e.g., User, Expense, Income, LifeEvent, Simulation, AiAdvice, Scenario).
• Views that render HTML/SCSS (using Bootstrap) for both form inputs and simulation visualizations.
◦ Services:
• OpenAIAdviceService (interacting with GPT via OpenAI API).
• GNewsService (interacting with GNews API for economic news).
◦ Background Jobs and Mailers:
• Jobs, channels (for real-time features), and mailers for notifications.
– Database:
◦ A PostgreSQL database holding users’ data, simulation records, life events, etc.
– External APIs:
◦ OpenAI API for generating AI advice.
◦ GNews API for fetching economic/news updates.
– Deployment & Infrastructure:
◦ Docker containers and Heroku for application hosting.
◦ CI/CD pipelines (GitHub Actions) for testing and build automation.
– Third-Party Integration:
◦ Devise for user authentication.
◦ Bootstrap for front-end styling and responsiveness.
b. Relationships and Data Flow:
– Illustrate the flow from the Client (browser) sending HTTP requests to the Rails server.
– Show the MVC cycle: controllers receiving requests, interacting with service layers (which might call external APIs), and then rendering views.
• Data input from users traveling to controllers.
• Service layer calls to external APIs (OpenAI and GNews).
• Results returning to be rendered in the view.
• CI/CD and deployment flows (from GitHub repository through GitHub Actions to Docker and Heroku).
c. Architectural Patterns and Design Principles:
– Emphasize the use of the MVC pattern for separation of concerns.
– Note the integration of external service APIs through dedicated service classes.
– Highlight containerization (Docker) and automated deployment (Heroku, GitHub Actions).
• From Clients to Rails Controllers.
• From controllers to services (e.g., OpenAIAdviceService and GNewsService).
• From models to the PostgreSQL database.
– Optionally, include a high-level overview of the CI/CD pipeline showing GitHub Actions triggering builds and deployments via Docker/Heroku.