A backend service that stores arbitrary data as posts and controls visibility based on user permissions. The permission system has three levels:
access = 0– Guest (default, can view public posts)access = 1– Moderator (can view posts with access ≤ 1)access = 2– Admin (can view all posts)
At the time of writing, only the backend is complete; the frontend is under development and will be documented later.
- Technology Stack
- Code Style & Documentation
- Project Structure
- Frontend Status
- Getting Started
- API Endpoints
- Node.js – JavaScript runtime
- Express.js – Web framework
- MongoDB – NoSQL database (with Mongoose ODM)
- JavaScript (ES6+) – Full‑stack language
The codebase follows a strict commenting convention to keep it self‑documenting and maintainable. Every file, data structure, and function is preceded by a descriptive comment block.
Each file must begin with a comment block that describes its purpose, lists all imports (grouped by external libraries and internal modules), and declares exports.
/*
* Brief description of the file
* IMPORTS:
* - imported libraries
* - from internal directories
* - imported objects: purpose
* EXPORTS:
* - exported objects
*/Every file ends with a footer comment that clearly marks its end.
/*
* END OF 'filename' FILE
*/For data structures (e.g., Mongoose schemas) the following format is used:
/*
* Brief description of the structure
* Fields:
* - field name - purpose
*/Route handler functions (typically POST, GET, DELETE) are documented with detailed information about the route, request body, and response body.
/*
* Brief description of the function
* Route: API path
* Request body:
* - field: description
* - (if a nested structure is passed)
* - field: structure with following fields:
* - subfield: description
* Response body:
* - field - description
*/For utility functions, middleware, and other non‑route functions, a simpler comment style is used (still including a description and details of parameters/return values when needed).
The repository is organised as follows:
.
├── client/ # (In development) Frontend application
├── middleware/
│ ├── upload.js # Handles file uploads, enforces file size/type limits
│ └── validation.js # Validates incoming structures for posts and users
├── models/
│ ├── post.js # Mongoose schema for posts
│ └── user.js # Mongoose schema for users
├── routes/
│ ├── posts.js # Route handlers for post‑related endpoints
│ └── users.js # Route handlers for user‑related endpoints
├── package.json # Project metadata and dependencies
└── server.js # Entry point – starts Node server and connects to MongoDB
-
client/ – Frontend code (currently under development, will be added later).
-
middleware/upload.js – Manages file uploads, validates file types and sizes.
-
middleware/validation.js – Validates request bodies for posts and users against defined schemas.
-
models/ – Defines the database structures (Mongoose schemas) for Post and User.
-
routes/ – Contains all route handlers for processing requests related to posts and users.
-
server.js – Bootstraps the Express server and establishes the MongoDB connection.
The frontend part of the application is currently under development. Once ready, this section will be updated with instructions for setting up and running the client.
- Node.js (v14 or later)
- MongoDB (v7.0.37 or later)
- Clone the repository:
git clone https://github.com/DK6asDK6/library_test.git
cd library_test- Install dependencies:
npm installStart server in production mode:
npm startThe main endpoints are:
- POST /api/users - Register new user
- GET /api/users - Get list of all users (request allowed only for admins)
- POST /api/users/login - Log user in
- POST /api/users/access - Set user's access level (request allowed only for admins)
- POST /api/users/reset - Reset user's password (old password required)
- POST /api/users/reset_admin - Reset other user's password (request allowed only for admins)
- POST /api/posts/:uid - Create new post (access 1 or more required)
- GET /api/posts/:uid - Show all posts (if user is not admin, only approved ones are shown)
- GET /api/posts/one/:id - Show one post
- POST /api/posts/appr/:uid - Approve or Revoke post (request allowed only for admins)
- DELETE /api/posts/:uid/:id - Remove one post (request allowed only for admins)