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