This outlines the architecture and the design of this sample Document Management application.
-
Bounded context:
- Document Management
- DocumentShare Management
- User Management
-
Ubiquitous language
- Document: A file that's uploaded to the disk.
- DocumentShare: A url that can be used to download a document.
- User: An authenticated user that can upload/delete and view documents created by them.
-
Domain Layer
Contains the core business logic.
-
Entities (Objects that have a unique identity)
- Document (id, name, path, user,documentShares, metadata, created_at, updated_at)
- Metadata (id, document, size, type, tags, created_at, updated_at)
- DocumentShare (id, documentShareDownload, url, expires_at,status, created_at, updated_at)
- DocumentShareDownload (id, documentShare, count, created_at, updated_at)
- User (id, first_name, last_name, email, password_hash,documents,created_at, updated_at)
-
Value Objects
- Token: Holds the JWT token.
-
Repositories
- DocumentRepository
- DocumentShareRepository
- UserRepository
- ElasticSearchDocumentRepository
-
Services
- DocumentService
- UserService
- AuthenticationService
-
-
Infrastructure Layer
Manages persistence, security and external 3rd party services.
- Authentication middleware
- Implementation of Authentication service
- Implementation of Domain repositories
- ElasticSearch Repository implemetation.
- Document storage logic
-
Application Layer
Coordinates use cases and passes data to relevant layers.
- Implementation of Domain services.
- Commands to modify state.
-
Presentation Layer
Contains the Controllers that manages incoming request, validation, and response formatting.
Follow these steps to install and run this application.
Make sure you have the following installed.
- PHP 8.2
- Composer
- MySQL 8
Clone the repository to your local machine.
gh repo clone NuSnips/doc-manager
cd doc-manager
Run Composer to install the required dependencies
composer install
Ceate a .env file to configure your environment variables for the database connection and other settings. Use the .env.axample file as a template.
cp .env.example .env
Edit the .env file with your database and other environment details.
APP_URL=<your-app-url> (eg: http://localhost:8080)
DB_HOST=localhost
DB_PORT=3306
DB_NAME=<your_database_name>
DB_USER=<your_mysql_username>
DB_PASSWORD=<your_mysql_password>
JWT_SECRET="=uYonSPsh0ZhSDpmYarEepLYQvb5QvMTdEFStCpiVe2E="
ELASTICSEARCH_HOST="https://14ce0edeb0144ed0a2c532f218330623.us-central1.gcp.cloud.es.io:443"
ELASTICSEARCH_API_KEY="ZXRXa1ZwSUJKZTJpU0JYckZpZjE6TUhySEN5RE9SaEtaTXBGcEQxVmlMZw"
Make sure your MySQL server is running, then create the database.
mysql -u root -p
CREATE DATABASE <your_database_name>;
exit;
Run the database migrations from inside the project folder.
php vendor/bin/doctrine orm:schema-tool:create
php -S localhost:8080 -t public
Run tests
php vendor/bin/pest
Use an application such as Postman to access the API endpoints.
-
Register a user
- Endpoint
POST /register - Description: Registers a user
- Request body:
{ "first_name":"Jane", "last_name":"Smith", "email":"jane@email.com", "password":"password", }
- Endpoint
-
Login
-
Endpoint
POST /login -
Description: Login a user
-
Request body:
{ "email":"jane@email.com", "password":"password", } -
Response:
{ "token": "eyJhbGciOiJIUzI1NiIsInR..." }Use this generated token to authenticate other API requests by adding it as a Bearer token.
-
-
Create a document
-
Endpoint
POST /documents -
Description: Upload a document
-
Headers:
Authorization: Bearer <JWT_TOKEN> -
Request body:
- Form Data:
document: the file to uploadtags: array of tags
- Form Data:
-
-
List all documents created by authenticated user.
- Endpoint
GET /documents - Description: Retrieve all documents as an array.
- Headers:
Authorization: Bearer <JWT_TOKEN> - Response body:
{ 'documents':[] } - Endpoint
-
Search for documents created by authenticated user.
- Endpoint
GET /documents?q=[searchTerm] - Description: Retrieve all documents with name that matches the [searchTerm] as an array.
- Headers:
Authorization: Bearer <JWT_TOKEN> - Response body:
{ 'documents':[] } - Endpoint
-
List a single document created by authenticated user.
- Endpoint
GET /documents/[id] - Description: Retrieve a single document.
- Headers:
Authorization: Bearer <JWT_TOKEN> - Resonse body:
{ 'document': Object } - Endpoint
-
Deletes a document created by authenticated user.
- Endpoint
DELETE /documents/[id] - Description: Deletes document. - Headers:
Authorization: Bearer <JWT_TOKEN> - Response body:
{ "success": true, "message": "Document deleted successfully." } - Endpoint
-
Deletes a document created by authenticated user.
- Endpoint
GET /documents/generate-url/[id] - Description: Generate a shareable url
- Headers:
Authorization: Bearer <JWT_TOKEN> - Response body:
{ "success": true, "message": "Document shareable link generated successfully.", "link": "http://localhost/documents/download/af0c9ef6dce8fd34f17b538b62439865" }Open the link in a browser to download.
- Endpoint