How keiruu/takape works
Project Type and Purpose
• This is a full-stack MERN (MongoDB, Express, React, Node.js) single-page application called “Takape.ph” for finding local cafes across Panay Island.
• Front-end in React with Tailwind CSS and Firebase Authentication.
• Back-end in Node.js/Express with a REST API, using DAOs to interface with MongoDB.
File Structure Analysis
• Top-level directories:
• backend/ – Express API + DAO + CSV seed data
• frontend/ – React SPA with components, pages, contexts, services
• backend/api: controllers (.controller.js) + routes (.route.js) for cafés and reviews
• backend/dao: data-access layer (cafeDAO.js, reviewsDAO.js) encapsulating MongoDB operations
• frontend/src:
• components/ – reusable UI pieces
• pages/ – route-driven top-level views (Home, Cafe, Login, Signup, etc.)
• contexts/ – React Context for Auth and Café state
• services/ – HTTP client wrappers (CafeDataService.js) for the REST API
• Firebase.js – initializes Firebase Auth client
• Config files: craco.config.js (Tailwind), tailwind.config.js, package.json, server.js
Architecture Explanation
a. Main Components:
• Client (Browser): React SPA
• UI Components
• Routing (React Router via pages)
• AuthContext & CafeContext
• HTTP Service (axios instance in http-common.js)
• Authentication Service: Firebase Authentication (external, OAuth/JWT)
• API Gateway / Back-end: Express server (server.js → index.js)
• Routing Layer (cafes.route.js, reviews.route.js)
• Controller Layer (cafes.controller.js, reviews.controller.js)
• Data Access Layer (cafeDAO.js, reviewsDAO.js)
• Database: MongoDB (Atlas/Stitch deployment)
• Static Assets: served by React build (public/)
b. Relationships & Data Flow:
1. User interacts with React UI → triggers route change or component event
2. For protected routes, AuthContext uses Firebase SDK to sign in/up and obtain JWT
3. React service sends HTTP requests (with JWT in headers) to Express API
4. Express server’s route handler invokes controller → calls DAO
5. DAO reads/writes to MongoDB
6. Results bubble up controller → response back to client
c. Architectural Patterns & Principles:
• Layered architecture (Presentation, API, Controller, DAO, Database)
• MVC-style separation: Controllers handle HTTP logic, DAOs handle persistence
• Context API for state management in React
• Externalizing configuration (CRACO/Tailwind, env vars for DB/Firebase)
d. Key Technologies:
• React, React Router, Context API, Tailwind CSS
• Firebase Authentication SDK
• Axios (http-common.js)
• Node.js, Express.js
• MongoDB (via native driver or Mongoose inside DAOs)