Skip to content

Commit d55700a

Browse files
authored
demo(dashboard): add dashboard demo (#50)
Co-authored-by: Datata1 <>
1 parent 450945a commit d55700a

19 files changed

+1925
-0
lines changed

examples/dashboard/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CS_TOKEN=your-api-token-here

examples/dashboard/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.venv/
2+
.env
3+
__pycache__/

examples/dashboard/README.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Codesphere Dashboard Example
2+
3+
A comprehensive web dashboard demonstrating all features of the Codesphere SDK using FastAPI + HTMX.
4+
5+
## Features
6+
7+
This dashboard showcases the following SDK capabilities:
8+
9+
| Feature | SDK Methods Used |
10+
|---------|------------------|
11+
| **Teams** | `sdk.teams.list()`, `sdk.teams.get()` |
12+
| **Workspaces** | `sdk.workspaces.list()`, `sdk.workspaces.create()`, `workspace.update()`, `workspace.delete()`, `workspace.get_status()` |
13+
| **Environment Variables** | `workspace.env_vars.list()`, `workspace.env_vars.set()`, `workspace.env_vars.delete()` |
14+
| **Command Execution** | `workspace.execute_command()` |
15+
| **Pipeline/Landscape** | `workspace.landscape.save_profile()`, `workspace.landscape.deploy()`, `workspace.landscape.start_stage()`, `workspace.landscape.get_status()` |
16+
| **Logs** | `workspace.logs.collect()` |
17+
| **Git** | `workspace.git.get_head()`, `workspace.git.pull()` |
18+
| **Domains** | `team.domains.list()` |
19+
| **Usage** | `team.usage.get_landscape_summary()` |
20+
| **Metadata** | `sdk.metadata.list_datacenters()`, `sdk.metadata.list_plans()`, `sdk.metadata.list_images()` |
21+
22+
## Tech Stack
23+
24+
- **FastAPI** - Async Python web framework
25+
- **HTMX** - Dynamic HTML updates without JavaScript (via CDN)
26+
- **Tailwind CSS** - Utility-first CSS framework (via CDN)
27+
- **Jinja2** - Templating engine
28+
29+
## Quick Start
30+
31+
```bash
32+
# Navigate to the dashboard directory
33+
cd examples/dashboard
34+
35+
# Create a virtual environment
36+
uv venv .venv
37+
38+
# Install dependencies and the SDK
39+
uv pip install -r requirements.txt -e ../../
40+
41+
# Copy the example .env file and add your token
42+
cp .env.example .env
43+
# Edit .env and set your CS_TOKEN
44+
45+
# Run the dashboard
46+
source .venv/bin/activate
47+
uvicorn app:app --reload
48+
```
49+
50+
Then open your browser to: http://localhost:8000
51+
52+
## Configuration
53+
54+
1. Copy `.env.example` to `.env`:
55+
```bash
56+
cp .env.example .env
57+
```
58+
59+
2. Edit `.env` and add your Codesphere API token:
60+
```
61+
CS_TOKEN=your-api-token-here
62+
```
63+
64+
The dashboard automatically loads the `.env` file on startup.
65+
66+
## Project Structure
67+
68+
```
69+
dashboard/
70+
├── app.py # Main FastAPI application
71+
├── requirements.txt # Python dependencies
72+
├── .env.example # Example environment file
73+
├── .gitignore # Ignores .venv, .env, __pycache__
74+
├── README.md # This file
75+
├── static/
76+
│ └── style.css # Custom styles
77+
└── templates/
78+
├── base.html # Base layout template
79+
├── index.html # Dashboard home page
80+
├── team.html # Team detail page
81+
├── workspace.html # Workspace management page
82+
└── partials/ # HTMX partial templates
83+
├── command_output.html
84+
├── env_vars.html
85+
├── error.html
86+
├── git_info.html
87+
├── logs.html
88+
├── pipeline_status.html
89+
├── workspace_list.html
90+
└── workspace_status.html
91+
```
92+
93+
## Pages
94+
95+
### Dashboard Home
96+
- View all teams with avatars and datacenter info
97+
- Infrastructure overview (datacenters, plans, images)
98+
- SDK feature summary
99+
100+
### Team Detail
101+
- Create new workspaces with form
102+
- List all workspaces with live status
103+
- View custom domains
104+
- Usage summary for the last 7 days
105+
106+
### Workspace Management
107+
- Real-time status indicator (auto-refreshes every 10s)
108+
- Git repository info with pull button
109+
- Environment variables management (add/delete)
110+
- Command executor with terminal-like output
111+
- Pipeline deployment and stage controls
112+
- Log viewer for pipeline stages
113+
- Workspace settings update form
114+
115+
## HTMX Features
116+
117+
This example demonstrates several HTMX patterns:
118+
119+
- **Polling**: Workspace status auto-updates every 10 seconds
120+
- **Form Submissions**: All forms submit via HTMX for seamless updates
121+
- **Partial Updates**: Only relevant sections refresh, not the whole page
122+
- **Delete Confirmations**: Using `hx-confirm` for destructive actions
123+
- **Loading States**: Visual feedback during requests
124+
125+
## License
126+
127+
MIT License - See the repository root for details.

0 commit comments

Comments
 (0)