A comprehensive TypeScript application built with Effect.ts, MongoDB, and modern web development patterns. This application provides a robust account management system with authentication, authorization, and RESTful API endpoints.
- Effect.ts Integration: Leverages the powerful Effect.ts library for functional programming and error handling
- MongoDB Database: Full MongoDB integration with repositories pattern
- Authentication & Authorization: JWT-based authentication with role-based access control
- Account Management: Complete user account system with email verification
- RESTful API: HTTP API with comprehensive endpoints and middleware
- Type Safety: Full TypeScript implementation with strict type checking
- Email Service: Integrated email notifications and verification
- Security: Password hashing with Argon2, secure token management
- Validation: Schema validation using Effect.ts schemas
- Error Handling: Comprehensive error handling and validation
- Development Tools: ESLint, Prettier, and development tooling
src/
├── account/
│ ├── api/ # API endpoints and handlers
│ ├── policies/ # Authorization policies
│ ├── repositories/ # Data access layer
│ ├── schemas/ # Account-related schemas
│ └── services/ # Business logic services
├── authentication/
│ ├── schemas/ # Auth-related schemas
│ ├── authentication.ts # Auth middleware
│ └── authorization.ts # Authorization logic
├── config/
│ ├── db.ts # Database configuration
│ └── layer.ts # Effect layers
├── configuration/
│ └── configurationService.ts # App configuration
├── crypto/
│ ├── errors/ # Crypto-related errors
│ ├── schemas/ # Crypto schemas
│ └── services/ # Cryptographic services
├── email/
│ └── emailService.ts # Email functionality
├── schemas/
│ └── common/ # Shared schemas
├── templates/ # HTML email templates
└── index.ts # Application entry point
- Node.js (v18 or higher)
- MongoDB (local or cloud instance)
- npm or yarn package manager
-
Clone the repository:
git clone <repository-url> cd effect-mongodb-app
-
Install dependencies:
npm install
-
Set up environment variables: Create a
.envfile in the root directory:# Database MONGODB_URI=mongodb://localhost:27017/your-database # JWT Secrets JWT_ACCESS_SECRET=your-access-token-secret JWT_REFRESH_SECRET=your-refresh-token-secret # Email Configuration EMAIL_HOST=smtp.gmail.com EMAIL_PORT=587 EMAIL_USER=your-email@gmail.com EMAIL_PASS=your-app-password # App Configuration PORT=3000 NODE_ENV=development
-
Start MongoDB: Make sure MongoDB is running on your system or configure a cloud MongoDB connection.
npm run devnpm run buildnpm startPOST /api/people/signup- Create new accountPOST /api/people/signin- Sign in to accountPOST /api/people/verify-token- Verify email tokenPOST /api/people/invalidate- Invalidate refresh token
GET /api/people/:accountId- Get account by IDPATCH /api/people/:accountId- Update accountGET /api/people/verified/:accountId- Check if account is verifiedGET /api/people/my-account- Get current user accountGET /api/people/all/:accountId- Get all accounts (admin)
The application uses a layered configuration approach with Effect.ts:
- Database Layer: MongoDB connection and configuration
- Service Layers: Individual service configurations
- Authentication Layer: JWT and security settings
- Email Layer: SMTP and email template configuration
- Password Hashing: Uses Argon2 for secure password storage
- JWT Tokens: Access and refresh token authentication
- Input Validation: Comprehensive schema validation
- Authorization: Role-based access control
- Rate Limiting: Built-in request rate limiting
- Error Sanitization: Secure error messages
# Run tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage# Format code with Prettier
npm run format
# Lint code with ESLint
npm run lint
# Fix linting issues
npm run lint:fix
# Type checking
npm run type-checkThis project uses:
- ESLint: For code linting and consistency
- Prettier: For code formatting
- TypeScript: For type safety
- Effect.ts: For functional programming patterns
This application demonstrates several Effect.ts patterns:
- Services: Dependency injection and service layers
- Repositories: Data access with Effect.ts
- Error Handling: Comprehensive error management
- Validation: Schema-based validation
- Middleware: HTTP middleware with Effect.ts
- Authentication: Effect.ts authentication patterns
# Build and run with Docker
docker build -t effect-mongodb-app .
docker run -p 3000:3000 effect-mongodb-app# Install PM2
npm install -g pm2
# Start with PM2
pm2 start dist/index.js --name "effect-app"- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Effect.ts - For the powerful functional programming library
- MongoDB - For the database solution
- TypeScript - For type safety
- Node.js - For the runtime environment
If you have any questions or need help, please:
- Check the documentation
- Search existing issues
- Create a new issue if needed
Happy coding! 🎉