Skip to content

Commit 529a753

Browse files
committed
Update: backend README.md
1 parent 8e4ca0d commit 529a753

1 file changed

Lines changed: 105 additions & 33 deletions

File tree

backend-data-elaborator/README.md

Lines changed: 105 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,122 @@
1-
# backend-data-elaborator 🧠
1+
# Backend Data Elaborator 🧠
22

3-
This is the core API for the EDEAS system. It manages the database, validates incoming IoT data via cryptography, and serves the frontend application.
3+
Welcome to the **Backend Data Elaborator** module of the **Electro-Domestic Earthquake Alarm System**.
4+
This service is the "brain" of the operation: it receives real-time telemetry from the IoT devices, processes the data using seismic detection algorithms, and triggers alerts when necessary.
45

5-
## 🛠 Tech Stack
6-
* **Language:** Python 3.11
7-
* **Framework:** FastAPI
8-
* **Database:** PostgreSQL 15 + PostGIS (Spatial Extensions)
9-
* **ORM:** SQLAlchemy + GeoAlchemy2
10-
* **Security:** Python-ECDSA (NIST256p)
6+
## 📂 Project Structure
7+
8+
The project is organized to keep the source code, configurations, and environment definitions clean and separated.
9+
10+
```text
11+
backend-data-elaborator/
12+
├── api/
13+
│ ├── src/ # Main application source code (FastAPI/Flask)
14+
│ ├── tests/ # Unit and Integration tests
15+
│ ├── init-scripts/ # Database or service initialization scripts
16+
│ ├── Dockerfile # Docker image definition
17+
│ ├── docker-compose.yml # Local development orchestration
18+
│ ├── requirements.txt # Python dependencies
19+
│ └── .env # Environment variables (do not commit secrets!)
20+
└── README.md # This file
21+
```
22+
23+
## 🚀 Tech Stack
24+
25+
* **Language:** Python 3.x
26+
* **Framework:** FastAPI / Flask (adjust based on your actual implementation)
1127
* **Containerization:** Docker & Docker Compose
28+
* **CI/CD:** GitHub Actions (Automated build & push to GHCR)
29+
30+
---
31+
32+
## 🛠️ Getting Started
33+
34+
You can run this service either using Docker (Recommended 🐳) or manually with a Python virtual environment.
35+
36+
### Prerequisites
37+
38+
* **Docker** and **Docker Compose** installed.
39+
* **Python 3.10+** (only for manual execution).
40+
41+
### Option 1: Run with Docker (The "Chill" Way)
42+
43+
This is the preferred method as it ensures the environment is identical to production.
44+
45+
1. Navigate to the `api` directory:
46+
```bash
47+
cd api
48+
```
49+
50+
2. Create your environment file (if missing):
51+
```bash
52+
cp .env.example .env
53+
# Edit .env with your specific configuration
54+
```
1255

13-
## ⚙️ Configuration
56+
3. Build and start the container:
57+
```bash
58+
docker-compose up --build
59+
```
60+
61+
The service should now be running (usually on `http://localhost:8000` or similar, check your compose config).
62+
63+
### Option 2: Manual Execution
64+
65+
If you need to debug locally without Docker:
1466

15-
1. Create a `.env` file in this directory based on the following template:
67+
1. Navigate to the `api` directory:
68+
```bash
69+
cd api
70+
```
71+
72+
2. Create and activate a virtual environment:
73+
```bash
74+
python -m venv .venv
75+
# Windows
76+
.\.venv\Scripts\activate
77+
# Linux/Mac
78+
source .venv/bin/activate
79+
```
1680

17-
```ini
18-
# Database Credentials
19-
POSTGRES_USER=developer
20-
POSTGRES_PASSWORD=password
21-
POSTGRES_DB=monitoraggio_db
81+
3. Install dependencies:
82+
```bash
83+
pip install -r requirements.txt
84+
```
2285

23-
# Connection String (Ensure host is 'postgres' for Docker networking)
24-
DATABASE_URL=postgresql://developer:password@postgres:5432/monitoraggio_db
86+
4. Run the application (example for generic app):
87+
```bash
88+
# Command depends on your framework, e.g.:
89+
uvicorn src.main:app --reload
90+
# OR
91+
python src/main.py
2592
```
2693

27-
2. Ensure the `init-scripts/` folder contains the SQL script to enable PostGIS.
94+
---
2895

29-
## 🐳 Running the Server
96+
## 🧪 Testing
3097

31-
Run the application using Docker Compose:
98+
We believe in code quality. Here is how to run the test suite.
3299

100+
**Using Docker:**
33101
```bash
34-
# Build and Start
35-
docker-compose up -d --build
102+
docker-compose run backend pytest
103+
```
36104

37-
# View Logs
38-
docker-compose logs -f
105+
**Manual:**
106+
```bash
107+
pytest tests/
39108
```
40109

41-
### Endpoints
42-
* **Swagger Documentation:** [http://localhost:8000/docs](http://localhost:8000/docs)
43-
* **pgAdmin (DB Interface):** [http://localhost:8080](http://localhost:8080) (User: `admin@example.com`, Pass: `admin`)
110+
## 🐳 Deployment
44111

45-
## ⚠️ Troubleshooting
46-
* **"Type geometry does not exist":**
47-
If the database was created before PostGIS was enabled, run:
48-
```bash
49-
docker-compose exec postgres psql -U developer -d monitoraggio_db -c "CREATE EXTENSION IF NOT EXISTS postgis;"
50-
```
112+
This repository uses **GitHub Actions** for CI/CD.
113+
Every push to the `main` branch (involving this folder) triggers a workflow that:
114+
1. Builds the Docker image using the context `./backend-data-elaborator/api`.
115+
2. Pushes the image to **GitHub Container Registry (GHCR)**.
116+
117+
## 🤝 Contribution
118+
119+
1. Create a feature branch from `main`.
120+
2. Ensure your code follows the project's style guide.
121+
3. Write tests for new features.
122+
4. Open a Pull Request.

0 commit comments

Comments
 (0)