A robust RESTful API backend built with TypeScript, Express, Sequelize, and PostgreSQL. This project implements user authentication, session management, and follows clean architecture principles with proper separation of concerns.
- TypeScript: Fully typed codebase for better developer experience and code quality
- Express.js: Fast, unopinionated web framework for Node.js
- PostgreSQL: Powerful, open-source relational database
- Sequelize ORM: Promise-based Node.js ORM for PostgreSQL
- JWT Authentication: Secure token-based authentication
- Password Hashing: Bcrypt for secure password storage
- API Documentation: Interactive Swagger/OpenAPI documentation
- Error Handling: Centralized error handling middleware
- Logging: Winston logger for application logging
- ESLint & Prettier: Code quality and formatting tools
- Environment Variables: Secure configuration management with dotenv
Before running this project, make sure you have the following installed:
- Node.js (v18 or higher)
- npm or yarn
- PostgreSQL (v12 or higher)
-
Clone the repository
git clone <repository-url> cd backend
-
Install dependencies
npm install
-
Set up environment variables
Copy the
.env.examplefile to.env:cp .env.example .env
Update the
.envfile with your configuration:PORT=5000 SECRET_KEY=your-jwt-secret-key EXPIRE_TIME=24h DB_HOST=localhost DB_PORT=5432 DB_USER=your-database-username DB_PASSWORD=your-database-password DB_NAME=your-database-name
-
Create PostgreSQL database
createdb your-database-name
Or use your preferred PostgreSQL client to create the database.
npm run devThe server will start on http://localhost:5000 (or your configured PORT) with hot-reloading enabled.
npm run build
npm startOnce the server is running, access the interactive API documentation at:
http://localhost:5000/api-docs
backend/
├── src/
│ ├── config/ # Configuration files (database, logger)
│ ├── constants/ # Application constants and messages
│ ├── controllers/ # Request handlers
│ ├── docs/ # API documentation (Swagger/OpenAPI)
│ ├── interfaces/ # TypeScript interfaces
│ ├── middlewares/ # Express middlewares (auth, error handling)
│ ├── models/ # Sequelize models
│ ├── repository/ # Data access layer
│ ├── routes/ # API routes
│ ├── services/ # Business logic layer
│ ├── utils/ # Utility functions and helpers
│ ├── app.ts # Express app configuration
│ └── server.ts # Application entry point
├── .env.example # Environment variables template
├── .gitignore # Git ignore rules
├── eslint.config.ts # ESLint configuration
├── package.json # Project dependencies and scripts
├── tsconfig.json # TypeScript configuration
└── README.md # Project documentation
| Script | Description |
|---|---|
npm run dev |
Start development server with hot-reloading |
npm start |
Start production server |
npm run build |
Compile TypeScript to JavaScript |
npm run lint |
Run ESLint to check code quality |
npm run lint:fix |
Run ESLint and automatically fix issues |
- User registration
- User profile management
- User CRUD operations
- User login
- User logout
- Session management
- Token refresh
For detailed endpoint documentation, please refer to the Swagger documentation at /api-docs.
This project follows a layered architecture pattern:
- Routes Layer: Defines API endpoints and maps them to controllers
- Controllers Layer: Handles HTTP requests and responses
- Services Layer: Contains business logic
- Repository Layer: Handles data access and database operations
- Models Layer: Defines database schemas using Sequelize
- Middlewares: Cross-cutting concerns (authentication, error handling)
- Utils: Reusable utility functions
- Password Hashing: Passwords are hashed using bcrypt before storage
- JWT Authentication: Secure token-based authentication
- Environment Variables: Sensitive data stored in environment variables
- Input Validation: Request validation to prevent malicious input
- Error Handling: Secure error messages that don't expose sensitive information
Note: Testing setup is not yet implemented. Consider adding:
- Unit tests with Jest
- Integration tests
- E2E tests
This project uses:
- ESLint: For code linting and maintaining code standards
- Prettier: For consistent code formatting
- TypeScript: For type safety and better developer experience
Run linting:
npm run lintAuto-fix linting issues:
npm run lint:fix- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the ISC License.
Milan
- Express.js team for the excellent web framework
- Sequelize team for the powerful ORM
- TypeScript team for making JavaScript development better
Happy Coding! 🚀