108 lines
3.7 KiB
Text
108 lines
3.7 KiB
Text
# Configurable Mock API with Admin Interface - Project Plan
|
|
|
|
## Architecture Decisions (from @architect)
|
|
|
|
### Technology Stack
|
|
- **Framework**: FastAPI (over Flask) for automatic API documentation, async support, type safety.
|
|
- **Server**: Waitress as production WSGI server.
|
|
- **Database**: SQLite with SQLAlchemy ORM, aiosqlite for async.
|
|
- **Template Engine**: Jinja2 with sandboxed environment.
|
|
- **Admin UI**: Custom Jinja2 templates with Bootstrap 5 CDN, session-based authentication.
|
|
|
|
### Database Schema
|
|
- **endpoints** table: id, route (VARCHAR), method (VARCHAR), response_body (TEXT), response_code (INTEGER), content_type (VARCHAR), is_active (BOOLEAN), variables (JSON), headers (JSON), delay_ms (INTEGER), created_at, updated_at.
|
|
- Unique constraint on (route, method).
|
|
|
|
### Application Architecture
|
|
- Repository-Service-Controller pattern with Observer pattern for dynamic route updates.
|
|
- Modules: database, models, repositories, services, controllers, observers, schemas, middleware, utils.
|
|
|
|
### Dynamic Route Registration
|
|
- RouteManager service registers/unregisters endpoints at runtime via FastAPI's `add_api_route`.
|
|
- Observer pattern triggers route refresh on CRUD operations.
|
|
|
|
### Template Variable Rendering
|
|
- Variable sources: path params, query params, request headers, request body, system variables, endpoint defaults.
|
|
- Jinja2 with StrictUndefined to prevent silent failures.
|
|
|
|
### Admin Interface
|
|
- Simple credential store (admin username/password hash from env vars).
|
|
- Session-based authentication with middleware protecting `/admin/*` routes.
|
|
- Pages: Login, Dashboard, Endpoint List, Endpoint Editor, Request Logs (optional).
|
|
|
|
## Project Structure
|
|
```
|
|
mock_api_app/ # Align with user request
|
|
├── app.py
|
|
├── config.py
|
|
├── database.py
|
|
├── dependencies.py
|
|
├── middleware/
|
|
├── models/
|
|
├── repositories/
|
|
├── services/
|
|
├── controllers/
|
|
├── observers/
|
|
├── schemas/
|
|
├── static/
|
|
├── templates/
|
|
├── utils/
|
|
├── requirements.txt
|
|
├── README.md
|
|
└── .env.example
|
|
```
|
|
|
|
## Roadmap
|
|
|
|
### Phase 1: Foundation
|
|
- [x] Create project directory and structure
|
|
- [x] Set up SQLAlchemy model `Endpoint`
|
|
- [x] Configure FastAPI app with Jinja2 templates
|
|
- [x] Write `requirements.txt`
|
|
|
|
### Phase 2: Core Services
|
|
- [x] Implement `EndpointRepository`
|
|
- [x] Implement `RouteManager` service
|
|
- [x] Implement `TemplateService` with variable resolution
|
|
|
|
### Phase 3: Admin Interface
|
|
- [x] Authentication middleware
|
|
- [x] Admin controller routes
|
|
- [x] HTML templates (Bootstrap 5 CDN)
|
|
|
|
### Phase 4: Integration
|
|
- [x] Connect route observer
|
|
- [x] Add request logging (optional)
|
|
- [x] Health check endpoints
|
|
|
|
### Phase 5: Production Ready
|
|
- [x] Waitress configuration
|
|
- [x] Environment variable configuration
|
|
- [x] Comprehensive README
|
|
|
|
## Dependencies
|
|
See `requirements.txt` in architect spec.
|
|
|
|
## Security Considerations
|
|
- Template sandboxing
|
|
- SQL injection prevention via ORM
|
|
- Admin authentication with bcrypt
|
|
- Route validation to prevent path traversal
|
|
|
|
## Status Log
|
|
- 2025-03-13: Architectural specification completed by @architect.
|
|
- 2025-03-13: Project plan created.
|
|
- 2026-03-14: Project cleanup and optimization completed. All phases implemented. Integration tests passing. Project ready for demonstration/testing.
|
|
|
|
## Current Status (2026-03-14)
|
|
- ✅ Phase 1: Foundation completed
|
|
- ✅ Phase 2: Core Services completed
|
|
- ✅ Security fixes applied (critical issues resolved)
|
|
- ✅ Phase 3: Admin Interface completed
|
|
- ✅ Phase 4: Integration completed
|
|
- ✅ Phase 5: Production Ready completed
|
|
|
|
## Next Steps
|
|
1. Deploy to production environment (if needed).
|
|
2. Add advanced features: request logging, analytics, multi-user support.
|
|
3. Expand test coverage for repository and service layers.
|