Skip to content

Mr-Raza-Alam/Yantraksh-Backend

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

A backend built with TypeScript, Express, Prisma (MongoDB), Mongoose, Zod, JWT, OOP architecture, and a clean module-based structure.

This README explains how the project works, how to contribute, and how to test it.

πŸ“ Project Structure Overview

The backend follows a strict, scalable Object-Oriented, Modular Architecture.

src
β”‚
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ database.ts                # DB config
|   β”œβ”€β”€ client.ts                  # Prisma client instance
β”‚
β”œβ”€β”€ core/
β”‚   β”œβ”€β”€ AppError.ts           # Custom error class
β”‚
β”œβ”€β”€ middlewares/
β”‚   β”œβ”€β”€ validate.ts           # Zod validation middleware
β”‚   β”œβ”€β”€ requireUser.ts        # JWT auth middleware
β”‚   β”œβ”€β”€ errorHandler.ts       # Global error handler
β”‚
β”œβ”€β”€ prisma/
β”‚   β”œβ”€β”€ schema.prisma         # Prisma MongoDB schema
β”‚
β”œβ”€β”€ mongoose(not yet implemented implement from schema)/
β”‚   β”œβ”€β”€ merch.model.ts        # Mongoose models (example)
β”‚   β”œβ”€β”€ ticket.model.ts
β”‚   β”œβ”€β”€ accommodation.model.ts
β”‚
β”œβ”€β”€ modules/
β”‚   β”œβ”€β”€ auth/                 # Prisma Module (OOP)
β”‚   β”‚   β”œβ”€β”€ auth.routes.ts
β”‚   β”‚   β”œβ”€β”€ auth.controller.ts
β”‚   β”‚   β”œβ”€β”€ auth.service.ts
β”‚   β”‚   β”œβ”€β”€ auth.repository.ts
β”‚   β”‚   β”œβ”€β”€ auth.validators.ts
β”‚   β”‚
|   |  (To be done)
β”‚   β”œβ”€β”€ merch/                # Mongoose Module (OOP)
β”‚   β”œβ”€β”€ ticket/
β”‚   β”œβ”€β”€ accommodation/
β”‚
β”œβ”€β”€ types/
β”‚   β”œβ”€β”€ user.ts
β”‚   β”œβ”€β”€ auth.ts
β”‚   β”œβ”€β”€ request.ts
β”‚
└── server.ts                 # App entry point

🧠 Architecture Philosophy (MUST FOLLOW)

This codebase follows strict Object-Oriented rules:

βœ” Each module has 4 layers:

  1. Repository β†’ DB operations (Prisma OR Mongoose)
  2. Service β†’ Business logic (classes ONLY)
  3. Controller β†’ Request/Response handling
  4. Routes β†’ Route definitions

βœ” No business logic inside controllers

βœ” No raw Prisma/Mongoose calls outside repositories

βœ” No validation inside services (Zod middleware handles that)

βœ” No any types β€” use strict TypeScript types

βœ” Prisma is used ONLY for:

  • Users
  • Authentication
  • Competition
  • Team
  • Participation

βœ” Mongoose is used ONLY for:

  • Merch
  • Tickets
  • Accommodation

βš™οΈ How to Run the Project

1. Install dependencies

npm install

2. Create a .env file in the root

PORT=5000
DATABASE_URL="YOUR_MONGODB_URI"
JWT_SECRET="YOUR_RANDOM_SECRET"

⚠️ REQUIRED:

  • Use your own MongoDB Atlas URL for DATABASE_URL
  • JWT_SECRET must be a long random string

3. Run Prisma Client Generator

npx prisma generate

4. Start the development server

npm run dev

If everything is correct, you'll see:

Mongoose connected
Prisma connected
 Server running on port 5000

πŸ§ͺ Testing With Postman (Add your tests here)

Here are the base endpoints:


βœ… 1. Register User

POST http://localhost:5000/auth/register

Body (JSON):

{
  "name": "Rohit",
  "email": "rohit@example.com",
  "password": "123456",
  "userType": "AUS_STUDENT",
  "rollNumber": "AUS2024B12",
  "department": "CSE",
  "year": 3
}

If NON_AUS:

{
  "name": "John",
  "email": "john@example.com",
  "password": "123456",
  "userType": "NON_AUS"
}

βœ… 2. Login User

POST http://localhost:5000/auth/login

Body:

{
  "email": "rohit@example.com",
  "password": "123456"
}

Response:

{
  "token": "<jwt_token>"
}

βœ… 3. Get Logged-in User

GET http://localhost:5000/auth/me

Headers:

Authorization: Bearer <token>

Response:

{
  "id": "66af...",
  "name": "Rohit",
  "email": "rohit@example.com",
  "userType": "AUS_STUDENT",
  "rollNumber": "AUS2024B12"
}

πŸ”¨ How to Add a New Module (OOP + Clean Architecture)

Example for a Mongoose module (merch):

  1. Create folder:
src/modules/merch/
  1. Add:
merch.repository.ts  β†’ DB logic (Mongoose)
merch.service.ts     β†’ Business class
merch.controller.ts  β†’ Controller class
merch.routes.ts      β†’ Routes
  1. Add model in:
src/mongoose/merch.model.ts
  1. Register route in server:
app.use("/merch", merchRoutes);

πŸ›‘ Rules for Contributors

  • ❌ Do NOT write raw DB logic inside controllers/services
  • ❌ Do NOT bypass Zod validation
  • ❌ Do NOT use any type

βœ” Every module must follow:

Repository β†’ Service β†’ Controller β†’ Routes


πŸŽ‰ Ready to Build

About

This is backend architecture to design a platform for Yantraksh(Tech Fest 2026) at Assam University,Silchar

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 96.1%
  • EJS 3.9%