# earthquake-algarve/entertours architecture

> Architecture diagram of the GitHub repository earthquake-algarve/entertours, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/earthquake-algarve/entertours
- Repository: https://github.com/earthquake-algarve/entertours

## Overview

##### Project type and purpose
- This is a full-stack web application built with Next.js (app directory), React components, Tailwind CSS for styling, NextAuth for authentication, and Prisma as the ORM layer. It serves dynamic pages (SSR/SSG), provides its own REST-style API routes, and persists data in a relational database.

##### File structure
- Top-level:
- next.config.mjs, package.json, tsconfig.json, tailwind.config.ts – Next.js, build, and style configuration
- prisma/ – database schema and migration history
- src/app/ – Next.js “app” routes (pages, layouts, server-side code, API endpoints)
- src/components/ – reusable UI components (buttons, cards, dialogs, sections)
- src/db/ – database client instantiation (PrismaClient) and data-access functions
- src/lib/ – utility functions
- src/middleware.ts – middleware for routing/auth checks
- src/types/ – TypeScript definitions

##### Main components and their relationships
a. Client (Browser)
- Renders pages, runs React code, triggers data fetches to API or server-side rendering endpoints.
b. CDN/Edge Layer (optional on Vercel)
- Caches static assets (public/) and pre-rendered pages for performance.
c. Next.js Server
- Routing: app directory handles page rendering (SSR, SSG, streaming)
- API layer: src/app/api/* routes exposed over HTTP
- Middleware: src/middleware.ts for request interception (auth checks, redirects)
d. Authentication Service (NextAuth)
- Receives sign-in/sign-out requests under /api/auth
- Integrates with Prisma for session and user persistence
e. Data-access Layer (Prisma ORM)
- Encapsulated in src/db/db.ts and dbActions.ts
- Maps to the relational database (e.g., PostgreSQL, MySQL) defined in prisma/schema.prisma
f. Database
- Stores users, companies, tours, categories, etc.
- Migration history in prisma/migrations
g. External Services (if any)
- OAuth providers for NextAuth, third-party APIs for geolocation or payments (none explicitly in code)

Interactions:
- Client → Next.js (HTTP GET/POST) for pages and API calls
- Next.js → NextAuth → Prisma → Database for auth and data
- Next.js → Prisma → Database for business-logic API routes
- Next.js → CDN for static/public assets

##### Architectural patterns and design principles
- Layered architecture: UI layer (React components) → API layer (Next.js routes) → Data layer (Prisma + DB)
- Component-based UI: small, reusable React components in src/components and src/components/ui
- Convention over configuration: Next.js file-based routing in src/app
- Security: middleware for route protection, NextAuth sessions
- Migrations and schema as single source of truth (prisma/schema.prisma)

- Arrowheads indicating data flow direction
- Callouts for critical config files (next.config.mjs, prisma/schema.prisma) and middleware

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client and CDN
    Client["Browser UI"]:::frontend
    Static["CDN / public"]:::external
    Client -->|"requests static assets"| Static
    Client -->|"HTTP GET/POST"| NextServer

    %% Next.js Server Layer
    subgraph "Next.js Server"
        direction TB
        Middleware["Middleware"]:::backend
        PageRenderer["Next.js Page Renderer"]:::backend
        APIRoutes["API Routes"]:::backend
        AuthService["NextAuth Service"]:::backend
        Utils["Utility Functions"]:::backend
        Types["TypeScript Definitions"]:::backend

        Client -->|intercept| Middleware
        Middleware -->|routes to pages| PageRenderer
        Middleware -->|routes to API| APIRoutes

        PageRenderer -->|uses utils/types| Utils
        PageRenderer -->|uses utils/types| Types

        APIRoutes -->|uses utils/types| Utils
        APIRoutes -->|uses utils/types| Types
        APIRoutes -->|auth endpoints| AuthService

    end

    %% Data Access Layer
    subgraph "Prisma ORM" 
        direction TB
        DBClient["PrismaClient"]:::data
        DBActions["DB Actions"]:::data
    end

    AuthService -->|session/user persistence| DBClient
    APIRoutes -->|business logic| DBActions
    DBClient -->|executes queries| Database
    DBActions -->|executes queries| Database

    %% Database Layer
    subgraph "Database"
        direction TB
        DBSchema["prisma/schema.prisma"]:::data
        DBMigrations["prisma/migrations/"]:::data
        Database["Relational Database"]:::data
    end

    %% Configuration Files
    NextConfig["next.config.mjs"]:::external
    TailwindConfig["tailwind.config.ts"]:::external

    NextConfig -.-> NextServer
    TailwindConfig -.-> NextServer

    %% Utility and Types
    Utils -.-> NextServer
    Types -.-> NextServer

    %% Click Events
    click Client "https://github.com/earthquake-algarve/entertours/tree/main/src/components/"
    click Static "https://github.com/earthquake-algarve/entertours/tree/main/public/"
    click PageRenderer "https://github.com/earthquake-algarve/entertours/tree/main/src/app/"
    click APIRoutes "https://github.com/earthquake-algarve/entertours/tree/main/src/app/api/"
    click AuthService "https://github.com/earthquake-algarve/entertours/blob/main/src/app/api/auth/[...nextauth]/route.ts"
    click AuthService "https://github.com/earthquake-algarve/entertours/blob/main/src/app/api/auth/[...nextauth]/authOptions.ts"
    click Middleware "https://github.com/earthquake-algarve/entertours/blob/main/src/middleware.ts"
    click DBClient "https://github.com/earthquake-algarve/entertours/blob/main/src/db/db.ts"
    click DBActions "https://github.com/earthquake-algarve/entertours/blob/main/src/db/dbActions.ts"
    click DBSchema "https://github.com/earthquake-algarve/entertours/blob/main/prisma/schema.prisma"
    click DBMigrations "https://github.com/earthquake-algarve/entertours/tree/main/prisma/migrations/"
    click Utils "https://github.com/earthquake-algarve/entertours/tree/main/src/lib/"
    click Types "https://github.com/earthquake-algarve/entertours/tree/main/src/types/"
    click TailwindConfig "https://github.com/earthquake-algarve/entertours/blob/main/tailwind.config.ts"
    click NextConfig "https://github.com/earthquake-algarve/entertours/blob/main/next.config.mjs"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#005B96,color:#003F6B
    classDef backend fill:#DFFFD0,stroke:#6A994E,color:#386641
    classDef data fill:#FFE8D0,stroke:#D9822B,color:#974B0D
    classDef external fill:#E0E0E0,stroke:#757575,color:#333333
```
