Skip to content

phamhungcrab/StudentManagementSystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

# Student Management System

A clean, framework-free **HTML/CSS/JS frontend** backed by a **Node.js + Express API** (MongoDB via Mongoose by default; optional MySQL schema provided).

## Project Structure

```text
StudentManagementSystem/
├─ backend/                     # Node/Express API (MongoDB/Mongoose)
│  ├─ server.js
│  ├─ package.json
│  ├─ .env.example
│  ├─ config/
│  │  └─ db.js
│  ├─ controllers/
│  │  ├─ dashboardController.js
│  │  ├─ userController.js
│  │  ├─ studentController.js
│  │  ├─ classController.js
│  │  └─ departmentController.js
│  ├─ models/
│  │  ├─ User.js
│  │  ├─ Student.js
│  │  ├─ Class.js
│  │  └─ Department.js
│  ├─ routes/
│  │  ├─ dashboardRoutes.js
│  │  ├─ userRoutes.js
│  │  ├─ studentRoutes.js
│  │  ├─ classRoutes.js
│  │  └─ departmentRoutes.js
│  ├─ middlewares/
│  │  ├─ authMiddleware.js
│  │  └─ errorHandler.js
│  └─ utils/
│     ├─ csvHelper.js
│     ├─ pdfGenerator.js
│     └─ logger.js
│
├─ frontend/                    # Pure HTML/CSS/JS (no Jinja2)
│  ├─ index.html
│  ├─ students.html
│  ├─ classes.html
│  ├─ departments.html
│  ├─ users.html
│  ├─ settings.html
│  ├─ css/
│  │  ├─ style.css
│  │  ├─ dashboard.css
│  │  ├─ students.css
│  │  ├─ classes.css
│  │  ├─ departments.css
│  │  ├─ users.css
│  │  └─ settings.css
│  └─ js/
│     ├─ main.js
│     ├─ dashboard.js
│     ├─ students.js
│     ├─ classes.js
│     ├─ departments.js
│     ├─ users.js
│     └─ settings.js
│
├─ database/                    # MySQL option (schema + seeds + backups)
│  ├─ student_db.sql
│  ├─ seed_data.sql
│  └─ backups/
│     └─ README.md
│
├─ README.md
└─ package.json                 # Root package (optional combined scripts)
```

## Quick Start (MongoDB)

1. **Backend**

   ```bash
   cd backend
   cp .env.example .env (macOS or Linux)
   copy .env.example .env (Windows)
   # Edit .env → MONGO_URI, JWT_SECRET, CORS_ORIGIN
   npm i
   npm run seed:admin   # creates admin/admin123 if missing
   npm run dev          # starts backend on http://localhost:3000
   ```
2. **Frontend**

   * The backend serves `../frontend` statically. Open [http://localhost:3000/](http://localhost:3000/)
   * Login with **admin / admin123** to unlock user management.

## REST API (overview)

* **Auth**: `POST /api/auth/login`, `GET /api/auth/me`
* **Dashboard**: `GET /api/dashboard`
* **Students**: `GET/POST/PUT/DELETE /api/students`
* **Classes**: `GET/POST/PUT/DELETE /api/classes`, `PUT /api/classes/:id/students`
* **Departments**: `GET/POST/PUT/DELETE /api/departments`, `PUT /api/departments/:id/classes`
* **Users**: `GET/POST/PUT/DELETE /api/users` (admin only)

## Environment (.env)

```ini
PORT=3000
MONGO_URI=mongodb://127.0.0.1:27017/sms
JWT_SECRET=change-this-secret
CORS_ORIGIN=http://localhost:3000
MONGOOSE_DEBUG=false
```

## Switching to MySQL

* Use the SQL files in `database/` (`student_db.sql`, `seed_data.sql`).
* Replace `backend/config/db.js` and `backend/models/*` with Sequelize models.
* Controllers and routes can stay the same (they call model methods either way).

## Scripts

Backend (`/backend/package.json`):

```json
{
  "start": "node server.js",
  "dev": "nodemon server.js",
  "seed:admin": "node -e \"(async()=>{require('dotenv').config();const {connectDB}=require('./config/db');const User=require('./models/User');const {hashPassword}=require('./utils/password');await connectDB(process.env.MONGO_URI);const exists=await User.findOne({username:'admin'});if(!exists){const u=new User({username:'admin',password:await hashPassword('admin123'),role:'admin'});await u.save();console.log('seeded admin/admin123');}else{console.log('admin already exists');}process.exit(0)})();\""
}
```

## Security Notes

* Hash passwords (`bcryptjs`) — already implemented.
* Keep `JWT_SECRET` strong and private.
* Validate/sanitize inputs before saving to DB.
* Configure CORS to your real frontend origins in production.

## License

MIT (adjust as needed).


Bonus:
- https://nodejs.org/en    (Node.js and npm)
- https://www.mongodb.com/try/download/community-edition    (mongodb)
- https://www.mongodb.com/try/download/shell    (mongodb shell)
- setup environment variables
   (Win + R → type sysdm.cpl,
    Enter → Advanced tab → Environment Variables,
     Under System variables, find Path,
      click Edit,
       Add a line to mongosh.exe from mongodb shell)
- if you meet PowerShell is blocking scripts when run npm id
Press Windows key,
   Type powershell,
      Right-click Windows PowerShell → Run as administrator,
         Get-ExecutionPolicy -List,
            Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force,
               restart VS Code’s terminal if you use VS Code and try again

- npm install bcrypt ( to run npm run seed:admin)

About

Project1

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors