# nenowodev/studyflowbackend architecture

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

- Interactive diagram: https://gitdiagram.com/nenowodev/studyflowbackend
- Repository: https://github.com/nenowodev/studyflowbackend

## Overview

##### Project Type and Purpose
- This is a monolithic RESTful API server, written in PHP, exposing endpoints for a Course Mark Management System.
- It handles user authentication (JWT), user/course/enrollment management, assessment components, student marks, remark requests, advisor-student assignments, and advisor notes.
- The backend persists data in a relational database (MySQL or compatible), with DDL and seed scripts in the `db/` folder.

##### File Structure Analysis
- Top-level
- `.env`, `composer.json`/`composer.lock`: environment configuration and PHP dependencies
- `db/`: SQL scripts (schema, dummy data, clear tables)
- `public/index.php`: single entry-point (front controller)
- `src/`
– `Controllers/`: one controller per resource (e.g., `UserController.php`, `CourseController.php`, etc.)
– `db.php`: database connection and helper functions
– `jwtMiddleware.php`: authentication middleware
- `vendor/`: third-party libraries installed via Composer
- Pattern: A simple MVC-style routing: index.php → middleware → controllers → DB.

##### Key Insights from README
- All routes under Base URL use JSON for requests/responses.
- Authentication via JWT in Authorization header.
- Each resource follows CRUD operations with role-based access control.
- Core dependencies: PHP, Composer packages (likely a router), JWT library, MySQL.

