- Updated README.md to reflect new features and usage instructions. - Removed deprecated Dashboard.html component and integrated dashboard functionality directly into the main application. - Revised architecture documentation for clarity and added module map and request flow diagrams. - Enhanced maintenance model to include equipment association and cost tracking. - Updated requirements.txt to include new dependencies (httpx, pandas, numpy). - Improved consumption, maintenance, production, and reporting routes with better validation and response handling. - Added unit tests for maintenance and production routes, ensuring proper CRUD operations and validation. - Enhanced reporting service to calculate and return detailed summary statistics. - Redesigned Dashboard.html for improved user experience and integrated Chart.js for visualizing simulation results.
3.7 KiB
3.7 KiB
Architecture Documentation
Overview
CalMiner is a FastAPI application that collects mining project inputs, persists scenario-specific records, and surfaces aggregated insights. The platform targets Monte Carlo driven planning, with deterministic CRUD features in place and simulation logic staged for future work.
System Components
- FastAPI backend (
main.py,routes/): hosts REST endpoints for scenarios, parameters, costs, consumption, production, equipment, maintenance, simulations, and reporting. Each router encapsulates request/response schemas and DB access patterns. - Service layer (
services/): houses business logic.services/reporting.pyproduces statistical summaries, whileservices/simulation.pyprovides the Monte Carlo integration point. - Persistence (
models/,config/database.py): SQLAlchemy models map to PostgreSQL tables in schemabricsium_platform. Relationships connect scenarios to derived domain entities. - Presentation (
templates/,components/): server-rendered views support data entry (scenario and parameter forms) and the dashboard visualization powered by Chart.js. - Middleware (
middleware/validation.py): applies JSON validation before requests reach routers. - Testing (
tests/unit/): pytest suite covering route and service behavior.
Runtime Flow
- Users navigate to form templates or API clients to manage scenarios, parameters, and operational data.
- FastAPI routers validate payloads with Pydantic models, then delegate to SQLAlchemy sessions for persistence.
- Simulation runs (placeholder
services/simulation.py) will consume stored parameters to emit iteration results via/api/simulations/run. - Reporting requests POST simulation outputs to
/api/reporting/summary; the reporting service calculates aggregates (count, min/max, mean, median, percentiles, standard deviation). templates/Dashboard.htmlfetches summaries, renders metric cards, and plots distribution charts with Chart.js for stakeholder review.
Data Model Highlights
scenario: central entity describing a mining scenario; owns relationships to cost, consumption, production, equipment, and maintenance tables.capex,opex: monetary tracking linked to scenarios.consumption: resource usage entries parameterized by scenario and description.production_output: production metrics per scenario.equipmentandmaintenance: equipment inventory and maintenance events with dates/costs.simulation_result: staging table for future Monte Carlo outputs (not yet populated byrun_simulation).
Foreign keys secure referential integrity between domain tables and their scenarios, enabling per-scenario analytics.
Integrations and Future Work
- Monte Carlo engine:
services/simulation.pywill incorporate stochastic sampling (e.g., NumPy, SciPy) to populatesimulation_resultand feed reporting. - Persistence of results:
/api/simulations/runcurrently returns in-memory results; next iteration should persist tosimulation_resultand reference scenarios. - Authentication: not yet implemented; all endpoints are open.
- Deployment: documentation focuses on local development; containerization and CI/CD pipelines remain to be defined.
For extended diagrams and setup instructions reference:
- docs/development_setup.md — environment provisioning and tooling.
- docs/testing.md — pytest workflow and coverage expectations.
- docs/mvp.md — roadmap and milestone scope.
- docs/implementation_plan.md — feature breakdown aligned with the TODO tracker.
- docs/architecture_overview.md — supplementary module map and request flow diagram.