A robust TypeScript REST API with authentication, CRUD capabilities, and MySQL integration for the SummitLogic platform.
- User Authentication: Register and Login with bcrypt hashing
- JWT Tokens: Secure token-based authentication
- Health Check: Monitor API and database status
- CRUD Operations: Foundation for data management
- Type Safety: Full TypeScript implementation
- Security: Helmet.js, CORS, input validation
- Database: MySQL with connection pooling
- Beautiful Dashboard: Web interface to view endpoints and test API
- Node.js 18.0.0 or higher
- npm or yarn
- MySQL 5.7 or higher
- TypeScript 5.0 or higher
- Clone the repository or navigate to the project directory
- Install dependencies:
npm install- Configure environment variables:
cp .env.template .envThen edit .env with your database credentials and configuration.
- Create the database:
mysql -u root -p < database/schema.sqlCreate a .env file with the following variables:
PORT=3000
NODE_ENV=development
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_password
DB_NAME=summitlogic_db
DB_PORT=3306
JWT_SECRET=your_super_secret_jwt_key_here
JWT_EXPIRY=24h
API_BASE_URL=http://localhost:3000npm run devnpm run build
npm startnpm run lintThe API will start on http://localhost:3000
- GET
/api/health- Check API and database status
-
POST
/api/auth/register- Register a new user{ "email": "user@example.com", "password": "securePassword", "firstName": "John", "lastName": "Doe" } -
POST
/api/auth/login- Login user{ "email": "user@example.com", "password": "securePassword" }
SummitLogic_APIDB/
├── src/
│ ├── config/
│ │ ├── database.ts # Database connection pool
│ │ └── environment.ts # Environment configuration
│ ├── controllers/
│ │ ├── authController.ts # Authentication logic
│ │ └── healthController.ts # Health check logic
│ ├── middleware/
│ │ └── auth.ts # JWT authentication middleware
│ ├── routes/
│ │ ├── auth.ts # Auth routes
│ │ └── health.ts # Health routes
│ ├── types/
│ │ └── user.ts # User interfaces
│ └── index.ts # Main server file
├── database/
│ └── schema.sql # Database schema
├── public/
│ └── index.html # Dashboard UI
├── .env.template # Environment template
├── package.json
├── tsconfig.json
└── README.md
- Bcryptjs: Password hashing with 10 salt rounds
- JWT: Token-based authentication
- Helmet: HTTP headers security
- CORS: Cross-origin resource sharing protection
- Input Validation: Request data validation
- Middleware: Authentication middleware for protected routes
The database includes:
- users table: Stores user credentials and information
- projects table: Example table for CRUD operations (can be extended)
Run migrations:
mysql -u root -p < database/schema.sqlVisit http://localhost:3000 to access the dashboard with:
- Quick health check
- Register test
- Login test
- Real-time API responses
- Create a controller in
src/controllers/ - Define types in
src/types/ - Create routes in
src/routes/ - Import and use the routes in
src/index.ts
Example:
import { Router } from 'express';
import { authenticateToken } from '../middleware/auth';
const router = Router();
router.get('/data', authenticateToken, (req, res) => {
res.json({ message: 'Protected data' });
});
export default router;- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
MIT License - feel free to use this project
For issues or questions, please create an issue in the repository.
- User profile endpoints
- Password reset functionality
- Email verification
- Role-based access control
- Rate limiting
- API documentation (Swagger/OpenAPI)
- Unit tests
- Integration tests
- Docker support
- CI/CD pipeline
Built with ❤️ using TypeScript, Express.js, and MySQL