Skip to content

Commit e6b114d

Browse files
authored
refactor: turbo repo and divide app and package (#10)
1 parent bbaf445 commit e6b114d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4578
-7454
lines changed

.gitignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# dependencies
2+
node_modules
3+
.pnp
4+
.pnp.js
5+
6+
# testing
7+
coverage
8+
9+
# production
10+
dist
11+
build
12+
13+
# misc
14+
.DS_Store
15+
*.pem
16+
17+
# debug
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*
21+
pnpm-debug.log*
22+
23+
# local env files
24+
.env
25+
.env.local
26+
.env.development.local
27+
.env.test.local
28+
.env.production.local
29+
30+
# turbo
31+
.turbo
32+
33+
*.tsbuildinfo

apps/web/package.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "@atoma-agents/web",
3+
"version": "1.0.0",
4+
"private": true,
5+
"main": "./dist/server.js",
6+
"scripts": {
7+
"build": "tsc",
8+
"start": "node dist/server.js",
9+
"dev": "nodemon ./src/server.ts",
10+
"lint": "eslint . --ext .ts",
11+
"lint:fix": "eslint . --ext .ts --fix"
12+
},
13+
"dependencies": {
14+
"@atoma-agents/sui-agent": "workspace:*",
15+
"cors": "^2.8.5",
16+
"dotenv": "^16.4.7",
17+
"express": "^4.21.2"
18+
},
19+
"devDependencies": {
20+
"@types/cors": "^2.8.17",
21+
"@types/express": "^5.0.0",
22+
"@types/node": "^20.11.19",
23+
"@typescript-eslint/eslint-plugin": "^5.0.0",
24+
"@typescript-eslint/parser": "^5.0.0",
25+
"eslint": "^8.57.0",
26+
"nodemon": "^3.1.9",
27+
"ts-node": "^10.9.2",
28+
"typescript": "^5.7.3"
29+
}
30+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ app.use(v1routes);
3232
* @type {Application}
3333
* @description Express application instance configured with middleware and routes
3434
*/
35-
export default app;
35+
export default app;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import * as dotenv from 'dotenv';
44
dotenv.config();
55

66
// Application configuration
7-
export default {
7+
export const config = {
88
port: process.env.PORT || 2512, // Default port if not specified in environment
9-
};
9+
};
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Router } from 'express';
2-
import rootRouter from './root';
32
import queryRouter from './query';
3+
import rootRouter from './root';
44

55
/**
66
* Router instance for v1 API endpoints
77
* This router serves as the main entry point for all v1 API routes
88
* and aggregates sub-routers for different functionality domains
99
*/
10-
const v1Router = Router();
10+
const v1Router: Router = Router();
1111

1212
/**
1313
* Mount sub-routers to the v1 API router
@@ -21,7 +21,7 @@ const v1Router = Router();
2121
* - GET /query/* - Various blockchain data queries
2222
* - POST /query/batch - Batch query operations
2323
*/
24-
v1Router.use(rootRouter); // Handles basic and health check routes
25-
v1Router.use(queryRouter); // Handles query operations
24+
v1Router.use('/', rootRouter); // Handles basic and health check routes
25+
v1Router.use('/query', queryRouter); // Handles query operations
2626

2727
export default v1Router;

apps/web/src/routes/v1/query.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Router } from 'express';
2+
import { Request, Response } from 'express';
3+
4+
const queryRouter: Router = Router();
5+
6+
// Health check endpoint
7+
queryRouter.get('/health', (req: Request, res: Response) => {
8+
res.json({ status: 'healthy' });
9+
});
10+
11+
// Query endpoint
12+
const handleQuery = async (req: Request, res: Response): Promise<void> => {
13+
try {
14+
const { query } = req.body;
15+
16+
if (!query) {
17+
res.status(400).json({
18+
error: 'Missing query in request body',
19+
});
20+
return;
21+
}
22+
23+
// TODO: Implement query handling with sui-agent
24+
res.json({ message: 'Query received', query });
25+
} catch (error) {
26+
console.error('Error handling query:', error);
27+
res.status(500).json({
28+
error: 'Internal server error',
29+
});
30+
}
31+
};
32+
33+
// Handle unsupported methods
34+
const handleUnsupportedMethod = (req: Request, res: Response): void => {
35+
res.status(405).json({
36+
error: 'Method not allowed',
37+
});
38+
};
39+
40+
queryRouter.post('/', handleQuery);
41+
queryRouter.all('/', handleUnsupportedMethod);
42+
43+
export default queryRouter;
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Router } from 'express';
22
import { Request, Response } from 'express';
33

4-
const rootRouter = Router();
4+
const rootRouter: Router = Router();
55

66
/**
77
* GET /
@@ -11,7 +11,10 @@ const rootRouter = Router();
1111
* @description This endpoint serves as a basic test to verify the API is running
1212
*/
1313
rootRouter.get('/', (req: Request, res: Response) => {
14-
res.send('Hello World');
14+
res.json({
15+
message: 'Atoma Agents API',
16+
version: '1.0.0',
17+
});
1518
});
1619

1720
/**

apps/web/src/server.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import http from 'http';
2+
import app from './app';
3+
import { config } from './config';
4+
5+
/**
6+
* Main application class that initializes and starts the server
7+
*/
8+
class Main {
9+
private port: string | number;
10+
11+
/**
12+
* Initialize the application with port
13+
* @param port - Port number for the server to listen on
14+
*/
15+
constructor(port: string | number) {
16+
this.port = port;
17+
}
18+
19+
/**
20+
* Start the HTTP server
21+
*/
22+
async start() {
23+
const server = http.createServer(app);
24+
25+
// Graceful shutdown handler
26+
const shutdown = () => {
27+
console.log('Shutting down gracefully...');
28+
server.close(() => {
29+
console.log('Server closed');
30+
process.exit(0);
31+
});
32+
};
33+
34+
// Handle shutdown signals
35+
process.on('SIGTERM', shutdown);
36+
process.on('SIGINT', shutdown);
37+
38+
server.listen(this.port, () => {
39+
console.log(`Server is listening on port ${this.port}`);
40+
});
41+
}
42+
}
43+
44+
// Create and start the application
45+
const main = new Main(config.port);
46+
main.start().catch((error) => {
47+
console.error('Failed to start server:', error);
48+
process.exit(1);
49+
});

apps/web/tsconfig.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"target": "es2020",
5+
"module": "commonjs",
6+
"lib": ["es2020"],
7+
"declaration": true,
8+
"outDir": "dist",
9+
"rootDir": "src",
10+
"strict": true,
11+
"esModuleInterop": true,
12+
"skipLibCheck": true,
13+
"forceConsistentCasingInFileNames": true
14+
},
15+
"include": ["src/**/*"],
16+
"exclude": ["node_modules", "dist"],
17+
"references": [{ "path": "../../packages/sui-agent" }]
18+
}

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "atoma-agents",
3+
"private": true,
4+
"scripts": {
5+
"build": "turbo run build",
6+
"dev": "turbo run dev",
7+
"lint": "turbo run lint",
8+
"format": "prettier --write \"**/*.{ts,tsx,md}\""
9+
},
10+
"devDependencies": {
11+
"@turbo/gen": "^1.11.3",
12+
"prettier": "^3.1.1",
13+
"turbo": "^1.11.3"
14+
},
15+
"packageManager": "pnpm@8.9.0",
16+
"engines": {
17+
"node": ">=18.0.0"
18+
}
19+
}

0 commit comments

Comments
 (0)