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.
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
This codebase follows strict Object-Oriented rules:
- Repository β DB operations (Prisma OR Mongoose)
- Service β Business logic (classes ONLY)
- Controller β Request/Response handling
- Routes β Route definitions
- Users
- Authentication
- Competition
- Team
- Participation
- Merch
- Tickets
- Accommodation
npm installPORT=5000
DATABASE_URL="YOUR_MONGODB_URI"
JWT_SECRET="YOUR_RANDOM_SECRET"
- Use your own MongoDB Atlas URL for
DATABASE_URL JWT_SECRETmust be a long random string
npx prisma generatenpm run devIf everything is correct, you'll see:
Mongoose connected
Prisma connected
Server running on port 5000
Here are the base endpoints:
POST
http://localhost:5000/auth/register
{
"name": "Rohit",
"email": "rohit@example.com",
"password": "123456",
"userType": "AUS_STUDENT",
"rollNumber": "AUS2024B12",
"department": "CSE",
"year": 3
}{
"name": "John",
"email": "john@example.com",
"password": "123456",
"userType": "NON_AUS"
}POST
http://localhost:5000/auth/login
{
"email": "rohit@example.com",
"password": "123456"
}{
"token": "<jwt_token>"
}GET
http://localhost:5000/auth/me
Authorization: Bearer <token>
{
"id": "66af...",
"name": "Rohit",
"email": "rohit@example.com",
"userType": "AUS_STUDENT",
"rollNumber": "AUS2024B12"
}Example for a Mongoose module (merch):
- Create folder:
src/modules/merch/
- Add:
merch.repository.ts β DB logic (Mongoose)
merch.service.ts β Business class
merch.controller.ts β Controller class
merch.routes.ts β Routes
- Add model in:
src/mongoose/merch.model.ts
- Register route in server:
app.use("/merch", merchRoutes);- β Do NOT write raw DB logic inside controllers/services
- β Do NOT bypass Zod validation
- β Do NOT use
anytype
Repository β Service β Controller β Routes