# idieguez/geopark-api architecture

> Architecture diagram of the GitHub repository idieguez/geopark-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/idieguez/geopark-api
- Repository: https://github.com/idieguez/geopark-api

## Overview

#### Purpose and runtime
Geopark is a Node.js 22+/Express 5 REST backend for users to register, locate, and manage parked vehicles. It exposes JSON HTTP endpoints, persists operational data in MongoDB via Mongoose, and is intended to serve a separate client application. Production startup flows through `src/index.js`; the reusable Express application is assembled in `src/app.js`. Deployment support is indicated by `Procfile`.

#### Application composition and request boundary
`src/app.js` configures the Express request pipeline and mounts the three API domains: authentication, user account management, and vehicle management. It is the cross-cutting boundary for HTTP parsing, security middleware (Helmet, CORS, rate limiting), request logging, route dispatch, and final error handling.
- `src/app.js`
- `src/routes/auth-routes.js`
- `src/middlewares/error-middleware.js`

#### Authentication stage
Unauthenticated clients register or log in through the auth route/controller pair. Password handling uses bcrypt and successful login returns a stateless JWT. Protected account and vehicle operations pass through JWT verification middleware, which establishes the authenticated-user context used for authorization and data ownership.
- `src/routes/auth-routes.js`
- `src/controllers/auth-controller.js`
- `src/middlewares/auth-middleware.js`

#### User-account domain
The users domain exposes only operations on the authenticated caller’s account: read profile, patch permitted fields, and delete account. The controller mediates between authenticated request context, validated payloads, and the User persistence model.
- `src/routes/users-routes.js`
- `src/controllers/users-controller.js`
- `src/models/User.js`

#### Vehicle domain and ownership boundary
Vehicles are created and managed under the authenticated user, with license plate as the route-level resource identifier for detail, update, and deletion operations. Controllers must enforce that list and individual-resource operations remain scoped to the caller, preventing cross-user vehicle access.
- `src/routes/vehicles-routes.js`
- `src/controllers/vehicles-controller.js`
- `src/models/Vehicle.js`

#### Validation and error contract
Routes apply domain-specific Zod schemas through a common validation middleware before controllers execute. Failures and asynchronous exceptions converge on centralized error handling, using application-specific errors and a JSend-style response contract; development may expose diagnostic detail while production returns controlled messages.
- `src/middlewares/validation-middleware.js`
- `src/schemas/vehicles-schema.js`
- `src/utils/app-error.js`

#### Persistence, logging, and operations
`src/database.js` owns MongoDB connection lifecycle; Mongoose models define persisted users, vehicles, and logs. Environment-driven configuration is represented by `.env.example`. Tests run against an isolated in-memory MongoDB rather than the operational database, while the seed script supports initial Mongo data preparation.
- `src/database.js`
- `src/models/Log.js`
- `scripts/mongo/seed.js`

