A robust RESTful API built with Node.js and TypeScript for managing sales proposals, products, and client relationships
- Overview
- Features
- Technology Stack
- Architecture
- Prerequisites
- Installation
- Configuration
- Usage
- API Documentation
- Database Schema
- Testing
- Project Structure
- Contributing
- License
Alpha Tower Sales System is a comprehensive API solution designed to streamline sales operations through efficient management of products and user accounts. Built with modern technologies and following clean architecture principles, it provides a scalable foundation for sales-oriented applications.
- User Management: Complete CRUD operations with authentication and authorization
- Product Catalog: Comprehensive product management with inventory tracking
- Authentication: JWT-based security with token management
- File Upload: Avatar and file management with AWS S3 integration ready
- Data Validation: Robust input validation using Joi/Celebrate
- Database Management: TypeORM with PostgreSQL and migration support
- JWT token-based authentication
- Secure password hashing with bcryptjs
- Protected routes with middleware authentication
- User session management
- User registration and profile management
- Avatar upload and management
- User authentication and authorization
- Complete CRUD operations
- Product catalog with full CRUD operations
- Inventory tracking with quantity management
- Product categorization and description
- Price management with decimal precision
- Input validation with Celebrate/Joi
- CORS support for cross-origin requests
- Error handling with custom AppError class
- SQL injection protection through TypeORM
- File upload with Multer
- Avatar management system
- Static file serving
- AWS SDK integration ready
- Node.js - JavaScript runtime environment
- TypeScript - Type-safe JavaScript superset
- Express.js - Web application framework
- TypeORM - Object-Relational Mapping library
- PostgreSQL - Relational database system
- Authentication: JWT, bcryptjs
- Validation: Celebrate, Joi
- File Upload: Multer, AWS SDK
- Development: ts-node-dev, ESLint, Prettier
- Testing: Jest, Supertest
The application follows a modular architecture with clear separation of concerns:
βββ src/
β βββ modules/ # Business logic modules
β β βββ users/ # User management
β β βββ products/ # Product management
β βββ shared/ # Shared utilities and infrastructure
β β βββ http/ # Express server configuration
β β βββ middlewares/ # Custom middleware
β β βββ errors/ # Error handling
β βββ config/ # Application configuration
β βββ database/ # Database setup and migrations
β βββ routes/ # Route definitions
- Repository Pattern: Data access abstraction
- Service Layer: Business logic encapsulation
- Dependency Injection: Loose coupling between components
- Error Handling: Centralized error management
Before running this project, ensure you have the following installed:
- Node.js (v14.0.0 or higher)
- npm or yarn package manager
- PostgreSQL (v12.0 or higher)
- Git for version control
git clone https://github.com/fernandobritto/Alpha-Tower.git
cd Alpha-Tower# Using yarn (recommended)
yarn install
# Or using npm
npm installCreate a PostgreSQL database for the application:
CREATE DATABASE alpha_tower;Create a .env file in the root directory with the following variables:
# Server Configuration
SERVER_PORT=8080
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=your_username
DB_PASSWORD=your_password
DB_DATABASE=alpha_tower
# JWT Configuration
JWT_SECRET=your_jwt_secret_key
JWT_EXPIRES_IN=1d
# Upload Configuration
UPLOAD_PATH=./uploads# Run all pending migrations
yarn database:run
# Or using npm
npm run database:run# Development mode with hot reload
yarn localhost
# Or using npm
npm run localhostThe server will start on http://localhost:8080 π
The application uses TypeORM for database management. Create an ormconfig.json file:
{
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "your_username",
"password": "your_password",
"database": "alpha_tower",
"entities": ["src/modules/**/database/entities/*.ts"],
"migrations": ["src/database/migrations/*.ts"],
"cli": {
"migrationsDir": "src/database/migrations"
}
}Configure file upload settings in src/config/upload.ts:
export default {
directory: uploadFolder,
storage: multer.diskStorage({
destination: uploadFolder,
filename: (request, file, callback) => {
const fileHash = crypto.randomBytes(10).toString('hex')
const filename = `${fileHash}-${file.originalname}`
callback(null, filename)
},
}),
}# Development mode
yarn localhost
# Production mode
yarn start# Run migrations
yarn database:run
# Revert last migration
yarn database:revert
# Sync database schema
yarn database:sync# Run linting
yarn lint
# Fix linting issues
yarn lint-fix
# Run tests
yarn test
# Run tests with coverage
yarn test:coverageThe API provides the following endpoints:
POST /sessions- User login and token generation
GET /users- List all users (authenticated)GET /users/:id- Get user by ID (authenticated)POST /users- Create new userPUT /users/:id- Update user (authenticated)DELETE /users/:id- Delete user (authenticated)PATCH /users/avatar- Upload user avatar (authenticated)
GET /products- List all products (authenticated)GET /products/:id- Get product by ID (authenticated)POST /products- Create new product (authenticated)PUT /products/:id- Update product (authenticated)DELETE /products/:id- Delete product (authenticated)
For detailed API documentation, see docs/API.md.
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name VARCHAR NOT NULL,
email VARCHAR UNIQUE NOT NULL,
password VARCHAR NOT NULL,
avatar VARCHAR,
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW()
);CREATE TABLE products (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name VARCHAR NOT NULL,
description VARCHAR,
price DECIMAL(10,2) NOT NULL,
quantity INTEGER NOT NULL,
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW()
);For complete database documentation, see docs/DATABASE.md.
The project is configured with Jest for testing:
# Run all tests
yarn test
# Run tests in watch mode
yarn test:silent
# Generate coverage report
yarn test:coverageAlpha-Tower/
βββ src/
β βββ @types/ # Type definitions
β βββ config/ # Configuration files
β β βββ auth.ts # JWT configuration
β β βββ upload.ts # File upload configuration
β βββ database/ # Database setup
β β βββ index.ts # Database connection
β β βββ migrations/ # Database migrations
β βββ modules/ # Business modules
β β βββ products/ # Product management
β β β βββ controllers/ # Request handlers
β β β βββ database/ # Entities and repositories
β β β βββ routes/ # Route definitions
β β β βββ services/ # Business logic
β β βββ users/ # User management
β β βββ controllers/ # Request handlers
β β βββ database/ # Entities and repositories
β β βββ routes/ # Route definitions
β β βββ services/ # Business logic
β βββ routes/ # Main route configuration
β βββ shared/ # Shared utilities
β βββ errors/ # Error handling
β βββ http/ # Server configuration
β βββ middlewares/ # Custom middleware
βββ docs/ # Documentation
βββ resource/ # Static resources
βββ package.json # Dependencies and scripts
βββ tsconfig.json # TypeScript configuration
βββ jest.config.js # Testing configuration
βββ README.md # Project documentation
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Follow TypeScript best practices
- Use meaningful commit messages
- Add tests for new features
- Update documentation as needed
- Run linting before committing
This project is licensed under the ISC License - see the LICENSE file for details.
Fernando Britto
- LinkedIn: Fernando Britto
- GitHub: @fernandobritto
- Node.js community for excellent tooling
- TypeORM team for the robust ORM solution
- Express.js for the minimal and flexible framework
- All contributors who help improve this project
β If you found this project helpful, please give it a star! β