How nenowodev/studyflowbackend works
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