How portugol-devoteers/pcg-analyze-energy-costs works
Project Type and Purpose
• This is a full-stack web application.
• Front-end: React/TypeScript single-page app (SPA) for visualizing global energy consumption and running basic predictions.
• Back-end: Python/Flask REST API serving data and prediction endpoints.
• Data source: a CSV file of world energy consumption and minimal in-memory processing.
File Structure
Top-level split:
– public/ + src/ → React front-end
– server/ → Flask back-end
Key front-end subfolders:
• src/components → UI building blocks (Charts, Header, Footer, sections)
• src/pages & src/routes.tsx → route definitions for Home, About, PowerBi
• src/data & src/assets → static JSON and image assets
• src/i18n.ts & src/translations → localization
Back-end substructure:
• server/app/routes.py → HTTP endpoints
• server/app/services.py → business logic (data filtering, prediction)
• server/app/models.py → data schemas or structures
• server/app/utils.py → helper functions
• server/data/Consumo_Energia_Mundial.csv → raw data file
• server/run.py → app entry point
Extract Architectural Insights from README
• Front-end uses Node.js + npm, served on port 3000 by React Dev Server.
• Back-end uses Flask on a configurable port (e.g., 5000).
• There is no external database; the CSV file lives on the server.
• Communication is via REST calls from React to Flask.
Defining Main Components & Interactions
a. Components:
1. Browser/Client – hosts React SPA
2. React Application – UI layer broken into Pages, Components, Data Layers
3. Flask API Server – exposes REST endpoints
4. Data Source – CSV file and any in-memory model
5. (Optional) Node.js & Python runtime environments
b. Relationships & Data Flow:
• User actions in Browser → React Router loads a Page → React Component
• React Component calls “fetch” or “axios” to Flask endpoint (e.g., /predict, /top10)
• Flask routes.py receives request → delegates to services.py → reads CSV → computes JSON → returns HTTP response
• React receives JSON → updates state → re-renders chart components
c. Architectural Patterns:
• Front-end: Component-based MVC-ish pattern with a service layer for API calls
• Back-end: Layered architecture (Routes → Services → Models/Utils)
• Separation of concerns between presentation (React) and data processing (Flask)
d. Key Technologies:
• Front-end: React, TypeScript, Tailwind CSS, i18next (for translations), Chart library
• Back-end: Python3, Flask, Pandas (likely used in services for CSV), virtualenv
• Build & Config: Webpack (implied via Create-React-App), postcss.config.js, tsconfig.json, package.json, requirements.txt