# Datalayer

## Data Layer

The Data Layer is the only component you, as the client, must implement. This layer stores and manages credential data securely within your infrastructure. The Client-Gateway communicates with the Data Layer over HTTP.

### Responsibilities

Your implementation should support the following operations:

1. **Create:** Add a new credential to the database.
2. **Import:** Import an existing credential from external systems.
3. **Revoke:** Mark a credential as revoked.
4. **Verify:** Validate the status of a credential.

### Example Implementation

You can implement the Data Layer using any database technology. Below is an example using MongoDB.

#### Setting Up MongoDB

1. Install MongoDB on your infrastructure or use a managed service.
2. Create a `credentials` collection.

#### Example Code

Here is an example of a simple Node.js service for the Data Layer:

```javascript
const express = require('express');
const mongoose = require('mongoose');

const app = express();
app.use(express.json());

const CredentialSchema = new mongoose.Schema({
  credential_id: String,
  name: String,
  type: String,
  status: String,
  expires_at: Date,
});

const Credential = mongoose.model('Credential', CredentialSchema);

app.post('/create', async (req, res) => {
  const credential = new Credential(req.body);
  await credential.save();
  res.status(201).json({ success: true });
});

app.listen(5000, () => console.log('Data Layer service running on port 5000'));
```

Client should setup the datalayer URL on dashboard in order to gateway forward requests to the Data Layer for processing.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wallid.io/certishop-on-prem/datalayer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
