How thenilimnetwork/leafletint works
Project Type and Purpose
• This is a full-stack, route-planning web application.
• Frontend: Next.js (app directory), React/TypeScript, Tailwind CSS, a library of UI components.
• Backend: Standalone Node.js microservice (“airport-backend”) serving airport data and lookup APIs.
• AI module: In‐repo “src/ai” flows that call an external LLM (“GEMINI_API_KEY”) for terrain suitability checks or guidance.
• External services: OpenRouteService, AirportDB, and Gemini LLM.
File Structure
• Top-level
– next.config.ts, tailwind.config.ts, tsconfig.json → Next.js/TypeScript config.
– apphosting.yaml → GCP App Engine deploy manifest for frontend or backend.
• airport-backend/
– server.js → Express (or vanilla) server exposing REST endpoints.
– data/airports.csv → Local CSV airport database.
– package.json → Node.js microservice dependencies.
• src/
– app/… → Next.js app-router pages & server actions (e.g., getRoute.ts).
– components/… → Reusable UI components (controls, map display, theming, plus a UI library under components/ui).
– ai/… → AI orchestration code: genkit.ts, flows/terrain-suitability-check.ts.
– lib/… → Utilities for airports, routing, generic helpers.
• Configuration files for Nix (.idx/dev.nix), VSCode, and environment variables (.env.local).
Key Architectural Patterns
• Full-stack separation: Next.js handles SSR/SSG and client-side UI, while the dedicated Node.js service handles raw data access.
• Modular AI flows: The “src/ai” layer abstracts calls to the LLM and implements domain-specific logic (terrain suitability).
• API layering: Frontend ↔ Next.js Server Actions ↔ airport-backend (or directly ↔ third-party APIs) ↔ External services.
• Shared utilities in “src/lib” to keep domain logic DRY.
Main Components and Their Interactions
a. Frontend (Next.js)
• React pages (src/app/page.tsx), components, hooks.
• Server Actions (getRoute) that can run on the server and call downstream APIs.
• UI layer issues calls to backend or AI module.
b. Backend Service (airport-backend)
• REST endpoint(s) (e.g., /airports, /airport/:id).
• Reads airports.csv, responds with JSON.
c. AI Module (src/ai)
• Orchestrates calls to Gemini API and optionally to OpenRouteService for terrain data.
• Returns augmented route insights.
d. External Services
• OpenRouteService API (routing, distance, elevation).
• AirportDB API (if used, based on AIRPORTDB_API_KEY).
• Gemini LLM (for reasoning or terrain checks).
e. Deployment & Dev Environment
• .idx/dev.nix for reproducible development.
• apphosting.yaml for GCP deployment.
Important Design Principles
• Separation of concerns: UI vs. business logic vs. data access vs. AI orchestration.
• Modularity: “src/components”, “src/lib”, “src/ai” layers.
• Scalability: The airport-backend can be containerized and autoscaled; Next.js can be deployed serverlessly.