Main entry points: [`src/app.js`](https://github.com/idieguez/geopark-api/blob/main/src/app.js) (Express application), [`src/database.js`](https://github.com/idieguez/geopark-api/blob/main/src/database.js) (MongoDB lifecycle), [`src/routes/users-routes.js`](https://github.com/idieguez/geopark-api/blob/main/src/routes/users-routes.js) (User routes), [`src/routes/vehicles-routes.js`](https://github.com/idieguez/geopark-api/blob/main/src/routes/vehicles-routes.js) (Vehicle routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_startup["Production startup<br/>Node.js entry<br/>[index.js]"]
end

subgraph group_http["HTTP API"]
  node_app["Express application<br/>request pipeline<br/>[app.js]"]
  node_auth_middleware["JWT authentication<br/>middleware<br/>[auth-middleware.js]"]
  node_validation["Request validation<br/>middleware"]
  node_error_handler["Central error handler<br/>error middleware"]
  node_app_error["Application errors<br/>error contract<br/>[app-error.js]"]
end

subgraph group_domains["Domains"]
  node_auth_routes["Auth routes<br/>public routes<br/>[auth-routes.js]"]
  node_auth_controller["Auth controller<br/>authentication<br/>[auth-controller.js]"]
  node_users_routes["User routes<br/>protected routes<br/>[users-routes.js]"]
  node_users_controller["Users controller<br/>account operations"]
  node_vehicles_routes["Vehicle routes<br/>protected routes<br/>[vehicles-routes.js]"]
  node_vehicles_controller["Vehicles controller<br/>vehicle operations"]
  node_vehicle_schemas["Vehicle schemas<br/>Zod schemas<br/>[vehicles-schema.js]"]
end

subgraph group_data["Data &amp; Operations"]
  node_user_model[("User model<br/>Mongoose model<br/>[User.js]")]
  node_vehicle_model[("Vehicle model<br/>Mongoose model<br/>[Vehicle.js]")]
  node_database[("MongoDB lifecycle<br/>database connection<br/>[database.js]")]
  node_log_model[("Log model<br/>Mongoose model<br/>[Log.js]")]
  node_seed["Mongo seed script<br/>data preparation<br/>[seed.js]"]
end

node_startup -->|"connects"| node_database
node_startup -->|"starts"| node_app
node_app -->|"mounts"| node_auth_routes
node_app -->|"mounts"| node_users_routes
node_app -->|"mounts"| node_vehicles_routes
node_app -->|"final handler"| node_error_handler
node_auth_routes -->|"validates"| node_validation
node_auth_routes -->|"dispatches"| node_auth_controller
node_auth_controller -->|"creates and verifies users"| node_user_model
node_users_routes -->|"requires JWT"| node_auth_middleware
node_users_routes -->|"validates"| node_validation
node_users_routes -->|"dispatches"| node_users_controller
node_users_controller -->|"reads and updates"| node_user_model
node_vehicles_routes -->|"requires JWT"| node_auth_middleware
node_vehicles_routes -->|"validates"| node_validation
node_vehicles_routes -->|"dispatches"| node_vehicles_controller
node_validation -->|"uses"| node_vehicle_schemas
node_vehicles_controller -->|"owner-scoped CRUD"| node_vehicle_model
node_user_model -->|"persists through"| node_database
node_vehicle_model -->|"persists through"| node_database
node_log_model -->|"persists through"| node_database
node_seed -->|"prepares"| node_database
node_app_error -->|"handled by"| node_error_handler

click node_startup "https://github.com/idieguez/geopark-api/blob/main/src/index.js"
click node_app "https://github.com/idieguez/geopark-api/blob/main/src/app.js"
click node_auth_routes "https://github.com/idieguez/geopark-api/blob/main/src/routes/auth-routes.js"
click node_auth_controller "https://github.com/idieguez/geopark-api/blob/main/src/controllers/auth-controller.js"
click node_users_routes "https://github.com/idieguez/geopark-api/blob/main/src/routes/users-routes.js"
click node_users_controller "https://github.com/idieguez/geopark-api/blob/main/src/controllers/users-controller.js"
click node_vehicles_routes "https://github.com/idieguez/geopark-api/blob/main/src/routes/vehicles-routes.js"
click node_vehicles_controller "https://github.com/idieguez/geopark-api/blob/main/src/controllers/vehicles-controller.js"
click node_auth_middleware "https://github.com/idieguez/geopark-api/blob/main/src/middlewares/auth-middleware.js"
click node_validation "https://github.com/idieguez/geopark-api/blob/main/src/middlewares/validation-middleware.js"
click node_vehicle_schemas "https://github.com/idieguez/geopark-api/blob/main/src/schemas/vehicles-schema.js"
click node_error_handler "https://github.com/idieguez/geopark-api/blob/main/src/middlewares/error-middleware.js"
click node_app_error "https://github.com/idieguez/geopark-api/blob/main/src/utils/app-error.js"
click node_user_model "https://github.com/idieguez/geopark-api/blob/main/src/models/User.js"
click node_vehicle_model "https://github.com/idieguez/geopark-api/blob/main/src/models/Vehicle.js"
click node_database "https://github.com/idieguez/geopark-api/blob/main/src/database.js"
click node_log_model "https://github.com/idieguez/geopark-api/blob/main/src/models/Log.js"
click node_seed "https://github.com/idieguez/geopark-api/blob/main/scripts/mongo/seed.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_startup toneBlue
class node_app,node_auth_middleware,node_validation,node_error_handler,node_app_error toneAmber
class node_auth_routes,node_auth_controller,node_users_routes,node_users_controller,node_vehicles_routes,node_vehicles_controller,node_vehicle_schemas toneMint
class node_user_model,node_vehicle_model,node_database,node_log_model,node_seed toneRose
```

## Components

### Runtime

- [Production startup](https://github.com/idieguez/geopark-api/blob/main/src/index.js): Node.js entry · `src/index.js`

### HTTP API

- [Express application](https://github.com/idieguez/geopark-api/blob/main/src/app.js): request pipeline · Configures parsing, security, logging, dispatch, and final errors. · `src/app.js`
- [JWT authentication](https://github.com/idieguez/geopark-api/blob/main/src/middlewares/auth-middleware.js): middleware · Establishes authenticated-user context. · `src/middlewares/auth-middleware.js`
- [Request validation](https://github.com/idieguez/geopark-api/blob/main/src/middlewares/validation-middleware.js): middleware · Applies domain Zod schemas before controllers. · `src/middlewares/validation-middleware.js`
- [Central error handler](https://github.com/idieguez/geopark-api/blob/main/src/middlewares/error-middleware.js): error middleware · Returns controlled JSend-style error responses. · `src/middlewares/error-middleware.js`
- [Application errors](https://github.com/idieguez/geopark-api/blob/main/src/utils/app-error.js): error contract · `src/utils/app-error.js`

### Domains

- [Auth routes](https://github.com/idieguez/geopark-api/blob/main/src/routes/auth-routes.js): public routes · `src/routes/auth-routes.js`
- [Auth controller](https://github.com/idieguez/geopark-api/blob/main/src/controllers/auth-controller.js): authentication · Registers users, verifies passwords, and issues JWTs. · `src/controllers/auth-controller.js`
- [User routes](https://github.com/idieguez/geopark-api/blob/main/src/routes/users-routes.js): protected routes · `src/routes/users-routes.js`
- [Users controller](https://github.com/idieguez/geopark-api/blob/main/src/controllers/users-controller.js): account operations · `src/controllers/users-controller.js`
- [Vehicle routes](https://github.com/idieguez/geopark-api/blob/main/src/routes/vehicles-routes.js): protected routes · Uses license plate as the detail resource identifier. · `src/routes/vehicles-routes.js`
- [Vehicles controller](https://github.com/idieguez/geopark-api/blob/main/src/controllers/vehicles-controller.js): vehicle operations · Scopes lists and individual vehicles to the authenticated owner. · `src/controllers/vehicles-controller.js`
- [Vehicle schemas](https://github.com/idieguez/geopark-api/blob/main/src/schemas/vehicles-schema.js): Zod schemas · `src/schemas/vehicles-schema.js`

### Data & Operations

- [User model](https://github.com/idieguez/geopark-api/blob/main/src/models/User.js): Mongoose model · `src/models/User.js`
- [Vehicle model](https://github.com/idieguez/geopark-api/blob/main/src/models/Vehicle.js): Mongoose model · `src/models/Vehicle.js`
- [MongoDB lifecycle](https://github.com/idieguez/geopark-api/blob/main/src/database.js): database connection · Owns MongoDB connection lifecycle. · `src/database.js`
- [Log model](https://github.com/idieguez/geopark-api/blob/main/src/models/Log.js): Mongoose model · `src/models/Log.js`
- [Mongo seed script](https://github.com/idieguez/geopark-api/blob/main/scripts/mongo/seed.js): data preparation · Prepares initial Mongo data. · `scripts/mongo/seed.js`

## Connections

- Production startup → MongoDB lifecycle: connects
- Production startup → Express application: starts
- Express application → Auth routes: mounts
- Express application → User routes: mounts
- Express application → Vehicle routes: mounts
- Express application → Central error handler: final handler
- Auth routes → Request validation: validates
- Auth routes → Auth controller: dispatches
- Auth controller → User model: creates and verifies users
- User routes → JWT authentication: requires JWT
- User routes → Request validation: validates
- User routes → Users controller: dispatches
- Users controller → User model: reads and updates
- Vehicle routes → JWT authentication: requires JWT
- Vehicle routes → Request validation: validates
- Vehicle routes → Vehicles controller: dispatches
- Request validation → Vehicle schemas: uses
- Vehicles controller → Vehicle model: owner-scoped CRUD
- User model → MongoDB lifecycle: persists through
- Vehicle model → MongoDB lifecycle: persists through
- Log model → MongoDB lifecycle: persists through
- Mongo seed script → MongoDB lifecycle: prepares
- Application errors → Central error handler: handled by
