# adodeveloper/sistema-demoras architecture

> Architecture diagram of the GitHub repository adodeveloper/sistema-demoras, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adodeveloper/sistema-demoras
- Repository: https://github.com/adodeveloper/sistema-demoras

## Overview

##### Project type and purpose
- This is a monolithic full-stack web application built with Next.js (App Router).
- It exposes React-based UI pages under src/app, a set of RESTful API endpoints under src/app/api, and uses Prisma as an ORM to persist data.
- Authentication is handled via NextAuth in src/app/api/auth and a custom lib/auth.js wrapper.

##### File structure
- Top-level modules:
- lib/ – helper modules (lib/prisma.js for the Prisma client; lib/auth.js for auth wrappers)
- prisma/ – database schema (schema.prisma), migrations, and seeds
- public/ – static assets
- src/app/ – Next.js App Router’s pages, layouts, and API routes
- src/components/ – shared React components (Header, Loader, PDF generators)
- src/context/ – React Context (SessionProvider)
- middleware.js – route middleware (auth checks, redirects)
- API routes are organized by resource (barcos, bitacoras, demoras, equipos, recepcion, roles, tickets, transportes, users, chat, etc.).
- Next.config.mjs, tsconfig.json, jsconfig.json, Tailwind and PostCSS configs handle build and styling.

##### Key insights from the README
- Created with create-next-app and uses next/font for font optimization.
- Standard Next.js development and deployment flows; intended for Vercel but portable to any Node host.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Browser(("Browser")):::service

    %% Next.js Server
    subgraph "Next.js Server"
        %% Presentation Layer
        subgraph "Presentation Layer"
            Pages["React UI Pages<br/>(src/app)"]:::presentation
            Components["Shared Components<br/>(src/components)"]:::presentation
            SessionCtx["SessionProvider<br/>(src/context/SessionProvider.js)"]:::presentation
        end

        %% API Layer
        subgraph "API Layer"
            API["RESTful API Endpoints<br/>(src/app/api)"]:::api
            NextAuth["NextAuth Routes<br/>(route.js)"]:::service
            AuthWrapper["Auth Wrapper<br/>(lib/auth.js)"]:::service
            Middleware["Route Middleware<br/>(middleware.js)"]:::service
        end
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        Prisma["Prisma Client<br/>(lib/prisma.js)"]:::data
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        DB[(Database<br/>PostgreSQL)]:::data
        Schema["Schema & Migrations<br/>(prisma/schema.prisma,<br/>migrations/20250210204927_init)"]:::data
        Seed["Seed Script<br/>(prisma/seed.js)"]:::data
    end

    %% Static Assets and Config
    Assets["Static Assets<br/>(public/)"]:::service
    Config["Next.js Config<br/>(next.config.mjs)"]:::config
    Tailwind["Tailwind & PostCSS<br/>(tailwind.config.mjs,<br/>postcss.config.mjs)"]:::config
    TSConfig["Path Config<br/>(tsconfig.json,<br/>jsconfig.json)"]:::config

    %% Relationships
    Browser -->|"GET/POST UI"| Pages
    Browser -->|"fetch()/XHR"| API
    Browser -->|"GET static"| Assets
    Pages -->|"useContext"| SessionCtx
    Pages -->|"import components"| Components
    API -->|"invoke"| AuthWrapper
    API -->|"validateSession()"| NextAuth
    API -->|"middleware checks"| Middleware
    API -->|"prisma.query()/mutate()"| Prisma
    AuthWrapper -->|"wraps"| NextAuth
    Prisma -->|"connect"| DB
    Schema -->|"migrate"| DB
    Seed -->|"seed data"| DB

    %% Click Events
    click Pages "https://github.com/adodeveloper/sistema-demoras/tree/main/src/app"
    click Components "https://github.com/adodeveloper/sistema-demoras/tree/main/src/components"
    click API "https://github.com/adodeveloper/sistema-demoras/tree/main/src/app/api"
    click NextAuth "https://github.com/adodeveloper/sistema-demoras/blob/main/src/app/api/auth/[...nextauth]/route.js"
    click AuthWrapper "https://github.com/adodeveloper/sistema-demoras/blob/main/lib/auth.js"
    click Prisma "https://github.com/adodeveloper/sistema-demoras/blob/main/lib/prisma.js"
    click Schema "https://github.com/adodeveloper/sistema-demoras/blob/main/prisma/schema.prisma"
    click Schema "https://github.com/adodeveloper/sistema-demoras/tree/main/prisma/migrations/20250210204927_init"
    click Seed "https://github.com/adodeveloper/sistema-demoras/blob/main/prisma/seed.js"
    click Middleware "https://github.com/adodeveloper/sistema-demoras/blob/main/middleware.js"
    click SessionCtx "https://github.com/adodeveloper/sistema-demoras/blob/main/src/context/SessionProvider.js"
    click Assets "https://github.com/adodeveloper/sistema-demoras/tree/main/public/"
    click Config "https://github.com/adodeveloper/sistema-demoras/blob/main/next.config.mjs"
    click Tailwind "https://github.com/adodeveloper/sistema-demoras/blob/main/tailwind.config.mjs"
    click Tailwind "https://github.com/adodeveloper/sistema-demoras/blob/main/postcss.config.mjs"
    click TSConfig "https://github.com/adodeveloper/sistema-demoras/blob/main/tsconfig.json"
    click TSConfig "https://github.com/adodeveloper/sistema-demoras/blob/main/jsconfig.json"

    %% Styles
    classDef presentation fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef api fill:#E6F4EA,stroke:#1B7A44,color:#1B7A44;
    classDef data fill:#FFE8D6,stroke:#D97706,color:#B45309;
    classDef service fill:#F0F0F0,stroke:#6B7280,color:#374151;
    classDef config fill:#F9FAFB,stroke:#9CA3AF,color:#4B5563;
```
