# projetopetx/frontend architecture

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

- Interactive diagram: https://gitdiagram.com/projetopetx/frontend
- Repository: https://github.com/projetopetx/frontend

## Overview

##### Project Type and Purpose
- The project serves as a full-stack application where the front-end (client-side pages) and back-end (API routes) are integrated. It also takes advantage of server-side capabilities (e.g., Next Auth API for authentication) and modern styling and coding practices (Tailwind, ESLint, Prettier).

##### Analyzing the File Structure
- Top-Level Files: The presence of .eslintrc.json, .prettierrc, tailwind.config.ts, next.config.ts, and package.json indicates standard configuration and build scripts.
- Public Directory: Stores static assets.
- src Directory: Contains all source code with two major subfolders:
- app: This is the heart of the project where all Next.js pages and layouts are defined. Different folders within “app” represent distinct routes or UI sections (for example, “animais”, “estoque”, “lista-animais”, “login”).
▪ Each route folder contains its own layout.tsx and page.tsx files, which implement the design and component structure for that route.
▪ A SessionWrapper.tsx indicates a component for session management that might provide authentication context to the app.
▪ The “api” folder inside “app” contains Next.js API routes (e.g., “api/auth/[...nextauth]/route.ts”) which support authentication, likely using NextAuth.
- components: Contains reusable UI components (Button, Header, TextField).
- Other Notable Files:
- middleware.ts likely implements request-level middleware for routing or authorization.
- tsconfig.json and eslint.config.mjs are part of project configuration for TypeScript and linting.

##### Architectural Patterns & Technologies
- Next.js Application Pattern: Emphasizes file-system based routing, server-side rendering, and API routes.
- Separation of Concerns:
- “app” folder for routing and rendering.
- “api” routes for backend functionality (authentication and possibly data related to animals, stock, etc.).
- “components” folder for reusable UI modules.
- Middleware for cross-cutting concerns.
- Use of Tailwind (via tailwind.config.ts), indicating component-level styling.
- NextAuth integration as seen in the [ ...nextauth ] folder, which is essential for authentication flow.
- Recurring pattern: Each route’s layout and page files suggest a modular MVC-like organization.

##### Final Points
- Every architectural component and their interconnections (user flow, API calls, layout hierarchy) are captured.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External User
    U["User / Browser"]:::external

    %% Middleware
    M["Middleware"]:::middleware

    %% Global Layout and Session Management
    G["Global Layout"]:::layout
    S["Session Management"]:::session

    %% UI Layer Subgraphs
    subgraph "UI Layer"
        %% Animais Route
        subgraph "Animais Route"
            AL["Animais Layout"]:::page
            AP["Animais Page"]:::page
        end
        %% Estoque Route
        subgraph "Estoque Route"
            EL["Estoque Layout"]:::page
            EP["Estoque Page"]:::page
        end
        %% Lista Animais Route
        subgraph "Lista Animais Route"
            LL["Lista Animais Layout"]:::page
            LP["Lista Animais Page"]:::page
        end
        %% Login Route
        subgraph "Login Route"
            LNL["Login Layout"]:::page
            LNP["Login Page"]:::page
        end
    end

    %% API Layer
    subgraph "API Layer"
        NA["NextAuth API"]:::api
    end

    %% Shared Libraries
    RC["Reusable UI Components"]:::components
    RA["Shared Assets"]:::assets

    %% Connections
    U -->|"sends request"| M
    M -->|"processes request"| G
    G -->|"wraps UI"| S

    %% Global Layout feeds into UI Layer pages
    S --> AL
    S --> EL
    S --> LL
    S --> LNL

    %% Each route layout connects to its own page
    AL --> AP
    EL --> EP
    LL --> LP
    LNL --> LNP

    %% UI Pages depend on Shared Components and Assets
    AP --> RC
    AP --> RA
    EP --> RC
    EP --> RA
    LP --> RC
    LP --> RA
    LNP --> RC
    LNP --> RA

    %% Login page interacts with API for authentication
    LNP -->|"authenticates"| NA

    %% Click Events
    click AL "https://github.com/projetopetx/frontend/blob/main/src/app/animais/layout.tsx"
    click AP "https://github.com/projetopetx/frontend/blob/main/src/app/animais/page.tsx"
    click EL "https://github.com/projetopetx/frontend/blob/main/src/app/estoque/layout.tsx"
    click EP "https://github.com/projetopetx/frontend/blob/main/src/app/estoque/page.tsx"
    click LL "https://github.com/projetopetx/frontend/blob/main/src/app/lista-animais/layout.tsx"
    click LP "https://github.com/projetopetx/frontend/blob/main/src/app/lista-animais/page.tsx"
    click LNL "https://github.com/projetopetx/frontend/blob/main/src/app/login/layout.tsx"
    click LNP "https://github.com/projetopetx/frontend/blob/main/src/app/login/page.tsx"
    click G "https://github.com/projetopetx/frontend/blob/main/src/app/layout.tsx"
    click S "https://github.com/projetopetx/frontend/blob/main/src/app/SessionWrapper.tsx"
    click NA "https://github.com/projetopetx/frontend/blob/main/src/app/api/auth/[...nextauth]/route.ts"
    click RC "https://github.com/projetopetx/frontend/tree/main/src/components"
    click RA "https://github.com/projetopetx/frontend/tree/main/src/assets"
    click M "https://github.com/projetopetx/frontend/blob/main/src/middleware.ts"

    %% Styles
    classDef external fill:#cfe2f3,stroke:#6fa8dc,stroke-width:2px;
    classDef middleware fill:#fce5cd,stroke:#f1c232,stroke-width:2px;
    classDef layout fill:#d9ead3,stroke:#6aa84f,stroke-width:2px;
    classDef session fill:#ead1dc,stroke:#b854a3,stroke-width:2px;
    classDef page fill:#c9daf8,stroke:#6d9eeb,stroke-width:2px;
    classDef api fill:#f4cccc,stroke:#e06666,stroke-width:2px;
    classDef components fill:#fff2cc,stroke:#f1c232,stroke-width:2px;
    classDef assets fill:#d0e0e3,stroke:#89a1a1,stroke-width:2px;
```
