# mateav23/fullstack-app-pern architecture

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

- Interactive diagram: https://gitdiagram.com/mateav23/fullstack-app-pern
- Repository: https://github.com/mateav23/fullstack-app-pern

## Overview

##### Project type and purpose
- From the file tree and README, this is a full-stack product administration system.
- Frontend is a React/TypeScript SPA built with Vite, Tailwind CSS, React Router, Axios, Valibot.
- Backend is a Node.js/TypeScript REST API using Express.js, Sequelize (PostgreSQL), Swagger, Jest for testing.

##### File structure
- Top level separates “client/” (frontend) and “server/” (backend).
- Frontend:
- src/components, layouts, views → React UI components and pages (NewProduct, EditProduct, Products).
- src/services/ProductService.ts → HTTP client layer (Axios).
- src/router.tsx → client-side routing (React Router).
- Tailwind config, Vite config → build tool and styling pipeline.
- Backend:
- src/server.ts & src/index.ts → application entrypoints.
- src/router.ts → Express routes mounting handlers.
- src/handlers/product.ts → controller layer (CRUD).
- src/models/Product.model.ts → Sequelize ORM models.
- src/config/db.ts → DB connection setup (PostgreSQL).
- src/config/swagger.ts → Swagger documentation setup.
- src/middleware → validation, error handling.
- src/data/index.ts → seed or migration logic.
- __test__ folders → Jest tests for unit/integration.

##### README for additional insights
- Full CRUD on products, data-validation on both ends, responsive UI, API doc at /docs, automated tests.
- Emphasizes TypeScript safety, layered architecture (frontend <→ backend <→ DB).

