How swirl86/mern-crud-budget-app works
Project type and purpose
• This is a MERN-stack full-stack application for personal budget management.
• Users interact with a React/Tailwind single-page app to add, view, and delete budget items.
• The frontend communicates over HTTP with an Express/Node.js backend that persists data in MongoDB.
File structure
• Top-level “budget-app” directory splits into two clear components:
• backend/ – Express server, REST routes (budgetItems.js), Mongoose model (BudgetItem.js), seed/test data.
• frontend/ – Vite-powered React app: pages, components, custom hooks, API service, Tailwind CSS.
• Configuration and build files: package.json in each tier, Vite and Tailwind configs, ESLint, .gitignore, README.md.
README for additional insights
• Tech stack: React + Vite + Tailwind on the frontend; Node + Express + MongoDB on the backend.
• State management via custom React hooks (useFetch…, useDelete…, etc.).
• Future plans include auth, categorization, reporting, external API integrations—points that will extend the architecture.
Main components and their responsibilities
a. Frontend (React SPA)
• UI layer: pages (Home, FinancialTable), components (Header, Table cells, Footer).
• Data-fetch layer: services/api.js + custom hooks to call REST endpoints.
• Styling: Tailwind CSS, Vite dev/build pipeline.
b. Backend (Express/Node.js)
• HTTP layer: server.js initializes Express, middleware, and mounts budgetItems routes under /api.
• Routing/controllers: routes/budgetItems.js handles GET, POST, DELETE.
• Data layer: models/BudgetItem.js defines the schema, interacts with MongoDB via Mongoose.
• Testdata: seedBudgetData.js + testData.js to populate or reset the database.
c. Database
• MongoDB instance (could be local or cloud) storing budget items in a “budgetitems” collection.
d. (Optional) Dev tools & external services
• Vite development server (front-end), Nodemon or similar for back-end auto-reload, ESLint.
Component interactions and data flow
1. User → React UI (clicks “Add” or “Delete”)
2. React hook (e.g., useUpdateBudgetItems) → API service (services/api.js)
3. HTTP request → Express route (/api/budgetItems)
4. Route handler → Mongoose model → MongoDB
5. MongoDB response → Model → Route handler → JSON response → React hook → UI update
Architectural patterns and design principles
• Layered architecture: Presentation (React), API (Express controllers), Data access (Mongoose models), Database.
• MVC-style separation in backend: routes/controllers vs. models.
• Single-Page Application on frontend: stateful React with hooks.
• RESTful API design.
• Future extensibility: add auth middleware, reporting micro-services, external integration adapters.