# jjunior96/next-template architecture

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

- Interactive diagram: https://gitdiagram.com/jjunior96/next-template
- Repository: https://github.com/jjunior96/next-template

## Overview

##### Component Relationships

- Client-side components interaction with API routes
- API routes interaction with services
- Error handling flow
- Data flow between components

##### Development Infrastructure

- Testing infrastructure (Jest, RTL, Cypress)
- Build tools (Next.js configuration)
- Style system (Styled Components)
- Form handling (React Hook Form + Yup)

Use the following visual elements:

- Blue: Frontend components
- Green: API/Backend services
- Yellow: Testing infrastructure
- Purple: External services
- Red: Error handling
- Gray: Utilities and helpers

Special Considerations:

##### SSR Architecture
- Next.js SSR flow
- Interaction between server and client components
- Styled-components SSR setup

##### Testing Flow
- How Jest, RTL, and Cypress interact with the application
- Test utilities and mocks

##### Development Tools
- ESLint, Prettier, and Husky workflow
- How lint-staged fits into the process

##### State Management
- Local state management
- Form state handling with React Hook Form

- Any abbreviations or technical terms
- Component groupings

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Next[Next.js Frontend]
        Pages[Pages]:::frontend
        Components[Components]:::frontend
        Templates[Templates]:::frontend
        Styles[Styles]:::frontend
        
        Next --> Pages
        Next --> Components
        Next --> Templates
        Next --> Styles
    end

    subgraph API
        APIRoutes["API Routes"]:::api
        APIMiddleware["API Middleware"]:::middleware
        CacheMiddleware["Cache Middleware"]:::middleware
        ErrorMiddleware["Error Handler"]:::middleware
        LoggerMiddleware["Logger"]:::middleware
        
        APIRoutes --> APIMiddleware
        APIMiddleware --> CacheMiddleware
        CacheMiddleware --> ErrorMiddleware
        ErrorMiddleware --> LoggerMiddleware
    end

    subgraph Services
        APIService["API Service"]:::service
        ExternalAPIs["External APIs"]:::external
        
        APIService --> ExternalAPIs
    end

    subgraph ErrorHandling
        BaseError["Base Error"]:::error
        BadRequest["Bad Request Error"]:::error
        Internal["Internal Error"]:::error
        NotFound["Not Found Error"]:::error
        
        BaseError --> BadRequest
        BaseError --> Internal
        BaseError --> NotFound
    end

    subgraph Utils
        Functions["Functions"]:::util
        Utils["Utils"]:::util
        Constants["Constants"]:::util
    end

    subgraph Testing
        Jest["Jest Setup"]:::test
        Cypress["Cypress Tests"]:::test
        TestUtils["Test Utils"]:::test
    end

    subgraph Build
        NextConfig["Next.js Config"]:::config
        TSConfig["TypeScript Config"]:::config
        EnvVars["Environment Variables"]:::config
    end

    subgraph DevTools
        ESLint["ESLint"]:::tool
        Prettier["Prettier"]:::tool
        Husky["Husky"]:::tool
    end

    Next --> APIRoutes
    APIRoutes --> APIService
    APIService --> ErrorHandling
    Utils --> Services
    
    %% Click events
    click Pages "https://github.com/jjunior96/next-template/tree/main//src/pages"
    click Components "https://github.com/jjunior96/next-template/tree/main//src/components"
    click Templates "https://github.com/jjunior96/next-template/tree/main//src/templates"
    click Styles "https://github.com/jjunior96/next-template/tree/main//src/styles"
    click APIRoutes "https://github.com/jjunior96/next-template/tree/main//src/pages/api"
    click APIMiddleware "https://github.com/jjunior96/next-template/blob/main//src/middlewares/api.middleware.ts"
    click CacheMiddleware "https://github.com/jjunior96/next-template/blob/main//src/middlewares/cache.middleware.ts"
    click ErrorMiddleware "https://github.com/jjunior96/next-template/blob/main//src/middlewares/errorHandler.middleware.ts"
    click LoggerMiddleware "https://github.com/jjunior96/next-template/blob/main//src/middlewares/logger.middleware.ts"
    click APIService "https://github.com/jjunior96/next-template/blob/main//src/services/api.ts"
    click BaseError "https://github.com/jjunior96/next-template/blob/main//src/errors/BaseError.ts"
    click BadRequest "https://github.com/jjunior96/next-template/blob/main//src/errors/BadRequestError.ts"
    click Internal "https://github.com/jjunior96/next-template/blob/main//src/errors/InternalError.ts"
    click NotFound "https://github.com/jjunior96/next-template/blob/main//src/errors/NotFoundError.ts"
    click Functions "https://github.com/jjunior96/next-template/tree/main//src/functions"
    click Utils "https://github.com/jjunior96/next-template/tree/main//src/utils"
    click Constants "https://github.com/jjunior96/next-template/tree/main//src/constants"
    click Jest "https://github.com/jjunior96/next-template/blob/main//.jest/setup.ts"
    click Cypress "https://github.com/jjunior96/next-template/tree/main//cypress/e2e"
    click TestUtils "https://github.com/jjunior96/next-template/tree/main//src/utils/tests"
    click NextConfig "https://github.com/jjunior96/next-template/blob/main//next.config.js"
    click TSConfig "https://github.com/jjunior96/next-template/blob/main//tsconfig.json"
    click EnvVars "https://github.com/jjunior96/next-template/blob/main//src/@types/environment.d.ts"
    click ESLint "https://github.com/jjunior96/next-template/blob/main//.eslintrc.json"
    click Prettier "https://github.com/jjunior96/next-template/blob/main//.prettierrc"
    click Husky "https://github.com/jjunior96/next-template/tree/main//.husky/pre-commit"

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef middleware fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef service fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#e74c3c,stroke:#c0392b,color:white
    classDef error fill:#e74c3c,stroke:#c0392b,color:white
    classDef util fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef test fill:#f1c40f,stroke:#f39c12,color:black
    classDef config fill:#1abc9c,stroke:#16a085,color:white
    classDef tool fill:#34495e,stroke:#2c3e50,color:white
```
