A comprehensive backend API for managing Debating Society operations, including user management, session tracking, task assignment, and anonymous feedback systems.
- Features
- Tech Stack
- Quick Start
- API Documentation
- Project Structure
- Database Schema
- Authentication
- Testing
- Deployment
- Contributing
- TechHead: System administrator with user verification capabilities
- President: Society leader with task assignment and management powers
- Cabinet: Administrative members with attendance tracking and feedback abilities
- Member: Regular members with task and attendance viewing capabilities
- β User registration and authentication (JWT-based)
- β Role-based authorization with verification system
- β Task assignment and tracking
- β Session attendance management
- β Anonymous messaging to President
- β Anonymous feedback system for members
- β Session reports and analytics
- β Dashboard data for Presidents
- β CORS enabled for cross-origin requests
| Technology | Purpose |
|---|---|
| Node.js | Runtime environment |
| TypeScript | Type-safe development |
| Express.js | Web framework |
| Prisma 7 | Modern ORM with PostgreSQL adapter |
| PostgreSQL | Primary database |
| JWT | Authentication tokens |
| bcryptjs | Password hashing |
| CORS | Cross-origin resource sharing |
- Node.js 18 or higher
- PostgreSQL database
- npm or yarn package manager
-
Clone the repository
git clone https://github.com/mobi2400/Debsoc-Backend.git cd Debsoc-Backend -
Install dependencies
npm install
-
Set up environment variables
cp .env.example .env
Edit
.envwith your configuration:DATABASE_URL="postgresql://user:password@localhost:5432/debsoc" JWT_SECRET="your-super-secret-jwt-key-min-32-characters" PORT=3000 NODE_ENV=development
-
Generate Prisma Client
npm run prisma:generate
-
Run database migrations
npm run prisma:migrate
-
Create TechHead account (manual database insert required)
// Generate password hash const bcrypt = require('bcryptjs'); const hash = await bcrypt.hash('your-password', 10); console.log(hash);
INSERT INTO "TechHead" (id, name, email, password, "createdAt", "updatedAt") VALUES ( gen_random_uuid(), 'Tech Admin', 'techhead@debsoc.com', '<paste_hashed_password_here>', NOW(), NOW() );
-
Start development server
npm run dev
Server will be running at http://localhost:3000
http://localhost:3000/api
All protected endpoints require a JWT token in the Authorization header:
Authorization: Bearer <your-jwt-token>
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /login |
Public | Login TechHead |
| POST | /verify/president |
TechHead | Verify President account |
| POST | /verify/cabinet |
TechHead | Verify Cabinet account |
| POST | /verify/member |
TechHead | Verify Member account |
| GET | /unverified-users |
TechHead | Get all unverified users |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /register |
Public | Register new President |
| POST | /login |
Public | Login President |
| POST | /tasks/assign |
President (Verified) | Assign task to Cabinet/Member |
| POST | /feedback/give |
President (Verified) | Give feedback to Member |
| GET | /sessions |
President (Verified) | Get session reports |
| GET | /dashboard |
President (Verified) | Get dashboard data |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /register |
Public | Register new Cabinet member |
| POST | /login |
Public | Login Cabinet member |
| POST | /attendance/mark |
Cabinet (Verified) | Mark session attendance |
| GET | /tasks |
Cabinet (Verified) | Get assigned tasks |
| POST | /feedback/give |
Cabinet (Verified) | Give feedback to Member |
| GET | /sessions |
Cabinet (Verified) | Get session reports |
| POST | /messages/president |
Cabinet (Verified) | Send anonymous message to President |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /register |
Public | Register new Member |
| POST | /login |
Public | Login Member |
| GET | /attendance |
Member (Verified) | Get own attendance records |
| GET | /tasks |
Member (Verified) | Get assigned tasks |
| POST | /messages/president |
Member (Verified) | Send anonymous message to President |
| GET | /feedback |
Member (Verified) | Get received feedback |
curl -X POST http://localhost:3000/api/president/register \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "president@debsoc.com",
"password": "securepassword123"
}'curl -X POST http://localhost:3000/api/president/login \
-H "Content-Type: application/json" \
-d '{
"email": "president@debsoc.com",
"password": "securepassword123"
}'curl -X POST http://localhost:3000/api/president/tasks/assign \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <your-jwt-token>" \
-d '{
"name": "Prepare debate motion",
"description": "Research and prepare motion for next session",
"deadline": "2025-11-30T18:00:00Z",
"assignedToMemberId": "<member-id>"
}'Debsoc-Backend/
βββ src/
β βββ controllers/ # Business logic
β β βββ techHead.controller.ts
β β βββ president.controller.ts
β β βββ cabinet.controller.ts
β β βββ member.controller.ts
β βββ routes/ # API route definitions
β β βββ techHead.routes.ts
β β βββ president.routes.ts
β β βββ cabinet.routes.ts
β β βββ member.routes.ts
β βββ middleware/ # Custom middleware
β β βββ auth.middleware.ts
β βββ types/ # TypeScript type definitions
β β βββ express.d.ts
β βββ lib/ # Utilities
β β βββ prisma.ts
β βββ prisma/ # Database
β β βββ schema.prisma
β βββ prisma.config.ts # Prisma configuration
β βββ index.ts # Application entry point
βββ .env.example # Environment variables template
βββ package.json
βββ tsconfig.json
βββ AI_RULES.md # AI development guidelines
βββ API_TESTING_GUIDE.md # Testing instructions
βββ DEPLOYMENT_GUIDE.md # Deployment instructions
βββ CODEBASE_ANALYSIS.md # Architecture documentation
βββ Debsoc_API_Collection.postman_collection.json
- TechHead: System administrators
- President: Society presidents
- Cabinet: Cabinet members
- Member: Regular members
- Session: Debate/meeting sessions
- Attendance: Member attendance records
- Task: Assigned tasks
- AnonymousMessage: Anonymous messages to President
- AnonymousFeedback: Anonymous feedback to Members
TechHead ββverifiesββ> President, Cabinet, Member
President ββassignsββ> Task ββtoββ> Cabinet, Member
President ββgivesββ> AnonymousFeedback ββtoββ> Member
Cabinet ββgivesββ> AnonymousFeedback ββtoββ> Member
Cabinet ββmarksββ> Attendance ββforββ> Member
Cabinet/Member ββsendsββ> AnonymousMessage ββtoββ> President
{
"id": "user-uuid",
"email": "user@example.com",
"role": "President|Cabinet|Member|TechHead",
"isVerified": true|false,
"iat": 1234567890,
"exp": 1234567890
}- User registers β Receives JWT token (unverified)
- TechHead verifies user β User status updated
- User logs in again β Receives new JWT with verified status
- User can access protected routes
Request β authMiddleware β authorizeRoles β requireVerification β Controller
Import Debsoc_API_Collection.postman_collection.json into Postman for complete API testing.
See API_TESTING_GUIDE.md for detailed step-by-step testing instructions.
# Health check
curl http://localhost:3000/
# Test CORS
curl -H "Origin: http://example.com" \
-H "Access-Control-Request-Method: POST" \
-H "Access-Control-Request-Headers: Content-Type" \
-X OPTIONS \
http://localhost:3000/api/president/register| Script | Description |
|---|---|
npm run dev |
Start development server with hot reload |
npm run build |
Compile TypeScript to JavaScript |
npm start |
Run production server |
npm run format |
Format code with Prettier |
npm run format:check |
Check code formatting |
npm run prisma:generate |
Generate Prisma Client |
npm run prisma:migrate |
Run database migrations |
npm run prisma:studio |
Open Prisma Studio GUI |
npm run prisma:push |
Push schema changes to database |
See DEPLOYMENT_GUIDE.md for comprehensive deployment instructions.
- Render - Easy deployment with PostgreSQL
- Railway - Auto-deployment from GitHub
- Heroku - Classic PaaS with addons
- DigitalOcean - App Platform with databases
- Update CORS to specific domains
- Set strong JWT_SECRET
- Use production database
- Enable HTTPS
- Add rate limiting
- Configure logging
- Set up monitoring
| Variable | Description | Required | Default |
|---|---|---|---|
DATABASE_URL |
PostgreSQL connection string | Yes | - |
JWT_SECRET |
Secret key for JWT tokens | Yes | - |
PORT |
Server port | No | 3000 |
NODE_ENV |
Environment mode | No | development |
ALLOWED_ORIGINS |
CORS allowed origins | No | * |
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Follow TypeScript best practices
- Maintain type safety
- Write meaningful commit messages
- Update documentation for new features
- Test all endpoints before committing
ISC
- mobi2400 - GitHub
- Express.js team for the excellent web framework
- Prisma team for the modern ORM
- TypeScript team for type safety
Built with β€οΈ for the Debating Society
For detailed documentation, see: