README.md

# GeoControl API

## Installation and Setup

### Prerequisites

Before starting, ensure you have the following installed on your system:

- **Node.js** (Recomended version: latest LTS)
- **npm** (Node Package Manager, included with Node.js)

### Installing Dependencies

Run the following command to install all required dependencies:

```sh
npm install

Running the Application

Starting the API Server

To start the server, run:

npm start

By default, the server runs on

http://localhost:5000

Development Mode (Hot Reloading)

For development with hot reloading, use:

npm run dev

This mode restarts the server automatically when code changes.

Debugging

For debugging with hot reloading enabled:

Creating the Root User

To create the SQLite database file and att to it an admin user with credentials root:rootpassword, execute:

npm run create-root

Windows Execution Policy Issue

If you encounter an execution policy error like:

+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess

Run the following command before executing scripts:

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

API Documentation

The API follows an OpenAPI specification, with the definition stored in:

doc/swagger_v1.yaml

Once the application is running, the Swagger UI is available at:

**http://localhost:5000/api/v1/doc**

The Swagger documentation provides a complete definition and description of the system, including object schemas, detailed endpoint specifications with input and output parameters, error definitions, and a brief functional overview of each API operation. It serves as the authorative reference for understanding how the system is designed to function.

Project Structure

The project follows a modular architecture, ensuring maintainability, separation of concerns, and scalability. Each module is structured to serve a specific purpose.

/coverage

/data

/doc

/docker

/logs

/scripts

/src - Main source folder

Contains all the following subfolders with the source code.

/test - Test folder

Path Aliases

To avoid relative imports, TypeScript path aliases are defined in tsconfig.json>

		"paths": {
			"@models/*": ["models/*"],
			"@errors/*": ["models/errors/*"],
			"@dao/*": ["models/dao/*"],
			"@dto/*": ["models/dto/*"],
			"@repositories/*": ["repositories/*"],
			"@services/*": ["services/*"],
			"@routes/*": ["routes/*"],
			"@controllers/*": ["controllers/*"],
			"@middlewares/*": ["middlewares/*"],
			"@database": ["database/connection.ts"],
			"@config": ["config/config.ts"],
			"@utils": ["utils.ts"],
			"@app": ["app.ts"],
			"@test/*": ["../test/*"]
		}

This allows importing modules like:

import { UserRepository } from "@repositories/UserRepository";

instead of using relative paths like:

import { UserRepository } from "../repositories/UserRepository";

API Versioning

All API endpoints include /v1/ in their URL paths (e.g., /api/v1/users).

This approact allows for backward compatibility when introducing breaking changes in the future. If a newer version of an endpoint requires different input parameters or returns a different response structure, a new version (e.g., /api/v2/users) can be created while keeping the old version operational. This prevents service disruptions for existing clients that depend on previous API versions.


## Punto di ingresso

Il **README.md** è il riferimento da consultare per primo: descrive prerequisiti, comandi e struttura del progetto. È quindi il “manuale d’uso” che sostituisce le spiegazioni frammentarie del prof.

## Installazione delle dipendenze

1. Verificare di avere **Node ≥ LTS** e **npm**.
2. Eseguire `npm install` per scaricare tutte le dipendenze definite nel progetto - operazione da ripetere anche se pensiamo di aver già installato qualcosa, perché il pacchetto fornito contiene tutte le librerie necessarie.

## Avvio del backend

- **Modalità standard**: `npm start` avvia il server su <http://localhost:5000>.
- **Modalità sviluppo con hot-reload**: `npm run dev` ricarica il codice a ogni salvataggio, evitando riavvii manuali.
- **Debug con hot-reload**:
    - Windows → `npm run debug-win`
    - Unix → `npm run debug-unix`
        
        Il prof insiste che questi script sono già configurati: basta lanciarli, senza modifiche.
        

## Primo accesso: creazione utente amministratore

Per effettuare chiamate autenticate serve un utente. Il comando `npm run create-root` popola il database (SQLite di default) con l’utente `root : rootpassword` (**password lunga ≥ 5 caratteri**, per rispettare la validazione dell’entità `User`).

## Architettura del progetto

Il repository segue una **struttura modulare**:

- `/src` - codice applicativo suddiviso in **config**, **controllers**, **models (DAO/DTO/errors)**, **repositories**, **services**, **routes**, **middlewares** e **utils**.
- `/test` - suite Jest con unit, integration, e2e e una collezione Postman completa.
- Cartelle di servizio: `/coverage` (report test), `/data` (SQLite), `/logs` (file di log), `/docker` (containerizzazione), `/doc` (OpenAPI).
- **Path aliases** (definiti in `tsconfig.json`) eliminano i percorsi relativi, migliorando leggibilità e refactoring.

## Comandi utili (recap)