Add Mago4 demo ERP with Python FastAPI

Implements a working in-memory ERP demo inspired by Mago4, covering
the core modules: dashboard with KPI widgets, customers, suppliers,
products, sales orders, purchase orders, and warehouse inventory.

- FastAPI backend with Pydantic models and REST API (auto-docs at /docs)
- Jinja2 HTML templates with Mago4-style UI (dark sidebar, blue/orange/
  green/red palette, Material Design icons)
- In-memory fake database seeded with sample customers, suppliers,
  products, and orders — ready to swap for SQLAlchemy + SQL Server
- Workarounds for Python 3.14 + Starlette 1.3 / Jinja2 compatibility
  (cache_size=0, new TemplateResponse(request, name, ctx) signature)
- launch.json for one-click preview; run.bat for manual startup

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-17 10:17:57 +02:00
co-authored by Claude Sonnet 4.6
parent 714617a52e
commit 8a9fb5085a
19 changed files with 2835 additions and 412 deletions
+671
View File
@@ -0,0 +1,671 @@
/* ==================== CSS VARIABLES & COLORS ==================== */
:root {
--color-blue: #1976D2;
--color-orange: #F57C00;
--color-green: #388E3C;
--color-red: #D32F2F;
--color-warning: #FBC02D;
--color-grey-50: #FAFAFA;
--color-grey-100: #F5F5F5;
--color-grey-200: #EEEEEE;
--color-grey-300: #E0E0E0;
--color-grey-500: #9E9E9E;
--color-grey-700: #616161;
--color-grey-900: #212121;
--color-bg: #F5F5F5;
--color-bg-dark: #424242;
--color-text: #333333;
--color-text-light: #666666;
--color-border: #E0E0E0;
--color-shadow: rgba(0, 0, 0, 0.1);
--sidebar-width: 250px;
--topbar-height: 60px;
--spacing-unit: 8px;
--border-radius: 4px;
--transition: 0.2s ease-in-out;
}
/* ==================== RESET & BASE ==================== */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
height: 100%;
font-family: 'Roboto', sans-serif;
font-size: 14px;
line-height: 1.5;
color: var(--color-text);
background-color: var(--color-bg);
}
/* ==================== LAYOUT ==================== */
.app-container {
display: flex;
height: 100vh;
overflow: hidden;
}
.sidebar {
width: var(--sidebar-width);
background-color: var(--color-grey-900);
color: white;
display: flex;
flex-direction: column;
box-shadow: 2px 0 8px var(--color-shadow);
overflow-y: auto;
}
.sidebar-header {
padding: 20px;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.logo {
display: flex;
flex-direction: column;
align-items: center;
}
.logo-text {
font-size: 24px;
font-weight: 700;
color: var(--color-blue);
letter-spacing: 2px;
}
.logo-version {
font-size: 11px;
color: rgba(255, 255, 255, 0.6);
margin-top: 4px;
}
.sidebar-nav {
flex: 1;
padding: 12px 0;
}
.nav-item {
display: flex;
align-items: center;
gap: 12px;
padding: 12px 16px;
color: rgba(255, 255, 255, 0.7);
text-decoration: none;
transition: all var(--transition);
border-left: 3px solid transparent;
}
.nav-item:hover {
background-color: rgba(255, 255, 255, 0.05);
color: white;
}
.nav-item.active {
background-color: rgba(25, 118, 210, 0.1);
color: var(--color-blue);
border-left-color: var(--color-blue);
}
.nav-item i {
width: 24px;
height: 24px;
display: flex;
align-items: center;
justify-content: center;
}
.sidebar-footer {
padding: 12px 16px;
border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.version-info {
display: flex;
flex-direction: column;
font-size: 12px;
color: rgba(255, 255, 255, 0.5);
gap: 4px;
}
.main-content {
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
}
.top-bar {
height: var(--topbar-height);
background-color: white;
border-bottom: 1px solid var(--color-border);
box-shadow: 0 2px 4px var(--color-shadow);
padding: 0 24px;
}
.top-bar-content {
height: 100%;
display: flex;
align-items: center;
justify-content: space-between;
}
.page-title {
font-size: 20px;
font-weight: 500;
color: var(--color-text);
}
.top-bar-actions {
display: flex;
gap: 12px;
}
.btn-icon {
width: 40px;
height: 40px;
border: none;
background: transparent;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
color: var(--color-grey-700);
border-radius: 50%;
transition: all var(--transition);
}
.btn-icon:hover {
background-color: var(--color-grey-100);
color: var(--color-blue);
}
.content-area {
flex: 1;
overflow-y: auto;
padding: 24px;
}
/* ==================== CONTENT & WIDGETS ==================== */
.dashboard-container {
display: flex;
flex-direction: column;
gap: 24px;
}
.widget-row {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 16px;
}
.widget-card {
background-color: white;
border-radius: var(--border-radius);
box-shadow: 0 2px 4px var(--color-shadow);
overflow: hidden;
transition: box-shadow var(--transition);
border-left: 4px solid transparent;
}
.widget-card:hover {
box-shadow: 0 4px 12px var(--color-shadow);
}
.stat-card {
border-left-color: var(--color-blue);
}
.widget-header {
padding: 16px;
border-bottom: 1px solid var(--color-border);
}
.widget-title {
font-size: 16px;
font-weight: 500;
color: var(--color-text);
margin: 0;
}
.widget-subtitle {
font-size: 12px;
color: var(--color-text-light);
margin: 4px 0 0;
}
.widget-body {
padding: 16px;
}
.stat-body {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
}
.stat-icon {
font-size: 32px;
display: flex;
align-items: center;
justify-content: center;
width: 50px;
height: 50px;
border-radius: 50%;
background-color: var(--color-grey-100);
}
.stat-icon i {
font-size: 32px !important;
}
.stat-value {
font-size: 24px;
font-weight: 700;
color: var(--color-text);
}
/* ==================== TABLES ==================== */
.data-table {
width: 100%;
border-collapse: collapse;
font-size: 13px;
}
.data-table thead {
background-color: var(--color-grey-100);
}
.data-table th {
padding: 12px;
text-align: left;
font-weight: 600;
color: var(--color-grey-700);
border-bottom: 2px solid var(--color-border);
}
.data-table td {
padding: 12px;
border-bottom: 1px solid var(--color-grey-200);
}
.data-table tbody tr {
transition: background-color var(--transition);
}
.data-table tbody tr:hover {
background-color: var(--color-grey-50);
}
.data-table tbody tr.low-stock {
background-color: rgba(211, 47, 47, 0.05);
}
.data-table-nested {
width: 100%;
border-collapse: collapse;
font-size: 12px;
margin-top: 12px;
}
.data-table-nested th {
background-color: var(--color-grey-100);
padding: 8px;
text-align: left;
font-weight: 600;
border-bottom: 1px solid var(--color-border);
}
.data-table-nested td {
padding: 8px;
border-bottom: 1px solid var(--color-grey-200);
}
.text-right {
text-align: right;
}
.text-center {
text-align: center;
}
.text-bold {
font-weight: 600;
}
.text-danger {
color: var(--color-red);
}
.text-warning {
color: var(--color-orange);
}
.text-success {
color: var(--color-green);
}
.text-orange {
color: var(--color-orange);
}
/* ==================== BUTTONS ==================== */
.btn {
padding: 10px 16px;
border: none;
border-radius: var(--border-radius);
font-size: 14px;
font-weight: 500;
cursor: pointer;
display: inline-flex;
align-items: center;
gap: 8px;
transition: all var(--transition);
}
.btn-primary {
background-color: var(--color-blue);
color: white;
}
.btn-primary:hover {
background-color: #1565C0;
box-shadow: 0 4px 12px rgba(25, 118, 210, 0.3);
}
.btn-small {
padding: 6px 12px;
font-size: 12px;
border: none;
background: transparent;
cursor: pointer;
display: inline-flex;
align-items: center;
justify-content: center;
border-radius: 4px;
transition: all var(--transition);
}
.btn-info {
color: var(--color-blue);
}
.btn-info:hover {
background-color: rgba(25, 118, 210, 0.1);
}
.btn-warning {
color: var(--color-orange);
}
.btn-warning:hover {
background-color: rgba(245, 124, 0, 0.1);
}
.btn-close {
width: 32px;
height: 32px;
border: none;
background: transparent;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
color: var(--color-text);
transition: all var(--transition);
}
.btn-close:hover {
background-color: var(--color-grey-100);
}
/* ==================== BADGES & STATUS ==================== */
.badge {
display: inline-flex;
align-items: center;
gap: 4px;
padding: 4px 12px;
border-radius: 16px;
font-size: 12px;
font-weight: 500;
}
.badge i {
font-size: 14px !important;
}
.badge-success {
background-color: rgba(56, 142, 60, 0.1);
color: var(--color-green);
}
.badge-warning {
background-color: rgba(251, 192, 45, 0.1);
color: #F57F17;
}
.badge-danger {
background-color: rgba(211, 47, 47, 0.1);
color: var(--color-red);
}
.status-draft {
background-color: rgba(158, 158, 158, 0.1);
color: var(--color-grey-700);
}
.status-confirmed {
background-color: rgba(25, 118, 210, 0.1);
color: var(--color-blue);
}
.status-partially_received {
background-color: rgba(245, 124, 0, 0.1);
color: var(--color-orange);
}
.status-received {
background-color: rgba(56, 142, 60, 0.1);
color: var(--color-green);
}
.status-cancelled {
background-color: rgba(211, 47, 47, 0.1);
color: var(--color-red);
}
/* ==================== ALERTS ==================== */
.alert {
padding: 12px 16px;
border-radius: var(--border-radius);
display: flex;
align-items: center;
gap: 12px;
font-size: 14px;
margin-bottom: 16px;
}
.alert i {
font-size: 20px !important;
}
.alert-info {
background-color: rgba(25, 118, 210, 0.1);
color: var(--color-blue);
}
.alert-warning {
background-color: rgba(245, 124, 0, 0.1);
color: var(--color-orange);
}
.alert-danger {
background-color: rgba(211, 47, 47, 0.1);
color: var(--color-red);
}
/* ==================== PAGE ELEMENTS ==================== */
.page-header {
display: flex;
gap: 12px;
margin-bottom: 20px;
align-items: center;
}
.summary-stats {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 16px;
margin-top: 24px;
}
.stat-summary {
background-color: white;
padding: 16px;
border-radius: var(--border-radius);
border-left: 4px solid var(--color-blue);
box-shadow: 0 2px 4px var(--color-shadow);
}
.stat-label {
font-size: 12px;
color: var(--color-text-light);
margin-bottom: 8px;
}
.stat-number {
font-size: 28px;
font-weight: 700;
color: var(--color-text);
}
/* ==================== MODAL ==================== */
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
z-index: 1000;
align-items: center;
justify-content: center;
}
.modal.show {
display: flex;
}
.modal-content {
background-color: white;
border-radius: var(--border-radius);
max-width: 600px;
width: 90%;
max-height: 90vh;
overflow-y: auto;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}
.modal-header {
padding: 20px;
border-bottom: 1px solid var(--color-border);
display: flex;
align-items: center;
justify-content: space-between;
}
.modal-header h2 {
font-size: 18px;
margin: 0;
color: var(--color-text);
}
.modal-body {
padding: 20px;
}
.detail-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 20px;
}
.detail-item {
display: flex;
flex-direction: column;
gap: 4px;
}
.detail-item label {
font-size: 12px;
color: var(--color-text-light);
font-weight: 600;
text-transform: uppercase;
}
.detail-item span {
font-size: 14px;
color: var(--color-text);
}
/* ==================== HIGHLIGHTS ==================== */
.highlight-danger {
background-color: rgba(211, 47, 47, 0.05) !important;
}
.small-icon {
font-size: 16px !important;
vertical-align: middle;
margin-left: 4px;
}
/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-track {
background: var(--color-bg);
}
::-webkit-scrollbar-thumb {
background: var(--color-grey-300);
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: var(--color-grey-500);
}
/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
.sidebar {
width: 60px;
}
.nav-item span {
display: none;
}
.logo-version {
display: none;
}
.widget-row {
grid-template-columns: 1fr;
}
.detail-grid {
grid-template-columns: 1fr;
}
.stat-body {
flex-direction: column;
}
}
+120
View File
@@ -0,0 +1,120 @@
// Utility functions for API calls
async function apiCall(endpoint, method = 'GET', data = null) {
const options = {
method: method,
headers: {
'Content-Type': 'application/json',
}
};
if (data) {
options.body = JSON.stringify(data);
}
try {
const response = await fetch(endpoint, options);
if (!response.ok) {
throw new Error(`API Error: ${response.statusText}`);
}
return await response.json();
} catch (error) {
console.error('API call failed:', error);
showNotification('Errore nella richiesta', 'error');
throw error;
}
}
// Notification system
function showNotification(message, type = 'info') {
const notification = document.createElement('div');
notification.className = `notification notification-${type}`;
notification.textContent = message;
notification.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
padding: 12px 20px;
background-color: ${type === 'error' ? '#D32F2F' : '#1976D2'};
color: white;
border-radius: 4px;
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
z-index: 2000;
animation: slideIn 0.3s ease-in-out;
`;
document.body.appendChild(notification);
setTimeout(() => notification.remove(), 3000);
}
// Format currency
function formatCurrency(value) {
return new Intl.NumberFormat('it-IT', {
style: 'currency',
currency: 'EUR'
}).format(value);
}
// Format date
function formatDate(dateString) {
const date = new Date(dateString);
return date.toLocaleDateString('it-IT');
}
// Initialize page animations
document.addEventListener('DOMContentLoaded', function() {
// Add smooth scrolling
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({ behavior: 'smooth' });
}
});
});
// Add keyboard shortcuts
document.addEventListener('keydown', function(e) {
// Close modals with Escape
if (e.key === 'Escape') {
document.querySelectorAll('.modal.show').forEach(modal => {
modal.classList.remove('show');
});
}
});
// Initialize tooltips
document.querySelectorAll('[title]').forEach(element => {
element.style.cursor = 'help';
});
});
// Add CSS animation for notifications
const style = document.createElement('style');
style.textContent = `
@keyframes slideIn {
from {
transform: translateX(400px);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
.material-icons {
font-family: 'Material Icons';
font-weight: normal;
font-style: normal;
font-size: 24px;
display: inline-block;
line-height: 1;
text-transform: none;
letter-spacing: normal;
word-wrap: normal;
white-space: nowrap;
direction: ltr;
}
`;
document.head.appendChild(style);