Skip to content

TutorEdge/tutoredge-backend

Repository files navigation

📘 Project README

Fastify + MongoDB Backend

⚡ Features

  • Fastify server with TypeScript
  • MongoDB database integration
  • User roles: Student, Tutor, Parent, Admin
  • JWT authentication
  • API versioning (/v1)
  • Swagger UI documentation at /docs
  • Dockerized for development and production

📂 Project Folder Structure

backend/
│
├─ src/
│   ├─ config/          # Database & environment configuration
│   │   ├─ db.ts
│   │   └─ env.ts
│   │
│   ├─ controllers/     # Handle requests → call services
│   │   ├─ auth.controller.ts
│   │   └─ user.controller.ts
│   │
│   ├─ services/        # Business logic
│   │   └─ auth.service.ts
│   │
│   ├─ models/          # MongoDB schemas
│   │   └─ User.ts
│   │
│   ├─ routes/          # API endpoints
│   │   ├─ auth.routes.ts
│   │   └─ user.routes.ts
│   │
│   ├─ middlewares/     # Auth, validation, error handling
│   │   └─ auth.ts
│   │
│   ├─ utils/           # Helpers: JWT, hash functions
│   │   ├─ jwt.ts
│   │   └─ hash.ts
│   │
│   ├─ app.ts           # Fastify app setup
│   └─ server.ts        # Entry point (start server)
│
├─ .env                 # Environment variables
├─ .env.example         # Example environment config
├─ .gitignore
├─ package.json
├─ tsconfig.json
├─ .eslintrc.js
├─ .prettierrc
└─ docker-compose.yml

🛠 Prerequisites

  • Node.js >= 18
  • npm
  • Docker & Docker Compose (optional)
  • MongoDB (if running locally, otherwise use Docker)

🚀 Run Using npm (Local)

  1. Install dependencies:
npm install
  1. Create .env file (based on .env.example)
PORT=3000
MONGO_URI=mongodb://localhost:27017/fastifydb
JWT_SECRET=supersecret123
  1. Start server in development mode:
npm run dev
  1. Access endpoints:
  • Health check: GET http://localhost:3000/v1/health
  • Swagger UI: http://localhost:3000/docs
  • Signup/Login/Forgot Password APIs: /v1/auth/...
  • User profile: /v1/user/profile (requires JWT token)

🐳 Run Using Docker

  1. Build and start services:
docker-compose up --build
  1. Services included:
  • backend: Fastify app on PORT from .env (default 3000)
  • mongo: MongoDB container, port 27017
  1. Example connection inside container:
MONGO_URI=mongodb://mongo:27017/fastifydb
  1. Stop containers:
docker-compose down

📄 Standard Git Commit Types

Type Description
feat: A new feature (e.g., feat(auth): add login API)
fix: A bug fix
docs: Documentation only changes
style: Code style changes (formatting, no logic change)
refactor: Code refactoring, no feature or bug fix
test: Adding or fixing tests
chore: Maintenance tasks (build, package updates)
perf: Performance improvements
ci: Changes to CI/CD pipelines
build: Changes to build system or dependencies
revert: Revert previous commit

Example commits:

feat(auth): add signup and login endpoints
fix(auth): correct password hashing issue
docs: add README and Swagger documentation
refactor(user): simplify profile controller

📌 Notes

  • Always rebuild Docker image if new dependencies are added:
docker-compose up --build
  • JWT token is required for protected routes (Authorization: Bearer <token>).
  • Swagger UI helps test APIs directly: http://localhost:3000/docs

About

TutorEdge/tutoredge-backend

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published