a. Main components
1) Browser / Client SPA (React + Valibot + Axios)
2) HTTP/API Layer (Express.js server)
3) Controller/Handler Layer (product handlers, middleware)
4) Data Layer / ORM (Sequelize + models)
5) Database (PostgreSQL)
6) API Documentation (Swagger UI)
7) Testing (Jest) – optional as a side component
b. Relationships & data flows
- Browser sends HTTP requests (GET/POST/PUT/DELETE) via Axios → Express router.
- Router dispatches to handlers → middleware for validation → calls service/data layer.
- Sequelize maps handlers’ queries to SQL → PostgreSQL stores/retrieves data.
- Swagger UI served from Express for /docs.
- Jest tests simulate requests against Express in test environment.
c. Architectural patterns & principles
- Layered (Presentation, API, Business/Controller, Data Access, Persistence).
- Single Page Application with RESTful backend.
- MVC-style separation in backend (router→handler→model).
- Type-safe contracts (TypeScript) and validation at boundary.
d. Key technologies/frameworks
- Frontend: React, TypeScript, Vite, Tailwind CSS, React Router, Axios, Valibot.
- Backend: Node.js, Express, TypeScript, Sequelize, PostgreSQL, Swagger, Jest.

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Frontend Zone
  subgraph "Frontend (Client)"
    direction TB
    Browser["Browser / SPA"]:::frontend
    Main["main.tsx"]:::frontend
    Router["Router (React Router)"]:::frontend
    Views["Views / Pages"]:::frontend
    Layouts["Layouts"]:::frontend
    Components["UI Components"]:::frontend
    Service["ProductService (Axios)"]:::frontend
    Types["Type Definitions"]:::frontend
    Utils["Validation Helpers (Valibot)"]:::frontend
    Configs["Vite & Tailwind Configs"]:::frontend
  end

  %% Backend Zone
  subgraph "Backend (Server)"
    direction TB
    Express["Express Server"]:::backend
    APIRouter["API Router"]:::backend
    Middleware["Middleware (Validation & Error Handling)"]:::backend
    Handlers["Product Handlers"]:::backend
    Models["ProductModel (Sequelize)"]:::persistence
    DBConfig["DB Connection Config"]:::persistence
    Database["PostgreSQL"]:::persistence
    Swagger["Swagger UI (/docs)"]:::docs
    Seed["Data Seeding / Initialization"]:::backend
  end

  %% Testing Zone
  subgraph "Testing"
    direction TB
    JestServer["Jest Server Tests"]:::tests
    JestHandlers["Jest Handler Tests"]:::tests
  end

  %% Frontend Flow
  Browser --> Main
  Main --> Router
  Router --> Views
  Views --> Layouts
  Views --> Components
  Views --> Service
  Service --> Types
  Service --> Utils
  Main --> Configs

  %% Client to Server
  Service -->|"HTTP Requests"| Express

  %% Backend Flow
  Express --> APIRouter
  APIRouter --> Middleware
  Middleware --> Handlers
  Handlers --> Models
  Models --> Database
  DBConfig --> Models
  Seed --> Database
  Express --> Swagger

  %% Testing Flow
  JestServer --> Express
  JestHandlers --> Handlers

  %% Click Events - Frontend
  click Main "https://github.com/mateav23/fullstack-app-pern/blob/main/client/src/main.tsx"
  click Components "https://github.com/mateav23/fullstack-app-pern/tree/main/client/src/components/"
  click Layouts "https://github.com/mateav23/fullstack-app-pern/blob/main/client/src/layouts/Layout.tsx"
  click Views "https://github.com/mateav23/fullstack-app-pern/tree/main/client/src/views/"
  click Router "https://github.com/mateav23/fullstack-app-pern/blob/main/client/src/router.tsx"
  click Service "https://github.com/mateav23/fullstack-app-pern/blob/main/client/src/services/ProductService.ts"
  click Types "https://github.com/mateav23/fullstack-app-pern/blob/main/client/src/types/index.ts"
  click Utils "https://github.com/mateav23/fullstack-app-pern/blob/main/client/src/utils/index.ts"
  click Configs "https://github.com/mateav23/fullstack-app-pern/blob/main/client/vite.config.ts"
  click Configs "https://github.com/mateav23/fullstack-app-pern/blob/main/client/tailwind.config.js"

  %% Click Events - Backend
  click Express "https://github.com/mateav23/fullstack-app-pern/blob/main/server/src/server.ts"
  click Express "https://github.com/mateav23/fullstack-app-pern/blob/main/server/src/index.ts"
  click APIRouter "https://github.com/mateav23/fullstack-app-pern/blob/main/server/src/router.ts"
  click Handlers "https://github.com/mateav23/fullstack-app-pern/blob/main/server/src/handlers/product.ts"
  click Middleware "https://github.com/mateav23/fullstack-app-pern/blob/main/server/src/middleware/index.ts"
  click Models "https://github.com/mateav23/fullstack-app-pern/blob/main/server/src/models/Product.model.ts"
  click DBConfig "https://github.com/mateav23/fullstack-app-pern/blob/main/server/src/config/db.ts"
  click Swagger "https://github.com/mateav23/fullstack-app-pern/blob/main/server/src/config/swagger.ts"
  click Seed "https://github.com/mateav23/fullstack-app-pern/blob/main/server/src/data/index.ts"

  %% Click Events - Testing
  click JestServer "https://github.com/mateav23/fullstack-app-pern/blob/main/server/src/__test__/server.test.ts"
  click JestHandlers "https://github.com/mateav23/fullstack-app-pern/blob/main/server/src/handlers/__test__/product.test.ts"

  %% Styles
  classDef frontend fill:#E0F7FA,stroke:#00838F,color:#006064
  classDef backend fill:#E8F5E9,stroke:#2E7D32,color:#1B5E20
  classDef persistence fill:#FFF3E0,stroke:#EF6C00,color:#E65100
  classDef docs fill:#ECEFF1,stroke:#607D8B,color:#37474F
  classDef tests fill:#F5F5F5,stroke:#9E9E9E,color:#616161
```
