Skip to content

KshitijChavan-Stack/authflow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AuthFlow πŸ”

A production-ready Authentication & Authorization microservice built with Node.js, Express, MongoDB, and Redis.

Features

Phase 1: Core Authentication (Current)

  • βœ… User registration with email verification
  • βœ… Secure login with JWT tokens
  • βœ… Refresh token rotation
  • βœ… Password reset flow
  • βœ… User profile management
  • βœ… Account lockout after failed login attempts
  • βœ… Rate limiting and security headers

Phase 2: Advanced Features (Planned)

  • πŸ”„ OAuth integration (Google, GitHub)
  • πŸ”„ Two-factor authentication (TOTP)
  • πŸ”„ Role-based access control (RBAC)
  • πŸ”„ Session management
  • πŸ”„ Enhanced security features

Phase 3: Production Ready (Planned)

  • πŸ”„ Client SDK
  • πŸ”„ Admin dashboard API
  • πŸ”„ Comprehensive testing
  • πŸ”„ Docker containerization
  • πŸ”„ CI/CD pipeline

Tech Stack

  • Runtime: Node.js v18+ (ES Modules)
  • Framework: Express.js
  • Database: MongoDB with Mongoose
  • Cache: Redis (IORedis)
  • Authentication: JWT, bcrypt
  • Validation: Joi
  • Email: Nodemailer
  • Logging: Winston
  • Security: Helmet, express-rate-limit

πŸ“‹ Prerequisites

  • Node.js v18 or higher
  • Docker Desktop (for MongoDB and Redis)
  • Git

Getting Started

1. Clone the repository

git clone https://github.com/YOUR_USERNAME/authflow.git
cd authflow

2. Install dependencies

npm install

3. Set up environment variables

Copy .env.example to .env and update the values:

cp .env.example .env

4. Start MongoDB and Redis with Docker

docker compose up -d

Verify containers are running:

docker ps

5. Test the setup

node test-setup.js

You should see:

βœ… MongoDB connected successfully
βœ… Redis connected successfully

6. Start the development server

npm run dev

The API will be available at http://localhost:5000

πŸ“ Project Structure

authflow/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ config/          # Database and Redis configuration
β”‚   β”œβ”€β”€ models/          # Mongoose schemas
β”‚   β”œβ”€β”€ repositories/    # Database operations
β”‚   β”œβ”€β”€ services/        # Business logic
β”‚   β”œβ”€β”€ controllers/     # Route handlers
β”‚   β”œβ”€β”€ middlewares/     # Auth, validation, error handling
β”‚   β”œβ”€β”€ routes/          # API routes
β”‚   β”œβ”€β”€ validators/      # Request validation schemas
β”‚   β”œβ”€β”€ utils/           # Utility functions
β”‚   β”œβ”€β”€ app.js           # Express app setup
β”‚   └── server.js        # Server entry point
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ unit/            # Unit tests
β”‚   └── integration/     # Integration tests
β”œβ”€β”€ logs/                # Application logs
β”œβ”€β”€ .env                 # Environment variables (not in git)
β”œβ”€β”€ .env.example         # Environment variables template
β”œβ”€β”€ docker-compose.yml   # Docker services configuration
└── package.json

πŸ”Œ API Endpoints (Coming Soon)

Authentication

POST   /api/v1/auth/register          - Register new user
POST   /api/v1/auth/verify-email      - Verify email
POST   /api/v1/auth/resend-verification - Resend verification email
POST   /api/v1/auth/login             - Login user
POST   /api/v1/auth/refresh           - Refresh access token
POST   /api/v1/auth/logout            - Logout user
POST   /api/v1/auth/forgot-password   - Request password reset
POST   /api/v1/auth/reset-password    - Reset password

User Management

GET    /api/v1/user/profile           - Get user profile
PUT    /api/v1/user/profile           - Update user profile
PUT    /api/v1/user/password          - Change password
DELETE /api/v1/user/account           - Delete account

πŸ§ͺ Testing

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

🐳 Docker Commands

# Start services
docker compose up -d

# Stop services
docker compose down

# View logs
docker compose logs -f

# Connect to MongoDB shell
docker exec -it authflow_mongodb mongosh -u admin -p password123

# Connect to Redis CLI
docker exec -it authflow_redis redis-cli

πŸ”’ Security Features

  • Password hashing with bcrypt
  • JWT-based authentication
  • Refresh token rotation
  • Account lockout after failed attempts
  • Rate limiting on all endpoints
  • Security headers with Helmet
  • Input validation with Joi
  • Email verification required
  • Secure password reset flow

πŸ“ Environment Variables

See .env.example for all available configuration options.

🀝 Contributing

This is a learning project. Feel free to fork and experiment!

License

MIT License - feel free to use this project for learning purposes.

Author

Kshitij Chavan

Acknowledgments

  • Built as a portfolio project to demonstrate backend development skills
  • Inspired by modern authentication best practices

Status: 🚧 Work in Progress - Phase 1 (Core Authentication) in development


---

## Step 2: Update .gitignore

Make sure your `.gitignore` is complete:

Dependencies

node_modules/ package-lock.json yarn.lock

Environment variables

.env .env.local .env.*.local

Logs

logs/ .log npm-debug.log yarn-debug.log* yarn-error.log*

OS files

.DSStore .DS_Store? .* .Spotlight-V100 .Trashes

IDE

.vscode/ .idea/ _.swp _.swo *~

Testing

coverage/ .nyc_output/

Build

dist/ build/

Docker

.docker/

About

Production-ready Authentication & Authorization Microservice

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published