##### Diagramming the Architecture
a. Main Components
- API Consumers (e.g., Web App, Mobile App, CLI, Postman)
- HTTP API Gateway (public/index.php)
- JWT Middleware (src/jwtMiddleware.php)
- Controllers Layer (src/Controllers/*.php)
- Data Access Layer (src/db.php)
- Relational Database (MySQL)
- Optional: Env config (.env) and Composer autoloader (vendor/)
b. Relationships & Data Flow
1. Client sends HTTP request →
2. public/index.php bootstrap →
3. JWT Middleware verifies token (or rejects) →
4. Request routed to appropriate Controller →
5. Controller calls db.php functions (SQL queries) →
6. Database executes queries →
7. Controller builds JSON response →
8. Response sent back via HTTP to Client
c. Architectural Patterns & Principles
- Front Controller pattern (single `index.php`)
- Middleware chain for cross-cutting concerns (JWT auth)
- Controller per resource (separation of concerns)
- Centralized DB connection (singleton or factory in `db.php`)
- Role-based access enforcement at controller level
d. Key Technologies & Libraries
- PHP 7+
- Composer autoloading & installed packages (e.g., firebase/php-jwt)
- MySQL (or MariaDB)
- dotenv library for environment variables

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Clients
    Clients["Clients<br/>(Web App, Mobile App, CLI, Postman)"]:::external

    %% Configuration & Autoload
    Env[".env"]:::config
    subgraph "Composer & Dependencies"
        CompJSON["composer.json"]:::config
        CompLock["composer.lock"]:::config
        Vendor["vendor/"]:::config
    end

    %% Flow Start
    Clients -->|HTTP/JSON| API_Gateway
    Env --> API_Gateway
    CompJSON --> API_Gateway
    CompLock --> API_Gateway
    Vendor --> API_Gateway

    %% API Gateway Layer
    API_Gateway["API Gateway<br/>(public/index.php)"]:::gateway

    %% Middleware Layer
    API_Gateway -->|Bootstrap & Route| JWT_MW
    JWT_MW["JWT Middleware<br/>(src/jwtMiddleware.php)"]:::middleware

    %% Controllers Layer
    JWT_MW -->|Route Request| Controllers
    subgraph "Controllers Layer"
        UserCtrl["UserController"]:::controller
        CourseCtrl["CourseController"]:::controller
        EnrollmentCtrl["EnrollmentController"]:::controller
        AssessCompCtrl["AssessmentComponentController"]:::controller
        StudentMarkCtrl["StudentMarkController"]:::controller
        RemarkReqCtrl["RemarkRequestController"]:::controller
        AdvisorStudCtrl["AdvisorStudentController"]:::controller
        AdvisorNoteCtrl["AdvisorNoteController"]:::controller
        NotificationCtrl["NotificationController"]:::controller
    end

    %% Data Access Layer
    Controllers -->|SQL Queries| DataLayer
    DataLayer["Data Access Layer<br/>(src/db.php)"]:::data

    %% Database & Scripts
    DataLayer -->|Execute Queries| Database
    subgraph "DB Scripts"
        Schema["dbstruct.sql"]:::script
        Dummy["dummy.sql"]:::script
        ClearTbl["cleartable.sql"]:::script
    end
    Schema -->|Defines Schema| Database
    Dummy -->|Seed Data| Database
    ClearTbl -->|Teardown| Database

    Database["Relational Database<br/>(MySQL)"]:::storage

    %% Click Events
    click API_Gateway "https://github.com/nenowodev/studyflowbackend/blob/main/public/index.php"
    click JWT_MW "https://github.com/nenowodev/studyflowbackend/blob/main/src/jwtMiddleware.php"
    click UserCtrl "https://github.com/nenowodev/studyflowbackend/blob/main/src/Controllers/UserController.php"
    click CourseCtrl "https://github.com/nenowodev/studyflowbackend/blob/main/src/Controllers/CourseController.php"
    click EnrollmentCtrl "https://github.com/nenowodev/studyflowbackend/blob/main/src/Controllers/EnrollmentController.php"
    click AssessCompCtrl "https://github.com/nenowodev/studyflowbackend/blob/main/src/Controllers/AssessmentComponentController.php"
    click StudentMarkCtrl "https://github.com/nenowodev/studyflowbackend/blob/main/src/Controllers/StudentMarkController.php"
    click RemarkReqCtrl "https://github.com/nenowodev/studyflowbackend/blob/main/src/Controllers/RemarkRequestController.php"
    click AdvisorStudCtrl "https://github.com/nenowodev/studyflowbackend/blob/main/src/Controllers/AdvisorStudentController.php"
    click AdvisorNoteCtrl "https://github.com/nenowodev/studyflowbackend/blob/main/src/Controllers/AdvisorNoteController.php"
    click NotificationCtrl "https://github.com/nenowodev/studyflowbackend/blob/main/src/Controllers/NotificationController.php"
    click DataLayer "https://github.com/nenowodev/studyflowbackend/blob/main/src/db.php"
    click Schema "https://github.com/nenowodev/studyflowbackend/blob/main/db/dbstruct.sql"
    click Dummy "https://github.com/nenowodev/studyflowbackend/blob/main/db/dummy.sql"
    click ClearTbl "https://github.com/nenowodev/studyflowbackend/blob/main/db/cleartable.sql"
    click Env "https://github.com/nenowodev/studyflowbackend/blob/main/.env"
    click CompJSON "https://github.com/nenowodev/studyflowbackend/blob/main/composer.json"
    click CompLock "https://github.com/nenowodev/studyflowbackend/blob/main/composer.lock"
    click Vendor "https://github.com/nenowodev/studyflowbackend/tree/main/vendor/"

    %% Styles
    classDef external fill:#bbdefb,stroke:#0d47a1,stroke-width:1px;
    classDef gateway fill:#e3f2fd,stroke:#1e88e5,stroke-width:1px;
    classDef middleware fill:#ffe0b2,stroke:#fb8c00,stroke-width:1px;
    classDef controller fill:#c8e6c9,stroke:#388e3c,stroke-width:1px;
    classDef data fill:#fff9c4,stroke:#fbc02d,stroke-width:1px;
    classDef storage fill:#fff59d,stroke:#f9a825,stroke-width:1px;
    classDef config fill:#cfd8dc,stroke:#607d8b,stroke-width:1px;
    classDef script fill:#f5f5f5,stroke:#9e9e9e,stroke-width:1px;
```
