Grazie per il tuo interesse nel contribuire ad AgriRomagna! 🌾
- Node.js ≥ 20
- npm ≥ 10
- SQLite (bundled via
better-sqlite3)
# Clone the repository
git clone <repo-url>
cd agri-romagna
# Install dependencies
npm install
# Copy environment variables
cp .env.example .env
# Generate Prisma client
npm run db:generate
# Run database migrations
npm run db:migrate
# Seed the database with demo data
npm run db:seed
# Start the development server
npm run devThe app will be available at http://localhost:3000.
| Password | Role | |
|---|---|---|
| marco@tondini.farm | agriromagna2025 | coop_admin |
| giulia@sanvittore.it | agriromagna2025 | member |
| luca@lafratta.it | agriromagna2025 | farmer |
| anna@cabianca.farm | agriromagna2025 | member |
feature/<short-description>
fix/<short-description>
refactor/<short-description>
- TypeScript is required for all source files
- ESLint enforces code style — run
npm run lintbefore committing - Error messages and UI labels are in Italian to match the platform locale
- API errors follow RFC 7807 Problem Details (see
src/lib/api-errors.ts)
src/
├── app/ # Next.js App Router pages and API routes
│ ├── api/ # REST API endpoints (one folder per domain)
│ ├── dashboard/ # Protected dashboard pages
│ └── login/ # Authentication page
├── components/ # Reusable React components
├── generated/ # Prisma-generated client (auto-generated)
└── lib/ # Shared utilities, services, and data layers
├── auth-service.ts # JWT authentication (bcrypt + jsonwebtoken)
├── api-response.ts # Response helpers + withAuth wrapper
├── api-errors.ts # RFC 7807 error helpers + withErrorHandling
├── rbac-middleware.ts # Role-based access control (70+ permissions)
├── data-layer.ts # Prisma query abstraction layer
├── config.ts # Zod-validated environment configuration
└── validators/ # Zod request validation schemas
prisma/
├── schema.prisma # Database schema (SQLite)
├── migrations/ # Prisma migration files
└── seed.ts # Database seeding script
tests/
├── api/ # API route integration tests
├── e2e/ # Playwright end-to-end tests
└── lib/ # Unit tests for library modules
All API routes must be protected with authentication and RBAC unless explicitly public.
Using withAuth (preferred for simple routes):
import { withAuth, createSuccessResponse } from "@/lib/api-response";
export const GET = withAuth("fields:read", async (request, user) => {
// `user` is the authenticated user with correct RBAC role
return createSuccessResponse({ data: "..." });
});Using authorizeRoute (for routes with dynamic params or complex logic):
import { authorizeRoute, createSuccessResponse } from "@/lib/api-response";
import { withErrorHandling } from "@/lib/api-errors";
export const GET = withErrorHandling(async (request, { params }) => {
const { denied } = await authorizeRoute(request, "fields:read");
if (denied) return denied;
// ...
});GET /api/health— Health checks and probesPOST /api/auth— Login, register, OTP, token refreshGET /api/auth— Current user info (self-validates token)POST /api/onboarding— Cooperative registration
# Run all tests
npm test
# Run in watch mode
npm run test:watch
# Run with coverage
npm run test:coverage
# Run a specific test file
npx vitest run tests/api/routes.test.ts# Install browsers (first time only)
npx playwright install
# Run E2E tests
npm run test:e2e
# Open interactive test UI
npm run test:e2e:ui- Unit tests go in
tests/lib/with the pattern<module>.test.ts - API integration tests go in
tests/api/ - E2E tests go in
tests/e2e/with the pattern<feature>.spec.ts - Mock
next/headersand@/lib/auth-servicefor API route tests (seetests/api/routes.test.ts)
The project uses SQLite via Prisma with the better-sqlite3 adapter.
# Generate the Prisma client after schema changes
npm run db:generate
# Create a new migration
npm run db:migrate
# Reset the database (drops all data)
npm run db:reset
# Seed the database
npm run db:seed- Edit
prisma/schema.prisma - Run
npm run db:migrateto create a migration - Run
npm run db:generateto update the Prisma client - Update
prisma/seed.tsif new models need seed data - Update
src/lib/data-layer.tswith query helpers for new models
# Build and run with Docker Compose
docker-compose up --build
# Or build manually
docker build -t agri-romagna .
docker run -p 3000:3000 agri-romagna- Create a feature branch from
main - Make focused, well-scoped changes
- Ensure
npm run lintandnpm testpass - Write tests for new functionality
- Update documentation if adding new API routes or features
- Submit a PR with a clear description of changes