# rolland306/tutor-connect architecture

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

- Interactive diagram: https://gitdiagram.com/rolland306/tutor-connect
- Repository: https://github.com/rolland306/tutor-connect

## Overview

##### Project Type & Purpose
- This is a full-stack web application (“Tutor Connect”) whose goal is to provide an online tutoring exchange platform.
- Frontend: React single-page application (SPA) built with Vite.
- Backend: Node.js + Express REST API, intended to connect to PostgreSQL (but currently reading JSON under server/config/data).

##### High-Level Architecture Components
a. Frontend Layer
- Built in client/src using React components and React Router.
- Bundled and served by Vite (client/vite.config.js).
- Static public assets (HTML/CSS) under client/public.
b. API Layer
- Express server (server/server.js) exposing REST endpoints under server/routes/*.js.
- Each route delegates to a controller (server/controllers/*.js) implementing business logic.
c. Data Layer
- Temporary JSON “data store” under server/config/data/*.json (chapters, classes, users).
- database.js abstracts DB access (currently reading JSON; later swap in PostgreSQL).
- dotenv.js for environment config; reset.js for seed/reset logic.
d. External Services & Dev Tools
- Environment variables via .env (handled in dotenv.js).
- Potential future PostgreSQL database instance.

##### Interactions & Data Flow
1. User interacts with React SPA → triggers UI events in components (e.g., search class, post comment).
2. SPA issues HTTP requests (GET/POST/PUT/DELETE) to Express API endpoints (/api/users, /api/chapters, etc.).
3. Express router picks up request → calls appropriate controller method.
4. Controller uses database.js abstraction to read/write JSON or PostgreSQL.
5. Data returned to controller → JSON response sent back to SPA.
6. SPA updates UI state based on API response.

##### Architectural Patterns & Design Principles
- MVC-style on server: Routes (entry point) → Controllers (business logic) → Data layer (models/JSON store).
- Component-based design on client: Reusable React components (Card, Navigation, pages).
- Clear separation of concerns:
- Presentation (React)
- API layer (Express)
- Data persistence (JSON/SQL)

##### Essential Details to Capture
- The client/server boundary via REST API.
- The MVC pattern on the server (Routes → Controllers → Data).
- The data persistence strategy (JSON vs. PostgreSQL).
- The build & serve process (Vite for frontend, Node for API).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        ViteDev["Vite Dev Server"]:::frontend
        ReactApp["React SPA"]:::frontend
        subgraph "Source"
            direction TB
            ReactSource["client/src"]:::frontend
            Components["components"]:::frontend
            Pages["pages"]:::frontend
        end
        Entry["client/src/index.js"]:::frontend
        App["client/src/App.jsx"]:::frontend
        Public["Static Public Assets (client/public)"]:::frontend
        ViteConfig["Vite Configuration (client/vite.config.js)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        ExpressServer["Express Server (server/server.js)"]:::backend
        subgraph "Routes (server/routes)"
            direction TB
            UsersRoute["users.js"]:::backend
            ChaptersRoute["chapters.js"]:::backend
            ClassesRoute["classes.js"]:::backend
            CommentsRoute["comments.js"]:::backend
            NotesRoute["notes.js"]:::backend
            StudentsRoute["students.js"]:::backend
            TutorsRoute["tutors.js"]:::backend
        end
        subgraph "Controllers (server/controllers)"
            direction TB
            UsersCtrl["users.js"]:::backend
            ChaptersCtrl["chapters.js"]:::backend
            ClassesCtrl["classes.js"]:::backend
            CommentsCtrl["comments.js"]:::backend
            NotesCtrl["notes.js"]:::backend
            StudentsCtrl["students.js"]:::backend
            TutorsCtrl["tutors.js"]:::backend
        end
        subgraph "Data Layer"
            direction TB
            DBAbstraction["database.js"]:::backend
            subgraph "JSON Data Store (server/config/data)"
                direction TB
                UsersJSON["users.json"]:::database
                ChaptersJSON["chapters.json"]:::database
                ClassesJSON["classes.json"]:::database
            end
            EnvConfig["dotenv.js"]:::config
            ResetScript["reset.js"]:::config
        end
    end

    %% External Future DB
    PostgreSQL["PostgreSQL Database"]:::database

    %% Interactions
    ReactApp -->|"HTTP Request"| ExpressServer
    ExpressServer -->|routes request| UsersRoute
    ExpressServer -->|routes request| ChaptersRoute
    ExpressServer -->|routes request| ClassesRoute
    ExpressServer -->|routes request| CommentsRoute
    ExpressServer -->|routes request| NotesRoute
    ExpressServer -->|routes request| StudentsRoute
    ExpressServer -->|routes request| TutorsRoute

    UsersRoute -->|"calls"| UsersCtrl
    ChaptersRoute -->|"calls"| ChaptersCtrl
    ClassesRoute -->|"calls"| ClassesCtrl
    CommentsRoute -->|"calls"| CommentsCtrl
    NotesRoute -->|"calls"| NotesCtrl
    StudentsRoute -->|"calls"| StudentsCtrl
    TutorsRoute -->|"calls"| TutorsCtrl

    UsersCtrl -->|uses| DBAbstraction
    ChaptersCtrl -->|uses| DBAbstraction
    ClassesCtrl -->|uses| DBAbstraction
    CommentsCtrl -->|uses| DBAbstraction
    NotesCtrl -->|uses| DBAbstraction
    StudentsCtrl -->|uses| DBAbstraction
    TutorsCtrl -->|uses| DBAbstraction

    DBAbstraction -->|reads/writes| UsersJSON
    DBAbstraction -->|reads/writes| ChaptersJSON
    DBAbstraction -->|reads/writes| ClassesJSON
    DBAbstraction -->|can switch to| PostgreSQL

    EnvConfig -->|loads| ExpressServer
    ResetScript -->|operates on| UsersJSON
    ResetScript -->|operates on| ChaptersJSON
    ResetScript -->|operates on| ClassesJSON

    ReactApp -->|renders| Components
    ReactApp -->|renders| Pages
    ReactApp -->|entry point| Entry
    ReactApp -->|root component| App
    ViteDev -->|bundles & serves| ReactApp

    %% Click Events Frontend
    click ReactSource "https://github.com/rolland306/tutor-connect/tree/main/client/src"
    click Components "https://github.com/rolland306/tutor-connect/tree/main/client/src/components"
    click Pages "https://github.com/rolland306/tutor-connect/tree/main/client/src/pages"
    click Entry "https://github.com/rolland306/tutor-connect/blob/main/client/src/index.js"
    click App "https://github.com/rolland306/tutor-connect/blob/main/client/src/App.jsx"
    click Public "https://github.com/rolland306/tutor-connect/tree/main/client/public"
    click ViteConfig "https://github.com/rolland306/tutor-connect/blob/main/client/vite.config.js"

    %% Click Events Backend
    click ExpressServer "https://github.com/rolland306/tutor-connect/blob/main/server/server.js"
    click UsersRoute "https://github.com/rolland306/tutor-connect/blob/main/server/routes/users.js"
    click ChaptersRoute "https://github.com/rolland306/tutor-connect/blob/main/server/routes/chapters.js"
    click ClassesRoute "https://github.com/rolland306/tutor-connect/blob/main/server/routes/classes.js"
    click CommentsRoute "https://github.com/rolland306/tutor-connect/blob/main/server/routes/comments.js"
    click NotesRoute "https://github.com/rolland306/tutor-connect/blob/main/server/routes/notes.js"
    click StudentsRoute "https://github.com/rolland306/tutor-connect/blob/main/server/routes/students.js"
    click TutorsRoute "https://github.com/rolland306/tutor-connect/blob/main/server/routes/tutors.js"
    click UsersCtrl "https://github.com/rolland306/tutor-connect/blob/main/server/controllers/users.js"
    click ChaptersCtrl "https://github.com/rolland306/tutor-connect/blob/main/server/controllers/chapters.js"
    click ClassesCtrl "https://github.com/rolland306/tutor-connect/blob/main/server/controllers/classes.js"
    click CommentsCtrl "https://github.com/rolland306/tutor-connect/blob/main/server/controllers/comments.js"
    click NotesCtrl "https://github.com/rolland306/tutor-connect/blob/main/server/controllers/notes.js"
    click StudentsCtrl "https://github.com/rolland306/tutor-connect/blob/main/server/controllers/students.js"
    click TutorsCtrl "https://github.com/rolland306/tutor-connect/blob/main/server/controllers/tutors.js"
    click DBAbstraction "https://github.com/rolland306/tutor-connect/blob/main/server/config/database.js"
    click UsersJSON "https://github.com/rolland306/tutor-connect/blob/main/server/config/data/users.json"
    click ChaptersJSON "https://github.com/rolland306/tutor-connect/blob/main/server/config/data/chapters.json"
    click ClassesJSON "https://github.com/rolland306/tutor-connect/blob/main/server/config/data/classes.json"
    click EnvConfig "https://github.com/rolland306/tutor-connect/blob/main/server/config/dotenv.js"
    click ResetScript "https://github.com/rolland306/tutor-connect/blob/main/server/config/reset.js"

    %% Styles
    classDef frontend fill:#D6EFFF,stroke:#0094FF,color:#000
    classDef backend fill:#FFE8D6,stroke:#FF7F11,color:#000
    classDef database fill:#E0FFD6,stroke:#2CA01C,color:#000
    classDef config fill:#F0E6FF,stroke:#8E44AD,color:#000
```
