# ajliy97/ferrelect architecture

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

- Interactive diagram: https://gitdiagram.com/ajliy97/ferrelect
- Repository: https://github.com/ajliy97/ferrelect

## Overview

##### Project type and purpose
- This is a full-stack Next.js application (React on the front end + serverless backend API routes) that uses Tailwind CSS for styling and MongoDB for data persistence.
- It was scaffolded with create-next-app and is intended to render pages at the "/" route and serve a simple cards API at "/api/cards."

##### File structure
- Top-level directories:
- app/ – Next.js App Router pages and layout
- components/ – React UI components (Card, Navbar, Contact form, etc.)
- pages/api/ – Next.js API route(s), specifically cards.ts to CRUD cards
- lib/ – database utility (mongo.ts for MongoDB connection)
- public/ – static assets (including public/db folder)
- Configuration files:
- next.config.ts – Next.js config
- tsconfig.json – TypeScript config
- tailwind.config.js & postcss.config.mjs – Tailwind CSS setup
- eslint.config.mjs – linting rules

##### README
- Confirms it’s a Next.js project, describes how to run locally and deploy on Vercel.

##### Main components and relationships
a. Frontend layer (Next.js App Router)
- app/layout.tsx: global layout + globals.css
- app/page.tsx: home page
- components/: reusable UI (Card, Navbar, MobileNavbar, Contact)
- Styling: Tailwind via tailwind.config.js, global CSS in app/globals.css
b. API layer (Next.js Serverless Functions)
- pages/api/cards.ts: handles HTTP requests (GET/POST) for card data
c. Data layer (MongoDB)
- lib/mongo.ts: MongoClient wrapper, connects to a MongoDB instance
- public/db: (if used for a local JSON store or seed)
d. Deployment/Hosting
- Vercel (implied from README) runs both the frontend and serverless functions
e. External services
- next/font (Geist) for font optimization
- MongoDB Atlas (or self-hosted) for data persistence

##### Architectural patterns and design principles
- Separation of concerns: UI components vs. page-level routing vs. API routes vs. database logic
- Serverless pattern: Next.js API routes deployed as serverless functions
- App Router (file-based routing)
- CSS utility-first (Tailwind)
- Connection pooling and reuse in lib/mongo.ts

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User
    Browser["Browser (User)"]:::external

    %% Hosting
    subgraph "Vercel (Hosting)"
        direction TB
        subgraph "Frontend Layer"
            direction TB
            NextApp["Next.js App Router<br/>(app/)"]:::frontend
            HomePage["Home Page<br/>(app/page.tsx)"]:::frontend
            Layout["Global Layout & Styles<br/>(app/layout.tsx + globals.css)"]:::frontend
            Components["UI Components<br/>• Card<br/>• Navbar<br/>• MobileNavbar<br/>• Contact"]:::frontend
            Tailwind["Tailwind CSS<br/>(tailwind.config.js + postcss.config.mjs)"]:::frontend
            NextApp -->|imports| HomePage
            NextApp -->|imports| Layout
            NextApp -->|imports| Components
            NextApp -->|uses| Tailwind
        end

        subgraph "API Layer"
            direction TB
            ApiRoute["Cards API Route<br/>(pages/api/cards.ts)"]:::backend
            MongoConnector["MongoDB Connector<br/>(lib/mongo.ts)"]:::backend
            ApiRoute -->|uses| MongoConnector
        end
    end

    %% External Services
    subgraph "External Services"
        direction TB
        FontService["next/font Service"]:::external
        MongoDB["MongoDB Atlas"]:::database
        PublicAssets["Static Assets & Seed<br/>(public/)"]:::external
    end

    %% Flows
    Browser -->|HTTP GET /| NextApp
    Browser -->|HTTP GET/POST /api/cards| ApiRoute
    NextApp -->|fetch fonts| FontService
    ApiRoute -->|queries| MongoDB
    PublicAssets -->|serves| NextApp

    %% Click Events
    click NextApp "https://github.com/ajliy97/ferrelect/tree/main/app/"
    click HomePage "https://github.com/ajliy97/ferrelect/blob/main/app/page.tsx"
    click Layout "https://github.com/ajliy97/ferrelect/blob/main/app/layout.tsx"
    click Layout "https://github.com/ajliy97/ferrelect/blob/main/app/globals.css"
    click Components "https://github.com/ajliy97/ferrelect/blob/main/components/card.tsx"
    click Components "https://github.com/ajliy97/ferrelect/blob/main/components/navbar.tsx"
    click Components "https://github.com/ajliy97/ferrelect/blob/main/components/mobile-navbar.tsx"
    click Components "https://github.com/ajliy97/ferrelect/blob/main/components/contact.tsx"
    click Tailwind "https://github.com/ajliy97/ferrelect/blob/main/tailwind.config.js"
    click Tailwind "https://github.com/ajliy97/ferrelect/blob/main/postcss.config.mjs"
    click ApiRoute "https://github.com/ajliy97/ferrelect/blob/main/pages/api/cards.ts"
    click MongoConnector "https://github.com/ajliy97/ferrelect/blob/main/lib/mongo.ts"
    click PublicAssets "https://github.com/ajliy97/ferrelect/tree/main/public/"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#007ACC,stroke-width:2px
    classDef backend fill:#DFF8E8,stroke:#28A745,stroke-width:2px
    classDef database fill:#FFF4D0,stroke:#DB9E00,stroke-width:2px
    classDef external fill:#F0F0F0,stroke:#888888,stroke-dasharray: 5 5,stroke-width:2px
```
