A production-ready Node.js Express REST API for managing acquisitions, featuring authentication, rate limiting, security middleware, and containerized deployment.
- Authentication & Authorization - JWT-based authentication with secure cookie handling
- Rate Limiting & Bot Protection - Powered by Arcjet for intelligent threat detection
- Database - PostgreSQL with Drizzle ORM and Neon serverless support
- Security - Helmet, CORS, and comprehensive security middleware
- Containerization - Docker support with development and production configurations
- CI/CD - GitHub Actions workflows for linting, testing, and Docker builds
- Code Quality - ESLint, Prettier, and automated testing with Jest
- Node.js 20.x or higher
- Docker & Docker Compose
- PostgreSQL database (or Neon account for serverless)
- Arcjet account for security features
-
Clone the repository
git clone https://github.com/ahmed6394/acquisitions.git cd acquisitions -
Install dependencies
npm install
-
Set up environment variables
cp .env.example .env.development
-
Configure your
.env.development# Server PORT=3000 NODE_ENV=development # Database (Neon) DATABASE_URL=postgresql://user:password@host:5432/database # JWT JWT_SECRET=your-super-secret-key JWT_EXPIRES_IN=7d # Arcjet ARCJET_KEY=your-arcjet-key ARCJET_ENV=development
-
Run database migrations
npm run db:migrate
-
Start the development server
npm run dev
-
Start with Docker Compose
npm run dev:docker # or ./scripts/dev.shThis will:
- Build the application container
- Start Neon Local proxy for database
- Run migrations automatically
- Enable hot reload
-
View logs
docker compose -f docker-compose.dev.yml logs -f
-
Stop containers
docker compose -f docker-compose.dev.yml down
# Run all tests
npm run test
# Run tests with coverage
npm run test -- --coverage| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Welcome message |
| GET | /health |
Health check with uptime |
| GET | /api |
API status |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register |
Register new user |
| POST | /api/auth/login |
User login |
| POST | /api/auth/logout |
User logout |
| POST | /api/auth/refresh |
Refresh access token |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/users |
Get all users (admin) |
| GET | /api/users/:id |
Get user by ID |
| PUT | /api/users/:id |
Update user |
| DELETE | /api/users/:id |
Delete user |
acquisitions/
βββ .github/
β βββ workflows/ # CI/CD workflows
βββ scripts/
β βββ dev.sh # Development startup script
β βββ prod.sh # Production startup script
βββ src/
β βββ config/
β β βββ arcjet.js # Arcjet security configuration
β β βββ database.js # Database connection
β β βββ logger.js # Winston logger setup
β βββ controllers/
β β βββ auth.controller.js
β β βββ user.controller.js
β βββ middleware/
β β βββ auth.middleware.js
β β βββ security.middleware.js
β βββ models/
β β βββ user.model.js # Drizzle schema
β βββ routes/
β β βββ auth.routes.js
β β βββ users.routes.js
β βββ services/
β β βββ auth.service.js
β β βββ users.service.js
β βββ utils/
β β βββ cookies.js
β β βββ format.js
β β βββ jwt.js
β βββ validations/
β β βββ auth.validation.js
β β βββ users.validation.js
β βββ app.js # Express app setup
β βββ index.js # Entry point
βββ tests/
β βββ app.test.js # API tests
βββ .env.example
βββ docker-compose.dev.yml
βββ docker-compose.yml
βββ Dockerfile
βββ Dockerfile.dev
βββ drizzle.config.js
βββ eslint.config.js
βββ jest.config.mjs
βββ package.json
| Script | Description |
|---|---|
npm run dev |
Start development server with hot reload |
npm run start |
Start production server |
npm run lint |
Run ESLint |
npm run lint:fix |
Fix ESLint errors |
npm run format |
Format code with Prettier |
npm run format:check |
Check formatting |
npm run db:generate |
Generate Drizzle migrations |
npm run db:migrate |
Run database migrations |
npm run db:studio |
Open Drizzle Studio |
npm run dev:docker |
Start Docker development environment |
npm run prod:docker |
Start Docker production environment |
npm run test |
Run Jest tests |
# Build and start
docker compose -f docker-compose.dev.yml up --build
# Stop
docker compose -f docker-compose.dev.yml down# Build and start
docker compose up --build -d
# View logs
docker compose logs -f
# Stop
docker compose downdocker pull <your-dockerhub-username>/acquisitions:latest
docker run -p 3000:3000 --env-file .env <your-dockerhub-username>/acquisitions:latest- Bot Detection - Identifies and blocks malicious bots
- Rate Limiting - Sliding window rate limiting per IP
- Shield - Protection against common attacks
- JWT tokens with secure HTTP-only cookies
- Password hashing with bcrypt
- Role-based access control (user/admin)
- Helmet for secure HTTP headers
- Configurable CORS policies
-
Lint and Format (
.github/workflows/lint-and-format.yml)- Runs ESLint and Prettier checks
- Triggered on push and pull requests
-
Tests (
.github/workflows/tests.yml)- Runs Jest test suite
- Generates coverage reports
- Triggered on push and pull requests
-
Docker Build (
.github/workflows/docker-build-and-push.yml)- Builds Docker image
- Pushes to Docker Hub
- Triggered on push to main
Configure these in GitHub repository settings:
| Secret | Description |
|---|---|
DOCKER_USERNAME |
Docker Hub username |
DOCKER_PASSWORD |
Docker Hub access token |
DATABASE_URL |
PostgreSQL connection string |
ARCJET_KEY |
Arcjet API key |
This project uses Drizzle ORM with PostgreSQL. Schema is defined in src/models/.
# Generate new migration
npm run db:generate
# Apply migrations
npm run db:migrate
# Open Drizzle Studio (GUI)
npm run db:studioFor local development with Neon:
- Create a Neon account at neon.tech
- Create a new project
- Copy the connection string to
.env.development
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the ISC License - see the LICENSE file for details.
Ahmed
- GitHub: @ahmed6394
β Star this repository if you found it helpful!