A production-ready RESTful API for managing content fragments with advanced format conversion capabilities
Features β’ Tech Stack β’ Getting Started β’ API Overview β’ Architecture
Fragments is a scalable, cloud-native microservice that enables users to store, manage, and convert various types of content fragments. Built with modern development practices, this API demonstrates proficiency in backend development, cloud services, and software engineering principles.
Key Highlights:
- π Secure authentication using AWS Cognito and JWT
- ποΈ Persistent storage with AWS DynamoDB and S3
- π Intelligent format conversion (text, markdown, images, JSON, YAML, CSV)
- π Production-grade logging with Pino
- π³ Containerized deployment with Docker
- β Comprehensive testing with Jest
- π‘οΈ Security best practices with Helmet and CORS
- Multi-format Support: Handle text, markdown, HTML, CSV, JSON, YAML, and images (PNG, JPEG, WebP, AVIF, GIF)
- CRUD Operations: Create, read, update, and delete fragments with ease
- Format Conversion: Automatically convert between compatible formats
- Markdown β HTML/Plain Text
- CSV β JSON
- JSON β YAML
- Images β Multiple formats using Sharp
- AWS DynamoDB: Fast, scalable NoSQL database for metadata
- AWS S3: Reliable object storage for fragment data
- AWS Cognito: Enterprise-grade authentication and authorization
- Hot Reload: Fast development with Nodemon
- Debug Mode: Built-in debugging support for VS Code and Chrome DevTools
- Comprehensive Logging: Structured logging with configurable levels
- Code Quality: ESLint and Prettier for consistent code style
- Testing Suite: Unit and integration tests with Jest and Hurl
- Node.js - JavaScript runtime
- Express.js 5.x - Fast, unopinionated web framework
- Passport.js - Authentication middleware
- AWS DynamoDB - NoSQL database for fragment metadata
- AWS S3 - Object storage for fragment data
- AWS Cognito - User authentication and JWT verification
- Sharp - High-performance image processing
- Markdown-it - Markdown parser and compiler
- Pino - Fast JSON logger
- Helmet - Security middleware
- CORS - Cross-origin resource sharing
- Compression - Response compression
- Docker - Containerization
- Docker Compose - Multi-container orchestration
- Jest - Testing framework
- Hurl - Integration testing
- ESLint - Code linting
- Prettier - Code formatting
- Nodemon - Development server with hot reload
Node.js >= 14.x
npm >= 6.x
Docker (optional, for containerized deployment)-
Clone the repository
git clone https://github.com/yasinhajilou/fragments.git cd fragments -
Install dependencies
npm install
-
Configure environment variables
cp debug.env.example debug.env # Edit debug.env with your AWS credentials and configuration -
Start the development server
npm run dev
The API will be available at http://localhost:8080
# Build and run with Docker Compose
docker-compose up --build
# Run in detached mode
docker-compose up -d| Method | Endpoint | Description |
|---|---|---|
POST |
/v1/fragments |
Create a new fragment |
GET |
/v1/fragments |
Get all fragments for authenticated user |
GET |
/v1/fragments/:id |
Get a specific fragment |
GET |
/v1/fragments/:id.:ext |
Get fragment with format conversion |
PUT |
/v1/fragments/:id |
Update an existing fragment |
DELETE |
/v1/fragments/:id |
Delete a fragment |
GET |
/v1/fragments/:id/info |
Get fragment metadata |
Text Formats:
text/plain- Plain texttext/markdown- Markdowntext/html- HTMLtext/csv- CSV
Data Formats:
application/json- JSONapplication/yaml- YAML
Image Formats:
image/png- PNGimage/jpeg- JPEGimage/webp- WebPimage/avif- AVIFimage/gif- GIF
# Convert markdown to HTML
GET /v1/fragments/{id}.html
# Convert CSV to JSON
GET /v1/fragments/{id}.json
# Convert PNG to JPEG
GET /v1/fragments/{id}.jpg
# Convert JSON to YAML
GET /v1/fragments/{id}.yamlfragments/
βββ src/
β βββ app.js # Express application setup
β βββ index.js # Application entry point
β βββ server.js # HTTP server configuration
β βββ auth/ # Authentication strategies
β βββ model/ # Database layer
β βββ models/ # Data models
β β βββ fragment.js # Fragment class with conversion logic
β βββ routes/ # API routes
β β βββ index.js # Route definitions
β β βββ api/ # API endpoints
β βββ logger/ # Logging configuration
β βββ response.js # Response utilities
β βββ hash.js # Hashing utilities
βββ tests/
β βββ unit/ # Unit tests
β βββ integration/ # Integration tests with Hurl
βββ scripts/ # Utility scripts
βββ .github/ # GitHub workflows (CI/CD)
βββ Dockerfile # Container configuration
βββ docker-compose.yml # Multi-container setup
βββ jest.config.js # Jest configuration
βββ eslint.config.mjs # ESLint rules
βββ package.json # Dependencies and scripts
- MVC Architecture: Separation of concerns with models, routes, and controllers
- Middleware Pattern: Modular request processing pipeline
- Factory Pattern: Fragment creation and management
- Repository Pattern: Database abstraction layer
npm testnpm run coveragenpm run test:integrationnpm run test:watch| Command | Description |
|---|---|
npm start |
Run in production mode |
npm run dev |
Run with hot reload (debug logging) |
npm run debug |
Run with Node.js inspector enabled |
npm test |
Run unit tests |
npm run test:watch |
Run tests in watch mode |
npm run test:integration |
Run integration tests |
npm run coverage |
Generate test coverage report |
npm run lint |
Check code quality with ESLint |
- Helmet.js: Security headers and protection against common vulnerabilities
- CORS: Configurable cross-origin resource sharing
- JWT Verification: Secure token-based authentication with AWS Cognito
- Input Validation: Type checking and sanitization
- Error Handling: Secure error responses without sensitive data leakage
- Compression: Gzip/Brotli response compression
- Efficient Logging: Fast JSON logging with Pino
- Async Operations: Non-blocking I/O for database and file operations
- Image Processing: Hardware-accelerated image conversion with Sharp
- Graceful Shutdown: Proper cleanup with Stoppable
This project demonstrates proficiency in:
β
Backend Development: RESTful API design, Express.js, Node.js
β
Cloud Computing: AWS services (DynamoDB, S3, Cognito)
β
DevOps: Docker, containerization, CI/CD practices
β
Testing: Unit testing, integration testing, TDD
β
Security: Authentication, authorization, secure coding
β
Software Engineering: Clean code, design patterns, documentation
β
Database Design: NoSQL data modeling, efficient queries
β
API Design: RESTful principles, versioning, error handling
Yasin Hajilou
Passionate about building scalable, cloud-native applications with modern technologies. This project showcases my ability to design and implement production-ready backend systems with best practices in mind.
UNLICENSED - Educational project for BTI Semester 5
Built with β€οΈ for learning and growth
β If you find this project interesting, please consider giving it a star!