Skip to content

RESTful API built with TypeScript, Express, and Mongoose, following a clean MVC architecture. Includes authentication, authorization, and integration testing using Vitest and Supertest.

Notifications You must be signed in to change notification settings

Garkatron/ExpressQuizzApi

Repository files navigation

logo

๐Ÿง  Express Quizz API

TypeScript Express MongoDB Vitest Swagger

RESTful API built with TypeScript, Express, and Mongoose, following a clean MVC architecture.
Includes authentication, authorization, and integration testing using Vitest and Supertest.


๐Ÿš€ Key Features

  • ๐Ÿงฉ Question Management โ€“ Create, edit, delete, and retrieve questions.
  • ๐Ÿ“š Collections System โ€“ Group questions into collections.
  • ๐Ÿ‘ค User Authentication โ€“ Register, login, and manage users securely.
  • ๏ฟฝ๏ฟฝ๏ฟฝ JWT Tokens โ€“ Stateless authentication for users.
  • ๐Ÿ›ก๏ธ Role-Based Permissions โ€“ Admin and standard user access control.
  • ๐Ÿงช Integration Testing โ€“ Powered by Vitest, Supertest, and mongodb-memory-server.
  • โš™๏ธ Clean Architecture (MVC + OOP) โ€“ Modular and scalable project structure.
  • ๐Ÿ“– API Documentation โ€“ Auto-generated using Swagger UI.
  • ๐Ÿชต Structured Logging โ€“ Using Pino and Morgan for detailed request logs.
  • ๐Ÿงฐ Validation & Security โ€“ Helmet, Rate Limiting, HPP, Express Validator, and CORS.

๐Ÿงฉ Main Technologies

Category Libraries
Framework Express 5
Language TypeScript
Database Mongoose
Auth JWT, bcrypt
Security Helmet, CORS, Rate Limiter, HPP
Logging Pino, Morgan
Testing Vitest, Supertest, MongoDB Memory Server
Docs Swagger JSDoc + Swagger UI
DI tsyringe

๐Ÿ“‚ Project Structure

src/
โ”œโ”€โ”€ main.ts         ๐Ÿ›๏ธ
โ”œโ”€โ”€ configs/        ๐Ÿ“„
โ”œโ”€โ”€ controllers/    ๐ŸŽฎ
โ”œโ”€โ”€ databases/      ๐Ÿ—ƒ๏ธ
โ”‚ โ””โ”€โ”€ mongoose.ts   ๐Ÿงบ
โ”œโ”€โ”€ dtos/
โ”œโ”€โ”€ interfaces/
โ”œโ”€โ”€ middlewares/    โš”๏ธ
โ”œโ”€โ”€ models/         ๐Ÿ˜๏ธ
โ”œโ”€โ”€ routes/         ๐Ÿ›ฃ๏ธ
โ”œโ”€โ”€ utils/          ๐Ÿ› ๏ธ
โ”œโ”€โ”€ constants.ts
โ”œโ”€โ”€ .env.test       ๐Ÿงช
โ”œโ”€โ”€ .env.production ๐Ÿš€
โ”œโ”€โ”€ .env.example
โ””โ”€โ”€ .env            ๐Ÿ—๏ธ

๐Ÿงฑ Architecture Overview

  • Controllers โ†’ Handle HTTP requests/responses.

  • Services / Modules โ†’ Business logic, injected via tsyringe.

  • Models โ†’ Mongoose schemas.

  • DTOs & Interfaces โ†’ Define TypeScript types and contracts.

  • Middlewares โ†’ Validation, Auth, Logging, Error handling.

  • Utils โ†’ Helpers (e.g., token generation, formatting).

Follows Clean Architecture principles with OOP and dependency injection.

๐Ÿ“‘ Scripts

Command Description
npm run dev Run development server with live reload
npm run build Compile TypeScript to dist
npm start Run compiled production server
npm test Run integration tests
npm run test:watch Run tests in watch mode
npm run prettier Format codebase
npm run clean Remove compiled files (dist/)

๐Ÿงช Testing

  • Run tests once
    • npm run test
  • Run tests in watch mode
    • npm run test:watch

๐Ÿ“– API Documentation

Swagger UI is available at: http://localhost:8080/api/docs

Automatically generated from JSDoc annotations using:

  • swagger-jsdoc

  • swagger-ui-express

๐Ÿ” Authentication Flow

  1. User registers (/api/v1/auth/register)

  2. User logs in and receives JWT token

  3. Token must be included in headers:

    • Authorization: Bearer
  4. Middleware verifies token and applies role-based access (e.g. EDIT_COLLECTION, DELETE_QUESTION)

๐Ÿค Contributing

Contributions, issues, and feature requests are welcome!
Feel free to open a pull request or issue.

  1. Fork the repo
  2. Create a new branch (feature/my-feature)
  3. Commit your changes
  4. Push to your branch
  5. Open a Pull Request ๐Ÿš€

๐Ÿ“œ Licence

MIT ยฉ 2025 @Garkatron

About

RESTful API built with TypeScript, Express, and Mongoose, following a clean MVC architecture. Includes authentication, authorization, and integration testing using Vitest and Supertest.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors