How akinojoey/socialnetworkingservice works
Main Components
• Frontend Client:
• Represented by static assets in the “public” directory (bundled JS files like login.bundle.js, main.bundle.js, etc.) and assets in “src/assets.”
• Responsive design powered by Tailwind, Flowbite, and daisyUI.
• Backend Web Server:
• The main entry point (public/index.php) routes requests via the “src/routing” module.
• Within “src,” you have Models (business logic), Views (presentation layer in “src/views”), and Helpers/Middleware for authentication, session handling, and security.
• Controllers are likely part of the routing and middleware files.
• Database:
• MySQL is used, with migrations (in “src/database/migrations”), seeders, and the DAO pattern found in “src/database/data_access” for structured database operations.
• Real-Time Communication Server:
• A dedicated chat server implemented in “bin/chat_server.php” using Ratchet to support private WebSocket-based messaging.
• Cron Jobs and Scheduled Tasks:
• Several cron scripts (in “cron”) handle scheduled posts, deletion of expired tokens, and seeding. Also, there is a command-based CLI architecture in “src/commands” for tasks like migrations, deploying, and seeding.
• External Dependencies & Services:
• PHPMailer for email, ImageMagick and ffmpeg for media processing, Carbon for date handling, along with third-party APIs (e.g., Pixabay for dummy images).
• NGINX acting as the web server and reverse proxy (especially for WSS).
• Amazon EC2 for hosting and Certbot for SSL/TLS certificate management.
Relationships and Interactions
• User Interactions:
• End users interact with the application via a browser. Their requests hit the NGINX web server and are served the static frontend assets.
• Client-side JavaScript handles interactions (post submissions, login, chat) and makes API calls.
• Backend Request Flow:
• Incoming requests are processed by the router (in “src/routing/routes.php”) and pass through middleware (authentication, CSRF, email verification, etc.) before calling the appropriate business logic (models, commands).
• Responses are rendered through HTML/JSON renderers (in “src/response/render”).
• Database Interactions:
• The backend invokes DAO methods (interfaces and implementations found in “src/database/data_access”) to interact with the MySQL database, using migrations and seeders to manage the schema and test data.
• Scheduled & Asynchronous Tasks:
• Cron jobs periodically trigger commands (e.g., PostScheduled for moving scheduled posts to published, seed_prototype for generating dummy data).
• Real-Time Chat:
• The WebSocket server (chat_server.php) serves direct messaging, with communication facilitated between a connected client and backend services.
• Security & Validation:
• Middleware intercepts requests to verify sessions, validate CSRF tokens, process signed URLs (via SignatureValidationMiddleware), and ensure data integrity using Helpers like ValidationHelper and CipherHelper.
Architectural Patterns and Design Principles
• MVC Architecture:
• Clearly demarcate models, views, and routing logic (akin to controllers) – even if controllers are interwoven with the router.
• DAO Pattern:
• All database operations funnel through defined interfaces and their implementations.
• Middleware Chain:
• A layered approach to security and request validation.
• Microservices-Like Separation:
• Though not a microservices application per se, there is separation between web requests (HTTP), background jobs (cron/commands), and real-time socket communications.
Relevant Technologies and Frameworks
• Frontend:
• HTML, CSS (Tailwind), JavaScript (bundled via webpack)
• Third-party libraries: flowbite, daisyUI, Flatpickr for date selection.
• Backend:
• PHP, Composer for dependency management, PHP’s built-in session handling, and PHPMailer.
• Ratchet library for WebSockets.
• Database:
• MySQL.
• Tools/Deployment:
• NGINX, Amazon EC2, cron jobs, Supervisor for process management, Certbot for TLS.