Skip to main content

Your First Project

This guide will walk you through creating your first Solverhood project from scratch. By the end of this tutorial, you'll have a working application that demonstrates core features.

Prerequisites

Before starting, ensure you have:

  • Node.js (v18 or higher)
  • Git installed
  • A code editor (VS Code recommended)
  • Basic knowledge of JavaScript/TypeScript

Project Setup

1. Create a New Project

# Create a new directory
mkdir my-solverhood-project
cd my-solverhood-project

# Initialize a new Node.js project
npm init -y

# Install Solverhood SDK
npm install @solverhood/sdk

2. Project Structure

Create the following directory structure:

my-solverhood-project/
├── src/
│ ├── components/
│ ├── services/
│ ├── utils/
│ └── index.js
├── tests/
├── package.json
├── .env
└── README.md

3. Environment Configuration

Create a .env file with your configuration:

# Solverhood API Configuration
SOLVERHOOD_API_KEY=your_api_key_here
SOLVERHOOD_ENVIRONMENT=development

# Database Configuration
DATABASE_URL=postgresql://user:password@localhost:5432/mydb

# Application Configuration
PORT=3000
NODE_ENV=development

Building Your First Feature

1. Basic API Integration

Create src/services/solverhood.js:

const { SolverhoodClient } = require('@solverhood/sdk');

class SolverhoodService {
constructor() {
this.client = new SolverhoodClient({
apiKey: process.env.SOLVERHOOD_API_KEY,
environment: process.env.SOLVERHOOD_ENVIRONMENT,
});
}

async createProject(projectData) {
try {
const project = await this.client.projects.create({
name: projectData.name,
description: projectData.description,
settings: projectData.settings,
});

return project;
} catch (error) {
console.error('Error creating project:', error);
throw error;
}
}

async getProject(projectId) {
try {
const project = await this.client.projects.get(projectId);
return project;
} catch (error) {
console.error('Error fetching project:', error);
throw error;
}
}

async listProjects() {
try {
const projects = await this.client.projects.list();
return projects;
} catch (error) {
console.error('Error listing projects:', error);
throw error;
}
}
}

module.exports = SolverhoodService;

2. Create a Simple API Server

Create src/index.js:

const express = require('express');
const SolverhoodService = require('./services/solverhood');

const app = express();
const solverhoodService = new SolverhoodService();

// Middleware
app.use(express.json());

// Routes
app.get('/health', (req, res) => {
res.json({ status: 'healthy', timestamp: new Date().toISOString() });
});

app.post('/projects', async (req, res) => {
try {
const project = await solverhoodService.createProject(req.body);
res.status(201).json(project);
} catch (error) {
res.status(500).json({ error: error.message });
}
});

app.get('/projects', async (req, res) => {
try {
const projects = await solverhoodService.listProjects();
res.json(projects);
} catch (error) {
res.status(500).json({ error: error.message });
}
});

app.get('/projects/:id', async (req, res) => {
try {
const project = await solverhoodService.getProject(req.params.id);
res.json(project);
} catch (error) {
res.status(500).json({ error: error.message });
}
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});

3. Add Dependencies

Update your package.json:

{
"name": "my-solverhood-project",
"version": "1.0.0",
"description": "My first Solverhood project",
"main": "src/index.js",
"scripts": {
"start": "node src/index.js",
"dev": "nodemon src/index.js",
"test": "jest"
},
"dependencies": {
"@solverhood/sdk": "^1.0.0",
"express": "^4.18.0",
"dotenv": "^16.0.0"
},
"devDependencies": {
"nodemon": "^2.0.0",
"jest": "^29.0.0"
}
}

Testing Your Application

1. Start the Server

# Install dependencies
npm install

# Start the development server
npm run dev

2. Test the API

Use curl or a tool like Postman to test your endpoints:

# Health check
curl http://localhost:3000/health

# Create a project
curl -X POST http://localhost:3000/projects \
-H "Content-Type: application/json" \
-d '{
"name": "My First Project",
"description": "A test project",
"settings": {
"autoSave": true,
"notifications": true
}
}'

# List projects
curl http://localhost:3000/projects

Adding More Features

1. Error Handling

Create src/utils/errorHandler.js:

class AppError extends Error {
constructor(message, statusCode) {
super(message);
this.statusCode = statusCode;
this.status = `${statusCode}`.startsWith('4') ? 'fail' : 'error';
this.isOperational = true;

Error.captureStackTrace(this, this.constructor);
}
}

const errorHandler = (err, req, res, next) => {
err.statusCode = err.statusCode || 500;
err.status = err.status || 'error';

if (process.env.NODE_ENV === 'development') {
res.status(err.statusCode).json({
status: err.status,
error: err,
message: err.message,
stack: err.stack,
});
} else {
res.status(err.statusCode).json({
status: err.status,
message: err.message,
});
}
};

module.exports = { AppError, errorHandler };

2. Validation

Create src/utils/validation.js:

const { AppError } = require('./errorHandler');

const validateProject = (projectData) => {
const { name, description } = projectData;

if (!name || name.trim().length === 0) {
throw new AppError('Project name is required', 400);
}

if (name.length > 100) {
throw new AppError('Project name must be less than 100 characters', 400);
}

if (description && description.length > 500) {
throw new AppError('Project description must be less than 500 characters', 400);
}

return true;
};

module.exports = { validateProject };

Next Steps

Congratulations! You've successfully created your first Solverhood project. Here are some suggestions for what to build next:

1. Add Authentication

  • Implement JWT-based authentication
  • Add user registration and login
  • Secure your API endpoints

2. Database Integration

  • Set up PostgreSQL with Prisma or Sequelize
  • Create data models for your projects
  • Implement data persistence

3. Frontend Development

  • Create a React or Vue.js frontend
  • Build a user interface for managing projects
  • Add real-time updates with WebSockets

4. Advanced Features

  • Implement file uploads
  • Add search and filtering
  • Create reporting and analytics
  • Set up automated testing

5. Deployment

  • Deploy to a cloud platform
  • Set up CI/CD pipelines
  • Configure monitoring and logging

Resources

Getting Help

If you run into issues:

  1. Check the troubleshooting guide
  2. Review the API documentation
  3. Join our community discussions
  4. Contact support at support@solverhood.com