A comprehensive monorepo starter for authentication, multi-factor authentication (MFA), session management, and modern full-stack development using MongoDB, Express, React, Next.js, and Node.js. This project is production-ready, fully documented, and designed for rapid prototyping and scalable deployments.
- Project Structure
- Features
- Setup & Installation
- Environment Variables
- Scripts
- Backend (Express/Node)
- Frontend (React/Vite)
- Frontend (Next.js)
- Authentication & MFA
- Session Management
- Logging & Monitoring
- API Documentation (Swagger/OpenAPI)
- Rate Limiting & Security
- Database
- Testing
- Deployment
- Contributing
- Troubleshooting
- License
├── apps/
│ ├── client/
│ │ ├── web-react/ # React + Vite SPA
│ │ └── web-next/ # Next.js SSR/SSG app
│ └── server/ # Express + TypeScript backend
├── package.json # Monorepo root scripts
├── README.md # Project documentation
└── ...
- Full-stack authentication (register, login, password reset)
- Multi-factor authentication (MFA) with TOTP
- Session management (view, revoke, device tracking)
- Role-based access (extensible)
- Rate limiting (global, auth, sensitive)
- Centralized logging (Winston + Better Stack)
- API documentation (OpenAPI/Swagger)
- Environment-driven config
- Health check endpoint
- Modern UI (Tailwind, shadcn/ui)
- React (SPA) and Next.js (SSR/SSG) clients
- TypeScript everywhere
- Production-ready scripts
- Clone the repo:
git clone <repo-url> cd authly-mern
- Install dependencies:
npm install --workspaces
- Configure environment variables:
- Copy
.env.exampleto.envin each app and fill out required values.
- Copy
- Run all apps in development:
npm run dev
- React: http://localhost:5173
- Next.js: http://localhost:3000
- Backend: http://localhost:8000
See .env.example in each app for all required variables. Key backend variables:
PORT,NODE_ENV,APP_ORIGIN,BASE_PATH,MONGO_URI,JWT_SECRET,JWT_REFRESH_SECRET,RESEND_API_KEY,MAILER_SENDER,LOGTAIL_SOURCE_TOKEN,LOGTAIL_INGEST_ENDPOINT,RATE_LIMIT_*,SWAGGER_UI_ENABLED
npm run dev— Start all apps in dev modenpm run build— Build all appsnpm run start— Start backend in productionnpm run typecheck— Type-check all appsnpm run lint— Lint all codenpm run format— Format codebase
- Located in
apps/server - REST API with endpoints for auth, mfa, session
- Centralized error handling
- JWT authentication
- Passport.js integration
- Rate limiting via
express-rate-limit - Logging via Winston and Better Stack (Logtail)
- Swagger UI at
/docs(if enabled) - Health check at
/
- Located in
apps/client/web-react - SPA with modern UI (Tailwind, shadcn/ui)
- React Query for data fetching
- Authentication flows (register, login, password reset, MFA)
- Session management UI
- Environment-driven config
- Located in
apps/client/web-next - SSR/SSG app with Next.js 14+
- Modern UI (Tailwind, shadcn/ui)
- Middleware for route protection
- Authentication and MFA flows
- Session management
- Register, login, password reset endpoints
- Email verification
- MFA setup, verify, revoke endpoints
- TOTP-based MFA (compatible with Google Authenticator, Authy, etc.)
- View active sessions
- Revoke sessions
- Device/user agent tracking
- Winston logger with console, file, and Logtail transports
- Sensitive data redaction
- Logtail integration for Better Stack
- Health and error logs
- OpenAPI 3.1 YAML spec in
apps/server/src/docs/openapi.yml - Swagger UI at
/docs(if enabled) - All endpoints documented
- Global, auth, and sensitive rate limiters
- Configurable via environment variables
- Centralized error handling
- CORS configuration for multiple origins
- MongoDB (Atlas or local)
- Mongoose models for User, Session, VerificationCode
- Connection managed in
apps/server/src/database/database.ts
- Type-checking via TypeScript
- Linting via ESLint
- Prettier for formatting
- (Add unit/integration tests as needed)
- Backend: Deployable to any Node.js host (Heroku, Vercel, AWS, etc.)
- React: Deployable to Vercel, Netlify, or any static host
- Next.js: Deployable to Vercel (recommended)
- Environment variables required for production
- Fork the repo and create a feature branch
- Follow code style and commit guidelines
- Submit PRs with clear descriptions
- All contributions welcome!
- CORS errors: Ensure backend allows your frontend origin in CORS config
- Database errors: Check
MONGO_URIand database connectivity - Logtail issues: Verify
LOGTAIL_SOURCE_TOKENand endpoint - Port conflicts: Change ports in
.envfiles as needed - Build errors: Run
npm run typecheckandnpm run lintfor diagnostics
This project is licensed under the ISC License. See LICENSE for details.
For questions or support, open an issue or contact the maintainer.