> For the complete documentation index, see [llms.txt](https://docs.devonyx.fr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.devonyx.fr/getting-started/frontend-web.md).

# Frontend (Web)

### Stack

Le frontend est une application React + TypeScript, buildée avec Vite.js. Le styling est assuré par Tailwindcss, avec des animations Framer-Motion et la cartographie Leaflet.

### Structure des dossiers

```
client/
├── public/                 # Assets statiques
├── src/
│   ├── components/         # Composants réutilisables
│   │   ├── Dashboard.tsx
│   │   ├── Layout.tsx      # Layout protégé (sidebar + outlet)
│   │   ├── FarmMap.tsx     # Carte Leaflet des parcelles
│   │   ├── Charts.tsx      # Graphiques (météo, etc.)
│   │   ├── NotificationCenter.tsx
│   │   └── Icon.tsx
│   ├── pages/              # Pages routées
│   │   ├── Landing.tsx     # Page publique d'accueil
│   │   ├── Auth.tsx        # Login / Register
│   │   ├── Parcelles.tsx
│   │   ├── Cultures.tsx
│   │   ├── Meteo.tsx
│   │   └── Alertes.tsx
│   ├── context/
│   │   └── AuthContext.tsx # Contexte d'authentification global
│   ├── api.ts              # Client API typé + helpers de mapping
│   ├── data.ts             # Données mock / fallback
│   ├── router.tsx          # Configuration React Router
│   ├── main.tsx            # Point d'entrée
│   └── App.tsx             # (déprécié — non utilisé)
├── index.html
├── vite.config.ts
└── package.json
```

### Routing

Le routing est géré par **React Router (`createBrowserRouter`)** avec deux types de gardes:

* `RequireAuth` : redirige vers `/auth` si l'utilisateur n'a pas de token.
* `GuestOnly` : redirige vers `/dashboard` si l'utilisateur est déjà connecté.

#### Routes publiques

| Chemin  | Composant  | Description              |
| ------- | ---------- | ------------------------ |
| `/`     | `Landing`  | Page d'accueil marketing |
| `/auth` | `AuthPage` | Connexion / inscription  |

#### Routes. protégées (sous `AppLayout` )

| Chemin       | Composant   | Description           |
| ------------ | ----------- | --------------------- |
| `/dashboard` | `Dashboard` | Vue d'ensemble        |
| `/parcelles` | `Parcelles` | Gestion des parcelles |
| `/cultures`  | `Cultures`  | Gestion des cultures  |
| `/alertes`   | `Alertes`   | Liste des alertes     |
| `/meteo`     | `Meteo`     | Visualisation météo   |

### Client API typé

Le fichier `src/api.ts` expose un objet `api` typé reflétant exactement les endpoints du backend :&#x20;

```tsx
import { api } from './api'

// Récupérer toutes les parcelles
const parcelles = await api.parcelles.getAll()

// Créer une culture
const culture = await api.cultures.create({
  nom: 'Blé',
  date_semis: '2026-10-15',
  id_parcelle: 1
})

// Connexion
const { token, user } = await api.auth.login(email, motDePasse)
```

Le client gère automatiquement :&#x20;

* L'injection du header `Authorization: Bearer <token>` depuis `localStorage`
* La sérialisation JSON
* Le parsing des erreurs server

#### Variable d'environnement

| Variable       | Défaut | Description                                                                        |
| -------------- | ------ | ---------------------------------------------------------------------------------- |
| `VITE_API_URL` | `/api` | URL de base de l'API. En dev, le proxy Vite redirige `/api` vers `localhost:3000`. |

### Gestion de l'authentification

Le `AuthContext` (`src/context/AuthContext.tsx`) expose:

* `token` : JWT courant (synchronisé avec `localStorage`)
* `user` : utilisateur connecté
* `login (email, mot de passe)` / r`egister(...)` / `logout()`

Tous les composants peuvent y accéder via `useAuth()`

### Cartographie

`FarmMap.tsx` utilise **Leaflet + react-leaflet** pour afficher les parcelles géocalisées sur une carate intéractive. Le helper `normalizeParcelles()`  (dans `api.ts` ) convertit les cordonnées GPS réelles en position normalisées 0-100% utilisables aussi pour des mini-cartes SVG.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.devonyx.fr/getting-started/frontend-web.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
