How n-xus-ll/web-app works
1. This repository is a full-stack web application with three main runtimes: a React/Vite frontend, a Kotlin/Ktor backend, and a PostgreSQL database. The backend is organized as a multi-module Gradle project under backend/ktor-backend.
2. The frontend lives in frontend/ and is a single-page app built with React. It contains page-level views for items, loans, users, locations, statistics, profiles, login/register, and a map page. The UI is split into reusable components, a map context, and service wrappers that call backend APIs.
3. The backend server module is the main application runtime. It uses Ktor for HTTP routing, serialization, logging, and likely WebSocket/RPC support. Entry points and bootstrap are in server/src/main/kotlin/main.kt, Routing.kt, Http.kt, Serialization.kt, and Resources.kt.
4. The backend is layered: routes/controllers live in routes/ and features/*/*Routes.kt, business logic is in feature services such as LoansService, and persistence is abstracted through repository/ plus database/ entity/mapper/table definitions. This is a classic API → service → repository → database flow.
5. The primary business domains are items, loans, users, and locations. Each domain has its own route/model files, and there are database tables and DTO/entity classes for items, locations, users, and lookup/reference data like categories, item conditions, and damage policies.
6. Authentication is handled on the backend in auth/ with JWT support. The frontend has dedicated auth services and protected routing (PrivateRoute.jsx), so the app likely uses token-based session state passed between client and server.
7. PostgreSQL is the persistent store. The schema is defined in database/schema.sql and seeded via database/seed.sql, while the backend’s database/tables/* and database/*Mapper.kt files map the relational schema into application objects.
8. There is a Kotlin DSL subsystem in server/src/main/kotlin/dsl/ with lexer, parser, AST, semantic analyzer, interpreter, and GeoJSON export. That means the backend accepts a custom query or scripting language, validates it, executes it, and can convert results into geospatial output.
9. Spatial/geographic data is a first-class concern. The backend has geo-point models, parsers/formatters, GeoJSON utilities, and a MapPage plus geocoding service on the frontend. This suggests map-based item/location visualization and location lookup are key features.
10. The core module provides shared contract code: service interfaces, request/response models, and common types such as GeoPoint, LoginRequest, and UserResponse. This module is shared between client and server to keep API/data contracts aligned.
11. The client module is a Kotlin RPC client built around the shared core. Its presence, along with kotlinx-rpc dependencies and Rpc.kt files on both client and server, indicates a typed RPC layer in addition to or alongside the HTTP API.
12. Operationally, the repo is containerized. There are Dockerfiles for both frontend and backend, Docker Compose files at the repo root, and a GitHub Actions workflow for deployment. The frontend also uses Nginx for production serving.
13. The backend includes tests for HTTP/RPC behavior and the DSL interpreter. That implies the more complex boundaries being validated are the API layer, remote contract layer, and custom query language rather than the React UI.
14. For diagramming, the core data flow is: browser UI → frontend service layer → backend routes/RPC → domain services → repositories/ORM tables → PostgreSQL, with side paths for auth/JWT, DSL execution, and geospatial conversion/GeoJSON output.
Main entry points: Routing.kt Routing · repository Repositories · main.kt Server main · docker-compose.yml Compose
Components 21
Frontend
React/Vite SPA and browser-side services
- App shell · Top-level client application and route composition
frontend/src/App.jsx - Pages · Page-level screens for items, loans, users, auth, map, and stats
frontend/src/pages - Components · Reusable presentation components and workflows
frontend/src/components - Services · Frontend service wrappers for backend APIs and geocoding
frontend/src/services - Map context · Shared browser state for map interactions
frontend/src/contexts/MapContext.jsx
Backend
Ktor server, domain layers, and API/runtime infrastructure
- Server main · Bootstrap, routing, serialization, and runtime wiring
backend/ktor-backend/server/src/main/kotlin/main.kt - HTTP setup · HTTP server configuration and middleware setup
backend/ktor-backend/server/src/main/kotlin/Http.kt - Routing · Top-level route registration for server features
backend/ktor-backend/server/src/main/kotlin/Routing.kt - Auth · Authentication service and JWT configuration
backend/ktor-backend/server/src/main/kotlin/auth/AuthService.kt - Items · Item domain routes, models, and reference data
backend/ktor-backend/server/src/main/kotlin/features/items/ItemRoutes.kt - Loans · Loan workflow, service logic, DTOs, and routes
backend/ktor-backend/server/src/main/kotlin/features/loans/LoansService.kt - Users · User domain models and routes
backend/ktor-backend/server/src/main/kotlin/features/users/UserModel.kt - Locations · Location routes and models
backend/ktor-backend/server/src/main/kotlin/routes/LocationRoutes.kt - DSL engine · Lexer, parser, semantic analysis, interpreter, and GeoJSON export
backend/ktor-backend/server/src/main/kotlin/dsl - Repositories · Persistence layer for items, locations, users, and DSL queries
backend/ktor-backend/server/src/main/kotlin/repository - ORM tables · Entity, mapper, and table definitions for relational persistence
backend/ktor-backend/server/src/main/kotlin/database - Spatial utils · Geo-point parsing, formatting, and GeoJSON helpers
backend/ktor-backend/server/src/main/kotlin/features/common/spatial/GeoJson.kt
Shared Contracts
Common Kotlin code used by client and server
- Core contracts · Common request/response models and service contracts
backend/ktor-backend/core/src/commonMain/kotlin - RPC client · Kotlin RPC client built on shared contracts
backend/ktor-backend/client/src/commonMain/kotlin
Ops
Containerization and deployment assets
- Compose · Local runtime wiring for frontend, backend, and database
docker-compose.yml
Connections 28
- App shell → Pages: navigates to · App shell renders page-level routes
- App shell → Components: uses · App composes reusable UI widgets
- Pages → Services: calls · Screens fetch and mutate data through service wrappers
- Pages → Map context: shares state · Map-related screens use common map state
- Components → Services: invokes · Interactive widgets trigger service calls
- Services → RPC client: typed RPC · Frontend service layer aligns with shared client contracts
- Server main → HTTP setup: configures · Bootstraps HTTP server behavior
- Server main → Routing: registers · Installs top-level routes
- Server main → Auth: enables · Wires authentication into runtime
- Routing → Items: mounts · Routes requests into item feature module
- Routing → Loans: mounts · Routes requests into loan feature module
- Routing → Users: mounts · Routes requests into user feature module
- Routing → Locations: mounts · Routes requests into location feature module
- Routing → DSL engine: mounts · Routes DSL/query execution endpoints
- Auth → Core contracts: shares models · Authentication uses shared request/response types
- Items → Repositories: reads/writes · Item feature persists through repositories
- Loans → Repositories: reads/writes · Loan workflows depend on persistence layer
- Users → Repositories: reads/writes · User feature uses repository access
- Locations → Repositories: reads/writes · Location feature uses repository access
- Repositories → ORM tables: maps to · Repositories operate over entities and tables
- ORM tables → PostgreSQL: persists in · ORM mapping targets PostgreSQL schema
- DSL engine → Repositories: queries through · DSL interpreter executes against repository-backed data
- DSL engine → Spatial utils: exports · DSL results can be converted to GeoJSON and spatial output
- Spatial utils → ORM tables: supports · Spatial helpers align with stored geo data
- RPC client → Core contracts: depends on · Typed RPC client uses shared contracts
- Compose → Server main: starts · Compose brings up backend runtime
- Compose → App shell: starts · Compose serves frontend runtime
- Compose → PostgreSQL: starts · Compose provisions PostgreSQL