# thedarklee/logisystem-app architecture

> Architecture diagram of the GitHub repository thedarklee/logisystem-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thedarklee/logisystem-app
- Repository: https://github.com/thedarklee/logisystem-app

## Overview

1. This is a Next.js App Router application: the `app/` tree contains both the user-facing pages and the server-side API route handlers. That makes the repo a single full-stack codebase rather than a separate frontend/backend split.

2. The product domain looks like an operations and access-control system. The main business areas are access events, cards/badges, users, vehicles, and “envíos” (shipments/dispatches), with dashboards built around those entities.

3. The backend boundary is implemented with Next.js route handlers under `app/api/*`. These handlers expose CRUD-style endpoints for `users`, `vehicles`, `cards`, and `envios`, plus specialized endpoints for `auth/login`, `setup`, `access`, and dashboard statistics.

4. Data persistence is centralized in `lib/mongodb.ts` / `lib/mongodb.js` and the `models/` directory. The presence of model files for `Envio`, `LecturaAcceso`, `Tarjeta`, `Usuario`, and `Vehiculo` indicates a MongoDB-based data layer with domain models sitting below the API routes.

5. Access control is its own subsystem. The API exposes `app/api/access/manual`, `app/api/access/rfid`, and `app/api/access/latest`, which suggests the system ingests access events from both manual entry and RFID reads, and also provides the most recent event for the UI or polling.

6. The RFID experience crosses the frontend/backend boundary through `components/RFIDListener.tsx`. That component likely acts as the client-side bridge that watches for RFID-related state or events and then updates access flows in the UI.

7. The dashboard UI is organized as a protected application area under `app/dashboard/`, with its own layout at `app/dashboard/layout.tsx`. This area contains subpages for access, cards, users, vehicles, envíos, and several analytics views.

8. Analytics is split into dedicated dashboard pages and dedicated data endpoints. The API has `app/api/dashboard/stats` and `app/api/dashboards/{envios,operacional,tendencia}`, while the UI has corresponding pages plus chart components like `_DonutChart`, `_BarrasChart`, and `_AreaChart`. That suggests the pages fetch aggregated data rather than raw records.

9. The app appears to have a standard authentication boundary: `/login` is the public entry point for sign-in, and `/dashboard` is the main authenticated workspace. `app/api/auth/login` is the server-side login endpoint supporting that flow.

10. There is also a `setup` API route, which usually means first-run initialization or environment/bootstrap behavior. In architecture terms, that is an administrative bootstrap path separate from normal CRUD operations.

11. The root `app/page.tsx` is likely a simple landing or redirect page, while the real product surface lives in `/login` and `/dashboard`. This keeps the public entry surface small and pushes most interactions into the authenticated area.

12. Overall, the repo is structured around a clean separation: Next.js pages render the UI, route handlers expose domain operations, MongoDB-backed models hold state, and chart components consume aggregated API data for operational reporting. The key diagrammatic boundaries are public vs authenticated UI, UI vs API routes, and domain CRUD vs specialized access/analytics workflows.

