This project demonstrates advanced software architecture concepts, focusing on Domain-Driven Design (DDD) principles, Clean Architecture, and functional error handling using the Either pattern. The project is implemented with TypeScript, Node.js, NestJS, and follows test-driven development practices using Vitest.
- Domain-Driven Design (DDD) principles
- Clean Architecture implementation
- Functional error handling with Either pattern (Left/Right)
- TypeScript with Node.js and NestJS
- Test-driven development using Vitest
- JWT Authentication using RS256 with public/private keys
- Prisma ORM for database access
- AWS S3 integration for file storage
- OpenAPI documentation available at
/apiendpoint
- Aggregate patterns
- Value Objects
- Domain Events with Pub/Sub patterns
- Subdomain organization
- In-memory repositories for testing
- SOLID principles implementation:
- Single Responsibility Principle (SRP)
- Interface Segregation Principle (ISP)
- Dependency Inversion Principle (DIP)
- JWT authentication and authorization
- Data validation with Zod
- RESTful API design
Based on the project's folder structure, it follows a well-organized architecture:
Contains foundational elements used throughout the application:
- Either pattern implementation for functional error handling
- Domain events infrastructure
- Generic entity implementations
- Base repository interfaces
Contains the core business logic organized into subdomains:
-
Enterprise: Contains domain entities and business rules
- Entities:
Question,Answer,Student,QuestionComment,AnswerComment - Value objects:
Slug,QuestionDetails,AnswerWithAuthor - Entity lists:
QuestionAttachmentList,AnswerAttachmentList
- Entities:
-
Application: Contains use cases and domain services
- Use cases:
CreateQuestion,AnswerQuestion,EditQuestion,DeleteQuestion,ChooseQuestionBestAnswer, etc. - Repository interfaces defining domain persistence contracts
- Cryptography interfaces for domain security concerns
- Use cases:
- Notification-related entities and services
- Subscribers for handling domain events
Contains implementation details and technical concerns:
- JWT Strategy: Implements authentication using RS256 with public/private keys
- Guards: Protects routes requiring authentication
- Decorators: Simplifies access to authenticated user information
- Controllers: RESTful API endpoints mapped to use cases
- Presenters: Data transformation for API responses
- Pipes: Request validation using Zod schemas
- Prisma ORM implementation for database access
- Repository implementations
- JWT implementation for token generation and validation
- Bcrypt implementation for password hashing
- AWS S3 integration for file uploads and attachments
- Configuration management with environment variables
The project implements a robust JWT authentication mechanism:
- RS256 Algorithm: Uses asymmetric public/private key pairs for enhanced security
- Passport Integration: NestJS Passport module with JWT strategy
- Global Guard: Automatically protects all endpoints with opt-out for public routes
- Token Payload Validation: Uses Zod schema to validate token structure
- Private/Public Key Management: Keys stored as Base64-encoded environment variables
The project employs a comprehensive testing approach:
- Unit Tests: For domain logic and use cases using in-memory repositories
- E2E Tests: For API endpoints with supertest
- Test Factories: For consistent entity creation in tests
- Repository Doubles: In-memory implementations for testing
- Node.js
- TypeScript
- Docker (for PostgreSQL database)
-
Clone the repository:
git clone https://github.com/235471/Forum.git cd your-repo-name -
Install dependencies:
npm install
-
Set up environment variables:
- Create a
.envfile based on.env.example - Generate public and private keys for JWT authentication
- Create a
-
Start the database:
docker-compose up -d
- Run Prisma migrations:
npx prisma migrate dev
The project uses Vitest for test-driven development:
# Run unit tests
npm test
# Run tests in watch mode
npm run test:watch
# Run e2e tests
npm run test:e2e