Migrate from Quart to Flask and add MariaDB dynamic database
Major Changes: - Migrated web framework from Quart (async) to Flask (sync) - Added MariaDB database integration with SQLAlchemy ORM - Implemented dynamic content management for portfolio New Features: - Database models for Profile, Skills, Projects, ProjectTags, and SocialLinks - RESTful API endpoints for CRUD operations on all entities - Database initialization script (init_db.py) with sample data - Docker Compose configuration with MariaDB service Modified Files: - app.py: Replaced Quart with Flask, added database initialization - config.py: Added database configuration with environment variables - routes/home.py: Converted async to sync, added database queries - requirements.txt: Replaced Quart/Hypercorn with Flask/Gunicorn, added Flask-SQLAlchemy and PyMySQL - docker-compose.yml: Added MariaDB service with health checks - templates/: Updated all templates to use dynamic data from database with Jinja2 - .env.example: Added database configuration variables - README.md: Complete rewrite with new setup instructions and API documentation New Files: - models.py: SQLAlchemy models for all database entities - init_db.py: Database initialization script - routes/api.py: REST API endpoints for content management Benefits: - Simplified architecture (sync vs async) - Better ecosystem compatibility - Dynamic content management via database - Easy content updates through REST API - Improved deployment with standard WSGI server (Gunicorn)
This commit is contained in:
230
README.md
230
README.md
@@ -1,93 +1,183 @@
|
||||
# Python Server - Hersel.it
|
||||
# Portfolio Dinamico - Hersel.it
|
||||
|
||||
Questo progetto è un'applicazione web sviluppata con **Quart** e configurata per essere eseguita tramite **Hypercorn**
|
||||
Portfolio personale sviluppato con **Flask** e **MariaDB**, con gestione dinamica dei contenuti tramite API REST.
|
||||
|
||||
## Requisiti
|
||||
## 🚀 Caratteristiche
|
||||
|
||||
- **Framework**: Flask (migrato da Quart per semplificare l'architettura)
|
||||
- **Database**: MariaDB per la gestione dinamica dei contenuti
|
||||
- **ORM**: SQLAlchemy con Flask-SQLAlchemy
|
||||
- **API REST**: Endpoint per gestire progetti, competenze, profilo e social links
|
||||
- **Docker**: Configurazione completa con Docker Compose
|
||||
- **Responsive**: Design responsive con Bootstrap 5
|
||||
|
||||
## 📋 Requisiti
|
||||
|
||||
- Python 3.10 o superiore
|
||||
- MariaDB/MySQL 11.2 o superiore (o usa Docker Compose)
|
||||
- Pip (gestore dei pacchetti Python)
|
||||
|
||||
# Installazione
|
||||
## 🔧 Installazione Locale
|
||||
|
||||
1. Clona il repository:
|
||||
```bash
|
||||
git clone https://github.com/BluLupo/hersel.it.git
|
||||
cd hersel.it
|
||||
```
|
||||
### 1. Clona il repository
|
||||
```bash
|
||||
git clone https://github.com/BluLupo/hersel.it.git
|
||||
cd hersel.it
|
||||
```
|
||||
|
||||
2. Crea Ambiente Virtuale
|
||||
```bash
|
||||
python3 -m venv env
|
||||
```
|
||||
### 2. Crea e attiva ambiente virtuale
|
||||
```bash
|
||||
python3 -m venv env
|
||||
source env/bin/activate # Linux/Mac
|
||||
# oppure
|
||||
env\Scripts\activate # Windows
|
||||
```
|
||||
|
||||
3. Attiva Ambiente Virtuale
|
||||
```bash
|
||||
source env/bin/activate
|
||||
```
|
||||
### 3. Installa le dipendenze
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
4. Installa Le Dipendenze
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
# Configurazione
|
||||
Modifica il file <b>hypercorn_config.toml</b> se necessario per adattarlo al tuo ambiente
|
||||
Esempio di configurazione predefinita (hypercorn_config.toml):
|
||||
### 4. Configura le variabili d'ambiente
|
||||
```bash
|
||||
cp .env.example .env
|
||||
# Modifica .env con le tue credenziali del database
|
||||
```
|
||||
|
||||
```toml
|
||||
bind = "0.0.0.0:5000"
|
||||
workers = 1
|
||||
reload = true
|
||||
```
|
||||
# Avvio Applicazione
|
||||
```bash
|
||||
hypercorn -c hypercorn_config.toml app:app
|
||||
```
|
||||
### 5. Configura MariaDB
|
||||
Crea il database e l'utente:
|
||||
```sql
|
||||
CREATE DATABASE portfolio_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
CREATE USER 'portfolio_user'@'localhost' IDENTIFIED BY 'portfolio_password';
|
||||
GRANT ALL PRIVILEGES ON portfolio_db.* TO 'portfolio_user'@'localhost';
|
||||
FLUSH PRIVILEGES;
|
||||
```
|
||||
|
||||
### 6. Inizializza il database
|
||||
```bash
|
||||
python init_db.py
|
||||
```
|
||||
|
||||
# 🚀 Avvio dell'applicazione con Docker
|
||||
Questa applicazione utilizza Quart come web framework asincrono e Hypercorn come ASGI server
|
||||
### 7. Avvia l'applicazione
|
||||
```bash
|
||||
# Modalità sviluppo
|
||||
python app.py
|
||||
|
||||
⚙️ Requisiti
|
||||
# Modalità produzione con Gunicorn
|
||||
gunicorn -w 4 -b 0.0.0.0:5000 app:app
|
||||
```
|
||||
|
||||
## 🐳 Installazione con Docker
|
||||
|
||||
### Requisiti
|
||||
- Docker
|
||||
- Docker Compose
|
||||
|
||||
# 📄 Come avviare l'applicazione
|
||||
1 - Crea un nuovo file docker-compose.yml nella tua macchina, con il seguente contenuto (oppure copialo direttamente da <a href="https://github.com/BluLupo/hersel.it/blob/master/docker-compose.yml">Qui</a> ):
|
||||
|
||||
```yml
|
||||
version: "3.9"
|
||||
|
||||
services:
|
||||
quartapp:
|
||||
image: python:3.10-slim
|
||||
container_name: quartapp
|
||||
working_dir: /app
|
||||
ports:
|
||||
- "127.0.0.1:5000:5000"
|
||||
restart: always
|
||||
command: >
|
||||
sh -c "
|
||||
apt-get update &&
|
||||
apt-get install -y git &&
|
||||
[ -d /app/.git ] || git clone https://github.com/BluLupo/hersel.it.git /app &&
|
||||
pip install --no-cache-dir -r requirements.txt &&
|
||||
hypercorn -c hypercorn_config.toml app:app
|
||||
"
|
||||
environment:
|
||||
- PYTHONUNBUFFERED=1
|
||||
```
|
||||
|
||||
2 - Esegui il servizio con Docker Compose:
|
||||
### Avvio rapido
|
||||
```bash
|
||||
docker-compose up
|
||||
```
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
# 🔗 Accesso all'applicazione
|
||||
Una volta avviata, l'applicazione sarà accessibile da:
|
||||
L'applicazione sarà disponibile su `http://localhost:5000`
|
||||
|
||||
Docker Compose avvierà automaticamente:
|
||||
- Container MariaDB sulla porta 3306
|
||||
- Container Flask sulla porta 5000
|
||||
- Inizializzazione automatica del database
|
||||
|
||||
## 📁 Struttura del Progetto
|
||||
|
||||
```
|
||||
hersel.it/
|
||||
├── app.py # Applicazione Flask principale
|
||||
├── config.py # Configurazione
|
||||
├── models.py # Modelli SQLAlchemy
|
||||
├── init_db.py # Script inizializzazione database
|
||||
├── requirements.txt # Dipendenze Python
|
||||
├── docker-compose.yml # Configurazione Docker
|
||||
├── .env.example # Esempio variabili d'ambiente
|
||||
├── routes/
|
||||
│ ├── home.py # Route homepage
|
||||
│ └── api.py # API REST endpoints
|
||||
├── templates/ # Template Jinja2
|
||||
│ ├── index.html
|
||||
│ ├── head.html
|
||||
│ ├── navbar.html
|
||||
│ └── content/
|
||||
│ ├── about.html
|
||||
│ ├── project.html
|
||||
│ └── links.html
|
||||
└── static/ # File statici (CSS, JS, immagini)
|
||||
```
|
||||
|
||||
## 🔌 API REST Endpoints
|
||||
|
||||
### Profile
|
||||
- `GET /api/profile` - Ottieni informazioni profilo
|
||||
- `PUT /api/profile` - Aggiorna profilo
|
||||
|
||||
### Skills
|
||||
- `GET /api/skills` - Lista competenze
|
||||
- `POST /api/skills` - Crea competenza
|
||||
- `PUT /api/skills/<id>` - Aggiorna competenza
|
||||
- `DELETE /api/skills/<id>` - Elimina competenza
|
||||
|
||||
### Projects
|
||||
- `GET /api/projects` - Lista progetti
|
||||
- `POST /api/projects` - Crea progetto
|
||||
- `PUT /api/projects/<id>` - Aggiorna progetto
|
||||
- `DELETE /api/projects/<id>` - Elimina progetto
|
||||
|
||||
### Social Links
|
||||
- `GET /api/social-links` - Lista link social
|
||||
- `POST /api/social-links` - Crea link social
|
||||
- `PUT /api/social-links/<id>` - Aggiorna link social
|
||||
- `DELETE /api/social-links/<id>` - Elimina link social
|
||||
|
||||
## 📊 Schema Database
|
||||
|
||||
### Tabelle
|
||||
- `profile` - Informazioni personali
|
||||
- `skills` - Competenze tecnologiche
|
||||
- `projects` - Portfolio progetti
|
||||
- `project_tags` - Tag/badge progetti
|
||||
- `social_links` - Link profili social
|
||||
|
||||
## 🔄 Migrazione da Quart a Flask
|
||||
|
||||
Questo progetto è stato migrato da Quart (framework asincrono) a Flask (framework sincrono) per:
|
||||
- Semplificare l'architettura
|
||||
- Migliorare la compatibilità con librerie esistenti
|
||||
- Facilitare il deployment con server WSGI standard (Gunicorn)
|
||||
- Ridurre la complessità per un portfolio che non richiede operazioni async intensive
|
||||
|
||||
## 🛠️ Sviluppo
|
||||
|
||||
### Aggiungere un nuovo progetto via API
|
||||
```bash
|
||||
http://127.0.0.1:5000
|
||||
```
|
||||
curl -X POST http://localhost:5000/api/projects \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"title": "Nuovo Progetto",
|
||||
"description": "Descrizione del progetto",
|
||||
"image_url": "img/project.webp",
|
||||
"github_url": "https://github.com/username/repo",
|
||||
"tags": [
|
||||
{"name": "Python", "color_class": "bg-primary"},
|
||||
{"name": "Flask", "color_class": "bg-info"}
|
||||
]
|
||||
}'
|
||||
```
|
||||
|
||||
## 📝 Licenza
|
||||
|
||||
Copyright Hersel Giannella
|
||||
|
||||
## 🔗 Link Utili
|
||||
|
||||
- Portfolio Live: [https://hersel.it](https://hersel.it)
|
||||
- GitHub: [https://github.com/BluLupo](https://github.com/BluLupo)
|
||||
- LinkedIn: [https://linkedin.com/in/hersel](https://linkedin.com/in/hersel)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user