How ngovanhuong94/twit works
Main Components
• Client (Frontend):
• Built with React and using React Router for SPA navigation.
• Uses Redux along with Thunk middleware for state management.
• Incorporates Material-UI for the UI components.
• Handles API calls via axios that use JWT for authentication.
• Server (Backend):
• A Node.js and Express REST API.
• Utilizes Passport.js for authentication.
• Contains routes for posts and users, with validations, as seen in the “server/routes” and “server/validation” directories.
• Data persistence is managed using MongoDB with Mongoose as the ORM.
• Database:
• MongoDB is used for storing data.
Relationships and Interactions
• The Frontend communicates with the Backend through API calls (using axios) to perform CRUD operations and authentication.
• The Backend processes requests, interacts with the Database, and returns responses (such as post data, user data, etc.) to the Frontend.
• Authentication flow typically involves sending credentials from the client, verifying them on the server (using Passport.js), and then issuing a JWT for subsequent calls.
Architectural Patterns and Design Principles
• Separation of concerns: Clear division between the client (presentation layer) and the server (business logic and data persistence layers).
• MVC/MVVM-like structure: The server is organized with models (in server/models), views (manifested via API responses), and controllers (in server/routes and validations).
• Redux for state management in the frontend promotes a unidirectional data flow.
• RESTful API design principles are followed on the server side.
• Client (React App):
• Components Layer (UI, forms, posts list, login/register pages, etc.)
• Actions and Reducers (Redux logic handling state and API calls)
• Utilties (e.g., setting auth header)
• API Gateway:
• Axios-driven interaction that sends requests from the client to the server
• Server (Express API):
• Routes for users and posts
• Middleware for authentication (Passport.js) and validations
• Models that interact with MongoDB
• Database:
• MongoDB storing user and post data
Additional Specific Details
• For the Frontend:
• For the Backend:
• File structure’s role—how endpoints implemented in “server/routes” connect to the corresponding models in “server/models” and how validations influence these routes.
• Notes about environment configurations (like the .env file).