How earthquake-algarve/entertours works
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