Skip to content

lucaf1990/effect-mongodb-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Effect.ts MongoDB Application

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.

πŸš€ Features

  • 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

πŸ“ Project Structure

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

πŸ› οΈ Prerequisites

  • Node.js (v18 or higher)
  • MongoDB (local or cloud instance)
  • npm or yarn package manager

πŸ“¦ Installation

  1. Clone the repository:

    git clone <repository-url>
    cd effect-mongodb-app
  2. Install dependencies:

    npm install
  3. Set up environment variables: Create a .env file 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
  4. Start MongoDB: Make sure MongoDB is running on your system or configure a cloud MongoDB connection.

πŸš€ Getting Started

Development Mode

npm run dev

Build for Production

npm run build

Start Production Server

npm start

πŸ“š API Endpoints

Authentication

  • POST /api/people/signup - Create new account
  • POST /api/people/signin - Sign in to account
  • POST /api/people/verify-token - Verify email token
  • POST /api/people/invalidate - Invalidate refresh token

Account Management

  • GET /api/people/:accountId - Get account by ID
  • PATCH /api/people/:accountId - Update account
  • GET /api/people/verified/:accountId - Check if account is verified
  • GET /api/people/my-account - Get current user account
  • GET /api/people/all/:accountId - Get all accounts (admin)

πŸ”§ Configuration

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

πŸ›‘οΈ Security Features

  • 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

πŸ§ͺ Testing

# Run tests
npm test

# Run tests in watch mode
npm run test:watch

# Run tests with coverage
npm run test:coverage

πŸ“ Development Scripts

# 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-check

πŸ” Code Quality

This project uses:

  • ESLint: For code linting and consistency
  • Prettier: For code formatting
  • TypeScript: For type safety
  • Effect.ts: For functional programming patterns

πŸ“– Effect.ts 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

πŸš€ Deployment

Using Docker

# Build and run with Docker
docker build -t effect-mongodb-app .
docker run -p 3000:3000 effect-mongodb-app

Using PM2

# Install PM2
npm install -g pm2

# Start with PM2
pm2 start dist/index.js --name "effect-app"

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“ž Support

If you have any questions or need help, please:

  1. Check the documentation
  2. Search existing issues
  3. Create a new issue if needed

Happy coding! πŸŽ‰

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors