# Development Guide This guide covers the architecture, code organization, and contribution guidelines for the Romanoff Fire Alarm Management System. ## Architecture Overview ### Application Structure ``` romanoff/ ├── run.py # Entry point - starts Flask dev server ├── import_data.py # Data import utility ├── requirements.txt # Dependencies ├── app/ │ ├── __init__.py # Flask app factory │ ├── models.py # SQLAlchemy models │ ├── routes.py # Web routes & API endpoints │ ├── templates/ # Jinja2 templates │ └── static/ # CSS, JavaScript assets └── instance/ # SQLite database (auto-created) ``` ### Design Patterns **Flask App Factory** The application uses the factory pattern in `app/__init__.py`: ```python def create_app(): app = Flask(__name__) # Configure app db.init_app(app) # Register blueprints app.register_blueprint(main_bp) app.register_blueprint(api_bp, url_prefix='/api') return app ``` **Blueprint Organization** Routes are organized into two blueprints: - `main_bp` - Web routes serving HTML pages - `api_bp` - REST API endpoints (prefixed with `/api`) **Model-View Separation** - Models (`models.py`) handle data persistence - Routes (`routes.py`) handle request/response logic - Templates (`templates/`) handle presentation ### Data Flow ``` User Browser ↓ Flask Routes (routes.py) ↓ SQLAlchemy Models (models.py) ↓ SQLite Database (instance/romanoff.db) ``` ## Database Schema ### Entity Relationship ``` ┌─────────────┐ │ Job │ ├─────────────┤ │ id (PK) │ │ job_number │───────┐ │ job_name │ │ │ ... │ │ └─────────────┘ │ │ │ │ 1:N │ 1:N ↓ ↓ ┌─────────────┐ ┌─────────────┐ │ Phase │ │ Material │ ├─────────────┤ ├─────────────┤ │ id (PK) │ │ id (PK) │ │ job_id (FK) │ │ job_id (FK) │ │ phase_type │ │ part_number │ │ ... │ │ ... │ └─────────────┘ └─────────────┘ ``` ### Models **Job** - Core project entity - Contains budget, team assignments, milestones, dates - Has many phases and materials (cascade delete) **Phase** - Project schedule phases - Types: rough_in, trim, commissioning, final, turnover - Tracks dates, completion status, man hours **Material** - Inventory tracking - Tracks ordering, receipt, and delivery ## Frontend Architecture ### Template Hierarchy ``` base.html ├── dashboard.html - Charts and statistics ├── jobs.html - Job list with filters ├── job_detail.html - Single job view ├── job_form.html - Create/edit job ├── schedule.html - Phase management └── materials.html - Material tracking ``` ### JavaScript Strategy **Shared Utilities** (`static/js/app.js`) ```javascript // API helpers async function apiGet(url) { ... } async function apiPost(url, data) { ... } async function apiPut(url, data) { ... } async function apiDelete(url) { ... } // Formatting function formatCurrency(value) { ... } function formatDate(dateString) { ... } // UI helpers function showToast(message, type) { ... } function getProgressClass(percent) { ... } function debounce(func, wait) { ... } function confirmAction(message) { ... } ``` **Page-Specific Scripts** Each template contains embedded `