ASAgriSense/Docs/Tech Stack

Architecture

Tech Stack

Full reference for every technology in the platform, with version and rationale. This document reflects the actual versions installed — verify against package.json files for patches.

Frontend#

LayerTechnologyVersionWhy
FrameworkNext.js16.1.5App Router, React Server Components, file-based routing, edge middleware.
UI libraryReact19.2.0Function components, concurrent features, Server/Client composition.
LanguageTypeScript5.9.2Strict mode throughout. Discriminated unions for domain concepts.
StylingTailwind CSS4.1.xv4 with CSS @theme tokens. No separate config file — tokens live in globals.css.
Data fetchingSWR2.3.4Stale-while-revalidate pattern; shared config via @repo/swr-config.
Auth (client)Clerk (@clerk/nextjs)latestOrganizations = multi-tenancy. JWT session claims carry permissions for edge-side checks.
AnimationsMotion12.xDeclarative animation for UI transitions.
IconsLucide React0.574.0Consistent, tree-shakeable icon set.
Validation (client)Zod3.25.xRuntime schema validation. Shared schemas between client and API via @repo/validation.

Design system#

The design system lives entirely in shared/brand and shared/ui. All color tokens are defined as CSS variables in shared/brand/src/styles/globals.css via the Tailwind v4 @theme directive and automatically become Tailwind utilities. Key design tokens:

TokenCSS variableValue (light)
Primary green--color-primary#11d452
Background--color-background#f8fafc
Surface--color-surface#ffffff
Text primary--color-text-primary#0f172a
Text secondary--color-text-secondary#475569
Shell panel--color-shell-panelrgba(255 255 255 / 0.86)

Utility class sets available from brand globals: card-base, card-interactive, glass-card, shell-panel, brand-container, btn-primary, and badge variants.

Backend#

LayerTechnologyVersionWhy
API frameworkHono.js4.11.9Built for edge runtimes (Cloudflare Workers). TypeScript-first, lightweight, Zod validator built in.
RuntimeCloudflare WorkersV8 isolatesServerless edge — zero cold start, 275+ global locations, $0 dev tier.
DatabaseNeon PostgreSQLpg 16Serverless, HTTP-compatible, PostGIS for geospatial, branching per environment.
ORMDrizzle ORM0.45.2Type-safe queries, schema-as-code, migration files checked into git.
Validation (API)@hono/zod-validatorlatestEvery route validated against a Zod schema; 422 on failure.
JWTjose6.2.2Edge-compatible JWT verification (no Node.js crypto required).
File storageCloudflare R2S3-compatibleEvidence files, survey photos, farm map exports. No egress fees.

Cost model#

PhaseMonthly costNotes
Development$0Wrangler local dev + Neon free tier (3 GB) + Cloudflare Pages free.
MVP$0–15Workers 100k req/day free. Neon free → Pro at scale.
Production~$50Workers $5 + Neon Pro $19 + R2 $5 + Cloudflare Pro $20 + domain $1.
Enterprise$100–200Higher compute, dedicated Neon, enterprise Cloudflare features.

Build tooling#

ToolVersionRole
Turborepo2.7.3Monorepo task orchestration — parallel builds, remote caching.
npm workspacesnpm 11.xPackage linking and install hoisting.
Vitest3.2.4Unit and integration tests across all packages.
ESLint9.39.1v9 flat config via @repo/eslint-config. --max-warnings 0 enforced.
Prettier3.7.4Formatting. Run with npm run format.
Wrangler4.xCloudflare Workers local dev and deployment CLI.
tsuplatestBundler for shared/* packages.

Mobile (Phase 1)#

The mobile app for field data capture (farmer enrollment, GPS polygon walk, offline surveys) is a separate Flutter project. It is not in this repository.

LayerTechnologyNotes
FrameworkFlutter 3.xSingle codebase for Android.
StateRiverpodDI + reactive state.
Local DBSQLite + DriftOffline-first field storage.
Mapsflutter_map + OpenStreetMapFree, no Mapbox license required.
SyncCustom (batch, configurable interval)Default 4-hour batch sync to Workers API.

Geospatial processing#

All geospatial operations run in PostgreSQL via the PostGIS extension. No external geospatial service is used for polygon storage or area calculation.

sql
-- Area in hectares
SELECT ST_Area(ST_Transform(polygon_geom, 3857)) / 10000 AS area_ha
FROM plots;

-- Deforestation check — polygon intersects forest boundary after cutoff
SELECT p.id, ST_Intersects(p.polygon_geom, fr.boundary)
FROM plots p, forest_reference fr
WHERE fr.recorded_after = '2020-12-31';

-- All coordinates stored as WGS84 (EPSG:4326)
SELECT ST_AsGeoJSON(polygon_geom) FROM plots LIMIT 1;
Deforestation risk provider
Phase 1 uses the Global Forest Watch API for deforestation risk assessments. The provider is abstracted behind a ProviderAdapter interface in @repo/feature-deforestation-risk, making it swappable without changing the risk assessment service.