How c4lopsitta/cat-backend works
Major components
• Docker Containers: The project runs using Docker, so start by representing the three main containers:
• Nginx container: Acts as the web server and single page router for all /api/v1/... paths.
• PHP-FPM container: Hosts the PHP application, including the API handler and all the backend logic.
• MariaDB container: Provides the database backend.
• Application Layers within the PHP-FPM container:
• API Handler: Represent the central entry point (apiHandler.php) that processes incoming API requests.
• Routing and Handlers: The “app/BaseHandlers” folder contains specialized handlers (like Cats.php and Users.php) for different API endpoints.
• Data Access: The “app/DAO” directory includes various DAO classes (e.g., CatDAO, UserDAO, etc.) for interacting with the database and also Redis components.
• Domain Models: Identify “app/Model” which holds the core domain entities such as Cat, Token, and User.
• Utilities & Services: The “app/Utilities” directory, including email utilities and password/regex helpers, encapsulates common functionality.
• Testing/JSON Support: Additional components (e.g., app/Test and app/Jsons) support testing and facilitate JSON operations.
Relationships and data flows
• Clients send API requests that first hit the Nginx container.
• Nginx forwards these requests to the PHP-FPM container where apiHandler.php dispatches them to the appropriate BaseHandler (e.g., Cats or Users handler).
• The BaseHandlers work with the DAO layer to query or update data in the MariaDB (and possibly cache or additional data sources like Redis as indicated by app/DAO/Redis).
• Utility components (email sender, password management, etc.) support the business logic.
Architectural patterns and design principles
• Separation of Concerns: The architecture distinguishes clear responsibilities across different layers (routing, data access, domain modelling, and utility services).
• Containerization: The Docker-compose setup demonstrates micro-container architecture, with each container serving a dedicated purpose.
Relevant technologies and frameworks
• PHP with PHP-FPM for backend logic.
• Nginx serving as the reverse proxy and router for API requests.
• MariaDB for persistent storage.
• Use of Docker and docker-compose to orchestrate the containers.
• Additionally, utility libraries for emails, regular expressions, and unique ID generation show your use of helper functions for robust functionality.
• API Entrypoint (apiHandler.php)
• Base Handlers (with examples e.g., Cats.php, Users.php)
• DAO Layer (CatDAO, UserDAO, etc.)
• Models (Cat, Token, User)
• Utilities (emails, password, regex, etc.)
• API requests from clients to Nginx.
• Request forwarding from Nginx to PHP-FPM.
• Interactions from PHP-FPM’s API components to the MariaDB container.
• Any caching or secondary interactions (e.g., with Redis as indicated by the DAO classes).