# barbaraeguche/cartdash architecture

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

- Interactive diagram: https://gitdiagram.com/barbaraeguche/cartdash
- Repository: https://github.com/barbaraeguche/cartdash

## Overview

##### Project type and purpose
- This is a full‑stack grocery CRUD application (“cartdash”)
- Frontend: a single‑page React app built with Vite, Tailwind, Framer Motion
- Backend: a Flask REST API using PyMongo to interact with MongoDB Atlas
- Purpose: allow users to add, edit, delete, and view grocery items with smooth UI animations

##### File structure
- Top level: two main folders, “client” and “server,” plus config files (.gitignore, license, readme.md)
- client/
- src/: React components (header, footer, grocery‑card, etc.), hooks (groceryContext), UI primitives, API handlers, utilities (axiosConfig, constants)
- public/, index.html, Tailwind & ESLint configs, Vite, TypeScript configs
- server/
- app.py: Flask application exposing REST endpoints
- database.py: PyMongo connection logic to MongoDB Atlas
- requirements.txt, .env.example for environment variables
- Deployment scripts & environment: client deployed on Vercel, server on Render

##### Extract insights from the README
- Tech stack confirmation: React/Vite/Tailwind/Framer Motion + Flask/PyMongo + MongoDB Atlas
- Features: full CRUD, inline editing, toast notifications, responsive design
- Development & deployment flow: local Python venv for Flask, PNPM for React, separate .env files

a. Main components
- User’s Browser (UI in React)
- Frontend App (Vite dev server / Vercel host)
- API Layer in React (axios handlers making HTTP calls)
- Backend Server (Flask app on Render)
- Data Access Layer (database.py using PyMongo)
- Database (MongoDB Atlas)
- External Platforms (Vercel, Render)
b. Interactions and data flows
1. User action in Browser → React UI triggers axios request
2. Request travels from Vercel (or localhost:5173) → HTTP POST/GET/PUT/DELETE to Flask API endpoint
3. Flask (app.py) receives request → routes to handler → calls database.py
4. PyMongo driver executes CRUD operation on MongoDB Atlas
5. MongoDB returns JSON → Flask jsonify → HTTP response back to React
6. React updates state via groceryContext hook → UI re‑renders with new data
c. Architectural patterns & principles
- Frontend: Component‑based architecture, hooks for state management, separation between UI, API handlers, and utilities
- Backend: RESTful API, single responsibility (app.py for routing, database.py for data access)
- Clean separation of concerns, environment‑specific configs (.env for secrets)
d. Key technologies/frameworks
- Frontend: React, Vite, Tailwind CSS, Framer Motion, Axios, Context API
- Backend: Python, Flask, PyMongo
- Database: MongoDB Atlas
- Deployment: Vercel (frontend), Render (backend)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Browser["User's Browser"]:::external
        Main["main.tsx (Entry)"]:::frontend
        AppUI["app.tsx (App Component)"]:::frontend
        subgraph "UI Components"
            direction TB
            Header["header.tsx"]:::frontend
            Footer["footer.tsx"]:::frontend
            Card["grocery-card.tsx"]:::frontend
            List["grocery-list.tsx"]:::frontend
            EditForm["edit-grocery.tsx"]:::frontend
            InputBar["input-bar.tsx"]:::frontend
        end
        subgraph "State Management"
            direction TB
            Context["groceryContext.tsx"]:::frontend
        end
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        Handlers["handlers.ts (Axios Handlers)"]:::frontend
        Requests["requests.http"]:::frontend
        AxiosCfg["axiosConfig.ts"]:::frontend
    end

    %% Server Layer
    subgraph "Server Layer"
        direction TB
        FlaskApp["app.py (Flask API)"]:::backend
        DBAccess["database.py"]:::backend
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        Mongo["MongoDB Atlas"]:::data
    end

    %% External Services
    Vercel["Vercel (Frontend)"]:::external
    Render["Render (Backend)"]:::external

    %% Connections
    Browser -->|"loads"| Main
    Main -->|renders| AppUI
    AppUI -->|uses| Header
    AppUI -->|uses| Footer
    AppUI -->|uses| Card
    AppUI -->|uses| List
    AppUI -->|uses| EditForm
    AppUI -->|uses| InputBar
    AppUI -->|provides state| Context
    AppUI -->|calls| Handlers
    Handlers -->|uses| Requests
    Handlers -->|uses| AxiosCfg
    Handlers -->|HTTP GET/POST/PUT/DELETE| FlaskApp
    FlaskApp -->|calls| DBAccess
    DBAccess -->|CRUD operations| Mongo
    Mongo -->|returns data| DBAccess
    DBAccess -->|returns| FlaskApp
    FlaskApp -->|HTTP response| Handlers
    Handlers -->|updates| Context
    Context -->|updates UI| AppUI

    Browser -->|deployed on| Vercel
    FlaskApp -->|deployed on| Render

    %% Click Events
    click Main "https://github.com/barbaraeguche/cartdash/blob/main/client/src/main.tsx"
    click AppUI "https://github.com/barbaraeguche/cartdash/blob/main/client/src/app.tsx"
    click Header "https://github.com/barbaraeguche/cartdash/blob/main/client/src/components/header.tsx"
    click Footer "https://github.com/barbaraeguche/cartdash/blob/main/client/src/components/footer.tsx"
    click Card "https://github.com/barbaraeguche/cartdash/blob/main/client/src/components/grocery-card.tsx"
    click List "https://github.com/barbaraeguche/cartdash/blob/main/client/src/components/grocery-list.tsx"
    click EditForm "https://github.com/barbaraeguche/cartdash/blob/main/client/src/components/edit-grocery.tsx"
    click InputBar "https://github.com/barbaraeguche/cartdash/blob/main/client/src/components/input-bar.tsx"
    click Context "https://github.com/barbaraeguche/cartdash/blob/main/client/src/hooks/groceryContext.tsx"
    click Handlers "https://github.com/barbaraeguche/cartdash/blob/main/client/src/api/handlers.ts"
    click Requests "https://github.com/barbaraeguche/cartdash/blob/main/client/src/util/requests.http"
    click AxiosCfg "https://github.com/barbaraeguche/cartdash/blob/main/client/src/util/axiosConfig.ts"
    click FlaskApp "https://github.com/barbaraeguche/cartdash/blob/main/server/app.py"
    click DBAccess "https://github.com/barbaraeguche/cartdash/blob/main/server/database.py"

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#0D47A1,color:#0D47A1;
    classDef backend fill:#C8E6C9,stroke:#1B5E20,color:#1B5E20;
    classDef data fill:#FFE0B2,stroke:#E65100,color:#E65100;
    classDef external fill:#FFECB3,stroke:#F57F17,color:#F57F17;
```
