A NestJS-based backend application for managing archery tournaments, users, and authentication. Built with TypeScript, PostgreSQL, and MikroORM.
- Authentication: JWT-based authentication with Google OAuth support
- User Management: User registration, login, password reset functionality, password change
- Tournament Management: Create and manage archery tournaments with multiple applications support
- Application System: Tournament applications with deadline management and category-based restrictions
- Email Integration: Password reset and notification emails
- Database: PostgreSQL with MikroORM for type-safe database operations
- API: RESTful API with comprehensive endpoints
- Code Quality: Pre-commit hooks with ESLint and Prettier
Before running this application, make sure you have the following installed:
- Node.js (v18 or higher)
- pnpm (recommended) or npm
- Docker and Docker Compose (for database)
- PostgreSQL (if not using Docker)
-
Clone the repository
git clone <repository-url> cd archery-app-backend
-
Install dependencies
pnpm install
-
Set up environment variables Create a
.env
file in the root directory with the following variables:# Database Configuration DATABASE_HOST=localhost DATABASE_PORT=5432 DATABASE_USER=archery_user DATABASE_PASSWORD=archery_password DATABASE_NAME=archery_db # JWT Configuration JWT_SECRET=your-super-secret-jwt-key # Google OAuth Configuration GOOGLE_CLIENT_ID=your-google-client-id GOOGLE_CLIENT_SECRET=your-google-client-secret GOOGLE_CALLBACK_URL=http://localhost:3000/auth/google/callback # Application URLs FRONTEND_URL=http://localhost:5173 BACKEND_URL=http://localhost:3000 # Server Configuration PORT=3000 NODE_ENV=development
-
Start the PostgreSQL database
docker-compose up -d
-
Verify the database is running
docker-compose ps
If you prefer to use a local PostgreSQL installation:
- Create a database named
archery_db
- Create a user
archery_user
with passwordarchery_password
- Grant necessary permissions to the user
-
Start the development server
pnpm run start:dev
The application will be available at
http://localhost:3000
-
With debugging enabled
pnpm run start:debug
-
Build the application
pnpm run build
-
Start the production server
pnpm run start:prod
-
Generate a new migration (when you modify entities)
pnpm run mikro-orm migration:create
-
Run pending migrations
pnpm run mikro-orm migration:up
-
Check migration status
pnpm run mikro-orm migration:list
-
Revert the last migration
pnpm run mikro-orm migration:down
# Create a new migration
pnpm run mikro-orm migration:create
# Run all pending migrations
pnpm run mikro-orm migration:up
# Run migrations up to a specific version
pnpm run mikro-orm migration:up --to=Migration20241119213454
# Revert the last migration
pnpm run mikro-orm migration:down
# List all migrations and their status
pnpm run mikro-orm migration:list
# Show pending migrations
pnpm run mikro-orm migration:pending
pnpm run test
pnpm run test:e2e
pnpm run test:cov
pnpm run test:watch
pnpm run format
pnpm run lint
pnpm run build
src/
βββ auth/ # Authentication module
β βββ controllers/ # Auth controllers
β βββ services/ # Auth services
β βββ guards/ # JWT and role guards
β βββ strategies/ # Passport strategies
β βββ dto/ # Auth DTOs
βββ user/ # User management module
β βββ entity/ # User entity
β βββ controllers/ # User controllers
β βββ services/ # User services
β βββ dto/ # User DTOs
βββ tournament/ # Tournament management module
β βββ entity/ # Tournament entities
β βββ controllers/ # Tournament controllers
β βββ services/ # Tournament services
β βββ dto/ # Tournament DTOs
βββ email/ # Email service module
βββ config/ # Configuration files
βββ migrations/ # Database migrations
βββ main.ts # Application entry point
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Enable the Google+ API
- Create OAuth 2.0 credentials
- Add your redirect URI:
http://localhost:3000/auth/google/callback
- Update your
.env
file with the client ID and secret
For detailed setup instructions, see docs/GOOGLE_OAUTH_SETUP.md
Configure your email service for password reset functionality. See docs/EMAIL_SETUP.md for detailed instructions.
Make sure to update your environment variables for production:
NODE_ENV=production
DATABASE_HOST=your-production-db-host
DATABASE_PORT=5432
DATABASE_USER=your-production-db-user
DATABASE_PASSWORD=your-production-db-password
DATABASE_NAME=your-production-db-name
JWT_SECRET=your-production-jwt-secret
FRONTEND_URL=https://your-frontend-domain.com
BACKEND_URL=https://your-backend-domain.com
GOOGLE_CALLBACK_URL=https://your-backend-domain.com/auth/google/callback
-
Build the application
pnpm run build
-
Start the production server
pnpm run start:prod
The API endpoints are organized as follows:
- Authentication:
/auth/*
- Login, register, password reset - Users:
/users/*
- User management - Tournaments:
/tournaments/*
- Tournament management - Email:
/email/*
- Email-related endpoints
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
-
Database Connection Error
- Ensure PostgreSQL is running
- Check your database credentials in
.env
- Verify the database exists
-
Migration Errors
- Make sure all previous migrations are applied
- Check for syntax errors in your entity files
- Verify the database schema matches your entities
-
Port Already in Use
- Change the
PORT
in your.env
file - Or kill the process using the current port
- Change the
-
Google OAuth Issues
- Verify your Google OAuth credentials
- Check that the redirect URI matches exactly
- Ensure the Google+ API is enabled
If you encounter any issues:
- Check the existing documentation in the
docs/
folder - Review the error logs
- Ensure all prerequisites are installed
- Verify your environment variables are correctly set
The project uses Husky and lint-staged to ensure code quality:
- ESLint - Code linting and error detection
- Prettier - Code formatting
- TypeScript - Type checking
- Automatic formatting - Code is automatically formatted on commit
npm run lint
- Run ESLint with auto-fixnpm run format
- Format code with Prettiernpm run build
- Type checking and build