This repository contains our Internet Programming course project. The current codebase includes a working Node.js/Express backend for authentication and a bootstrapped React frontend scaffold. This README explains how to run both applications together and how the project is organized.
- Backend is implemented and runnable.
- MongoDB is required for the backend.
- Authentication endpoints are available: register, login, and get current user.
- Frontend structure and dependencies are initialized.
- Root scripts are available to run frontend and backend together.
- Frontend: React
- Backend: Node.js, Express.js
- Database: MongoDB with Mongoose
- Authentication: JWT
- Password Hashing: bcryptjs
Internet-Programming/
├── package.json # Root scripts for running both apps together
├── backend/
│ ├── config/ # Database connection and backend configuration
│ ├── controllers/ # HTTP request handlers
│ ├── middleware/ # Authentication middleware
│ ├── models/ # Mongoose models
│ ├── routes/ # API route definitions
│ ├── services/ # Business logic layer
│ ├── utils/ # Shared backend helpers
│ ├── .env.example # Example environment variables
│ ├── app.js # Express app setup
│ ├── server.js # Backend server entry point
│ └── package.json # Backend dependencies and scripts
├── frontend/
│ ├── public/ # Static frontend assets
│ │ ├── index.html
│ │ └── manifest.json
│ ├── package.json # Frontend dependencies and scripts
│ └── src/
│ ├── components/ # Reusable UI components
│ ├── context/ # React context providers
│ ├── pages/ # Page-level components
│ ├── routes/ # Frontend route definitions
│ ├── services/ # API communication layer
│ ├── utils/ # Frontend helper functions
│ ├── App.js # Main React app component
│ └── index.js # Frontend entry point
└── README.md
The project follows a layered modular architecture so that each feature remains organized and easy to extend.
routes/: defines API endpoints.controllers/: handles request and response flow.services/: contains business logic and data processing.models/: defines MongoDB schemas.middleware/: handles cross-cutting concerns such as authentication.utils/: shared helpers such as JWT generation.
pages/: top-level screens.components/: reusable UI components.routes/: client-side navigation.services/: calls backend APIs.context/: shared application state such as authentication.utils/: formatting and helper logic.
Frontend flow:
Page
-> Component
-> Service
-> Backend API
The target structure for future modules is:
backend/
├── controllers/
│ ├── authController.js
│ ├── userController.js
│ ├── postController.js
│ ├── commentController.js
│ ├── communityController.js
│ └── voteController.js
├── models/
│ ├── User.js
│ ├── Post.js
│ ├── Comment.js
│ ├── Community.js
│ └── Vote.js
├── routes/
│ ├── auth.js
│ ├── users.js
│ ├── posts.js
│ ├── comments.js
│ ├── communities.js
│ └── votes.js
└── services/
├── authService.js
├── userService.js
├── postService.js
├── commentService.js
├── communityService.js
└── voteService.js
- Node.js 18 or newer
- npm
- MongoDB running locally or via MongoDB Atlas
Use these commands from the project root to run both frontend and backend.
npm install
npm run install-all
npm run devThis starts:
- Backend (nodemon) from
backend/ - Frontend React development server from
frontend/
npm run dev: starts both apps at once.npm run server: runs backend in development mode (nodemon).npm run client: runs the frontend React dev server.npm run install-all: installs backend and frontend packages.npm run build: builds the frontend production bundle.
Additional helper scripts:
npm run install-server: installs backend dependencies only.npm run install-client: installs frontend dependencies only.
- Open a terminal in the backend folder.
- Install dependencies.
- Create the
.envfile. - Start MongoDB.
- Run the backend server.
cd backend
npm installCreate backend/.env using the example below:
PORT=5000
MONGO_URI=mongodb://adminUser:adminPassword@cluster0.3jpc2pm.mongodb.net/IP_Reddit_Clone?retryWrites=true&w=majority
JWT_SECRET=uni_jwt_secret_key_2026_yourname_authentication_super_secure
JWT_EXPIRE=100d
CLOUDINARY_CLOUD_NAME=dnf9logbk
CLOUDINARY_API_KEY=888965129536689
CLOUDINARY_API_SECRET=PuGcAv9liUgYYRfH9Om5DUp6zjY
NODE_ENV=developmentDevelopment mode with nodemon:
cd backend
npm run devProduction-style start:
cd backend
npm startOnce the backend is running, it will be available at:
http://localhost:5000
The frontend is initialized with React scripts and routing dependencies.
Run frontend only:
cd frontend
npm install
npm startPlanned frontend environment variable:
REACT_APP_API_URL=http://localhost:5000/apiPOST /api/auth/register # Register a new user
POST /api/auth/login # Login user
GET /api/auth/me # Get currently authenticated user
- A client sends login or register data to
/api/auth/.... - The route forwards the request to the controller.
- The controller validates required input.
- The service handles the main logic.
- The model interacts with MongoDB.
- A JWT token is returned on successful authentication.
config/database.js: connects the application to MongoDB.controllers/authController.js: handles register, login, and current-user requests.services/authService.js: contains authentication business logic.middleware/auth.js: protects private routes using JWT.models/User.js: stores user schema definition.utils/generateToken.js: creates JWT tokens.