Gemini Development Guide for AGP Project
Defines project architecture, coding rules, and troubleshooting for an AGP engineering app built with Dash and Plotly.
What this file does
Defines project architecture, coding rules, and troubleshooting for an AGP engineering app built with Dash and Plotly.
When to use it
- Onboarding a new developer to the AGP electrical transmission line design project
- Setting up Dash callback patterns and caching conventions
- Debugging Plotly graph rendering or stale state issues
- Establishing code review standards for a Dash-based engineering tool
Assumes this stack
Gemini Development Guide for AGP Project
This document provides a comprehensive guide for Gemini, the AI assistant, to effectively contribute to the AGP (Análisis General de Postaciones) project. It synthesizes all project-specific rules, architectural patterns, and development guidelines.
1. Project Overview
Purpose: AGP is a specialized engineering application for designing and analyzing electrical transmission line structures, ensuring compliance with AEA (Asociación Electrotécnica Argentina) standards.
Key Features:
- Structural and mechanical design of power line towers.
- Cable tensioning, wind load, and pole selection calculations.
- Interactive Dash/Plotly dashboard for visualization and analysis.
- 3D rendering of structures and load distributions.
- Management of structure families and cost analysis.
Target Users: Electrical and structural engineers involved in transmission line design.
2. Core Architectural Principles
- MVC Pattern:
- Models (
/models):AppStatemanages data and persistence. - Views (
/views,/components): Dash components render the UI. - Controllers (
/controllers): Handle user interactions, business logic, and callbacks.
- Models (
- Separation of Concerns: UI is decoupled from the core calculation engines.
- Configuration-Driven: Project behavior is controlled via
config/app_config.pyand structure-specific JSON files. - File-Based Persistence:
- Structure definitions (
.estructura.json), calculation results (.calculo*.json), and cache are stored in the/datadirectory. - CRITICAL: Always sanitize filenames by replacing spaces with underscores (e.g.,
nombre.replace(' ', '_')) in both save and load operations.
- Structure definitions (
- Caching System (
/data/cache):CalculoCacheclass manages all persistence.- Results are cached to prevent redundant, expensive calculations.
- Filenames are based on structure name and calculation type (e.g.,
MyProject.calculoCMC.json). - An MD5 hash of structure parameters determines cache validity.
3. Critical Development Rules & Protocols
Rule 1: Adherence to Existing Code
- ALWAYS review existing code in similar modules (
controllers,components,utils) before implementing new features. - REUSE existing patterns for callbacks, UI components, and data handling to maintain consistency. Do not invent new patterns.
Rule 2: No Mock/Placeholder Code
- NEVER use placeholder implementations, dummy data, or hardcoded values that should be calculated.
- If data is missing, raise a
ValueErroror returnNone. Do not invent fallback data. - If a feature cannot be fully implemented, clearly mark it as pending and notify the user. Do not create fake code that appears to work.
Rule 3: Python Script Execution
- To run any Python script, ALWAYS use the following command structure to ensure the correct virtual environment is used:
cd C:\Users\gpesoa\Downloads\portablepy\venvo\Scripts && python.exe [FULL_PATH_TO_SCRIPT] - Example:
cd C:\Users\gpesoa\Downloads\portablepy\venvo\Scripts && python.exe C:\Users\gpesoa\MobiDrive\jupyter_estructural_v2\app.py
Rule 4: Application Execution (No Hot Reload)
- The application must be run with
debug=False. Hot reload is DISABLED as it interferes with the application's state. - The standard workflow is:
- Make code changes.
- Stop the application (Ctrl+C).
- Relaunch with
python app.py. - Manually refresh the browser.
Rule 5: QA & Testing Protocol
- NEVER mark an issue as "✅ RESUELTO" (Resolved). This is the user's exclusive responsibility.
- After implementing a fix, the state must ALWAYS be marked as "🔧 TESTING PENDIENTE" (Pending Testing).
- The AI's role is to implement fixes, not to verify them.
Rule 6: Documentation and File Organization
- All new
.mddocumentation files must be placed in the/docsfolder. - Use emojis sparingly. Only colored circles/squares are permitted in code.
4. Technology Stack & Key Patterns
- Language: Python 3.x
- Framework: Dash, Dash-Bootstrap-Components
- Data: Pandas, NumPy
- Visualization: Plotly, Matplotlib
- Persistence: JSON, Openpyxl
Dash Callback Best Practices
- Function-Based Registration: NEVER use standalone
@callbackdecorators. All callbacks for a controller must be defined within aregister_callbacks(app)function. This prevents registration conflicts. - State vs. Input: Use
Statefor data that is needed but should not trigger the callback. UseInputfor events that should trigger the callback. prevent_initial_call=True: Use this in callbacks to prevent execution on page load. However, always add explicit checks (e.g.,if n_clicks is None:) as this is not a foolproof guarantee.allow_duplicate=True: Use this onOutputs that are updated by more than one callback (e.g., toast notifications, dynamic tables).- Stale State: CRITICAL: Dash
Statecan become stale. For file-backed data, ALWAYS reload the data from the source file (e.g.,actual.estructura.json) at the beginning of a critical callback instead of trusting the value fromState. - Unique IDs: When creating features similar to existing ones (e.g., a new modal system), use unique ID prefixes for all components and callbacks to avoid
DuplicateCallbackerrors.
Plotly Graph Handling
- CRITICAL: When saving a Plotly figure to cache, ALWAYS save it in TWO formats:
- PNG (
fig.write_image()): For static exports. - JSON (
fig.write_json()): Required for thedcc.Graphcomponent to render the figure interactively. If the JSON is missing, the graph will not appear when loaded from cache.
- PNG (
- Capturing Figures: When a function returns a Plotly figure object, capture the return value directly. Do NOT use
plt.gcf(), as that will capture a Matplotlib figure, leading to errors.
DataFrame Handling
- To preserve exact formatting (column widths, wrapping), serialize DataFrames to JSON using
df.to_json(orient='split')and load them usingpd.read_json(json_str, orient='split').
5. Common Troubleshooting Guide
TypeError: Unexpected keyword argument: A Dash component received a property it doesn't support (e.g., an internal'tipo'field). Filter out internal fields from the dictionary before passing it to the component.- Plotly Graphs Not Appearing from Cache: The figure's JSON file is missing. Ensure
fig.write_json()is called during the save-to-cache operation. - Callbacks Firing Unexpectedly: Use
dash.callback_contextto debug what triggered the callback. Add explicitif n_clicks is None:checks. DuplicateCallbackError: Multiple callbacks are targeting the sameOutputwithoutallow_duplicate=True, or component IDs are not unique across the application.- Component Lists in Dash: When building a list of components, use
list.append(component)for each item. Avoid usinglist.extend([title, component])with complex components, as it can cause rendering issues. - Data Contamination: When creating a new structure from a template, ensure fields like
nodos_editadosare reset to an empty list ([]) to avoid carrying over data from a previous structure.
What's inside
6 sections covering project overview, architecture, 6 development rules, tech stack, best practices, and troubleshooting
Change this for your project
- Replace
C:\Users\gpesoa\Downloads\portablepy\venvo\Scriptswith your virtual environment path - Replace
C:\Users\gpesoa\MobiDrive\jupyter_estructural_v2with your project root - Replace
AEA (Asociación Electrotécnica Argentina)with your relevant standards body
Where it goes
Keep it in your repository where the agent or team that needs it will read it.
Worth borrowing
- Save Plotly figures in both PNG and JSON formats for cache to preserve interactivity
- Register all callbacks inside a
register_callbacks(app)function to avoid conflicts - Reload file-backed data at the start of critical callbacks instead of trusting Dash State
Related Documents
Totem — Development Rules
Defines team-wide conventions for a pnpm monorepo: branch strategy, commit rules, tooling, and a mandatory knowledge-search workflow before coding.
MechCAD-MLLM
Proposes a MLLM + dual-decoder architecture for mechanical CAD generation, combining Drawing2CAD and CAD-GPT ideas.
Prompt Generator
Generates Stable Diffusion and Flux prompts via Qwen3-8B on Ollama, with a Gradio UI and CLI.
Agent Instructions
Defines a three-layer architecture (directive, orchestration, execution) for AI agents that self-anneal errors and update living SOPs.