# vwzn/contact-management architecture

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

- Interactive diagram: https://gitdiagram.com/vwzn/contact-management
- Repository: https://github.com/vwzn/contact-management

## Overview

##### Project Type & Purpose
- This is a full-stack contact management web application.
- Frontend: React + Vite + Tailwind CSS.
- Backend: Node.js + Express + Prisma ORM + MySQL.
- Purpose: CRUD operations on contacts and addresses, user authentication, search/filter, bulk operations.

##### File Structure
- Top-level: `/frontend` and `/backend`.
- Frontend:
- `src/components/…` holds UI components (forms, cards, lists).
- `src/lib/api/*Api.js` encapsulates REST calls to backend.
- `main.jsx` is the React entry point; `vite.config.js` and `tailwind.config.js` are build/styling setups.
- Backend (implied by README):
- `src/main.js` — Express server setup.
- `src/route/…` — route definitions.
- `src/controller/…` — route handlers.
- `src/service/…` — business logic.
- `src/validation/…` and `src/middleware/…` — input validation and cross-cutting concerns.
- `prisma/schema.prisma` + migrations — DB schema.

##### README for Additional Insights
- MERN stack, RESTful API at `/api`, running on port 3000.
- MySQL database via Prisma.
- React client runs on Vite dev server (port 5173).
- Features: user auth (login/register), contacts + addresses CRUD, smart search, theming.

a. Main Components:
1. Browser (User’s UI)
2. React Single-Page App (Vite Dev Server / Static Host)
3. REST API Layer (Express.js)
4. Business Logic Layer (Services, Validation, Middleware)
5. Data Access Layer (Prisma ORM)
6. MySQL Database
7. Optional External Services (e.g., email service or analytics)
b. Relationships & Data Flows:
- Browser ↔ React SPA (HTTP)
- React SPA ↔ Express API (HTTP calls via `AddressApi`, `ContactApi`, `UserApi`)
- Express API invokes middleware → controllers → services → Prisma → MySQL
- Prisma ↔ MySQL (SQL connection over network)
- Environment (ENV variables) feeding into server startup
c. Architectural Patterns & Principles:
- Layered architecture (Presentation → API → Service → Data Access → Database)
- Separation of concerns (UI vs. API vs. DB)
- RESTful design (resource-based endpoints)
- Client-side routing (React Router)
- ORM abstraction (Prisma)
d. Key Technologies & Frameworks:
- Frontend: React, React Router, Vite, Tailwind CSS
- Backend: Node.js, Express.js, Prisma
- Database: MySQL

##### Essential Elements
Browser → React → API → Controllers → Services → Prisma → MySQL, and backflow for responses.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "User Client" 
        direction TB
        Browser["Browser"]:::external
        ReactApp["React SPA\n(port 5173)"]:::frontend
        Browser -->|"HTTP"| ReactApp
        ReactApp -->|"Client-side Routing"| ReactRouter
        ReactApp -->|"UI Components"| ReactComponents
        ReactApp -->|"API Calls"| AddressApi
        ReactApp -->|"API Calls"| ContactApi
        ReactApp -->|"API Calls"| UserApi
    end

    ReactRouter["React Router"]:::frontend
    ReactComponents["UI Components"]:::frontend
    AddressApi["AddressApi"]:::api
    ContactApi["ContactApi"]:::api
    UserApi["UserApi"]:::api

    %% Backend Layer
    subgraph "Backend API Server\nExpress.js (port 3000)" 
        direction TB
        Env[".env\n(DATABASE_URL)"]:::config
        Env -->|loads| ExpressServer
        ExpressServer["Express Server"]:::backend

        subgraph "API Layer" 
            direction TB
            Routes["Route Definitions"]:::backend
            Controllers["Controllers"]:::backend
            Middleware["Middleware\n(Auth, Error Handling)"]:::backend
            Validation["Validation"]:::backend
        end

        subgraph "Business Logic\n& Services"
            direction TB
            Services["Services"]:::backend
        end

        ExpressServer --> Routes
        Routes --> Middleware
        Middleware --> Validation
        Validation --> Controllers
        Controllers --> Services
        Services --> Prisma
    end

    %% Data Access Layer
    subgraph "Data Access Layer" 
        direction TB
        Prisma["Prisma ORM"]:::datalayer
        Schema["schema.prisma"]:::datalayer
        Migrations["migrations"]:::datalayer
        Prisma -->|SQL Queries| MySQL
        Schema --> Prisma
        Migrations --> Prisma
    end

    %% Database
    MySQL["MySQL Database"]:::database

    %% External Services
    subgraph "External Services"
        direction TB
        EmailService["Email Service"]:::external
        Analytics["Analytics"]:::external
    end

    %% Connections
    ContactApi -->|HTTP| ExpressServer
    AddressApi -->|HTTP| ExpressServer
    UserApi -->|HTTP| ExpressServer
    ExpressServer -->|ORM Calls| Prisma
    Prisma -->|Connect| MySQL

    %% Click Events
    click ReactApp "https://github.com/vwzn/contact-management/tree/master/frontend/src"
    click main "https://github.com/vwzn/contact-management/blob/master/frontend/src/main.jsx"
    click ReactComponents "https://github.com/vwzn/contact-management/tree/master/frontend/src/components"
    click ReactRouter "https://github.com/vwzn/contact-management/blob/master/frontend/src/components/Layout.jsx"
    click AddressApi "https://github.com/vwzn/contact-management/blob/master/frontend/src/lib/api/AddressApi.js"
    click ContactApi "https://github.com/vwzn/contact-management/blob/master/frontend/src/lib/api/ContactApi.js"
    click UserApi "https://github.com/vwzn/contact-management/blob/master/frontend/src/lib/api/UserApi.js"
    click Tailwind "https://github.com/vwzn/contact-management/blob/master/frontend/tailwind.config.js"
    click Vite "https://github.com/vwzn/contact-management/blob/master/frontend/vite.config.js"
    click ExpressServer "https://github.com/vwzn/contact-management/blob/master/backend/src/main.js"
    click Routes "https://github.com/vwzn/contact-management/tree/master/backend/src/route"
    click Controllers "https://github.com/vwzn/contact-management/tree/master/backend/src/controller"
    click Services "https://github.com/vwzn/contact-management/tree/master/backend/src/service"
    click Validation "https://github.com/vwzn/contact-management/tree/master/backend/src/validation"
    click Middleware "https://github.com/vwzn/contact-management/tree/master/backend/src/middleware"
    click Schema "https://github.com/vwzn/contact-management/blob/master/backend/prisma/schema.prisma"
    click Migrations "https://github.com/vwzn/contact-management/tree/master/backend/prisma/migrations"
    click Env "https://github.com/vwzn/contact-management/blob/master/backend/.env"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,stroke-width:1px
    classDef backend fill:#E2F0D9,stroke:#2C8E00,stroke-width:1px
    classDef datalayer fill:#FFE5B4,stroke:#FF8C00,stroke-width:1px
    classDef database fill:#FFEBE6,stroke:#D12F19,stroke-width:1px,stroke-dasharray: 5 5
    classDef external fill:#F2F2F2,stroke:#6A737D,stroke-width:1px
    classDef api fill:#D6EAF8,stroke:#1B4F72,stroke-width:1px
    classDef config fill:#FDEBD0,stroke:#A04000,stroke-width:1px
```
