A scalable, modular, and production-grade backend system for ChainVerse Academy, built with NestJS and designed using clean architecture principles, domain separation, and enterprise-ready patterns.
This project represents a full architectural migration from Express.js to NestJS, aimed at transforming a flexible but loosely structured codebase into a highly maintainable, testable, and scalable system.
The backend is designed to support a modern learning platform with features such as:
- User authentication & role management
- Course creation and enrollment
- Certification and achievements
- Gamification systems
- Financial aid workflows
- Analytics and reporting
- Notifications and communication systems
Moving to NestJS enables:
- Clear modular boundaries → easier to scale teams and features
- Dependency Injection (DI) → better testability and loose coupling
- Consistent architecture → predictable code organization
- Built-in best practices → guards, interceptors, pipes, etc.
- Future microservice readiness
| Layer | Technology | Purpose |
|---|---|---|
| Framework | NestJS | Backend architecture |
| Language | TypeScript | Type safety & maintainability |
| Authentication | JWT (Access + Refresh Tokens) | Secure user sessions |
| Validation | class-validator / class-transformer | DTO validation |
| ORM | Prisma / TypeORM | Database abstraction |
| Database | PostgreSQL | Relational data storage |
| Caching | Redis (optional) | Performance optimization |
| Documentation | Swagger | API exploration |
| Storage | Local / S3-compatible | File uploads |
The system follows a feature-based modular architecture, where each domain is isolated and self-contained.
src/
│
├── auth/ # Authentication & JWT logic
├── users/ # Core user management
├── tutor-settings/ # Tutor-specific configurations
├── student-settings/ # Student preferences
├── admin-settings/ # Admin/moderator controls
├── courses/ # Course creation & management
├── reviews/ # Ratings & feedback
├── leaderboard/ # Ranking system
├── gamification/ # Points, badges, rewards
├── certification/ # Certificates & verification
├── financial-aid/ # Aid application system
├── reports/ # Analytics & reporting
├── notification/ # Email / in-app notifications
├── organization/ # Institutional management
├── subscription-plan/ # Plans & billing logic
├── session/ # Session tracking
└── common/ # Shared utilities & helpers
Each module follows a consistent internal structure:
module/
├── module.module.ts # Module definition
├── module.controller.ts # Route handlers (thin layer)
├── module.service.ts # Business logic
├── dto/ # Data Transfer Objects (validation)
├── entities/ # Database models / schemas
└── guards/ # Route protection logic
- Separation of concerns (Controller vs Service vs Data)
- Single Responsibility Principle
- Domain-driven structure
- Reusable shared utilities in
common/
The system uses JWT-based authentication with support for access and refresh tokens.
-
User logs in → receives:
- Access Token (short-lived)
- Refresh Token (long-lived)
-
Access token is used for API requests
-
Refresh token is used to issue new access tokens
Supported roles:
ADMINMODERATORTUTORSTUDENT
JwtAuthGuard→ validates authenticated usersRolesGuard→ enforces role-based permissions
- Multi-role authentication (Admin, Tutor, Student)
- Profile management per role
- Secure session handling
- Course creation & categorization
- Advanced filtering & search
- Reviews, ratings, and feedback
- Course analytics & reporting
- Points accumulation system
- Leaderboards (ranking users)
- Achievement badges
- NFT-based rewards (extensible)
- Certificate generation
- Download & verification
- Social sharing capabilities
- Controlled name-change request flow
- Student application workflow
- Admin review system
- Approval/rejection lifecycle
- Tutor performance insights
- Student progress tracking
- Course-level analytics
- Notifications (email/in-app ready)
- FAQ & legal pages
- Contact & messaging system
- Organization management
- Subscription plans
- Abuse reporting & moderation
# Clone repository
git clone https://github.com/your-username/chainverse-backend.git
# Enter project directory
cd chainverse-backend
# Install dependencies
npm installCreate a .env file in the root directory:
PORT=3000
DATABASE_URL=postgresql://user:password@localhost:5432/chainverse
JWT_SECRET=your_access_secret
JWT_REFRESH_SECRET=your_refresh_secret
💡 Tip: Use strong secrets and never commit
.envto version control.
# Development (watch mode)
npm run start:dev
# Build for production
npm run build
# Run production server
npm run start:prodAfter starting the server:
http://localhost:3000/api
This provides:
- Interactive API testing
- Request/response schemas
- Authentication support
# Unit tests
npm run test
# End-to-end tests
npm run test:e2e- Services should be unit tested
- Critical flows should have e2e coverage
- Mock external dependencies where needed
This migration was not just a rewrite—it was a system redesign focused on:
- Long-term maintainability
- Predictable development patterns
- Improved onboarding for new developers
- Scalability toward microservices
To maintain consistency across the codebase:
- ✅ Keep controllers thin (no business logic)
- ✅ Place logic inside services
- ✅ Use DTOs for all inputs
- ✅ Validate all external data
- ✅ Protect routes with guards
- ✅ Document endpoints with Swagger decorators
- ✅ Follow SOLID principles
Planned enhancements include:
- Microservices architecture (gRPC / Redis / RMQ)
- Real-time features (WebSockets)
- Blockchain/NFT integrations
- Payment gateway integration
- CI/CD pipelines
- Docker & container orchestration
We welcome contributions! Follow these steps:
- Fork the repository
- Create a feature branch (
feat/your-feature) - Follow coding and architectural standards
- Add validation and documentation
- Submit a Pull Request
- Must follow NestJS best practices
- Must include DTO validation
- Must include Swagger docs
- Must pass all tests
MIT License