Main entry points: [`app/api/access/manual/route.ts`](https://github.com/thedarklee/logisystem-app/blob/main/app/api/access/manual/route.ts) (Access API), [`app/api/dashboards/operacional/route.ts`](https://github.com/thedarklee/logisystem-app/blob/main/app/api/dashboards/operacional/route.ts) (Analytics API), [`app/dashboard/page.tsx`](https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/page.tsx) (Overview), [`app/api/users/route.ts`](https://github.com/thedarklee/logisystem-app/blob/main/app/api/users/route.ts) (Users API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui_public["Public UI"]
  node_root_page["Home<br/>page<br/>[page.tsx]"]
  node_login_page["Login<br/>auth page<br/>[page.tsx]"]
end

subgraph group_ui_dashboard["Dashboard UI"]
  node_dashboard_shell["Dashboard Shell<br/>layout<br/>[layout.tsx]"]
  node_dashboard_home["Overview<br/>dashboard page<br/>[page.tsx]"]
  node_access_ui["Access<br/>dashboard page<br/>[page.tsx]"]
  node_new_access_ui["New Access<br/>form page<br/>[page.tsx]"]
  node_cards_ui["Cards<br/>dashboard page<br/>[page.tsx]"]
  node_users_ui["Users<br/>dashboard page<br/>[page.tsx]"]
  node_new_user_ui["New User<br/>form page<br/>[page.tsx]"]
  node_vehicles_ui["Vehicles<br/>dashboard page<br/>[page.tsx]"]
  node_fleet_manage_ui["Fleet Admin<br/>dashboard page<br/>[page.tsx]"]
  node_shipments_ui["Shipments<br/>dashboard page<br/>[page.tsx]"]
  node_shipment_access_ui["Shipment Access<br/>dashboard page<br/>[page.tsx]"]
  node_envios_chart(("Donut Chart<br/>chart component<br/>[_DonutChart.tsx]"))
  node_operacional_chart(("Bars Chart<br/>chart component<br/>[_BarrasChart.tsx]"))
  node_tendencia_chart(("Area Chart<br/>chart component<br/>[_AreaChart.tsx]"))
end

subgraph group_api["API Routes"]
  node_stats_cards["Cards API<br/>route handlers<br/>[route.ts]"]
  node_stats_users["Users API<br/>route handlers<br/>[route.ts]"]
  node_stats_vehicles["Vehicles API<br/>route handlers<br/>[route.ts]"]
  node_stats_envios["Shipments API<br/>route handlers<br/>[route.ts]"]
  node_access_api["Access API<br/>route handlers<br/>[route.ts]"]
  node_latest_access_api["Latest Access<br/>route handler<br/>[route.ts]"]
  node_auth_api["Login API<br/>route handler<br/>[route.ts]"]
  node_setup_api["Setup API<br/>route handler<br/>[route.ts]"]
  node_dashboard_stats_api["Stats API<br/>route handler<br/>[route.ts]"]
  node_dashboards_api["Analytics API<br/>route handlers<br/>[route.ts]"]
end

subgraph group_data["Data Layer"]
  node_mongodb[("MongoDB<br/>connection<br/>[mongodb.ts]")]
  node_envio_model["Envio<br/>model<br/>[Envio.ts]"]
  node_access_model["Access Log<br/>model<br/>[LecturaAcceso.ts]"]
  node_card_model["Tarjeta<br/>model<br/>[Tarjeta.ts]"]
  node_user_model["Usuario<br/>model<br/>[Usuario.ts]"]
  node_vehicle_model["Vehiculo<br/>model<br/>[Vehiculo.ts]"]
end

node_rfid_listener(("RFID Listener<br/>client component<br/>[RFIDListener.tsx]"))

node_root_page -->|"entry"| node_login_page
node_login_page -->|"auth"| node_auth_api
node_auth_api -->|"reads"| node_mongodb
node_dashboard_shell -->|"wraps"| node_dashboard_home
node_dashboard_home -->|"loads"| node_dashboard_stats_api
node_access_ui -->|"records"| node_access_api
node_new_access_ui -->|"creates"| node_access_api
node_access_api -->|"stores"| node_access_model
node_latest_access_api -->|"reads"| node_access_model
node_cards_ui -->|"crud"| node_stats_cards
node_users_ui -->|"crud"| node_stats_users
node_new_user_ui -->|"creates"| node_stats_users
node_vehicles_ui -->|"crud"| node_stats_vehicles
node_fleet_manage_ui -->|"manages"| node_stats_vehicles
node_shipments_ui -->|"crud"| node_stats_envios
node_shipment_access_ui -->|"views"| node_access_api
node_dashboard_home -->|"analytics"| node_dashboards_api
node_envios_chart -->|"data"| node_dashboards_api
node_operacional_chart -->|"data"| node_dashboards_api
node_tendencia_chart -->|"data"| node_dashboards_api
node_cards_ui -->|"backed by"| node_card_model
node_users_ui -->|"backed by"| node_user_model
node_vehicles_ui -->|"backed by"| node_vehicle_model
node_shipments_ui -->|"backed by"| node_envio_model
node_access_api -->|"uses"| node_mongodb
node_stats_cards -->|"uses"| node_card_model
node_stats_users -->|"uses"| node_user_model
node_stats_vehicles -->|"uses"| node_vehicle_model
node_stats_envios -->|"uses"| node_envio_model
node_setup_api -->|"initializes"| node_mongodb
node_rfid_listener -->|"polls"| node_latest_access_api
node_rfid_listener -->|"triggers"| node_access_api

click node_root_page "https://github.com/thedarklee/logisystem-app/blob/main/app/page.tsx"
click node_login_page "https://github.com/thedarklee/logisystem-app/blob/main/app/login/page.tsx"
click node_dashboard_shell "https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/layout.tsx"
click node_dashboard_home "https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/page.tsx"
click node_access_ui "https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/accesos/page.tsx"
click node_new_access_ui "https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/accesos/nuevo/page.tsx"
click node_cards_ui "https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/tarjetas/page.tsx"
click node_users_ui "https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/usuarios/page.tsx"
click node_new_user_ui "https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/usuarios/nuevo/page.tsx"
click node_vehicles_ui "https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/vehiculos/page.tsx"
click node_fleet_manage_ui "https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/vehiculos/gestion/page.tsx"
click node_shipments_ui "https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/envios/page.tsx"
click node_shipment_access_ui "https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/envios/accesos/page.tsx"
click node_stats_cards "https://github.com/thedarklee/logisystem-app/blob/main/app/api/cards/route.ts"
click node_stats_users "https://github.com/thedarklee/logisystem-app/blob/main/app/api/users/route.ts"
click node_stats_vehicles "https://github.com/thedarklee/logisystem-app/blob/main/app/api/vehicles/route.ts"
click node_stats_envios "https://github.com/thedarklee/logisystem-app/blob/main/app/api/envios/route.ts"
click node_access_api "https://github.com/thedarklee/logisystem-app/blob/main/app/api/access/manual/route.ts"
click node_latest_access_api "https://github.com/thedarklee/logisystem-app/blob/main/app/api/access/latest/route.ts"
click node_auth_api "https://github.com/thedarklee/logisystem-app/blob/main/app/api/auth/login/route.ts"
click node_setup_api "https://github.com/thedarklee/logisystem-app/blob/main/app/api/setup/route.ts"
click node_dashboard_stats_api "https://github.com/thedarklee/logisystem-app/blob/main/app/api/dashboard/stats/route.ts"
click node_dashboards_api "https://github.com/thedarklee/logisystem-app/blob/main/app/api/dashboards/operacional/route.ts"
click node_mongodb "https://github.com/thedarklee/logisystem-app/blob/main/lib/mongodb.ts"
click node_envio_model "https://github.com/thedarklee/logisystem-app/blob/main/models/Envio.ts"
click node_access_model "https://github.com/thedarklee/logisystem-app/blob/main/models/LecturaAcceso.ts"
click node_card_model "https://github.com/thedarklee/logisystem-app/blob/main/models/Tarjeta.ts"
click node_user_model "https://github.com/thedarklee/logisystem-app/blob/main/models/Usuario.ts"
click node_vehicle_model "https://github.com/thedarklee/logisystem-app/blob/main/models/Vehiculo.ts"
click node_rfid_listener "https://github.com/thedarklee/logisystem-app/blob/main/components/RFIDListener.tsx"
click node_envios_chart "https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/dashboards/envios/_DonutChart.tsx"
click node_operacional_chart "https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/dashboards/operacional/_BarrasChart.tsx"
click node_tendencia_chart "https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/dashboards/tendencia/_AreaChart.tsx"

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_root_page,node_login_page toneBlue
class node_dashboard_shell,node_dashboard_home,node_access_ui,node_new_access_ui,node_cards_ui,node_users_ui,node_new_user_ui,node_vehicles_ui,node_fleet_manage_ui,node_shipments_ui,node_shipment_access_ui,node_envios_chart,node_operacional_chart,node_tendencia_chart toneAmber
class node_stats_cards,node_stats_users,node_stats_vehicles,node_stats_envios,node_access_api,node_latest_access_api,node_auth_api,node_setup_api,node_dashboard_stats_api,node_dashboards_api toneMint
class node_mongodb,node_envio_model,node_access_model,node_card_model,node_user_model,node_vehicle_model toneRose
class node_rfid_listener toneNeutral
```

## Components

### Public UI

Landing and sign-in surface

- [Home](https://github.com/thedarklee/logisystem-app/blob/main/app/page.tsx): page · Public landing or redirect entry point · `app/page.tsx`
- [Login](https://github.com/thedarklee/logisystem-app/blob/main/app/login/page.tsx): auth page · Public sign-in screen · `app/login/page.tsx`

### Dashboard UI

Authenticated application workspace

- [Dashboard Shell](https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/layout.tsx): layout · Authenticated app layout and navigation frame · `app/dashboard/layout.tsx`
- [Overview](https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/page.tsx): dashboard page · Main authenticated landing page · `app/dashboard/page.tsx`
- [Access](https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/accesos/page.tsx): dashboard page · Access events workspace · `app/dashboard/accesos/page.tsx`
- [New Access](https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/accesos/nuevo/page.tsx): form page · Create or capture an access event · `app/dashboard/accesos/nuevo/page.tsx`
- [Cards](https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/tarjetas/page.tsx): dashboard page · Badge and card management screen · `app/dashboard/tarjetas/page.tsx`
- [Users](https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/usuarios/page.tsx): dashboard page · User management screen · `app/dashboard/usuarios/page.tsx`
- [New User](https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/usuarios/nuevo/page.tsx): form page · Create user flow · `app/dashboard/usuarios/nuevo/page.tsx`
- [Vehicles](https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/vehiculos/page.tsx): dashboard page · Vehicle management screen · `app/dashboard/vehiculos/page.tsx`
- [Fleet Admin](https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/vehiculos/gestion/page.tsx): dashboard page · Vehicle management subpage · `app/dashboard/vehiculos/gestion/page.tsx`
- [Shipments](https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/envios/page.tsx): dashboard page · Envíos management screen · `app/dashboard/envios/page.tsx`
- [Shipment Access](https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/envios/accesos/page.tsx): dashboard page · Shipment-related access view · `app/dashboard/envios/accesos/page.tsx`
- [Donut Chart](https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/dashboards/envios/_DonutChart.tsx): chart component · Shipment analytics visualization · `app/dashboard/dashboards/envios/_DonutChart.tsx`
- [Bars Chart](https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/dashboards/operacional/_BarrasChart.tsx): chart component · Operational analytics visualization · `app/dashboard/dashboards/operacional/_BarrasChart.tsx`
- [Area Chart](https://github.com/thedarklee/logisystem-app/blob/main/app/dashboard/dashboards/tendencia/_AreaChart.tsx): chart component · Trend analytics visualization · `app/dashboard/dashboards/tendencia/_AreaChart.tsx`

### API Routes

Next.js server-side route handlers

- [Cards API](https://github.com/thedarklee/logisystem-app/blob/main/app/api/cards/route.ts): route handlers · CRUD for card records · `app/api/cards/route.ts`
- [Users API](https://github.com/thedarklee/logisystem-app/blob/main/app/api/users/route.ts): route handlers · CRUD for user records · `app/api/users/route.ts`
- [Vehicles API](https://github.com/thedarklee/logisystem-app/blob/main/app/api/vehicles/route.ts): route handlers · CRUD for vehicle records · `app/api/vehicles/route.ts`
- [Shipments API](https://github.com/thedarklee/logisystem-app/blob/main/app/api/envios/route.ts): route handlers · CRUD for envío records · `app/api/envios/route.ts`
- [Access API](https://github.com/thedarklee/logisystem-app/blob/main/app/api/access/manual/route.ts): route handlers · Manual and RFID access event ingestion · `app/api/access/manual/route.ts`
- [Latest Access](https://github.com/thedarklee/logisystem-app/blob/main/app/api/access/latest/route.ts): route handler · Returns most recent access event · `app/api/access/latest/route.ts`
- [Login API](https://github.com/thedarklee/logisystem-app/blob/main/app/api/auth/login/route.ts): route handler · Authentication endpoint for sign-in · `app/api/auth/login/route.ts`
- [Setup API](https://github.com/thedarklee/logisystem-app/blob/main/app/api/setup/route.ts): route handler · Bootstrap or first-run initialization · `app/api/setup/route.ts`
- [Stats API](https://github.com/thedarklee/logisystem-app/blob/main/app/api/dashboard/stats/route.ts): route handler · Dashboard aggregation endpoint · `app/api/dashboard/stats/route.ts`
- [Analytics API](https://github.com/thedarklee/logisystem-app/blob/main/app/api/dashboards/operacional/route.ts): route handlers · Aggregated analytics for operational dashboards · `app/api/dashboards/operacional/route.ts`

### Data Layer

MongoDB connection and domain models

- [MongoDB](https://github.com/thedarklee/logisystem-app/blob/main/lib/mongodb.ts): connection · Central database connection · `lib/mongodb.ts`
- [Envio](https://github.com/thedarklee/logisystem-app/blob/main/models/Envio.ts): model · Shipment domain model · `models/Envio.ts`
- [Access Log](https://github.com/thedarklee/logisystem-app/blob/main/models/LecturaAcceso.ts): model · Access event domain model · `models/LecturaAcceso.ts`
- [Tarjeta](https://github.com/thedarklee/logisystem-app/blob/main/models/Tarjeta.ts): model · Card or badge domain model · `models/Tarjeta.ts`
- [Usuario](https://github.com/thedarklee/logisystem-app/blob/main/models/Usuario.ts): model · User domain model · `models/Usuario.ts`
- [Vehiculo](https://github.com/thedarklee/logisystem-app/blob/main/models/Vehiculo.ts): model · Vehicle domain model · `models/Vehiculo.ts`

### Other components

- [RFID Listener](https://github.com/thedarklee/logisystem-app/blob/main/components/RFIDListener.tsx): client component · Client-side RFID bridge for access flows · `components/RFIDListener.tsx`

## Connections

- Home → Login: entry · Public users are directed into sign-in
- Login → Login API: auth · Login form submits credentials to the server
- Login API → MongoDB: reads · Authentication reads stored user data
- Dashboard Shell → Overview: wraps · Authenticated layout frames dashboard pages
- Overview → Stats API: loads · Overview pulls summary metrics
- Access → Access API: records · Access UI sends manual or captured events
- New Access → Access API: creates · New access flow posts event data
- Access API → Access Log: stores · Access events persist through the access model
- Latest Access → Access Log: reads · Latest access endpoint queries recent events
- Cards → Cards API: crud · Cards screen uses card CRUD endpoints
- Users → Users API: crud · Users screen uses user CRUD endpoints
- New User → Users API: creates · New user form submits to users API
- Vehicles → Vehicles API: crud · Vehicles screen uses vehicle CRUD endpoints
- Fleet Admin → Vehicles API: manages · Fleet management works through vehicle API
- Shipments → Shipments API: crud · Shipments screen uses envío CRUD endpoints
- Shipment Access → Access API: views · Shipment access view depends on access events
- Overview → Analytics API: analytics · Dashboard landing can consume aggregated analytics
- Donut Chart → Analytics API: data · Shipment chart is driven by aggregated endpoint data
- Bars Chart → Analytics API: data · Operational chart is driven by aggregated endpoint data
- Area Chart → Analytics API: data · Trend chart is driven by aggregated endpoint data
- Cards → Tarjeta: backed by · Card management persists through the card model
- Users → Usuario: backed by · User management persists through the user model
- Vehicles → Vehiculo: backed by · Vehicle management persists through the vehicle model
- Shipments → Envio: backed by · Shipment management persists through the envío model
- Access API → MongoDB: uses · Access handlers use the central database connection
- Cards API → Tarjeta: uses · Card CRUD operates on the card model
- Users API → Usuario: uses · User CRUD operates on the user model
- Vehicles API → Vehiculo: uses · Vehicle CRUD operates on the vehicle model
- Shipments API → Envio: uses · Shipment CRUD operates on the envío model
- Setup API → MongoDB: initializes · Setup route likely bootstraps persisted state
- RFID Listener → Latest Access: polls · Client-side RFID bridge can watch latest access state
- RFID Listener → Access API: triggers · RFID events feed into access ingestion flows
