This project is a secure document storage and retrieval API built with Express.js and TypeScript, simulating a simplified encrypted storage system with authentication, audit logging, and encrypted data at rest.
- Backend: Node.js, Express.js, TypeScript
- Auth: JWT (JSON Web Tokens)
- Database: MongoDB (supports both local and Atlas)
- Encryption: AES-256-CBC with Node.js
crypto - Testing: Jest, Supertest
- Docs: Optional Swagger support
- Deployment: Docker-ready (optional)
- 🔐 JWT Authentication
- 📄 Encrypted Document Storage
- 📥 Document Retrieval with Decryption
- 📝 Metadata Filtering
- 🛡️ Role-Based Access to Audit Logs
- 📊 Audit Logging for all API activity
- ✅ Unit tests for core functionality
npm installCreate a .env file in the root directory:
PORT=3000
MONGODB_URI=mongodb://localhost:27017/secure_document_storage
JWT_SECRET=secret-key
SECRET_KEY=secret-keyTo use MongoDB Atlas, replace
MONGO_URIwith your Atlas URI.
npm run devnpm testPOST /api/auth/login
Request:
{
"username": "user1",
"password": "password123"
}Response:
{
"token": "JWT_TOKEN"
}POST /api/documents– Store a document (with JWT)GET /api/documents– List documents of userGET /api/documents/:id– Retrieve a single document
GET /api/logs
Requires admin role.
- Encryption: Used
cryptomodule (AES-256-CBC) - Auth: JWT-based for stateless validation
- Audit Logging: Captures every access, success/failure, and user info
- Database: Swappable between local MongoDB and MongoDB Atlas
docker build -t code-challenge .
docker run -p 3000:3000 code-challengesrc/
├── __tests__/
├── config/
├── controllers/
├── lib/
├── middlewares/
├── models/
├── routes/
├── services/
├── swagger/
├── app.ts
├── server.ts
└── swagger.ts