A lightweight API designed to issue and track "thank-you" credits for various ecosystem interactions. This project is built with Node.js, Express, and TypeScript, following a robust, company-level directory structure for scalability and maintainability.
- Credit Issuance: API endpoint to issue credits for defined action types.
- Action Type Management: Enumerates valid ecosystem interactions (e.g.,
techModule,socialPost,referral). - Structured Logging: Centralized logging using Winston for better observability.
- Environment Configuration: Secure handling of environment variables.
- Rate Limiting: Basic protection against abuse.
- Security Headers: Uses Helmet for basic security enhancements.
- Docker Support: Containerized setup for consistent environments.
- Unit & E2E Testing: Configured with Vitest for reliable testing.
- Code Quality: ESLint for maintaining code style and quality.
- Runtime: Bun / Node
- Framework: Express.js
- Language: TypeScript
- Database (Placeholder): MongoDB (via Mongoose)
- Caching (Placeholder): Redis (via ioredis)
- Testing: Vitest, playwright
- Linting: ESLint, Prettier
- Containerization: Docker, Docker Compose
- Environment Variables:
dotenv, Joi - Logging: Winston
- Security:
express-rate-limit - Authentication (Placeholder): JWT, bcrypt
- Bun (or Node.js v18+)
- Docker & Docker Compose (optional)
-
Clone the repository:
git clone https://github.com/ShivShankarKushwaha/credit-engine cd credit-engine -
Install dependencies:
bun install
-
Set up environment variables: Create a
.envfile in the root directory based on.env.example:PORT=3000 NODE_ENV=development MONGO_URI=mongodb://localhost:27017/credit_engine_db REDIS_URL=redis://localhost:6379 JWT_SECRET=your_secret_key_here_for_development -
Start MongoDB and Redis (using Docker Compose for simplicity):
docker-compose up mongodb redis
Alternatively, ensure you have local instances of MongoDB and Redis running and update your
MONGO_URIandREDIS_URLin.envaccordingly. -
Run the development server:
bun run dev
-
** Commit and git push rules **
# To push code, ensure your branch name matches the required format (`type/name`), where `type` is one of: `ci`, `chore`, `docs`, `ticket`, `feat`, `fix`, `pref`, `refactor`, `revert`, or `style`. Protected branches (`master`, `integration`, `develop`) cannot be pushed to directly. # **Valid push workflow:** # Example: create a feature branch git checkout -b feat/my-new-feature # Add and commit your changes git add . git commit -m "feat: add my new feature" # Push to remote (will be validated by pre-push hook) git push origin feat/my-new-feature #Pushes that do not follow this convention will be rejected.
The API will be available at
http://localhost:3000.
- Build and run containers:
This will build the Docker image for the app and start all services (app, mongodb, redis).
docker-compose up --build
-
GET /api/credit: Check the credit score of yourself/anyone* -
POST /api/credit: Issues thank-you credits.Request Body Example:
{ "userId": "user123", "actionType": "socialPost", "amount": 10, "metadata": { "platform": "Twitter", "postUrl": "https://x.com/post/abc" } }
For live url testing see the test.rest file
- Run all tests:
bun test - Run unit tests:
bun run test:unit
- Run end-to-end tests:
bun run test:e2e
- Get coverage of the tests:
bun run coverage
- Run linter:
bun run lint
- Fix linting and formetting errors:
bun run format
-
Public/Private Credit Systems: Allow users to choose whether their credit profile is public (visible to others) or private (only visible to themselves and admins). API endpoints and database schema will be updated to support this privacy setting.
-
Sharable Credit Profiles: Enable users to generate a secure, shareable link to their credit profile. This link can be shared with others, respecting the user's privacy settings.
-
Admin Controls: Admins will have the ability to override privacy settings for moderation or compliance purposes.
-
Audit Logs: Track changes to privacy settings and sharing actions for transparency and security.
This project includes Dockerfile for containerization and vercel.json for serverless deployment using Vercel.
Note: This Readme.md is a comprehensive starting point. You will need to fill in specific details and further elaborate as you implement more features.
This credit-engine software is created upon Ts-Server starting template by Shiv Shankar Kushwaha.
