A simple todo application built with:
- MongoDB (Database)
- Express.js (Backend Framework)
- Angular (Frontend Framework)
- Node.js (Runtime Environment)
- Node.js (v16+ recommended)
- MongoDB (local or Atlas cluster)
- Angular CLI (for frontend)
- Clone the repository
- Install dependencies for both backend and frontend:
cd mean-todo-app/backend && npm install
cd ../todo-frontend && npm install- Create a
.envfile in the backend directory with:
MONGODB_URI=mongodb://localhost:27017/todoapp
PORT=3000
OR directly mongo connection string- API base URL is configured in
environment.ts:
export const environment = {
production: false,
apiUrl: 'http://localhost:3000/api'
};sudo systemctl start mongod # Linux
mongod # Mac/Windowscd backend
node server.jscd todo-frontend
npm start
or
ng serveUsername: default
Password: default
- Frontend: http://localhost:4200
- Backend API: http://localhost:3000/api/tasks
- Create, read, update, and delete tasks
- Real-time updates
- RESTful API backend
- MongoDB data persistence
mean-todo-app/
├── backend/ # Node.js/Express server
│ ├── models/ # MongoDB models (e.g., Task.js for task schema)
│ ├── routes/ # API routes (e.g., tasks.js for task-related endpoints)
│ ├── middleware/ # Middleware for request handling (e.g., authentication, logging)
│ └── server.js # Main server file to start the Express app
├── todo-frontend/ # Angular application
│ ├── src/ # Source code for the Angular app
│ │ ├── app/ # Angular components and services
│ │ │ ├── components/ # UI components (e.g., task list, task form)
│ │ │ ├── services/ # API services for HTTP requests (e.g., TodoService)
│ │ │ └── models/ # TypeScript interfaces (e.g., Task interface)
│ │ ├── assets/ # Static assets like images, stylesheets
│ │ ├── environments/ # Environment-specific configurations (e.g., API URLs)
│ │ └── main.ts # Application entry point
│ ├── angular.json # Angular CLI configuration file
│ ├── package.json # Frontend dependencies and scripts
│ ├── tsconfig.json # TypeScript configuration
│ └── README.md # Frontend-specific documentation
└── README.md # Main project documentationcurl -X GET http://localhost:3000/api/taskscurl -X POST http://localhost:3000/api/tasks \
-H "Content-Type: application/json" \
-d '{"title": "New Task", "dueDate": "2025-04-15T10:00:00Z"}'curl -X DELETE http://localhost:3000/api/tasks/<task_id>- Import the following endpoints into Postman:
- GET:
http://localhost:3000/api/tasks - POST:
http://localhost:3000/api/tasks - DELETE:
http://localhost:3000/api/tasks/<task_id>
- GET:
- Set headers for POST requests:
Content-Type: application/json
- Use the body tab in Postman to send JSON data for POST requests.
-
If MongoDB connection fails, verify:
- MongoDB service is running
- Connection URI in
.envis correct - No firewall blocking port 27017
-
For Angular issues:
- Check console errors in browser
- Verify API responses in Network tab
- Run
ng serve --opento debug
The MEAN Stack Todo Application follows a modular architecture with clear separation of concerns between the frontend and backend. Below is an overview of the architecture:
-
Frontend (Angular):
- Handles user interactions and displays data.
- Communicates with the backend via RESTful APIs.
- Built using Angular components, services, and modules.
-
Backend (Node.js + Express):
- Provides RESTful APIs for CRUD operations.
- Handles business logic and interacts with the database.
- Uses middleware for request validation and error handling.
-
Database (MongoDB):
- Stores tasks and their metadata (e.g., title, due date, completion status).
- Provides a flexible schema for data storage.
Below is a simplified flow diagram of the application:
+-------------+ HTTP Requests +-----------------+ Database Queries +-------------+
| | --------------------------> | | ----------------------------> | |
| Frontend | | Backend | | MongoDB |
| (Angular) | <-------------------------- | (Node.js + API) | <---------------------------- | (Database) |
| | JSON Responses | | Query Results | |
+-------------+ +-----------------+ +-------------+
To create a visual diagram, you can use tools like Mermaid or Draw.io. Below is a Mermaid diagram code snippet:
graph TD
A[Frontend (Angular)] -->|HTTP Requests| B[Backend (Node.js + Express)]
B -->|Database Queries| C[MongoDB]
C -->|Query Results| B
B -->|JSON Responses| A
To render this diagram:
- Copy the code above.
- Paste it into a Markdown file or a tool that supports Mermaid diagrams (e.g., GitHub, VS Code with Mermaid extension).
This architecture ensures scalability, maintainability, and a clear separation of concerns.
