How pedrohaveloso/postin works
Project Overview and Main Components
• Frontend: Built using React, TypeScript, Vite, and TailwindCSS. It’s organized into clear segments: data sources (APIs), data models, repositories, presenters, and UI components/pages.
• Backend/API: A PHP API that provides endpoints for user authentication, posting, favoriting posts, etc. It’s implemented in PHP without a framework (using Composer for autoloading) and follows some clean architecture principles by separating models, repositories (with interfaces/implementations), services, and routing.
• Database: A MySQL database (as seen in api/db.sql) that stores user and post data.
• External Services: While nothing third‐party is explicitly mentioned, note that the PHP API is hosted externally, even if temporarily.
Breaking Down the File Structure
• For the API:
– The “api/app” directory is subdivided into Models, Repository (with separate directories for Database classes and Interfaces), Routes, Services, and Utilities. This indicates a layered architecture where Repository interfaces/implementations mediate data access, and Services encapsulate business logic.
– The “api/public” directory will serve static resources, and “server.php” acts as the API gateway.
• For the Frontend:
– The “src/data” part contains datasources (with TypeScript files for calling the API), models for post and user actions, and repository classes, which mirror the separation in the API.
– The “src/presenter” directory includes business logic for transferring data into UI-friendly formats (with providers like ApiProvider and AuthProvider).
a. Main Components:
• Frontend:
• UI Layer: Composed of pages (HomePage, ProfilePage, etc.) and components (LoginForm, RegisterForm, Navbar, etc.)
• Presentation Layer: Presenters and Providers (e.g., PostPresenter, UserPresenter, ApiProvider, AuthProvider) that manage state and route data.
• Data Layer: Datasources (API calls) and repositories that fetch or manipulate data.
• Backend:
• API Gateway: server.php (front controller)
• Routing: Router and Routes to dispatch API calls.
• Business Logic: Services handling users and posts.
• Persistence Layer: Repositories implementing interfaces, communicating with the MySQL database.
• Data Models: PHP Models (e.g., PersonLoginModel, PersonRegisterModel, PostCreateModel) representing domain entities.
• Database: MySQL data store, as per api/db.sql.
b. Relationships and Interactions:
• The Frontend (in React) makes HTTP calls through the API datasources to the PHP API.
• On the API side, the Router receives these calls, dispatches them to the appropriate Services which then consult the Repositories.
• Repositories interface with the database to perform CRUD operations.
• Data flow from UI → Presenter/Provider → Datasource → API request.
• API request routed internally: Controller/Router → Service → Repository → Database.
• Responses flowing back from the Database upward to the Presenter and eventually the UI.
c. Architectural Patterns/Design Principles:
• API shows an attempt at Clean Architecture and Separation of Concerns by splitting Models, Repositories (with interfaces and dependency inversion), and Services.
• The frontend is organized with separation between data (repositories/datasources), presentation (presenters and providers), and UI (components/pages).
• Important flows such as user authentication (login, registration) and posting as separate flows.
d. Relevant Technologies:
• Frontend: React, TypeScript, Vite, TailwindCSS.
• Backend: PHP, MySQL, Composer.
• Miscellaneous: ESLint (for static analysis) in the root, NodeJS for the development server.